Skip to content

feat(pm-stack): rung-4 watchdog escalation hand-off (#6033) - #8357

Merged
dezren39 merged 3 commits into
mainfrom
queue/14781-6033-rung4-escalation
Nov 14, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/14781-6033-rung4-escalation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Implements the rung-4 escalation hand-off for the quota watchdog (issue #6033, design #6031). The decision layer (#6032, pm-stack/exporters/src/watchdog-state.ts) already decides escalate once every rung is spent; this PR adds the effect layer that word stands for, behind injected effectors so the policy is fully testable without a queue, network, or browser — the same layering #6032 used.

What lands

  • src/watchdog-escalation.ts
    • buildEscalationPacket — the full context packet from impl(pm-stack): quota watchdog escalation — fleet queue task + deduplicated incident issue for a browser-enabled agent #6033: outcome wanted (source produces a fresh latest.json with real quota windows), failure context (class, consecutive failures, the persisted repairLog, producer history reference, state-file path, adapter reference), required capability (browser-enabled agent; laptop Helium via CDP :19222; adapter origins only), acceptance (fresh producer document lands; the watchdog auto-closes), and the stop conditions (human-only challenge → mark human-blocked; outside the origin allowlist → stop and report on the incident issue).
    • planEscalation — exactly one enqueue_task + one open_issue for an escalating incident; returns deduped: true and no actions when the incident already carries an escalation record for the same (source, class) pair.
    • recordEscalation — persists the confirmed queue task id / issue number onto the incident.
    • planRecovery — on producer success: comment the resolution, close the incident issue, complete the queue task (state-side, decide's healthy path clears the incident in the same tick).
    • surfacingLine — the NEEDS DREW line: immediate (same tick) when human-blocked with a one-line reason; for ordinary escalations only after 24 h unresolved (ESCALATION_NEEDS_DREW_AFTER_MS), quiet before that.
    • applyEscalationActions — runs planned actions through the injected effectors in order.
  • src/watchdog-state.ts — Incident gains an optional escalation record (EscalationRecord); coerceHealth validates it structurally and drops malformed records, so older state files keep reading cleanly.
  • test/watchdog-escalation.test.ts — one test per impl(pm-stack): quota watchdog escalation — fleet queue task + deduplicated incident issue for a browser-enabled agent #6033 acceptance criterion (dedup, packet completeness, recovery sequence, human-blocked same-tick surfacing, 24 h quiet period, coercion round-trip), oracle = the acceptance text.
  • README updated: the rung-4 module is no longer listed as missing.

Tests

bun test ../exporters/test/watchdog-escalation.test.ts ../exporters/test/watchdog-state.test.ts from pm-stack/aggregator: 21 pass, 0 fail (includes the existing #6032 PBT/MBT suites — no regressions).

Remaining (owned by the #6032 remainder, noted in the README)

The oneshot entry point (src/watchdog.ts in exporters) that reads state, calls decide, and wires the production effectors (fleet CLI enqueue, gh issue create/comment/close) to these planners. This PR deliberately does not invent that host.

Links: task 14781 · issue #6033 · design #6031 · core #6032


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 00:17
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T20:59:55.327908Z
We couldn’t complete this review. Comment @codex review to try again.
92193bf New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e91ca6ef4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +185 to +189
escalation: {
class: health.currentClass ?? "unknown",
since: at,
queueTaskId: refs.queueTaskId,
issueRepo: ctx.issueRepo,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve earlier escalation refs when the failure class changes

When an unresolved source changes failure class, planEscalation intentionally creates another handoff, but this assignment replaces the previous class's issue and task references. planRecovery subsequently closes and completes only the latest pair, leaving the earlier issue and task open permanently. If the failure class changes back, the original pair is also forgotten for deduplication and another handoff is created. Preserve the records per class until recovery, or explicitly retire the previous handoff before replacing its references.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the shepherd fix commit on this PR (task 17233) — see the merge-ready note for the per-finding disposition; new regression tests in test/watchdog-escalation.test.ts (25/25 pass across the escalation + state suites).

Comment on lines +252 to +256
case "enqueue_task":
queueTaskId = await effectors.enqueueTask(action.packet);
break;
case "open_issue":
issueNumber = await effectors.openIssue(action);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain confirmed effect references when a later action fails

If enqueueTask succeeds but openIssue rejects, this function rejects without returning the confirmed queue task ID. The documented caller therefore cannot pass that reference to recordEscalation, and the next escalation plan still contains both creation actions. Retrying can enqueue duplicate repair work, while the first task has no persisted reference for recovery to complete. Expose and persist partial progress, and have subsequent planning retry only the missing effect rather than requiring both external operations to succeed before recording either.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the shepherd fix commit on this PR (task 17233) — see the merge-ready note for the per-finding disposition; new regression tests in test/watchdog-escalation.test.ts (25/25 pass across the escalation + state suites).

const incident = health.incident;
if (!incident) return null;
if (incident.humanBlocked || incident.surfacing === "human-blocked") {
return `NEEDS DREW: ${health.source} quota producer is human-blocked (${health.currentClass ?? "unknown"}: ${health.lastDetail || "human-only challenge"}) — incident ${incident.id}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Surface the persisted human-blocking challenge reason

When a repair encounters a human-only challenge, recordRungOutcome saves the challenge detail in repairLog without updating lastDetail. For example, a producer observation of HTTP 401 followed by a repair failure of passkey required on the laptop makes this line report session-expired: HTTP 401, omitting the intervention actually needed. Subsequent blocked ticks can overwrite lastDetail again while the human-blocked flag remains set. Render the persisted blocking reason rather than the latest producer-observation detail so the human-facing notification identifies the required action.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the shepherd fix commit on this PR (task 17233) — see the merge-ready note for the per-finding disposition; new regression tests in test/watchdog-escalation.test.ts (25/25 pass across the escalation + state suites).

@dezren39

Copy link
Copy Markdown
Member Author

agent-note:v1
state: picked-up
task: 17233
lane: code-a
worker: repo-worker-code
What: Shepherding PR #8357 to a terminal outcome (90-day review open-PR pass). Verified fresh: PR #8357 OPEN, head 3e91ca6, no held / user/owned / do-not-merge / do-not-auto-edit labels; issue #6033 OPEN; the module is NOT on current main. Codex review completed WITH three unresolved P2 findings on pm-stack/exporters/src/watchdog-escalation.ts: (1) line 189 — earlier escalation refs are replaced when the failure class changes, so planRecovery never closes the earlier issue/task and dedupe forgets them; (2) line 256 — a confirmed enqueueTask reference is lost when a later openIssue action fails, so a retry can enqueue duplicate repair work; (3) line 205 — the NEEDS DREW line reports lastDetail instead of the persisted human-blocking challenge reason in repairLog. Per the Codex findings gate, these must be dispositioned before any merge.
Next: fix all three findings in a dedicated worktree with tests, push, recheck, and merge on its merits.

@dezren39 dezren39 added work/assigned Queue worker lifecycle state queue/claimed Queue worker lifecycle state status/in-progress Queue worker lifecycle state labels Nov 14, 2026
repo-worker-tmp-code-b added 2 commits November 14, 2026 14:53
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@dezren39

Copy link
Copy Markdown
Member Author

agent-note:v1
state: merge-ready
task: 17233
lane: code-a
worker: repo-worker-code
What: Merging PR #8357 on its merits, with all three Codex P2 findings fixed in commit 92193bf (each finding thread also has a reply):

  • Preserve earlier escalation refs on class change: EscalationRecord gains a flat previous[] list; recordEscalation moves a displaced hand-off into previous instead of replacing it; planEscalation dedupe consults current + previous (a class that changes back finds its pair); planRecovery comments/closes/completes EVERY recorded pair. coerceHealth round-trips previous (watchdog-state.ts).
  • Retain confirmed refs on partial failure: applyEscalationActions now throws EscalationPartialError carrying the refs confirmed so far; recordEscalation merges same-class refs without overwriting confirmed ones or the original since; planEscalation resumes a partial hand-off by planning only the unconfirmed creation. A retry can no longer duplicate the confirmed task.
  • Surfacing reason: the human-blocked NEEDS DREW line now uses the persisted challenge detail from repairLog (the entry that tripped the human-blocked mark) instead of health.lastDetail, which later ticks can overwrite with a different symptom.
    Verification: bun test test/watchdog-escalation.test.ts test/watchdog-state.test.ts from pm-stack/exporters — 25/25 pass (9 pre-existing escalation tests + 12 state tests + 4 new regression tests). Current main merged cleanly before the fix commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant