@muggleai/works 5.26.0-staging.207 → 5.26.0-staging.209

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/plugin/.claude-plugin/plugin.json +1 -1
  5. package/dist/plugin/.codex-mcp.json +1 -1
  6. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  7. package/dist/plugin/.cursor-plugin/plugin.json +1 -1
  8. package/dist/plugin/.mcp.json +1 -1
  9. package/dist/plugin/agents/acceptance-tester.md +18 -2
  10. package/dist/plugin/hooks/README.md +7 -5
  11. package/dist/plugin/hooks/codex-hooks.json +4 -4
  12. package/dist/plugin/hooks/hooks.json +3 -3
  13. package/dist/plugin/scripts/guardrail-record-delegation.sh +25 -0
  14. package/dist/plugin/scripts/guardrail-walkthrough-gate.sh +6 -6
  15. package/dist/plugin/scripts/guardrail-watch-follow-through-gate.sh +48 -0
  16. package/dist/plugin/scripts/guardrails.mjs +443 -64
  17. package/dist/plugin/scripts/pr-watch-arm.sh +64 -37
  18. package/dist/plugin/scripts/pr-watch-due.sh +31 -0
  19. package/dist/plugin/scripts/pr-watch-events.sh +20 -6
  20. package/dist/plugin/scripts/pr-watch-loop.sh +21 -2
  21. package/dist/plugin/scripts/pr-watch-verdict.mjs +197 -0
  22. package/dist/plugin/skills/_shared/ci-check-to-command.md +2 -1
  23. package/dist/plugin/skills/do/background-e2e.md +89 -0
  24. package/dist/plugin/skills/do/e2e-acceptance.md +4 -0
  25. package/dist/plugin/skills/do/e2e-repair.md +1 -1
  26. package/dist/plugin/skills/do/fix-ci.md +24 -8
  27. package/dist/plugin/skills/do/open-prs/forward.md +3 -3
  28. package/dist/plugin/skills/do/pre-flight.md +4 -3
  29. package/dist/plugin/skills/do/resolve-conflicts.md +7 -3
  30. package/dist/plugin/skills/do/wave-e2e.md +3 -3
  31. package/dist/plugin/skills/do/wave-or-stream.md +51 -0
  32. package/dist/plugin/skills/muggle-do/SKILL.md +6 -2
  33. package/dist/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
  34. package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +5 -3
  35. package/dist/plugin/skills/muggle-pr-followup/blocked-tick.md +2 -0
  36. package/dist/plugin/skills/muggle-pr-followup/contract.md +40 -25
  37. package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +22 -8
  38. package/dist/release-manifest.json +3 -3
  39. package/package.json +1 -1
  40. package/plugin/.claude-plugin/plugin.json +1 -1
  41. package/plugin/.codex-mcp.json +1 -1
  42. package/plugin/.codex-plugin/plugin.json +1 -1
  43. package/plugin/.cursor-plugin/plugin.json +1 -1
  44. package/plugin/.mcp.json +1 -1
  45. package/plugin/agents/acceptance-tester.md +18 -2
  46. package/plugin/hooks/README.md +7 -5
  47. package/plugin/hooks/codex-hooks.json +4 -4
  48. package/plugin/hooks/hooks.json +3 -3
  49. package/plugin/scripts/guardrail-record-delegation.sh +25 -0
  50. package/plugin/scripts/guardrail-walkthrough-gate.sh +6 -6
  51. package/plugin/scripts/guardrail-watch-follow-through-gate.sh +48 -0
  52. package/plugin/scripts/guardrails.mjs +443 -64
  53. package/plugin/scripts/pr-watch-arm.sh +64 -37
  54. package/plugin/scripts/pr-watch-due.sh +31 -0
  55. package/plugin/scripts/pr-watch-events.sh +20 -6
  56. package/plugin/scripts/pr-watch-loop.sh +21 -2
  57. package/plugin/scripts/pr-watch-verdict.mjs +197 -0
  58. package/plugin/skills/_shared/ci-check-to-command.md +2 -1
  59. package/plugin/skills/do/background-e2e.md +89 -0
  60. package/plugin/skills/do/e2e-acceptance.md +4 -0
  61. package/plugin/skills/do/e2e-repair.md +1 -1
  62. package/plugin/skills/do/fix-ci.md +24 -8
  63. package/plugin/skills/do/open-prs/forward.md +3 -3
  64. package/plugin/skills/do/pre-flight.md +4 -3
  65. package/plugin/skills/do/resolve-conflicts.md +7 -3
  66. package/plugin/skills/do/wave-e2e.md +3 -3
  67. package/plugin/skills/do/wave-or-stream.md +51 -0
  68. package/plugin/skills/muggle-do/SKILL.md +6 -2
  69. package/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
  70. package/plugin/skills/muggle-pr-followup/arm-watcher.md +5 -3
  71. package/plugin/skills/muggle-pr-followup/blocked-tick.md +2 -0
  72. package/plugin/skills/muggle-pr-followup/contract.md +40 -25
  73. package/plugin/skills/muggle-pr-followup/state-schemas.md +22 -8
  74. /package/dist/{chunk-HGN35NEP.js → chunk-PQVRAFNE.js} +0 -0
@@ -14,7 +14,7 @@ Resolve red CI on a PR's head — lint/format, typecheck, failing unit tests, an
14
14
 
15
15
  ## Inputs from disk
16
16
 
17
- From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + local checkout / branch), `last_seen.json` (`ci_fix_attempts`, `ci_escalated_shas`, `pushed_shas`), `state.md` (worktree path, validation strategy).
17
+ From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + local checkout / branch), `last_seen.json` (`ci_fix_attempts`, `ci_escalated_shas`, `ci_rerun_shas`, `pushed_shas`), `state.md` (worktree path, validation strategy).
18
18
 
19
19
  ## Procedure
20
20
 
@@ -22,9 +22,13 @@ From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + local checkout
22
22
 
23
23
  Check out the PR branch in the session's working tree (per `state.md`). Capture `red_sha = prs.json[0].head_sha` — this cycle's `pre_cycle_sha` ([`cycle-size.md`](cycle-size.md)).
24
24
 
25
+ Then increment `last_seen.ci_fix_attempts[red_sha]` — before any fix, re-run or escalation, as a whole-file rewrite (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. Every dispatched cycle is an attempt, including one that only re-runs a check or escalates without pushing. That count is the only record the watcher and its turn-end gate accept that this red head was acted on; an escalation written without it is ignored and fix-ci is dispatched again ([`../muggle-pr-followup/state-schemas.md`](../muggle-pr-followup/state-schemas.md#last_seenjson)).
26
+
25
27
  ### Step 2 — Map each failing check to a local command
26
28
 
27
- Per [`../_shared/ci-check-to-command.md`](../_shared/ci-check-to-command.md). Fix the in-scope checks in the working tree; record out-of-scope checks for escalation (Step 6). A red `muggle-walkthrough` check takes Step 2.5.
29
+ Per [`../_shared/ci-check-to-command.md`](../_shared/ci-check-to-command.md). Fix the in-scope checks in the working tree; record out-of-scope checks for escalation (Step 6). A red `muggle-walkthrough` check takes Step 2.5; a red non-deterministic check takes Step 2.6.
30
+
31
+ How long a check takes to run — a 45-minute eval included — is never a reason to skip, defer or escalate it. A held fix needs the user's own words: a message they typed containing `HOLD WATCH #<pr-number>`.
28
32
 
29
33
  ### Step 2.5 — Red E2E walkthrough check
30
34
 
@@ -36,6 +40,18 @@ Per [`../_shared/ci-check-to-command.md`](../_shared/ci-check-to-command.md). Fi
36
40
 
37
41
  An empty-comment failure (no run ever posted) skips items 1–2: run the suite and settle the comment. Under a `unit-only` or `skip` validation in `state.md`, settle it with the verified skip code instead.
38
42
 
43
+ ### Step 2.6 — Red non-deterministic check: re-run once per head
44
+
45
+ A check whose verdict can change with nothing changed — an LLM-judged eval gate such as `skill-routing-eval`, `skill-gate-eval` or `agent-gate-eval` — gets one automatic re-run per head before anything escalates:
46
+
47
+ - **A deterministic check is also red and in scope** → skip the re-run. Fix that check (Steps 3–4); the push re-runs every check on the new head.
48
+ - **`red_sha` ∉ `last_seen.ci_rerun_shas`** → re-run the failed jobs of each such check's run, without pushing — the run id is the `/actions/runs/<run-id>/` segment of the check's `link` ([`../_shared/vcs/github/pr-checks.md`](../_shared/vcs/github/pr-checks.md)):
49
+ ```bash
50
+ gh run rerun <run-id> --failed --repo <owner>/<repo>
51
+ ```
52
+ GitLab retries the failed job instead ([`../_shared/vcs/gitlab/mr-pipeline.md`](../_shared/vcs/gitlab/mr-pipeline.md)). Append `red_sha` to `last_seen.ci_rerun_shas` (whole-file rewrite), skip Steps 3–4, and go to Step 5. The attempt was counted in Step 1; the watcher wakes on the re-run's verdict like any other.
53
+ - **`red_sha` ∈ `ci_rerun_shas`** — it already had its re-run and failed again → escalate per Step 6.
54
+
39
55
  ### Step 3 — Verify before push
40
56
 
41
57
  - Build (typecheck + lint on the changed surface) + unit suite must pass.
@@ -47,16 +63,15 @@ A fix that can't be made green locally is not pushed → Step 6.
47
63
 
48
64
  Commit per the `fix(ci): <check> — <what>` convention ([`../_shared/pr-followup-helpers/reply-routing.md`](../_shared/pr-followup-helpers/reply-routing.md)). Push. Append the new SHA to `last_seen.pushed_shas`. Then finish the tail [`cycle-size.md`](cycle-size.md) picked: a full fix reposts the walkthrough (a Step 2.5 repair settles it there instead), a minor one declares the skip. **No PR replies** — the fix commit is the response.
49
65
 
50
- ### Step 5 — Update state + respawn
66
+ ### Step 5 — Respawn
51
67
 
52
- - Increment `last_seen.ci_fix_attempts[red_sha]` — a whole-file rewrite (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool.
53
- - Respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md). CI on the new SHA is the verify loop — a still-red SHA returns as a fresh dispatch, bounded by the per-SHA fix budget (Step 6).
68
+ Respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md). CI on the new SHA — or the re-run's fresh verdict on the same one — is the verify loop: a still-red SHA returns as a fresh dispatch, bounded by the per-SHA fix budget (Step 6).
54
69
 
55
70
  ### Step 6 — Escalate (budget spent or out of scope)
56
71
 
57
- When the failing checks are all out of scope, or `ci_fix_attempts[red_sha]` has reached 3 with CI still red:
72
+ When the failing checks are all out of scope, a non-deterministic check is red again after its re-run on this head (Step 2.6), or this is the head's third cycle (`ci_fix_attempts[red_sha]` reached 3 in Step 1) and it could not push a fix:
58
73
 
59
- 1. Add `red_sha` to `last_seen.ci_escalated_shas` so the SHA is not re-fixed.
74
+ 1. Add `red_sha` to `last_seen.ci_escalated_shas` so the SHA is not re-fixed. This cycle's Step 1 attempt is what makes the entry count.
60
75
  2. Emit one terminal message naming the unresolved checks.
61
76
  3. Emit the cycle event with `outcome: "ci-escalated"` (Step 7).
62
77
  4. **Respawn the watcher** per [`respawn-watcher.md`](respawn-watcher.md). Escalation stops fix-ci from re-dispatching this SHA — but the poller must keep running: it reminds on the `ci_escalated` block and catches a new push, a new review, or the user's own fix. Skipping respawn here is the silent-stop bug the helper exists to prevent.
@@ -67,5 +82,6 @@ Emit one `muggle-do:cycle` event ([`../_shared/telemetry-events/muggle-do-cycle.
67
82
 
68
83
  ## Guardrails
69
84
 
70
- - Max 3 fix attempts per SHA; out-of-scope checks escalate immediately rather than churn. A walkthrough repair that pushes nothing keeps the head SHA, so the same budget bounds it.
85
+ - Max 3 fix attempts per SHA; out-of-scope checks escalate immediately rather than churn. A walkthrough repair or a re-run that pushes nothing keeps the head SHA, so the same budget bounds it.
86
+ - A non-deterministic check is re-run once per head before it escalates — never escalated on its first red, never re-run twice on one head.
71
87
  - No PR replies; the fix commit is the response.
@@ -12,7 +12,7 @@ Forward pipeline's Stage 7. Invoked by `/muggle-do` after stages 1–6 of a fres
12
12
 
13
13
  - Per-repo: name, path, branch.
14
14
  - Requirements: goal, acceptance criteria.
15
- - **Optional** E2E acceptance report from stage 6. Produced by [`../e2e-acceptance.md`](../e2e-acceptance.md); schema in [`../../muggle-pr-visual-walkthrough/SKILL.md`](../../muggle-pr-visual-walkthrough/SKILL.md).
15
+ - **Optional** E2E acceptance report from stage 6. Produced by [`../e2e-acceptance.md`](../e2e-acceptance.md) — inline, or returned by this change's background acceptance-tester ([`../background-e2e.md`](../background-e2e.md)); schema in [`../../muggle-pr-visual-walkthrough/SKILL.md`](../../muggle-pr-visual-walkthrough/SKILL.md). Only this change's own report: a sibling change's run never settles this PR.
16
16
 
17
17
  ## Wave cycles
18
18
 
@@ -48,8 +48,8 @@ Forward pipeline's Stage 7. Invoked by `/muggle-do` after stages 1–6 of a fres
48
48
  - `gitlab` → open the change via [`../../_shared/vcs/gitlab/mr-create.md`](../../_shared/vcs/gitlab/mr-create.md): `glab mr create --source-branch <branch> --target-branch <base> --title "..." --description "..."`. Capture the MR URL and iid.
49
49
 
50
50
  6. **Settle the designated walkthrough comment.** Creating the PR reserves one comment for the walkthrough, marked `muggle-pr-walkthrough` and empty until settled — the PR's walkthrough check fails while it stays that way.
51
- - E2E report exists → fire [`postPRVisualWalkthrough`](../../muggle-preferences/preference-gates/postPRVisualWalkthrough.md); on skip, leave the comment to the gate's own skip record. Otherwise invoke [`../../muggle-pr-visual-walkthrough/SKILL.md`](../../muggle-pr-visual-walkthrough/SKILL.md) Mode A with the PR number — it fills the reserved comment in place.
52
- - No E2E report (validation was `unit-only` or `skip`) → now that the PR exists, re-declare the skip Stage 6 recorded with the same code: `echo "MUGGLE_E2E_SKIP: <CODE>: <detail>"`, codes per [`../e2e-acceptance.md`](../e2e-acceptance.md). An accepted code settles the comment as a declared skip; a free-text reason is rejected and leaves it unsettled. A PR whose title says `[UNIT-ONLY]` still owes reviewers the why. The write runs detached, so confirm it landed: the walkthrough Stop gate holds the turn while the PR still shows the placeholder, and its block names a foreground command that prints `{"settled":true}` once the PR reads back the skip — run it, never a hand-written PATCH.
51
+ - E2E report exists → fire [`postPRVisualWalkthrough`](../../muggle-preferences/preference-gates/postPRVisualWalkthrough.md); on skip, leave the comment to the gate's own skip record. Otherwise invoke [`../../muggle-pr-visual-walkthrough/SKILL.md`](../../muggle-pr-visual-walkthrough/SKILL.md) Mode A with the PR number and repo passed explicitly — it fills the reserved comment in place. Explicit because a session carrying several changes may sit in another change's worktree, where the current branch's PR is the wrong one.
52
+ - No E2E report (validation was `unit-only` or `skip`), or a `SKIPPED` report → now that the PR exists, re-declare the skip Stage 6 recorded with the same code, from this PR's worktree: `echo "MUGGLE_E2E_SKIP: <CODE>: <detail>"`, codes per [`../e2e-acceptance.md`](../e2e-acceptance.md). An accepted code settles only the PRs of that worktree's change — the PRs opened from it and its checked-out branch's PR; a free-text reason is rejected and leaves it unsettled. A PR whose title says `[UNIT-ONLY]` still owes reviewers the why. The write runs detached, so confirm it landed: the walkthrough Stop gate holds the turn while the PR still shows the placeholder, and its block names a foreground command that prints `{"settled":true}` once the PR reads back the skip — run it, never a hand-written PATCH.
53
53
 
54
54
  7. **Overflow comment:** if the walkthrough skill returned a non-null `comment`, post it once using the provider resolved in Step 5 — `github` per [`../../_shared/vcs/github/top-level-comment.md`](../../_shared/vcs/github/top-level-comment.md), `gitlab` per [`../../_shared/vcs/gitlab/mr-note.md`](../../_shared/vcs/gitlab/mr-note.md). End the posted body with the signature line (command `/muggle-do`) per [`../../_shared/vcs/post-signature.md`](../../_shared/vcs/post-signature.md). Never post when `comment` is `null`.
55
55
 
@@ -36,7 +36,7 @@ Before asking anything, gather every fact you can resolve without the user:
36
36
  - Is the current checkout already a worktree? `git -C <repo> rev-parse --is-inside-work-tree` plus `git -C <repo> worktree list`.
37
37
  - Is the current checkout on the latest base? `muggle checkout-freshness --cwd <repo> --json` fetches and reports the verdict and `behindBy`. However stale or foreign the current checkout, a new worktree starts from `origin/<base>`, never from it.
38
38
  10. **`autoE2ETest` preference.** Read the session-context preferences line. Unset → treat as `always` (this gate's default — opposite of the system-wide `ask` default). `ask` → surface in Q13. `always` → no question; stage 6 runs.
39
- 11. **Wave candidate?** Two or more candidate repos, one PR each, and validation leaning `local-e2e` → the cycle is a wave per [`wave-e2e.md`](wave-e2e.md): the repos' services start together from their branches and one E2E run covers every PR. Record each repo's worktree path for the `Wave members` block. Not a wave → note why.
39
+ 11. **Wave or stream?** Group the task's PRs per [`wave-or-stream.md`](wave-or-stream.md). Parts of one change across repos form a **wave** ([`wave-e2e.md`](wave-e2e.md)): record each member's worktree path for the `Wave members` block, or `Wave: off — <reason>` when one fails a wave condition. Unrelated fixes — "fix these three bugs" — form a **stream**: one change per fix, each with its own slug, session directory, branch, worktree, PR and E2E run ([`background-e2e.md`](background-e2e.md)). When unsure, a stream. The questionnaire's answers apply to every change unless a fix names another repo; state the grouping in Q1's options so the user sees how many PRs ship and which share a run.
40
40
  12. **CI check present?** For each GitHub repo, whether `.github/workflows/muggle-walkthrough.yml` exists on its default branch. Missing and [`autoInstallCiWorkflow`](../muggle-preferences/preference-gates/autoInstallCiWorkflow.md) resolves to `ask` → surface in Q14.
41
41
 
42
42
  ## The consolidated questionnaire
@@ -44,7 +44,7 @@ Before asking anything, gather every fact you can resolve without the user:
44
44
  Present **one `AskUserQuestion`** (or the platform's structured-selection equivalent) that collects every remaining decision. Use detected values as defaults whenever possible. Questions to include, in this order:
45
45
 
46
46
  1. **Task scope clarification** — only if the task description is genuinely ambiguous. Offer 2–3 interpretations as options plus "Other — type a clarification." If the task is unambiguous, omit.
47
- 2. **Repo(s) to modify** — pre-selected with the best silent match. "Confirm <repo>" / "Change repo" / "Multi-repo (list them)". When multi-repo with one PR per repo, state in the option that the PRs ship as a wave tested together in one E2E run ([`wave-e2e.md`](wave-e2e.md)) — no separate question.
47
+ 2. **Repo(s) to modify** — pre-selected with the best silent match. "Confirm <repo>" / "Change repo" / "Multi-repo (list them)". When multi-repo, state in the option whether the PRs ship as a wave — one change, tested together in one E2E run — or a stream of independent changes, each tested on its own, per step 11 and [`wave-or-stream.md`](wave-or-stream.md) — no separate question.
48
48
  3. **Branch name** — default: `users/<user>/<slug>` derived from the task. "Use default" / "Use different name (type)".
49
49
  4. **Validation strategy** — the single most important question. Options:
50
50
  - **Local E2E** (Muggle Test Electron against a running localhost) — default if a dev server was detected.
@@ -81,6 +81,7 @@ After the user answers, write **`state.md`** with every resolved value, verbatim
81
81
  - Repos: <repo1>, <repo2>
82
82
  - Wave: <on | off — reason | N/A (single repo)>
83
83
  - Wave members: <one line per repo when on — `<owner/repo> → <worktree path> (branch <branch>)`; see wave-e2e.md>
84
+ - Sibling changes: <slugs of this session's other changes, or none; see background-e2e.md>
84
85
  - Branch: <branch-name>
85
86
  - Validation: <strategy>
86
87
  - Local URL: <url or N/A>
@@ -113,4 +114,4 @@ Return control to the muggle-do driver with a one-line summary: `pre-flight comp
113
114
  - Exactly **one** user turn. Zero follow-up questions inside this stage.
114
115
  - Silent detection **must** run before the questionnaire — never ask for a value you can detect.
115
116
  - Every detected value is a default, not a lock — the user can always override via "Type a different …".
116
- - Missing `state.md` or `iterations/001.md` at the end of this stage is a stage failure.
117
+ - Missing `state.md` or `iterations/001.md` at the end of this stage is a stage failure. Several changes → one session directory each, all written before Stage 2 starts on the first.
@@ -22,6 +22,10 @@ From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + branch + `head_
22
22
 
23
23
  Materialize the PR branch in its worktree per [`../_shared/pr-branch-worktree.md`](../_shared/pr-branch-worktree.md) (or use `state.md`'s `worktreePath`). Capture `rebase_sha = prs.json[0].head_sha` and the base branch (`baseRefName` from [`../_shared/vcs/github/pr-metadata.md`](../_shared/vcs/github/pr-metadata.md)). Capture the base tip too — `.base_commit.sha` from that recipe's `compare` call — and form `rebase_key = "<rebase_sha>..<base_tip_sha>"`. Both budget fields below are keyed on that pair, matching the watcher's Step 5; writing a bare SHA instead leaves an entry the watcher ignores, and the rebase re-dispatches forever.
24
24
 
25
+ Then increment `last_seen.conflict_resolve_attempts[rebase_key]` — before rebasing, as a whole-file rewrite (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. Every dispatched rebase is an attempt, including one that escalates on a conflict under `autoResolveConflicts=never` or fails verification. That count is the only record the watcher and its turn-end gate accept that this key was acted on; an entry in `conflict_escalated_keys` without it is ignored and the rebase is dispatched again ([`../muggle-pr-followup/state-schemas.md`](../muggle-pr-followup/state-schemas.md#last_seenjson)).
26
+
27
+ `autoRebase=always` makes this rebase binding. The CI or evals a force-push re-runs — however long they take — are never a reason to hold it; the only hold is the user's own message containing `HOLD WATCH #<pr-number>`.
28
+
25
29
  ### Step 2 — Rebase onto base (resolve conflicts if any)
26
30
 
27
31
  Run the rebase from [`../_shared/sync-branch-with-base.md`](../_shared/sync-branch-with-base.md) against the base branch, taking its `always` path unconditionally — this programmatic mode never asks, so skip the `autoRebase` prompt (the watcher already decided a rebase is due).
@@ -37,13 +41,13 @@ Build (typecheck + lint on the changed surface) + unit suite must pass. Size the
37
41
 
38
42
  ### Step 4 — Force-push + respawn
39
43
 
40
- Force-push per [`../_shared/vcs/common/push-to-branch.md`](../_shared/vcs/common/push-to-branch.md) (tool-agnostic instruction; handles the signing gate for rebased commits and directs to provider-specific force-push paths). Use `git push --force-with-lease` for the force operation. Append the new SHA to `last_seen.pushed_shas`; increment `last_seen.conflict_resolve_attempts[rebase_key]` **and** `last_seen.catch_up_rebases` — all whole-file rewrites (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. The second counter is unkeyed on purpose: `rebase_key` carries the base tip, so it mints a fresh budget every time the base moves and cannot bound a PR on an active base. Increment it on every push here, including one that later escalates, or a branch that fails the same way twenty times reads as having spent nothing. Finish the tail [`cycle-size.md`](cycle-size.md) picked — a full rebase reposts the walkthrough, a minor one declares the skip — then respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md). Its next tick re-checks the branch against its base on the new head — the rebase is its own verify loop, bounded by the per-SHA attempt budget.
44
+ Force-push per [`../_shared/vcs/common/push-to-branch.md`](../_shared/vcs/common/push-to-branch.md) (tool-agnostic instruction; handles the signing gate for rebased commits and directs to provider-specific force-push paths). Use `git push --force-with-lease` for the force operation. Append the new SHA to `last_seen.pushed_shas` and increment `last_seen.catch_up_rebases` (the per-key attempt was counted in Step 1) — both whole-file rewrites (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. That counter is unkeyed on purpose: `rebase_key` carries the base tip, so it mints a fresh budget every time the base moves and cannot bound a PR on an active base. Increment it on every push here, including one that later escalates, or a branch that fails the same way twenty times reads as having spent nothing. Finish the tail [`cycle-size.md`](cycle-size.md) picked — a full rebase reposts the walkthrough, a minor one declares the skip — then respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md). Its next tick re-checks the branch against its base on the new head — the rebase is its own verify loop, bounded by the per-SHA attempt budget.
41
45
 
42
46
  ### Step 5 — Escalate (can't resolve / budget spent)
43
47
 
44
- When `autoResolveConflicts=never`, the resolution failed verification, or `conflict_resolve_attempts[rebase_key]` has reached 2:
48
+ When `autoResolveConflicts=never`, the resolution failed verification, or this is the key's second attempt (`conflict_resolve_attempts[rebase_key]` reached 2 in Step 1) and it did not push:
45
49
 
46
- 1. Add `rebase_key` to `last_seen.conflict_escalated_keys` so the watcher does not re-dispatch this head against this base. If the base later moves, the key changes and the branch re-arms on its own — a conflict the user resolved upstream stops being this watcher's dead end.
50
+ 1. Add `rebase_key` to `last_seen.conflict_escalated_keys` so the watcher does not re-dispatch this head against this base. Step 1's attempt is what makes the entry count. If the base later moves, the key changes and the branch re-arms on its own — a conflict the user resolved upstream stops being this watcher's dead end.
47
51
  2. Emit one terminal escalation naming the PR and the conflicting files (or the failing verification, for a behind-only rebase that didn't verify).
48
52
  3. Respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md) — it keeps polling for the user's manual resolution or any new reviews.
49
53
 
@@ -6,14 +6,14 @@ So a wave is tested as one: start every repo's service from its wave branch, run
6
6
 
7
7
  ## When a cycle is a wave
8
8
 
9
- All of these hold, decided at pre-flight and recorded in `state.md`:
9
+ What makes PRs a wave rather than a stream of independent changes is defined in [`wave-or-stream.md`](wave-or-stream.md): the PRs need each other to work. A wave additionally needs all of these, decided at pre-flight and recorded in `state.md`:
10
10
 
11
11
  - Two or more repos carry changes this cycle.
12
12
  - Each changed repo gets exactly **one** PR — no stacked PRs, no second PR in the same repo.
13
13
  - Validation is `local-e2e`.
14
14
  - Every wave repo that serves part of the stack can run locally. A repo that only ships a library or config consumed by another wave repo is still a wave member; it just contributes no service of its own.
15
15
 
16
- Anything else is not a wave: each PR runs Stage 6 on its own, as before. Two PRs in one repo, or one repo whose service cannot start locally, fall back to per-PR runs — record the reason in `state.md` as `Wave: off — <reason>`.
16
+ Anything else is not a wave: each PR is a change of its own and runs Stage 6 on its own — in the background when other work is in flight, per [`background-e2e.md`](background-e2e.md). A wave can run in that background lane too, as one change: its brief carries every member ([`wave-or-stream.md`](wave-or-stream.md#the-acceptance-testers-brief)). Two PRs in one repo, or one repo whose service cannot start locally, fall back to per-PR runs — record the reason in `state.md` as `Wave: off — <reason>`.
17
17
 
18
18
  ## What pre-flight records
19
19
 
@@ -57,7 +57,7 @@ The SHAs are what the run tested. A result is only valid for the PRs at those SH
57
57
  1. **Open every PR first**, before settling any walkthrough. Each PR's walkthrough names its siblings, so all PR numbers must exist before the first one is written.
58
58
  2. **Body.** Add a `## Wave` section to each PR's body, after `## Validation`: one line per sibling PR (`owner/repo#n`), and the line `Tested together — merge all PRs in this wave together.`
59
59
  3. **Title.** Every PR in the wave takes the same E2E prefix. A wave run with failures retitles every member `[E2E FAILING]`, not only the implicated one — the run tested them as one change.
60
- 4. **Walkthrough.** Settle each PR's designated walkthrough comment with the **same** E2E report through [`muggle-pr-visual-walkthrough`](../muggle-pr-visual-walkthrough/SKILL.md) Mode A, passing that PR's number and repo explicitly — Mode A otherwise looks up the PR from the current branch, which in a multi-repo cycle is the wrong repo. The runs, screenshots, and dashboard links are identical on every PR; only the PR it is posted to differs.
60
+ 4. **Walkthrough.** Settle each PR's designated walkthrough comment with the **same** E2E report through [`muggle-pr-visual-walkthrough`](../muggle-pr-visual-walkthrough/SKILL.md) Mode A, passing that PR's number and repo explicitly — Mode A otherwise looks up the PR from the current branch, which in a multi-repo cycle is the wrong repo. The runs, screenshots, and dashboard links are identical on every PR; only the PR it is posted to differs. A `SKIPPED` wave run is re-declared from each member's worktree in turn: a declaration settles only the PR of the tree it runs in.
61
61
  5. **Record the PR numbers** on the `Wave members` lines in `state.md` (`… (branch <branch>) → PR #<n>`), so a later cycle on any one PR can find its siblings. Every slot a wave PR's watcher runs from gets the same `Wave` block.
62
62
 
63
63
  ## Stage 7.5 — repair across the wave
@@ -0,0 +1,51 @@
1
+ # Wave or stream — how a session's PRs group into changes
2
+
3
+ A session that opens more than one PR has opened a **wave**, a **stream**, or both, and each is tested differently. The grouping decides how many E2E runs the session owes and which report each PR carries, so it is settled once, at pre-flight, and every later stage reads it from `state.md`.
4
+
5
+ ## Wave
6
+
7
+ One change split across repos. The PRs only work together: the frontend PR calls an endpoint the backend PR adds; a library PR ships a type its consumers adopt in theirs.
8
+
9
+ - One PR per repo, all carrying parts of the same change.
10
+ - **One** E2E run against the combined stack, every service started from its member's branch. The same report goes on every PR in the wave, and they merge together.
11
+ - Procedure: [`wave-e2e.md`](wave-e2e.md).
12
+
13
+ ## Stream
14
+
15
+ Unrelated changes that ship in the same session: separate bugs, separate tasks. Each PR stands alone — it would pass review and work in production if none of the others ever merged.
16
+
17
+ - Each PR is its own change, with its own session directory, branch, worktree, E2E run and report.
18
+ - Each run goes to a background acceptance-tester while the session moves on, one local run at a time.
19
+ - Procedure: [`background-e2e.md`](background-e2e.md).
20
+
21
+ A session can hold both. A wave for one feature, opened alongside unrelated fixes, is one change in the stream: it gets one wave run, and each fix gets its own.
22
+
23
+ ## Deciding
24
+
25
+ For each pair of PRs, ask whether either needs the other to work.
26
+
27
+ | Answer | Grouping |
28
+ | :----- | :------- |
29
+ | Yes, and they are in different repos | Same wave |
30
+ | Yes, and they are in the same repo | A stack, not a wave: each PR is tested on its own branch, which already carries the PRs beneath it |
31
+ | No | Separate changes in the stream |
32
+
33
+ A wave also needs every serving repo to run locally ([`wave-e2e.md`](wave-e2e.md#when-a-cycle-is-a-wave)). Interdependent PRs whose stack cannot start together are tested per PR; record why as `Wave: off — <reason>`.
34
+
35
+ **When unsure, treat them as a stream.** A stream PR that needed a sibling fails visibly, and its repair loop names the missing piece. A wave that should have been a stream puts one change's report on another change's PR — the evidence reviewers trust most, vouching for code it never ran.
36
+
37
+ ## Recording
38
+
39
+ Pre-flight writes the grouping into `state.md`; no later stage re-derives it from branch names or diffs.
40
+
41
+ - **Wave** — one session directory for the wave, with `Wave: on` and its `Wave members` block ([`wave-e2e.md`](wave-e2e.md#what-pre-flight-records)).
42
+ - **Stream** — one session directory per change, each listing the others under `Sibling changes`.
43
+
44
+ A change that grows a second repo mid-cycle has become a wave: record the new member before Stage 6, never after a run has already been posted per PR.
45
+
46
+ ## The acceptance-tester's brief
47
+
48
+ A background run tests exactly one change, so its brief names exactly that change's PRs ([`background-e2e.md`](background-e2e.md#brief)):
49
+
50
+ - **A stream change** — its one repo, worktree, branch, head SHA and PR.
51
+ - **A wave** — every member's repo, worktree, branch, head SHA and PR. The agent starts the combined stack per [`wave-e2e.md`](wave-e2e.md) Stage 6, reports `Tested:` once per member, and names each failure's `implicatedRepo`.
@@ -25,7 +25,11 @@ Runs an autonomous dev cycle from requirements to PR. **Fire and review:** user
25
25
  | 7.5 | E2E repair loop | [`../do/e2e-repair.md`](../do/e2e-repair.md) |
26
26
  | 8 | Hand off to watcher | [`../muggle-pr-followup/SKILL.md`](../muggle-pr-followup/SKILL.md) |
27
27
 
28
- **Multi-repo waves.** When a task spans several repos with one PR each, the PRs form a wave: every repo's service starts from its branch, Stage 6 runs **one** E2E pass against the combined stack, and that same result is posted to every PR in the wave. See [`../do/wave-e2e.md`](../do/wave-e2e.md); pre-flight decides whether a cycle is a wave.
28
+ **Waves and streams.** A session's PRs are either a **wave** — one change split across repos — or a **stream** of independent changes, or both; [`../do/wave-or-stream.md`](../do/wave-or-stream.md) defines which is which, and pre-flight decides it once.
29
+
30
+ **Multi-repo waves.** When a task's PRs need each other to work — one PR per repo — they form a wave: every repo's service starts from its branch, Stage 6 runs **one** E2E pass against the combined stack, and that same result is posted to every PR in the wave. See [`../do/wave-e2e.md`](../do/wave-e2e.md); pre-flight decides whether a cycle is a wave.
31
+
32
+ **Streams — several changes in one session.** Unrelated fixes — several bugs in one request, or a second task while the first is still in flight — are separate changes, each with its own session directory, worktree, PR, and E2E run; a wave is one change among them. When a change reaches Stage 6 while other work is in front of the session, its run goes to a background `acceptance-tester` and the session moves on; the report comes back to the main session, which carries that change through Stages 7–8. One local run at a time, and a PR's walkthrough only ever carries its own change's run. See [`../do/background-e2e.md`](../do/background-e2e.md).
29
33
 
30
34
  Stage 7 dispatches one watcher per opened PR as its last action, gated on Stage 7.5's clearance — a cycle with unrepaired E2E failures never reaches a watcher.
31
35
 
@@ -36,7 +40,7 @@ The pipeline table lists **pointers, not summaries**. Open each stage's file and
36
40
  **Bootstrap before any code, in order:**
37
41
  1. Emit telemetry — [`../_shared/telemetry-emit.md`](../_shared/telemetry-emit.md), `skillName: "muggle-do"`.
38
42
  2. Create `~/.muggle-ai/muggle-do/sessions/<slug>/` with `state.md` + `iterations/001.md` (pre-flight owns this; do it even when running unattended).
39
- 3. `TodoWrite` one item per stage 1–8, Stage 7.5 included — these stages are the checklist; never swap in your own decomposition.
43
+ 3. `TodoWrite` one item per stage 1–8, Stage 7.5 included — these stages are the checklist; never swap in your own decomposition. Several changes → one set of stage items per change.
40
44
 
41
45
  **Per stage:** read the file → execute it → append a marker to `iterations/<NNN>.md` citing the evidence that file requires (jest exit code, E2E verdict + `runId`, screenshot path). A stage is done only when its evidence is written, never on recollection.
42
46
 
@@ -45,7 +45,7 @@ The skill recognizes its mode by inspecting `$ARGUMENTS` and falling back to on-
45
45
  | `reconcile` / `sweep` (optional `<slug>`) | — | **reconcile** → [`reconcile.md`](reconcile.md) |
46
46
  | `adopt` (optional `<slug>`) | — | **adopt** → [`adopt.md`](adopt.md) — take over a slot owned by a dead session; no slug lists the adoptable ones |
47
47
 
48
- **`--wake=<event>`** is passed only by an event wake's dispatch ([`arm-watcher.md`](arm-watcher.md) step 5) — it asserts the monitor already saw something new, so the tick's poll is justified. Manual invocations never pass it; with a live watcher they get watch-status, because a poll that nothing prompted is a main-session poll wasted. Recovery fires need no flag — a recoverable slot's watcher is dead by definition, so the gate falls through to tick. A stale cron firing against a re-armed slot hits the live-`watch.pid` branch and is absorbed as a status line, no provider calls.
48
+ **`--wake=<event>`** is passed only by an event wake's dispatch ([`arm-watcher.md`](arm-watcher.md) step 5), or by the follow-through Stop gate's instruction (`--wake=follow-through`) when the watch recorded due work nothing attempted — either asserts something is waiting, so the tick's poll is justified. Manual invocations never pass it; with a live watcher they get watch-status, because a poll that nothing prompted is a main-session poll wasted. Recovery fires need no flag — a recoverable slot's watcher is dead by definition, so the gate falls through to tick. A stale cron firing against a re-armed slot hits the live-`watch.pid` branch and is absorbed as a status line, no provider calls.
49
49
 
50
50
  Auto-track runs **reconcile** first, so a no-arg invocation also finalizes any slot whose PR merged or closed while its watcher was down (expired cron, ended session) and re-arms this session's own open slots whose watcher stopped silently (a dropped respawn). Reconcile recovers a watcher that was already running; it never seeds a first watcher for a PR — that is auto-track's / bootstrap's job — and never re-arms one this session does not own. A no-arg invocation is a request to track *your* PRs, so it can only ever end with the session watching PRs it pushed plus watchers it already had.
51
51
 
@@ -10,10 +10,10 @@ bash "<abs>/scripts/pr-watch-arm.sh" --slot "<slot>" --repo "<owner>/<repo>" --p
10
10
 
11
11
  The same argument that forbids authoring a per-slot `watch.sh` applies to arming itself. Performed from prose, the middle step — writing `watch-watermark.env` — is the one that gets dropped, and dropping it is silent: the loop gates every wake condition on that file, so it polls nothing, reports nothing and never reaches its terminal check, while still holding its PID lease and touching its heartbeat. Eleven such watchers once ran for hours across one session, missed nine merges and a red CI run between them, and every health signal said they were fine. Running one command cannot half-happen.
12
12
 
13
- Read the `DRAIN` lines it prints: they are the outstanding work the monitor will *not* tell you about, because the floors it just wrote mark that state as already seen. Steps 1-3 below are what the script does, and why.
13
+ Read the `DRAIN` lines it prints: they are the outstanding work as of the arm. Review ids and threads the drain read are floored, so the monitor will *not* tell you about those again. A stale branch or a red head is floored only when `last_seen.json` records a rebase or fix-ci cycle already attempted for that key or head ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)); otherwise the drain line says `not floored: dispatch …` and the loop's first poll reports it as an event. Re-arming is never a way to set work aside — it neither handles nor silences anything. Steps 1-3 below are what the script does, and why.
14
14
 
15
15
  1. **Drain.** Run one tick per [`contract.md`](contract.md). It acts on everything already outstanding — actionable threads (`gitlab`: discussions), body-only reviews past the watermark (GitHub-only — GitLab has no review envelope), a stale branch, red CI — and finalizes a terminal PR. If the tick dispatched a cycle, stop here: the cycle's exit path settles the watch when it finishes.
16
- 2. **Seed the watermark.** *(`pr-watch-arm.sh` does this; the reasoning is kept because the floors are subtle and wrong ones are quiet.)* Resolve the provider once per [`../_shared/vcs/detect-vcs.md`](../_shared/vcs/detect-vcs.md) — every fetch in this sequence uses that provider's recipes. Write the slot's watch watermark ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)) to the ids the **drain itself read** — the max review-id and comment-id observed at the drain's own fetch (Step 1), snapshotted at that read. Never let the loop capture its own baseline — the arming session writes it; and **never** from a fresh fetch taken after the drain, which would include a comment that arrived after the drain read the wave and mark it seen unread. Seeded to the drain's floor, anything landing after that read stays above the watermark and the monitor's first iteration surfaces it. Seed the CI floor (`CIRED`) from the same drain read: set it to the head SHA when the checks have **already settled red** at that read (no check pending, one or more in the `fail` bucket per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md)) — that red is what the drain just handled — and empty otherwise, so an escalated red head the drain already saw does not re-fire on the loop's first iteration. Seed the rebase floor (`REBASED`) the same way, from the drain's branch-standing read per [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md): set it to the current `rebase_key` (`<head_sha>..<base_tip_sha>`) when the drain found the branch already behind or conflicting — that staleness is what the drain just handled — and empty otherwise, so a branch the drain already rebased or escalated does not re-fire on the loop's first iteration. Seed the blocked-CI floor (`BLOCKED_CIDIGEST`) to the blocked fingerprint's `ci_digest` when arming while `last_seen.blocked` is already set, and empty otherwise — empty is the not-blocked state, in which the loop's blocked-resume probe stays dormant.
16
+ 2. **Seed the watermark.** *(`pr-watch-arm.sh` does this; the reasoning is kept because the floors are subtle and wrong ones are quiet.)* Resolve the provider once per [`../_shared/vcs/detect-vcs.md`](../_shared/vcs/detect-vcs.md) — every fetch in this sequence uses that provider's recipes. Write the slot's watch watermark ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)) to the ids the **drain itself read** — the max review-id and comment-id observed at the drain's own fetch (Step 1), snapshotted at that read. Never let the loop capture its own baseline — the arming session writes it; and **never** from a fresh fetch taken after the drain, which would include a comment that arrived after the drain read the wave and mark it seen unread. Seeded to the drain's floor, anything landing after that read stays above the watermark and the monitor's first iteration surfaces it. Seed the CI floor (`CIRED`) from the same drain read: set it to the head SHA only when the checks have **already settled red** at that read (no check pending, one or more in the `fail` bucket per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md)) **and** `last_seen.json` records a fix-ci attempt for that head — a cycle already ran for that red, so its escalation or retry is not news — and empty otherwise. Seed the rebase floor (`REBASED`) the same way, from the drain's branch-standing read per [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md): the current `rebase_key` (`<head_sha>..<base_tip_sha>`) only when the drain found the branch behind or conflicting **and** a rebase attempt is recorded for that key, empty otherwise. An escalation entry alone never floors anything: one with no attempt behind it records a decision nobody acted on, and flooring it is how a re-arming session once kept a stale branch and a red head silent for a day ([`state-schemas.md`](state-schemas.md#watch-watermarkenv) names the fields). Seed the blocked-CI floor (`BLOCKED_CIDIGEST`) to the blocked fingerprint's `ci_digest` when arming while `last_seen.blocked` is already set, and empty otherwise — empty is the not-blocked state, in which the loop's blocked-resume probe stays dormant. The script reads all three facts from `last_seen.json` through [`../../scripts/pr-watch-verdict.mjs`](../../scripts/pr-watch-verdict.mjs) `arm-floors`, and records what it found due in `watch-due.env` ([`state-schemas.md`](state-schemas.md#watch-dueenv)).
17
17
  3. **Dedup, then watch.** First read `<slot>/watch.pid` ([`state-schemas.md`](state-schemas.md#watchpid)): if it names a live process (`kill -0 "$pid"` succeeds) **and `owner.json` records this session**, a watcher already owns this slot — **skip arming, do not start a second**. This is what stops orphaned watchers from accumulating: the in-session monitor dying does not stop the OS loop it launched (on Windows a detached Git Bash loop keeps running and polling `gh` forever after the session ends), so checking a live task list is not enough — the PID lease is.
18
18
 
19
19
  **A live lease owned by a different session does not count as owned** — check it with `watcher_lease_is_foreign` from [`../../scripts/pr-watch-guards.sh`](../../scripts/pr-watch-guards.sh). A live PID proves the loop is running, never that anything is listening: an orphan left by a dead session keeps polling and keeps touching its heartbeat while its stdout is that session's closed monitor pipe, so every liveness signal reads healthy and the events reach nobody. Skipping on the PID alone let such a corpse block this session from arming the PR for the whole lifetime cap — seven days, since the default moved off six hours. When the guard reports a foreign lease, kill that PID, delete `watch.pid`, and arm fresh; note it in the slot's `followup.log` so the reclaim is visible.
@@ -38,6 +38,8 @@ Read the `DRAIN` lines it prints: they are the outstanding work the monitor will
38
38
 
39
39
  The label is `PR #<n> — <title>`. Label and command both matter: some task surfaces show one, some the other, and a slot-bearing command keeps the watch identifiable everywhere a raw script blob would not. One monitor per PR at a time: it is the watch's visible handle, showing as a running task while the PR is polled, and replaced by a fresh one each time the loop rolls over. Its loop checks about every 60 seconds, re-reading the watermark and touching the slot's `watch-heartbeat` file each iteration — the liveness beacon that tells [`reconcile.md`](reconcile.md) a quiet watch is still alive; on a newer submitted review, a newer thread comment (`gitlab`: a newer discussion note), a thread newly unresolved (`gitlab`: discussion), **the head SHA's checks settling red** (no check pending and one or more in the `fail` bucket per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md)), **the branch falling behind or conflicting with its base** (`behind_by > 0` or the conflict signal per [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md)), or — **only while the watch is blocked** (`BLOCKED_CIDIGEST` non-empty) — **the head's CI digest changing in any way** (not just to red) — it prints one line and **keeps watching**, advancing its in-memory floor so each event fires the tick exactly once. The review and thread floors are monotonic ids; the other three are not. The CI-red floor is the **head SHA**, because the check rollup is non-monotonic — it flips green↔red and resets on every push — so recording the red head SHA fires CI once per red head, and a later push re-arms it on the new SHA. The rebase floor (`REBASED`) is the **`rebase_key`** — `<head_sha>..<base_tip_sha>` — because staleness is a function of both sides: keying on the pair fires once per newly-due pair and re-arms when either the head or the base moves, where a head-only key would wedge permanently the first time the base advances (the head cannot change while nobody pushes). A head whose checks are still **pending** is never a red wake, and a branch with `behind_by == 0` and `mergeable == UNKNOWN` is never a rebase wake: pending checks may yet go green and conflict state is still computing, and the tick would idle on either (Steps 5–6) regardless. The blocked-CI signal is different in kind — a **resume** probe, live only while the watch is blocked: it wakes on any move of the head's CI digest (the same bucket-plus-sorted-name/conclusion signature the blocked fingerprint records — [`blocked-tick.md`](blocked-tick.md)) away from `BLOCKED_CIDIGEST`, so a block waiting on a green pass, a rerun, or an external deploy check resumes as promptly as one waiting on red. Quiet iterations print nothing and cost nothing — no model tokens are spent while the watch is quiet.
40
40
 
41
+ Each poll also rewrites the slot's `watch-due.env` whenever the due work changes — the rebase key found due and the head whose checks settled red, or an empty file when neither — so the session's turn-end gate can see work the watch reported without a provider call ([`state-schemas.md`](state-schemas.md#watch-dueenv)).
42
+
41
43
  The loop is **self-terminating**, so it never becomes one of those orphans. It claims the slot's `watch.pid`, then checks the guards from [`../../scripts/pr-watch-guards.sh`](../../scripts/pr-watch-guards.sh) at the top of every iteration before any `gh` call: `watcher_superseded` steps it down when a newer arm takes the slot; `watcher_window_elapsed` ends it one poll inside its monitor's timeout, printing a `ROLLOVER` line so the owning session re-arms; and `watcher_lifetime_exceeded` retires an orphan nothing supersedes. Every wait, a fetch backoff included, is clamped to the window, so no sleep carries the loop past its monitor. A failed fetch is never mistaken for a terminal PR — it counts toward `MUGGLE_PR_WATCH_MAX_FETCH_FAILURES` (60) with `watcher_fetch_backoff` between tries, so hours of outage are ridden out and the error lands in `<slot>/watch-fetch.log`. Terminal exit stays reserved for an observed `MERGED`/`CLOSED`.
42
44
 
43
45
  The lifetime cap comes from the [`watcherLifetime`](../muggle-preferences/preference-gates/watcherLifetime.md) preference — `7d` by default, `1d`, or `never` for unbounded. The loop cannot read preferences, so resolve the value at arm time, convert it to seconds, and export `MUGGLE_PR_WATCH_MAX_LIFETIME` into the monitor's environment; an already-set value wins and is never overwritten. `never` exports 0, which the guard reads as unbounded. Under a monitor the window ends each loop long before either cap, so it is the window, not this value, that retires a loop once its session is gone — within about 29 minutes. The lifetime bounds a loop run with the window disabled (`MUGGLE_PR_WATCH_MONITOR_WINDOW=0`).
@@ -45,7 +47,7 @@ Read the `DRAIN` lines it prints: they are the outstanding work the monitor will
45
47
  So it exits when the PR goes terminal, after `MUGGLE_PR_WATCH_MAX_FETCH_FAILURES` consecutive failed fetches, when a newer arm supersedes it, when its monitor window elapses, or once it passes the lifetime cap — never `while true` unbounded.
46
48
  4. **On event.** Polling never enters the session: the cadence lives entirely in the detached monitor loop (step 3), and the only thing the session ever receives is the monitor's one event line. That line wakes the session: the wake turn runs the tick (step 1) with `--wake=<event>` — the flag that tells routing's live-watcher gate this poll was prompted, not idle curiosity ([`SKILL.md`](SKILL.md#routing)) — and whatever cycle the tick produces runs **inline in the owning session** — never in a subagent. The session's full history is part of the cycle's context (decisions, review nuance, owner phrasing); a subagent only knows its briefing plus disk/provider state, and anything the briefing omits is silently missing from the cycle. The token cost of inline cycles is accepted — context beats cost. The tick still derives everything from live provider state; a terminal PR finalizes there while the monitor exits on its own. Persistent fetch failure → surface the reason; [`reconcile.md`](reconcile.md) re-arms the slot at the next start of the session that owns it.
47
49
 
48
- A `ROLLOVER` line is not an event to tick on: re-run [`pr-watch-arm.sh`](../../scripts/pr-watch-arm.sh) for the slot as a new monitor, without Step 3's dedup. Its `DRAIN` lines cover anything that landed between the old loop's last poll and the new one's first. Answer a monitor expiry notice for the slot the same way — it should not occur, since the window closes first, but if it does the loop is unheard and must be replaced.
50
+ A `ROLLOVER` line is not an event to tick on: re-run [`pr-watch-arm.sh`](../../scripts/pr-watch-arm.sh) for the slot as a new monitor, without Step 3's dedup. Its `DRAIN` lines cover anything that landed between the old loop's last poll and the new one's first, and work still unattempted wakes the new loop again — a rollover is not a reprieve. Answer a monitor expiry notice for the slot the same way — it should not occur, since the window closes first, but if it does the loop is unheard and must be replaced.
49
51
 
50
52
  **After a cycle** — advance the watermark to the **handled wave's snapshot**, in the same dispatched context that ran the cycle. Capture the max review-id and comment-id **at the start of handling** — the ids the cycle actually read when it derived the wave, before any reply is posted — and advance the watermark to exactly those. **Never** re-derive it from a live-max fetched after the replies land: a reviewer comment that arrives during the handling window — between reading the wave and posting the replies — lands below that post-reply max and is marked seen without ever being read. Snapshotting at the start-of-handling read keeps such a comment above the watermark, so the next tick surfaces it. That advance is also what stops the loop from reporting its own reply; a cycle that skips it leaves the watermark stale, and the next event is an echo.
51
53
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  The watcher's conditional path for a PR **blocked pending a human** — a durable block only the user can clear (an escalated rebase or CI budget spent, or an ambiguous review awaiting direction). Entered from [`contract.md`](contract.md) Step 7 (flag), then driven on each subsequent tick by Step 2.5 (resume gate). None of this runs on a normal tick: when `last_seen.blocked` is absent, the watcher skips straight through.
4
4
 
5
+ A block is entered only on a `block-*` verdict from the Step 6 verdict script. An escalation entry no cycle attempted is not a block — the verdict dispatches the work instead — and neither is the cost of running it.
6
+
5
7
  **Governing rule — one reminder per block, and the watch never stops.** The tick that flags the block reminds the owner once; every later blocked tick is silent. The watch keeps standing — the monitor stays visible, and ticks still run at their normal cadence (historically `1m`) whenever a wake or recovery cron fires — with fingerprint-based auto-resume clearing the block the moment external state moves. No repeat nagging, no cadence swap, no separate `reminded` flag: `blocked` present means the reminder has already been sent.
6
8
 
7
9
  ## The fingerprint
@@ -103,23 +103,48 @@ The watcher does **not** classify. Classification, batching, replying, escalatio
103
103
  5. Emit a `tick` event with `actionable_threads: <count>`, `dispatched_review_ids: [<id>, ...]`.
104
104
  6. Exit. **Reviews preempt CI** — when there is actionable feedback, this tick dispatches address-reviews and never polls CI. The watcher is now stopped; the dev cycle owns the PR and restarts the watcher when it finishes. (The watcher also self-unschedules in Step 2, terminal.)
105
105
 
106
- ### Step 5 — No actionable feedback → keep the branch rebased on its base
106
+ ### Step 5 — No actionable feedback → read the branch's standing against its base
107
107
 
108
- A merge-ready branch is **current with its base** — neither conflicting nor behind. From the Step 1 metadata, the branch needs a rebase when either:
108
+ A merge-ready branch is **current with its base** — neither conflicting nor behind. From the Step 1 metadata, the branch needs a rebase (`rebase_due`) when either:
109
109
 
110
110
  - the branch **conflicts** with its base — the provider's conflict signal per [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md), **or**
111
111
  - `behind_by > 0` — out of date with the base. Read this from the `compare` call (commit ancestry), **never** from `mergeStateStatus == BEHIND`: GitHub masks `BEHIND` behind `DIRTY`/`BLOCKED` and only surfaces it under "require branches up to date" protection, so a stale PR that is also awaiting review or has a red required check reports `BLOCKED` — and its staleness would go unseen. The compare recipe for this — and each provider's conflict signal — is dispatched in [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md).
112
112
 
113
+ `mergeable == UNKNOWN` with `behind_by == 0` is not due; `behind_by` is exact while GitHub is still computing conflict state, so a stale branch still counts.
114
+
113
115
  This trigger is **independent of approval and CI state**: an out-of-date branch is rebased whether or not it has been reviewed, approved, or has green checks. The watcher acts on staleness directly — it never waits for an approval to surface it.
114
116
 
115
117
  Rebase dedup is keyed on the **pair** `rebase_key = "<head_sha>..<base_tip_sha>"`, not on the head alone. Whether a branch conflicts is a function of both sides, so a head-only key wedges a PR permanently the first time the base moves: the head cannot change while nobody pushes, so one stale entry suppresses every genuinely new conflict that base movement introduces, forever. Take `base_tip_sha` from the Step 1 compare's `.base_commit.sha` (the base branch tip, which advances when the base does) — **never** `.merge_base_commit.sha`, which does not move when only the base advances and so would never re-arm.
116
118
 
117
- Entries written by an older watcher are bare head SHAs with no `..` — ignore them when reading `conflict_escalated_keys`, which re-arms any slot a head-only key had wedged.
119
+ Entries written by an older watcher are bare head SHAs with no `..`; the Step 6 verdict script ignores them, which re-arms any slot a head-only key had wedged.
118
120
 
119
121
  `conflict_resolve_attempts` bounds one key, never the PR. Because `rebase_key` carries the base tip, every advance of the base mints a fresh key and hands the branch a fresh pair of attempts, so on an active base that budget can never stop anything. The per-PR budget is the one that binds: `last_seen.catch_up_rebases` counts every rebase this PR has been dispatched for, no key resets it, and [`../muggle-preferences/preference-gates/maxCatchUpRebases.md`](../muggle-preferences/preference-gates/maxCatchUpRebases.md) caps it at 20 by default.
120
122
 
121
- If a rebase is due **and** `catch_up_rebases < maxCatchUpRebases` **and** `conflict_resolve_attempts[rebase_key] < 2` **and** `rebase_key` ∉ `conflict_escalated_keys` → dispatch and exit:
123
+ ### Step 6 — Poll CI for the head SHA, then take the verdict
124
+
125
+ Fetch the CI rollup for `prs.json[0].head_sha` per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md), provider resolved as in Step 3, and fold it into its bucket: `red`, `pending`, or `green` (green includes skipped checks and no checks).
126
+
127
+ Then run the verdict script. It is the **only** place this tick decides between dispatching and holding — never re-derive the decision from `last_seen.json` by reading it yourself. `<abs>` resolves from `${CLAUDE_PLUGIN_ROOT}/scripts/` as in [`arm-watcher.md`](arm-watcher.md); a slot with no `last_seen.json` feeds `/dev/null` instead:
128
+
129
+ ```sh
130
+ node "<abs>/scripts/pr-watch-verdict.mjs" tick --pr-key "<owner>/<repo>#<n>" --head <head_sha> \
131
+ --rebase-key "<head_sha>..<base_tip_sha>" --rebase-due <yes|no> --ci <red|pending|green> < "<slot>/last_seen.json"
132
+ ```
133
+
134
+ It prints one line, `VERDICT=<verdict>`. A non-zero exit is a broken install: report it and stop, never improvise a verdict. What it applies, in order:
135
+
136
+ 1. A rebase is due and `catch_up_rebases >= maxCatchUpRebases` (the cap from the user's preferences; the `rebase_budget_exhausted` flag is not consulted) → `block-rebase-budget-exhausted`.
137
+ 2. A rebase is due, `conflict_resolve_attempts[rebase_key] < 2`, and `rebase_key` ∉ `conflict_escalated_keys` → `dispatch-rebase`. With the per-key budget spent — `conflict_resolve_attempts[rebase_key] >= 2` or `rebase_key` ∈ `conflict_escalated_keys` — it falls through to CI.
138
+ 3. CI is `red`, `ci_fix_attempts[head_sha] < 3`, and `head_sha` ∉ `ci_escalated_shas` → `dispatch-fix-ci`. Red with `ci_fix_attempts[head_sha] >= 3` or `head_sha` ∈ `ci_escalated_shas` dispatches nothing — the fix budget is spent and the watcher does not re-dispatch. A check still pending (`bucket == "pending"`) never dispatches: the tick idles until CI settles, and a green head idles too.
139
+ 4. Otherwise `block-conflict-escalated`, `block-ci-escalated`, or `block-reviews-escalated` when the matching escalation stands, else `idle`.
140
+
141
+ **An escalation counts only with an attempt behind it.** An entry in `conflict_escalated_keys` suppresses a rebase only when `conflict_resolve_attempts[rebase_key] >= 1`, and an entry in `ci_escalated_shas` suppresses fix-ci only when `ci_fix_attempts[head_sha] >= 1`: a cycle ran and gave up. An entry with no attempt is ignored, and the work dispatches. Those fields are the executor's record of what its cycles did — never write an escalation entry or an attempt counter by hand.
122
142
 
143
+ **The verdict is binding.** The watch exists to drive the PR to merge-ready, and `autoRebase=always` means rebase without asking. How long a CI run or an eval takes is never a reason to hold a dispatch, and neither is a guess that the work is not worth it. The only hold is the user's own: a message they typed containing `HOLD WATCH #<pr-number>` for this PR. Asking them is allowed; answering a wake with a question instead of the dispatch is not. A Stop gate holds the turn open while work the watch recorded as due has no attempt behind it ([`../../hooks/README.md`](../../hooks/README.md)).
144
+
145
+ Act on the verdict:
146
+
147
+ - `dispatch-rebase` → dispatch and exit:
123
148
  1. Reset `last_seen.idle_tick_count` to 0.
124
149
  2. **Stop this watcher (single-thread):** cancel its cron exactly as in Step 4 — `/muggle-do`'s rebase respawns it when the cycle is done.
125
150
  3. Dispatch `/muggle-do` with a *rebase* directive (PR URL + slug; no review ids, no check names):
@@ -128,21 +153,9 @@ If a rebase is due **and** `catch_up_rebases < maxCatchUpRebases` **and** `confl
128
153
  ```
129
154
  The executor rebases onto the base: a behind-only branch replays cleanly and force-pushes; a conflicting branch resolves behind the `autoResolveConflicts` gate. Both paths are `/muggle-do`'s — the watcher only decides *that* a rebase is due, never how.
130
155
  4. Append a dispatching line to `followup.log`; emit a `tick` event with `rebase_needed: true`, `dispatched_rebase: true`.
131
- 5. Exit. The dev cycle owns the PR; its respawn restarts the watcher, whose next tick re-checks the branch against its base on the new head — the rebase is its own verify loop, bounded by the per-SHA attempt budget.
132
-
133
- If a rebase is due **and** `catch_up_rebases >= maxCatchUpRebases` → the PR has spent its catch-up budget. Do **not** dispatch, and do **not** fall through quietly: set `last_seen.rebase_budget_exhausted` to `true`, block the watch with reason `rebase_budget_exhausted` (Step 7), and report the count, the cap and the preference key on the PR. Twenty rebases without converging is a branch its owner has to decide about — rebase it onto a different base, split it, or close it — and a watcher that merely stops leaves them to discover it days later.
134
-
135
- That block is the one reason a fingerprint move does not clear (Step 2.5): base movement is precisely what spent the budget, so resuming on it would restore the loop the cap exists to end. It clears when the owner raises `maxCatchUpRebases` or the PR goes terminal.
136
-
137
- Otherwise — `behind_by == 0` and not conflicting (`mergeable == UNKNOWN` is fine here: `behind_by` is exact while GitHub is still computing conflict state, so a stale branch still triggers), or the per-key budget is spent (`conflict_resolve_attempts[rebase_key] >= 2` or `rebase_key` ∈ `conflict_escalated_keys`) → fall through to CI.
138
-
139
- ### Step 6 — No actionable feedback, branch current → poll CI for the head SHA
140
-
141
- Fetch the CI rollup for `prs.json[0].head_sha` per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md), provider resolved as in Step 3 (failed/running/success fold into the same red/pending/green buckets). Then, on the bucket:
142
-
143
- - **Any check still pending** (`bucket == "pending"`) → idle (wait for checks to settle).
144
- - **All checks green / skipped, or no checks** → idle (green path).
145
- - **One or more checks red** (`bucket == "fail"`), **and** `ci_fix_attempts[head_sha] < 3`, **and** `head_sha` ∉ `ci_escalated_shas` → dispatch and exit:
156
+ 5. Exit. The dev cycle owns the PR; its respawn restarts the watcher, whose next tick re-checks the branch against its base on the new head — the rebase is its own verify loop, bounded by the per-key attempt budget.
157
+ - `block-rebase-budget-exhausted` → the PR has spent its catch-up budget. Do **not** dispatch, and do **not** fall through quietly: set `last_seen.rebase_budget_exhausted` to `true`, block the watch with reason `rebase_budget_exhausted` (Step 7), and report the count, the cap and the preference key on the PR. Twenty rebases without converging is a branch its owner has to decide about — rebase it onto a different base, split it, or close it — and a watcher that merely stops leaves them to discover it days later. That block is the one reason a fingerprint move does not clear (Step 2.5): base movement is precisely what spent the budget, so resuming on it would restore the loop the cap exists to end. It clears when the owner raises `maxCatchUpRebases` or the PR goes terminal.
158
+ - `dispatch-fix-ci` → dispatch and exit:
146
159
  1. Reset `last_seen.idle_tick_count` to 0.
147
160
  2. **Stop this watcher (single-thread):** cancel its cron exactly as in Step 4 — `/muggle-do`'s fix-ci respawns it when the cycle is done.
148
161
  3. Dispatch `/muggle-do` with a *fix-ci* directive carrying the PR URL, slug, and the red check names (no review ids):
@@ -151,17 +164,19 @@ Fetch the CI rollup for `prs.json[0].head_sha` per [`../_shared/vcs/common/ci-ro
151
164
  ```
152
165
  4. Append a dispatching line to `followup.log`; emit a `tick` event with `checks_red: <count>`, `dispatched_ci_fix: true`.
153
166
  5. Exit. The dev cycle owns the PR; its respawn restarts the watcher, whose next tick re-checks CI on the new head SHA — CI itself is the verify loop.
154
- - **One or more red, but `ci_fix_attempts[head_sha] >= 3` or `head_sha` ∈ `ci_escalated_shas`** → idle. The fix budget is spent; `/muggle-do`'s fix-ci stage already recorded the escalation. The watcher does not re-dispatch.
167
+ - `block-conflict-escalated`, `block-ci-escalated`, `block-reviews-escalated` → blocked pending a human (Step 7).
168
+ - `idle` → transient idle (Step 7).
155
169
 
156
170
  ### Step 7 — Idle (remind when blocked pending a human)
157
171
 
158
- Any idle branch (Steps 4–6 that did not dispatch). First classify **why** this tick idled. It is **blocked pending a human** when the head is under a durable block that only the user can clear:
172
+ Any tick that did not dispatch. The Step 6 verdict says **why** it idled. It is **blocked pending a human** on a `block-*` verdict, a durable block only the user can clear:
159
173
 
160
- - `rebase_key` ∈ `conflict_escalated_keys` — a rebase `/muggle-do` gave up on (a semantic conflict, or `autoResolveConflicts=never`), reason `conflict_escalated`. This block clears on its own when the base moves: the new `base_tip_sha` yields a key the set does not contain, and the branch re-arms for a fresh rebase attempt; or
161
- - `head_sha` ∈ `ci_escalated_shas` — CI the fix-ci stage gave up on, reason `ci_escalated`; or
162
- - `last_seen.escalated_review_ids` is non-empty with the actionable set empty — an ambiguous review awaiting the user's direction, reason `reviews_escalated`.
174
+ - `block-conflict-escalated` — a rebase `/muggle-do` attempted and gave up on (a semantic conflict, or `autoResolveConflicts=never`), reason `conflict_escalated`. This block clears on its own when the base moves: the new `base_tip_sha` yields a key the set does not contain, and the branch re-arms for a fresh rebase attempt;
175
+ - `block-ci-escalated` — CI the fix-ci stage attempted and gave up on, reason `ci_escalated`;
176
+ - `block-reviews-escalated` — an ambiguous review in `last_seen.escalated_review_ids` awaiting the user's direction, with the actionable set empty, reason `reviews_escalated`;
177
+ - `block-rebase-budget-exhausted` — reason `rebase_budget_exhausted` (Step 6).
163
178
 
164
- Everything else that idles is **transient** — green and waiting for the next review, CI still pending, or `mergeable == UNKNOWN` — and must keep the responsive `1m` cadence; those turn a state on their own and the watcher should catch it promptly.
179
+ `idle` is **transient** — green and waiting for the next review, CI still pending, or `mergeable == UNKNOWN` — and must keep the responsive `1m` cadence; those turn a state on their own and the watcher should catch it promptly.
165
180
 
166
181
  **Transient idle** (no durable block): unchanged — increment `last_seen.idle_tick_count`, append an idle line to `followup.log` per [`output-templates/watcher-log.md`](output-templates/watcher-log.md), emit a `tick` event with `idle: true`, `blocked: false`, `actionable_threads: 0`, `dispatched_review_ids: []`, `rebase_needed: <bool>`, `dispatched_rebase: false`, `checks_red: <count or 0>`, `dispatched_ci_fix: false`. Exit through Step 7.5. The next tick fires from the monitor ([`arm-watcher.md`](arm-watcher.md)).
167
182
 
@@ -95,6 +95,7 @@ Keyed by `"<owner>/<repo>#<n>"`. One key per PR in the slot.
95
95
  "pushed_shas": ["<sha>", ...],
96
96
  "ci_fix_attempts": { "<sha>": <int> },
97
97
  "ci_escalated_shas": ["<sha>", ...],
98
+ "ci_rerun_shas": ["<sha>", ...],
98
99
  "conflict_resolve_attempts": { "<head-sha>..<base-tip-sha>": <int> },
99
100
  "conflict_escalated_keys": ["<head-sha>..<base-tip-sha>", ...],
100
101
  "catch_up_rebases": <int>,
@@ -118,12 +119,15 @@ Keyed by `"<owner>/<repo>#<n>"`. One key per PR in the slot.
118
119
  - `cycles_completed`: incremented each time `/muggle-do` completes an address-reviews invocation (regardless of actionable/ambiguous/mixed).
119
120
  - `escalated_review_ids`: review ids classified as ambiguous by `/muggle-do`. The watcher excludes these from the actionable set (both body-only reviews and the threads they own) so the same ambiguous review is never re-dispatched.
120
121
  - `pushed_shas`: every SHA `/muggle-do` has pushed for this PR. Append-only. Used by the resolve-reminder stage to recognize threads addressed by the loop.
121
- - `ci_fix_attempts`: per-SHA count of fix-ci cycles `/muggle-do` has run. The watcher stops dispatching fix-ci for a SHA once its count reaches 3. Keyed by head SHA.
122
- - `ci_escalated_shas`: head SHAs whose CI the fix-ci stage gave up on (attempts exhausted or only out-of-scope checks). The watcher excludes these from CI dispatch so a hopeless SHA is never re-fixed.
123
- - `conflict_resolve_attempts`: count of rebase cycles `/muggle-do` has run (behind-only or conflicting — both rebase onto the base). The watcher stops dispatching once a key's count reaches 2. Keyed by `rebase_key` — `"<head_sha>..<base_tip_sha>"`, the head paired with the base branch tip it was measured against.
124
- - `conflict_escalated_keys`: `rebase_key`s whose rebase `/muggle-do` gave up on (attempts exhausted, or a conflict under `autoResolveConflicts=never`). The watcher excludes these from rebase dispatch so a hopeless pairing is never re-attempted.
122
+ - `ci_fix_attempts`: per-SHA count of fix-ci cycles `/muggle-do` has run, incremented when a cycle starts — so a cycle that only re-runs a noisy check, or escalates without a push, still counts. The watcher stops dispatching fix-ci for a SHA once its count reaches 3. Keyed by head SHA. A count of 1 or more is the only evidence that floors a red head at arm time or releases the turn-end gate.
123
+ - `ci_escalated_shas`: head SHAs whose CI the fix-ci stage gave up on (attempts exhausted, only out-of-scope checks, or a noisy check red again after its re-run). Suppresses CI dispatch **only while `ci_fix_attempts[sha] >= 1`**; an entry with no attempt behind it is ignored and fix-ci dispatches anyway.
124
+ - `ci_rerun_shas`: heads on which fix-ci already re-ran its non-deterministic checks once. A noisy check red again on a listed head escalates instead of re-running a second time.
125
+ - `conflict_resolve_attempts`: count of rebase cycles `/muggle-do` has run (behind-only or conflicting — both rebase onto the base), incremented when a cycle starts. The watcher stops dispatching once a key's count reaches 2. Keyed by `rebase_key` — `"<head_sha>..<base_tip_sha>"`, the head paired with the base branch tip it was measured against. A count of 1 or more is the only evidence that floors a stale branch at arm time or releases the turn-end gate.
126
+ - `conflict_escalated_keys`: `rebase_key`s whose rebase `/muggle-do` gave up on (attempts exhausted, or a conflict under `autoResolveConflicts=never`). Suppresses rebase dispatch **only while `conflict_resolve_attempts[key] >= 1`**; an entry with no attempt behind it is ignored and the rebase dispatches anyway.
125
127
  - `catch_up_rebases`: how many rebases this PR has been dispatched for across its whole life. A plain counter, deliberately unkeyed: the two fields above key on `rebase_key`, which changes on every base advance and so hands an active base an unlimited supply of fresh budgets. Nothing resets this one, which makes it the only cap that binds. Capped by [`../muggle-preferences/preference-gates/maxCatchUpRebases.md`](../muggle-preferences/preference-gates/maxCatchUpRebases.md) — 20 by default, `never` for unbounded. Incremented by the rebase cycle on every push, whatever the outcome.
126
- - `rebase_budget_exhausted`: set once `catch_up_rebases` reaches the cap. The watcher then stops dispatching rebases for the PR entirely and blocks with reason `rebase_budget_exhausted` rather than idling, so the owner is told the branch is waiting on them. Cleared by raising the preference.
128
+ - `rebase_budget_exhausted`: set by the tick once `catch_up_rebases` reaches the cap, recording why the watch blocks with reason `rebase_budget_exhausted`. The verdict judges exhaustion from the counter and the cap, never from this flag, so raising the preference resumes rebases at once.
129
+
130
+ The escalation sets and attempt counters are written by the `/muggle-do` cycles that ran, and only by them. The dispatch decision that reads them lives in [`../../scripts/pr-watch-verdict.mjs`](../../scripts/pr-watch-verdict.mjs) ([`contract.md`](contract.md) Step 6), not in prose.
127
131
 
128
132
  Both are keyed on the pair, not the head alone, because whether a branch conflicts depends on both sides. Under a head-only key, a base that moves produces a genuinely new conflict against an unchanged head — and the stale entry suppresses it permanently, because nothing can change the head while the branch sits blocked. Pairing re-arms the budget whenever either side moves. Legacy entries written before this change are bare SHAs with no `..`; readers ignore them, which un-wedges any slot they had blocked.
129
133
 
@@ -213,14 +217,24 @@ The watch loop's comparison floor — plain `KEY=VALUE` lines, one file per slot
213
217
  - `REV` — highest submitted-review id already handled
214
218
  - `COM` — highest thread-comment id already handled
215
219
  - `THREADS` — semicolon-joined ids of threads already known unresolved
216
- - `CIRED` — head SHA whose settled-red CI the drain already handled; empty when the checks are green, still pending, or unseen. The CI floor is a SHA rather than a monotonic id because the check rollup flips green↔red and resets on each push — keying on the head SHA fires the loop once per red head and re-arms on the next push ([`arm-watcher.md`](arm-watcher.md)).
217
- - `REBASED` — the `rebase_key` (`<head_sha>..<base_tip_sha>`) whose behind/conflicting state the drain already handled; empty when the branch is current with its base or unseen. Keyed on the pair, not a monotonic id, because staleness depends on both sides — the loop fires once per newly-due pair and re-arms when the head or the base moves. Same key [`contract.md`](contract.md) Step 5 dedups rebase dispatch on; the monitor only signals a due rebase, the tick applies the `conflict_resolve_attempts` budget.
220
+ - `CIRED` — head SHA whose settled-red CI a fix-ci cycle already attempted (`ci_fix_attempts[sha] >= 1`); empty when the checks are green, still pending, unseen, or red with no attempt — the last so the loop reports it. The CI floor is a SHA rather than a monotonic id because the check rollup flips green↔red and resets on each push — keying on the head SHA fires the loop once per red head and re-arms on the next push ([`arm-watcher.md`](arm-watcher.md)).
221
+ - `REBASED` — the `rebase_key` (`<head_sha>..<base_tip_sha>`) whose behind/conflicting state a rebase cycle already attempted (`conflict_resolve_attempts[key] >= 1`); empty when the branch is current with its base, unseen, or stale with no attempt. Keyed on the pair, not a monotonic id, because staleness depends on both sides — the loop fires once per newly-due pair and re-arms when the head or the base moves. Same key [`contract.md`](contract.md) Steps 5–6 dedup rebase dispatch on; the monitor only signals a due rebase, the tick's verdict applies the budgets.
218
222
  - `BLOCKED_CIDIGEST` — the head's `ci_digest` at the moment a block was flagged (the same signature `blocked.fingerprint.ci_digest` carries); empty whenever the watch is not blocked. Non-empty arms the loop's blocked-resume probe: while set, the loop wakes on any move of the live digest away from this value, so a block resumes on a green pass, a rerun, or an external deploy check — not only on red. Written by [`blocked-tick.md`](blocked-tick.md) when a block is flagged and cleared to empty when it resumes.
219
223
 
220
- Written whole-file by the orchestrating session — the review/comment/CI/rebase floors seeded at arm time (`REV`/`COM` to the **drain's own observed max**, `CIRED`/`REBASED` to what the drain handled) and advanced after every cycle to the **handled wave's snapshot** (the max review-id and comment-id the cycle read at the start of handling, captured before replies were posted); `BLOCKED_CIDIGEST` is set and cleared by the blocked-tick flag/resume path, and every arm re-seeds it from `last_seen.blocked.fingerprint.ci_digest` so a rollover or respawn keeps the resume probe live. **Never** derived from a fresh fetch taken after the drain or after replies land: a later fetch includes ids that arrived in the handling window and were never read, and marking them seen swallows them ([`arm-watcher.md`](arm-watcher.md)). The advance also never moves any floor past an unresolved thread the cycle left unaddressed. Read by the watch loop each iteration; the loop never writes it. A stale watermark makes the next reported event the loop's own reply.
224
+ Written whole-file by the orchestrating session — the review/comment/CI/rebase floors seeded at arm time (`REV`/`COM` to the **drain's own observed max**, `CIRED`/`REBASED` to the red head and stale key a cycle already attempted) and advanced after every cycle to the **handled wave's snapshot** (the max review-id and comment-id the cycle read at the start of handling, captured before replies were posted); `BLOCKED_CIDIGEST` is set and cleared by the blocked-tick flag/resume path, and every arm re-seeds it from `last_seen.blocked.fingerprint.ci_digest` so a rollover or respawn keeps the resume probe live. **Never** derived from a fresh fetch taken after the drain or after replies land: a later fetch includes ids that arrived in the handling window and were never read, and marking them seen swallows them ([`arm-watcher.md`](arm-watcher.md)). The advance also never moves any floor past an unresolved thread the cycle left unaddressed. Read by the watch loop each iteration; the loop never writes it. A stale watermark makes the next reported event the loop's own reply.
221
225
 
222
226
  **Never `source` this file, and quote or extract values.** `THREADS` holds bare semicolons: sourced unquoted, the shell splits the line at the first `;` and silently drops every id after it — the loop then re-reports known threads as new. The watch loop must extract values verbatim (e.g. `grep '^THREADS=' | cut -d= -f2- | tr -d '"\r'`), tolerating quotes and CRLF; writers should quote the value anyway.
223
227
 
228
+ ## `watch-due.env`
229
+
230
+ The work the watch last saw due on its PR, for the owning session's turn-end gate — plain `KEY="value"` lines, one file per slot:
231
+
232
+ - `HEAD` — the head SHA the observation was made on.
233
+ - `REBASE_DUE` — the `rebase_key` found behind or conflicting with the base; empty when the branch is current.
234
+ - `CI_RED_HEAD` — the head whose checks settled red; empty when CI is green or still pending.
235
+
236
+ The file is **empty** when nothing is due. Written by [`../../scripts/pr-watch-arm.sh`](../../scripts/pr-watch-arm.sh) from the drain's read and rewritten by the loop whenever what is due changes; the session never writes it. The follow-through Stop gate ([`../../hooks/README.md`](../../hooks/README.md)) blocks the turn end while a non-empty record in a slot this session owns names work with no matching attempt in `last_seen.json`: a `REBASE_DUE` key with no `conflict_resolve_attempts` entry (under `autoRebase=always`, budget left), or a `CI_RED_HEAD` with no `ci_fix_attempts` entry. A later tick's `prs.json` naming another head supersedes the record.
237
+
224
238
  ## `watch.pid`
225
239
 
226
240
  A single line: the process id of the watch loop that currently owns this slot. Written once by the loop itself on start (`echo "$$" > watch.pid`); read by two parties, never rewritten in place:
File without changes