@muggleai/works 5.27.0-staging.229 → 5.27.0-staging.231
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/{chunk-N7DYL5J4.js → chunk-F5KU5ZP2.js} +4 -4
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/plugin/.codex-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +1 -1
- package/dist/plugin/.cursor-plugin/plugin.json +1 -1
- package/dist/plugin/.mcp.json +1 -1
- package/dist/plugin/agents/visual-walkthrough-builder.md +2 -0
- package/dist/plugin/hooks/README.md +1 -0
- package/dist/plugin/hooks/codex-hooks.json +2 -2
- package/dist/plugin/hooks/hooks.json +1 -1
- package/dist/plugin/scripts/guardrail-walkthrough-rerun.sh +26 -0
- package/dist/plugin/scripts/guardrails.mjs +48 -8
- package/dist/plugin/scripts/pr-watch-arm.sh +16 -2
- package/dist/plugin/scripts/pr-watch-loop.sh +12 -2
- package/dist/plugin/scripts/pr-watch-verdict.mjs +4 -2
- package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -2
- package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +2 -1
- package/dist/release-manifest.json +3 -3
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-mcp.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.cursor-plugin/plugin.json +1 -1
- package/plugin/.mcp.json +1 -1
- package/plugin/agents/visual-walkthrough-builder.md +2 -0
- package/plugin/hooks/README.md +1 -0
- package/plugin/hooks/codex-hooks.json +2 -2
- package/plugin/hooks/hooks.json +1 -1
- package/plugin/scripts/guardrail-walkthrough-rerun.sh +26 -0
- package/plugin/scripts/guardrails.mjs +48 -8
- package/plugin/scripts/pr-watch-arm.sh +16 -2
- package/plugin/scripts/pr-watch-loop.sh +12 -2
- package/plugin/scripts/pr-watch-verdict.mjs +4 -2
- package/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -2
- package/plugin/skills/muggle-pr-followup/state-schemas.md +2 -1
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"name": "muggleai",
|
|
10
10
|
"source": "./plugin",
|
|
11
11
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
12
|
-
"version": "5.27.0-staging.
|
|
12
|
+
"version": "5.27.0-staging.231"
|
|
13
13
|
}
|
|
14
14
|
]
|
|
15
15
|
}
|
|
@@ -3292,11 +3292,11 @@ function createCheckRun(repo, checkRun, run) {
|
|
|
3292
3292
|
function commentWithStatus(comments, status) {
|
|
3293
3293
|
return comments.find((comment) => classifyComment(comment.body) === status);
|
|
3294
3294
|
}
|
|
3295
|
+
function designatedComment(comments) {
|
|
3296
|
+
return comments.find((comment) => classifyComment(comment.body) !== "not-designated" /* NotDesignated */);
|
|
3297
|
+
}
|
|
3295
3298
|
function reserveComment(pr, comments, run) {
|
|
3296
|
-
|
|
3297
|
-
(comment) => classifyComment(comment.body) !== "not-designated" /* NotDesignated */
|
|
3298
|
-
);
|
|
3299
|
-
if (claimed) return false;
|
|
3299
|
+
if (designatedComment(comments)) return false;
|
|
3300
3300
|
return postPrComment(pr, renderReservedComment(), run);
|
|
3301
3301
|
}
|
|
3302
3302
|
function settleDependencyBotComment(pr, comments, login, run) {
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-
|
|
1
|
+
export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-F5KU5ZP2.js';
|
|
2
2
|
export { createChildLogger, e2e_exports as e2e, getConfig, getLocalQaTools, getLogger, getQaTools, local_exports as localQa, mcp_exports as mcp, e2e_exports as qa, src_exports as shared } from './chunk-A3YLVNL7.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
4
|
-
"version": "5.27.0-staging.
|
|
4
|
+
"version": "5.27.0-staging.231",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
7
7
|
"email": "support@muggle-ai.com"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
|
-
"version": "5.27.0-staging.
|
|
3
|
+
"version": "5.27.0-staging.231",
|
|
4
4
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"displayName": "Muggle AI",
|
|
4
4
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
5
|
-
"version": "5.27.0-staging.
|
|
5
|
+
"version": "5.27.0-staging.231",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Muggle AI",
|
|
8
8
|
"email": "support@muggle-ai.com"
|
package/dist/plugin/.mcp.json
CHANGED
|
@@ -46,6 +46,8 @@ existing=$(gh api "repos/<owner>/<repo>/issues/<prNumber>/comments" \
|
|
|
46
46
|
|
|
47
47
|
Match only comments carrying one of those markers — never every comment the loop user wrote — so an unrelated reply is never overwritten.
|
|
48
48
|
|
|
49
|
+
While a run is in flight, the comment carries a "new E2E run in progress" banner above the previous run's walkthrough. The PATCH replaces the whole body, banner included; never carry the banner or the previous walkthrough into the new body.
|
|
50
|
+
|
|
49
51
|
Report back: PR URL, whether an overflow comment was involved, and whether this was a fresh post or an update.
|
|
50
52
|
|
|
51
53
|
**Modes B/C (`render-for-new-pr` / `embed`)** — do not post, do not touch `gh`. Return the CLI output verbatim as your report:
|
|
@@ -47,6 +47,7 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
|
|
|
47
47
|
| `PostToolUse` (Bash) | `guardrail-record-comment-replies.sh` | record | an unresolved-thread fetch named review threads still awaiting an answer (classified by the `<!-- muggle-do:bot -->` marker, never the author login), a threaded reply the provider **confirmed** answered comments in one, or a `MUGGLE_REPLY_SKIP` marker deferred them | — | claim each thread and cover the comments answered, in the per-PR ledger beside the muggle-do slot |
|
|
48
48
|
| `PreToolUse` (Bash, `if` a command names `gh`/`glab`) | `guardrail-report-format.sh` | **enforce** | a `gh pr comment\|create\|edit` body — or a `gh api … issues/comments/<id>` PATCH editing one — reads like an E2E report but lacks the `build-pr-section` sentinel | — | **deny** — render via `muggle build-pr-section` instead |
|
|
49
49
|
| `PreToolUse` (muggle local execute/replay) | `guardrail-classify-gate.sh` | **enforce** | `muggle-test` is the skill in play and the target test case has no `pre-execution-classification` this session | — | **deny** — run Step 6f first (it calls `muggle-remote-test-script-list`, which is where the run learns the case has never passed) or record a legitimate skip via `MUGGLE_CLASSIFY_SKIP`. Scoped to `muggle-test`, so the single-target skills that legitimately skip classification are untouched; fails open when the test case can't be resolved |
|
|
50
|
+
| `PreToolUse` (muggle local execute/replay) | `guardrail-walkthrough-rerun.sh` | record | a browser run is about to start in a working tree (the tool call's `cwd`) whose branch has a PR, and that PR's walkthrough comment already shows a run or a skip | — | a detached job puts a "new E2E run in progress" banner, with its UTC start time, on top of the walkthrough the run will replace. The comment underneath is untouched, so the walkthrough check judges it as before; the run's own walkthrough replaces the whole body, banner included. A reserved placeholder or a comment already bannered is left alone |
|
|
50
51
|
| `Stop` | `guardrail-e2e-gate.sh` | **enforce** | unit tests passed this session, no E2E ran yet, and no skip was recorded | `autoE2ETest` | **block** the turn until E2E runs via `muggle-test` or a `MUGGLE_E2E_SKIP` marker records a legitimate skip (full message once, one-line reminders after; releases after 3 blocks). Quiet while a background acceptance-tester is in flight |
|
|
51
52
|
| `Stop` | `guardrail-terminal-gate.sh` | **enforce** | a PR went terminal this session and the next-options offer hasn't run since — an AskUserQuestion, or, while the session owns an open PR's watch slot, a closing message that asks the user | — | **block** the turn until the post-merge handoff runs (full message once, one-line reminders after; releases after 3 blocks; nothing but the offer resets the counter) |
|
|
52
53
|
| `Stop` | `guardrail-watch-gate.sh` | **enforce** | a PR opened this session that is still open and has no live watch — no session slot for it is terminal, stopped by its owner, or carries a `watch-heartbeat` touched within 15 minutes; a slot that is only seeded does not count | `autoWatchPR` | **block** the turn until the watch is armed per `muggle-pr-followup`'s `arm-watcher.md` or a `MUGGLE_WATCH_SKIP` marker records a legitimate skip (releases after 3 blocks). A PR clears once the session sees it go terminal or a provider lookup reports it merged or closed — what lets a PR whose slot post-merge cleanup deleted through. The lookup runs in a detached scan queued at turn end; a PR it has not reached yet still blocks, and one it could not reach fails open |
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"hooks": [
|
|
41
41
|
{
|
|
42
42
|
"type": "command",
|
|
43
|
-
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-classify-gate.sh
|
|
43
|
+
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-classify-gate.sh guardrail-walkthrough-rerun.sh",
|
|
44
44
|
"async": false,
|
|
45
45
|
"timeout": 10,
|
|
46
|
-
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-classify-gate.sh
|
|
46
|
+
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-classify-gate.sh guardrail-walkthrough-rerun.sh"
|
|
47
47
|
}
|
|
48
48
|
]
|
|
49
49
|
}
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"hooks": [
|
|
59
59
|
{
|
|
60
60
|
"type": "command",
|
|
61
|
-
"command": "set -- guardrail-classify-gate.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
|
|
61
|
+
"command": "set -- guardrail-dispatch.sh guardrail-classify-gate.sh guardrail-walkthrough-rerun.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
|
|
62
62
|
"async": false,
|
|
63
63
|
"timeout": 1
|
|
64
64
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -uo pipefail
|
|
3
|
+
|
|
4
|
+
# Walkthrough rerun notice (PreToolUse/muggle local execution tools).
|
|
5
|
+
# A browser run about to start on a working tree whose branch has a PR will
|
|
6
|
+
# replace that PR's walkthrough, so the comment gets a banner saying a new run
|
|
7
|
+
# is in progress before the run starts — never a decision, always {}. The
|
|
8
|
+
# provider calls run in a detached job, keyed on the tree the tool call names.
|
|
9
|
+
#
|
|
10
|
+
# The pre-filter re-states the execution tool names, like the classify gate's,
|
|
11
|
+
# so an unrelated payload never pays Node cold-start. `[-_]` because Codex
|
|
12
|
+
# reports an MCP tool with underscores where the server spells hyphens.
|
|
13
|
+
|
|
14
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
15
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
16
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
17
|
+
|
|
18
|
+
GUARDRAIL_SUBCOMMAND="walkthrough-rerun-notice"
|
|
19
|
+
|
|
20
|
+
guardrail_wants() {
|
|
21
|
+
guardrail_payload_matches 'muggle[-_]local[-_](execute[-_]test[-_]generation|execute[-_]replay)'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if guardrail_is_hook_script; then
|
|
25
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
26
|
+
fi
|
|
@@ -265,6 +265,7 @@ var GuardrailBackgroundJob = /* @__PURE__ */ ((GuardrailBackgroundJob2) => {
|
|
|
265
265
|
GuardrailBackgroundJob2["SettleBranchWalkthroughSkipped"] = "settle-branch-walkthrough-skipped";
|
|
266
266
|
GuardrailBackgroundJob2["SettleWalkthroughUnreasoned"] = "settle-walkthrough-unreasoned";
|
|
267
267
|
GuardrailBackgroundJob2["SettleWalkthroughNoAppLogicChange"] = "settle-walkthrough-no-app-logic-change";
|
|
268
|
+
GuardrailBackgroundJob2["NoteWalkthroughRerun"] = "note-walkthrough-rerun";
|
|
268
269
|
GuardrailBackgroundJob2["ScanWatchPrStates"] = "scan-watch-pr-states";
|
|
269
270
|
GuardrailBackgroundJob2["CommitDeferredState"] = "commit-deferred-state";
|
|
270
271
|
return GuardrailBackgroundJob2;
|
|
@@ -613,6 +614,9 @@ var WALKTHROUGH_SKIPPED_MARKER = "<!-- muggle-pr-walkthrough-status:skipped -->"
|
|
|
613
614
|
var WALKTHROUGH_COMMENT_HEADING = "### Muggle AI \u2014 PR visual walkthrough";
|
|
614
615
|
var REPORT_SENTINEL_TAG = new RegExp(`<!--\\s*${REPORT_SENTINEL}[^>]*-->\\s*`, "g");
|
|
615
616
|
var LAST_FULL_RUN_OPENING = "<details><summary>Last full E2E run on this PR</summary>";
|
|
617
|
+
var RERUN_NOTICE_OPENING = "<!-- muggle-pr-walkthrough-rerun -->";
|
|
618
|
+
var RERUN_NOTICE_CLOSING = "<!-- /muggle-pr-walkthrough-rerun -->";
|
|
619
|
+
var RERUN_NOTICE_BLOCK = new RegExp(`${RERUN_NOTICE_OPENING}[\\s\\S]*?${RERUN_NOTICE_CLOSING}\\s*`, "g");
|
|
616
620
|
var SHORT_SHA_LENGTH = 7;
|
|
617
621
|
var GH_COMMENT_TIMEOUT_MS = 1e4;
|
|
618
622
|
|
|
@@ -1772,12 +1776,28 @@ ${headline} Muggle verified \`${"NO_APP_LOGIC_CHANGE" /* NoAppLogicChange */}\`
|
|
|
1772
1776
|
}
|
|
1773
1777
|
function lastFullRunOf(body) {
|
|
1774
1778
|
const status = classifyComment(body);
|
|
1775
|
-
if (status === "reported" /* Reported */)
|
|
1779
|
+
if (status === "reported" /* Reported */) {
|
|
1780
|
+
return withoutRerunNotice(body).replace(REPORT_SENTINEL_TAG, "").trim();
|
|
1781
|
+
}
|
|
1776
1782
|
if (status !== "skipped" /* Skipped */) return null;
|
|
1777
1783
|
const start = body.indexOf(LAST_FULL_RUN_OPENING);
|
|
1778
1784
|
if (start === -1) return null;
|
|
1779
1785
|
return body.slice(start + LAST_FULL_RUN_OPENING.length).replace(/\s*<\/details>\s*$/, "").trim();
|
|
1780
1786
|
}
|
|
1787
|
+
var formatUtcMinute = (date) => `${date.toISOString().slice(0, 16).replace("T", " ")} UTC`;
|
|
1788
|
+
function hasRerunNotice(body) {
|
|
1789
|
+
return body.includes(RERUN_NOTICE_OPENING);
|
|
1790
|
+
}
|
|
1791
|
+
function withoutRerunNotice(body) {
|
|
1792
|
+
return body.replace(RERUN_NOTICE_BLOCK, "");
|
|
1793
|
+
}
|
|
1794
|
+
function withRerunNotice(body, startedAt) {
|
|
1795
|
+
return `${RERUN_NOTICE_OPENING}
|
|
1796
|
+
> **A new E2E run is in progress** \u2014 started ${formatUtcMinute(startedAt)}. The results below are from the previous run; this comment updates when the new run finishes.
|
|
1797
|
+
${RERUN_NOTICE_CLOSING}
|
|
1798
|
+
|
|
1799
|
+
` + withoutRerunNotice(body);
|
|
1800
|
+
}
|
|
1781
1801
|
function classifyComment(body) {
|
|
1782
1802
|
if (body.includes(REPORT_SENTINEL)) return "reported" /* Reported */;
|
|
1783
1803
|
if (!body.includes(WALKTHROUGH_SLOT_MARKER)) return "not-designated" /* NotDesignated */;
|
|
@@ -1797,11 +1817,11 @@ function walkthroughVerdict(bodies) {
|
|
|
1797
1817
|
function commentWithStatus(comments, status) {
|
|
1798
1818
|
return comments.find((comment) => classifyComment(comment.body) === status);
|
|
1799
1819
|
}
|
|
1820
|
+
function designatedComment(comments) {
|
|
1821
|
+
return comments.find((comment) => classifyComment(comment.body) !== "not-designated" /* NotDesignated */);
|
|
1822
|
+
}
|
|
1800
1823
|
function reserveComment(pr, comments, run) {
|
|
1801
|
-
|
|
1802
|
-
(comment) => classifyComment(comment.body) !== "not-designated" /* NotDesignated */
|
|
1803
|
-
);
|
|
1804
|
-
if (claimed) return false;
|
|
1824
|
+
if (designatedComment(comments)) return false;
|
|
1805
1825
|
return postPrComment(pr, renderReservedComment(), run);
|
|
1806
1826
|
}
|
|
1807
1827
|
function reserveWalkthroughComment(prUrl, run = defaultGhRunner) {
|
|
@@ -1837,13 +1857,22 @@ function settleWalkthroughCommentForNoAppLogicChange(prUrl, detail, run = defaul
|
|
|
1837
1857
|
if (!pr || !declared) return false;
|
|
1838
1858
|
const comments = listPrComments(pr, run);
|
|
1839
1859
|
if (comments === null) return false;
|
|
1840
|
-
const designated = comments
|
|
1841
|
-
(comment) => classifyComment(comment.body) !== "not-designated" /* NotDesignated */
|
|
1842
|
-
);
|
|
1860
|
+
const designated = designatedComment(comments);
|
|
1843
1861
|
const lastFullRun = designated ? lastFullRunOf(designated.body) : null;
|
|
1844
1862
|
const body = renderNoAppLogicChangeComment(declared, readPrHeadSha(pr, run), lastFullRun);
|
|
1845
1863
|
return designated ? patchPrComment(pr, designated.id, body, run) : postPrComment(pr, body, run);
|
|
1846
1864
|
}
|
|
1865
|
+
function noteWalkthroughRerunStarted(prUrl, run = defaultGhRunner, startedAt = /* @__PURE__ */ new Date()) {
|
|
1866
|
+
const pr = parsePrUrl(prUrl);
|
|
1867
|
+
if (!pr) return false;
|
|
1868
|
+
const comments = listPrComments(pr, run);
|
|
1869
|
+
if (comments === null) return false;
|
|
1870
|
+
const designated = designatedComment(comments);
|
|
1871
|
+
if (!designated) return false;
|
|
1872
|
+
if (classifyComment(designated.body) === "pending" /* Pending */) return false;
|
|
1873
|
+
if (hasRerunNotice(designated.body)) return false;
|
|
1874
|
+
return patchPrComment(pr, designated.id, withRerunNotice(designated.body, startedAt), run);
|
|
1875
|
+
}
|
|
1847
1876
|
function settleWalkthroughCommentAsUnreasoned(prUrl, run = defaultGhRunner) {
|
|
1848
1877
|
return settleWith(prUrl, renderUnreasonedSkipComment(), run);
|
|
1849
1878
|
}
|
|
@@ -2580,6 +2609,10 @@ function classifyGate() {
|
|
|
2580
2609
|
const reason = `Test case ${decision.testCaseId} has no pre-execution classification this session. Run muggle-test Step 6f for it first: classify replay-vs-regen per _shared/failure-mode-handling.md \xA7A, then emit one muggle-local-telemetry-event-emit with eventType "pre-execution-classification" for this test case. That step is what calls muggle-remote-test-script-list, which is the only place this run learns the test case has never passed or has failed repeatedly \u2014 cheap now, ~5 minutes of browser time to rediscover after the fact. If this execution genuinely has no classification step (a single user-picked target), say why and run \`echo "MUGGLE_CLASSIFY_SKIP: <reason>"\` \u2014 that records the skip for the rest of the session.`;
|
|
2581
2610
|
return denyTool(reason, host);
|
|
2582
2611
|
}
|
|
2612
|
+
function walkthroughRerunNotice() {
|
|
2613
|
+
startBackgroundJob("note-walkthrough-rerun" /* NoteWalkthroughRerun */, [], input.tool_input?.cwd ?? input.cwd);
|
|
2614
|
+
return "{}";
|
|
2615
|
+
}
|
|
2583
2616
|
function stageGate() {
|
|
2584
2617
|
const state = readState(sessionId);
|
|
2585
2618
|
const decision = stageGateDecision(state, unreadMandatoryStages(state));
|
|
@@ -2857,6 +2890,7 @@ var handlers = {
|
|
|
2857
2890
|
"record-stage-read": recordStageRead,
|
|
2858
2891
|
"record-stage-signals": recordStageSignals,
|
|
2859
2892
|
"classify-gate": classifyGate,
|
|
2893
|
+
"walkthrough-rerun-notice": walkthroughRerunNotice,
|
|
2860
2894
|
"stage-gate": stageGate,
|
|
2861
2895
|
"debug-path-gate": debugPathGate
|
|
2862
2896
|
};
|
|
@@ -2906,6 +2940,11 @@ function settleWalkthroughNoAppLogicChangeJob() {
|
|
|
2906
2940
|
if (prUrl && detail) settleWalkthroughCommentForNoAppLogicChange(prUrl, detail);
|
|
2907
2941
|
return "{}";
|
|
2908
2942
|
}
|
|
2943
|
+
function noteWalkthroughRerunJob() {
|
|
2944
|
+
const prUrl = defaultPrWalkthroughLookup.branchPrUrl();
|
|
2945
|
+
if (prUrl) noteWalkthroughRerunStarted(prUrl);
|
|
2946
|
+
return "{}";
|
|
2947
|
+
}
|
|
2909
2948
|
function scanWatchPrStatesJob() {
|
|
2910
2949
|
const scannedSessionId = jobArgs[0] ?? "unknown";
|
|
2911
2950
|
const state = readState(scannedSessionId);
|
|
@@ -2927,6 +2966,7 @@ var backgroundJobs = {
|
|
|
2927
2966
|
["settle-branch-walkthrough-skipped" /* SettleBranchWalkthroughSkipped */]: settleBranchWalkthroughSkippedJob,
|
|
2928
2967
|
["settle-walkthrough-unreasoned" /* SettleWalkthroughUnreasoned */]: settleWalkthroughUnreasonedJob,
|
|
2929
2968
|
["settle-walkthrough-no-app-logic-change" /* SettleWalkthroughNoAppLogicChange */]: settleWalkthroughNoAppLogicChangeJob,
|
|
2969
|
+
["note-walkthrough-rerun" /* NoteWalkthroughRerun */]: noteWalkthroughRerunJob,
|
|
2930
2970
|
["scan-watch-pr-states" /* ScanWatchPrStates */]: scanWatchPrStatesJob,
|
|
2931
2971
|
["commit-deferred-state" /* CommitDeferredState */]: commitDeferredStateJob
|
|
2932
2972
|
};
|
|
@@ -106,12 +106,14 @@ last_seen_file="${slot}/last_seen.json"
|
|
|
106
106
|
rebase_attempted=0
|
|
107
107
|
ci_attempted=0
|
|
108
108
|
blocked_digest_floor=""
|
|
109
|
+
rebase_budget_exhausted=0
|
|
109
110
|
while IFS= read -r evidence_line; do
|
|
110
111
|
evidence_line="${evidence_line%$'\r'}"
|
|
111
112
|
case "$evidence_line" in
|
|
112
113
|
REBASE_ATTEMPTED=*) rebase_attempted="${evidence_line#REBASE_ATTEMPTED=}" ;;
|
|
113
114
|
CI_ATTEMPTED=*) ci_attempted="${evidence_line#CI_ATTEMPTED=}" ;;
|
|
114
115
|
BLOCKED_CIDIGEST=*) blocked_digest_floor="${evidence_line#BLOCKED_CIDIGEST=}" ;;
|
|
116
|
+
REBASE_BUDGET_EXHAUSTED=*) rebase_budget_exhausted="${evidence_line#REBASE_BUDGET_EXHAUSTED=}" ;;
|
|
115
117
|
esac
|
|
116
118
|
done < <(node "${script_dir}/pr-watch-verdict.mjs" arm-floors --pr-key "${repo}#${pr_number}" \
|
|
117
119
|
--head "$head_sha" --rebase-key "$rebase_key" < "$last_seen_file" 2>/dev/null)
|
|
@@ -121,6 +123,15 @@ ci_red_floor=""
|
|
|
121
123
|
rebase_floor=""
|
|
122
124
|
[ -n "$rebase_due_key" ] && [ "$rebase_attempted" = "1" ] && rebase_floor="$rebase_due_key"
|
|
123
125
|
|
|
126
|
+
# A PR that spent its catch-up rebase budget is held for its owner whether or not
|
|
127
|
+
# the branch is stale yet: the tick refuses every rebase until maxCatchUpRebases
|
|
128
|
+
# is raised, so announcing one — here or on the loop's next base move — only asks
|
|
129
|
+
# the session for work the verdict turns down. The next arm reads a raised cap.
|
|
130
|
+
rebase_held=""
|
|
131
|
+
[ "$rebase_budget_exhausted" = "1" ] && rebase_held="1"
|
|
132
|
+
recorded_rebase_due_key="$rebase_due_key"
|
|
133
|
+
[ -n "$rebase_held" ] && recorded_rebase_due_key=""
|
|
134
|
+
|
|
124
135
|
thread_count=0
|
|
125
136
|
[ -n "$unresolved_threads" ] && thread_count=$(printf '%s' "$unresolved_threads" | tr ';' '\n' | grep -c .)
|
|
126
137
|
|
|
@@ -138,7 +149,9 @@ if [ -n "$ci_red_head" ]; then
|
|
|
138
149
|
fi
|
|
139
150
|
fi
|
|
140
151
|
if [ -n "$rebase_due_key" ]; then
|
|
141
|
-
if [ -n "$
|
|
152
|
+
if [ -n "$rebase_held" ]; then
|
|
153
|
+
echo "DRAIN branch stale at arm time — catch-up rebase budget spent (maxCatchUpRebases), held for the owner: no rebase to dispatch"
|
|
154
|
+
elif [ -n "$rebase_floor" ]; then
|
|
142
155
|
echo "DRAIN branch stale at arm time — a rebase already ran for key ${rebase_due_key}, floored"
|
|
143
156
|
else
|
|
144
157
|
echo "DRAIN branch stale at arm time — no rebase attempt recorded for key ${rebase_due_key}, not floored: dispatch rebase"
|
|
@@ -152,9 +165,10 @@ fi
|
|
|
152
165
|
printf 'CIRED="%s"\n' "$ci_red_floor"
|
|
153
166
|
printf 'REBASED="%s"\n' "$rebase_floor"
|
|
154
167
|
printf 'BLOCKED_CIDIGEST="%s"\n' "$blocked_digest_floor"
|
|
168
|
+
printf 'REBASE_HELD="%s"\n' "$rebase_held"
|
|
155
169
|
} > "${slot}/watch-watermark.env"
|
|
156
170
|
|
|
157
|
-
watch_record_due_work "$slot" "$head_sha" "$
|
|
171
|
+
watch_record_due_work "$slot" "$head_sha" "$recorded_rebase_due_key" "$ci_red_head"
|
|
158
172
|
|
|
159
173
|
# Claim the slot for this session. watcher_lease_is_foreign reads an absent
|
|
160
174
|
# owner.json as "not foreign", so a slot armed without one leases itself to a
|
|
@@ -55,6 +55,10 @@ echo "$$" > "${slot}/watch.pid"
|
|
|
55
55
|
started=$(date +%s)
|
|
56
56
|
fails=0
|
|
57
57
|
unseeded=0
|
|
58
|
+
# Set once the first iteration has run. Until then the window cannot roll the
|
|
59
|
+
# loop over, so a start-up slow enough to spend the whole window still gets one
|
|
60
|
+
# look at the PR rather than handing back a watch that never polled.
|
|
61
|
+
has_iterated=""
|
|
58
62
|
|
|
59
63
|
# In-memory floors, above the on-disk watermark. The watermark is advanced by
|
|
60
64
|
# the session after it handles a wave; these stop the loop re-reporting an event
|
|
@@ -105,10 +109,11 @@ while :; do
|
|
|
105
109
|
# the line is the owning session's cue to re-arm, and ending here is what
|
|
106
110
|
# frees the lease that re-arm needs. A loop that ran on past its monitor would
|
|
107
111
|
# keep that lease and heartbeat fresh while reporting to no one.
|
|
108
|
-
if watcher_window_elapsed "$started" "$(date +%s)"; then
|
|
112
|
+
if [ -n "$has_iterated" ] && watcher_window_elapsed "$started" "$(date +%s)"; then
|
|
109
113
|
echo "ROLLOVER pr=$pr_number monitor window of ${MUGGLE_PR_WATCH_MONITOR_WINDOW}s elapsed — re-arm to keep watching"
|
|
110
114
|
exit 0
|
|
111
115
|
fi
|
|
116
|
+
has_iterated=1
|
|
112
117
|
touch "${slot}/watch-heartbeat" 2>/dev/null
|
|
113
118
|
|
|
114
119
|
# No watermark yet means the arming session has not finished seeding. Wait
|
|
@@ -137,6 +142,7 @@ while :; do
|
|
|
137
142
|
watermark_ci_red=$(read_watermark_value CIRED)
|
|
138
143
|
watermark_rebase=$(read_watermark_value REBASED)
|
|
139
144
|
watermark_blocked_digest=$(read_watermark_value BLOCKED_CIDIGEST)
|
|
145
|
+
watermark_rebase_held=$(read_watermark_value REBASE_HELD)
|
|
140
146
|
|
|
141
147
|
state_line=$(watch_fetch_state "$repo" "$pr_number" "$slot" "$state_projection")
|
|
142
148
|
# One quick retry before counting a strike: a single flaky call should not
|
|
@@ -207,7 +213,11 @@ while :; do
|
|
|
207
213
|
fi
|
|
208
214
|
|
|
209
215
|
rebase_key="${head_sha}..${base_tip_sha}"
|
|
210
|
-
if [ "$
|
|
216
|
+
if [ "$watermark_rebase_held" = "1" ]; then
|
|
217
|
+
# The PR spent its catch-up rebase budget: however far the base moves, the
|
|
218
|
+
# tick refuses the rebase a wake would ask for, so nothing is due either.
|
|
219
|
+
due_rebase_key=""
|
|
220
|
+
elif [ "$rebase_key" = "$watermark_rebase" ] || [ "$rebase_key" = "$floor_rebase" ]; then
|
|
211
221
|
# Only a key already found due is ever floored, and the pair's standing
|
|
212
222
|
# cannot change until the head or the base moves, which mints a new key.
|
|
213
223
|
due_rebase_key="$rebase_key"
|
|
@@ -54,11 +54,12 @@ function isRebaseBudgetExhausted(lastSeenEntry, maxCatchUpRebases) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// src/pr-watch/armFloors.ts
|
|
57
|
-
function resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey) {
|
|
57
|
+
function resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey, maxCatchUpRebases) {
|
|
58
58
|
const blockedCiDigest = lastSeenEntry.blocked?.fingerprint?.ci_digest;
|
|
59
59
|
return {
|
|
60
60
|
isRebaseKeyAttempted: rebaseKey !== "" && isRebaseKeyAttempted(lastSeenEntry, rebaseKey),
|
|
61
61
|
isCiHeadAttempted: headSha !== "" && isCiHeadAttempted(lastSeenEntry, headSha),
|
|
62
|
+
isRebaseBudgetExhausted: isRebaseBudgetExhausted(lastSeenEntry, maxCatchUpRebases),
|
|
62
63
|
blockedCiDigest: typeof blockedCiDigest === "string" && !LINE_BREAK.test(blockedCiDigest) ? blockedCiDigest : ""
|
|
63
64
|
};
|
|
64
65
|
}
|
|
@@ -137,11 +138,12 @@ function runPrWatchVerdictCommand(commandLine, lastSeenJson, resolvePreferences)
|
|
|
137
138
|
const headSha = flags[HEAD_FLAG] ?? "";
|
|
138
139
|
const rebaseKey = flags[REBASE_KEY_FLAG] ?? "";
|
|
139
140
|
if (subcommand === "arm-floors" /* ArmFloors */) {
|
|
140
|
-
const evidence = resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey);
|
|
141
|
+
const evidence = resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey, resolvePreferences().maxCatchUpRebases);
|
|
141
142
|
return {
|
|
142
143
|
stdout: `REBASE_ATTEMPTED=${evidence.isRebaseKeyAttempted ? 1 : 0}
|
|
143
144
|
CI_ATTEMPTED=${evidence.isCiHeadAttempted ? 1 : 0}
|
|
144
145
|
BLOCKED_CIDIGEST=${evidence.blockedCiDigest}
|
|
146
|
+
REBASE_BUDGET_EXHAUSTED=${evidence.isRebaseBudgetExhausted ? 1 : 0}
|
|
145
147
|
`,
|
|
146
148
|
stderr: "",
|
|
147
149
|
exitCode: 0
|
|
@@ -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 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.
|
|
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. A PR that spent its catch-up rebase budget is the exception: its drain line says the rebase is `held for the owner`, and nothing is dispatched — the tick would refuse it — until the owner raises [`maxCatchUpRebases`](../muggle-preferences/preference-gates/maxCatchUpRebases.md). 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 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
|
|
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. Seed the rebase hold (`REBASE_HELD`) to `1` when `last_seen.json`'s `catch_up_rebases` has reached `maxCatchUpRebases` — the same check the tick's verdict blocks on — and empty otherwise: while it is set the loop raises no rebase wake on any base move. The script reads all four 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.
|
|
@@ -220,8 +220,9 @@ The watch loop's comparison floor — plain `KEY=VALUE` lines, one file per slot
|
|
|
220
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
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.
|
|
222
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.
|
|
223
|
+
- `REBASE_HELD` — `1` when the PR has spent its catch-up rebase budget (`catch_up_rebases` has reached [`maxCatchUpRebases`](../muggle-preferences/preference-gates/maxCatchUpRebases.md)), empty otherwise. While set, the loop raises no rebase wake and records no rebase as due however far the base moves: the tick's verdict refuses every rebase until the owner raises the cap, so a wake would only ask for work it turns down. Every arm recomputes it, so a raised cap lifts the hold at the next rollover or respawn.
|
|
223
224
|
|
|
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.
|
|
225
|
+
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, `REBASE_HELD` from the rebase budget) 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.
|
|
225
226
|
|
|
226
227
|
**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.
|
|
227
228
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"release": "5.26.0",
|
|
3
|
-
"buildId": "run-
|
|
4
|
-
"commitSha": "
|
|
5
|
-
"buildTime": "2026-10-
|
|
3
|
+
"buildId": "run-231-1",
|
|
4
|
+
"commitSha": "f40a2af32882991d5aa0270402d2345a4842dcc7",
|
|
5
|
+
"buildTime": "2026-10-27T06:19:37Z",
|
|
6
6
|
"serviceName": "muggle-ai-works-mcp"
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muggleai/works",
|
|
3
3
|
"mcpName": "io.github.multiplex-ai/muggle",
|
|
4
|
-
"version": "5.27.0-staging.
|
|
4
|
+
"version": "5.27.0-staging.231",
|
|
5
5
|
"description": "13 years of Microsoft hyperscale engineering, packaged as a harness for your AI coding agent.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
4
|
-
"version": "5.27.0-staging.
|
|
4
|
+
"version": "5.27.0-staging.231",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
7
7
|
"email": "support@muggle-ai.com"
|
package/plugin/.codex-mcp.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
|
-
"version": "5.27.0-staging.
|
|
3
|
+
"version": "5.27.0-staging.231",
|
|
4
4
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"displayName": "Muggle AI",
|
|
4
4
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
5
|
-
"version": "5.27.0-staging.
|
|
5
|
+
"version": "5.27.0-staging.231",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Muggle AI",
|
|
8
8
|
"email": "support@muggle-ai.com"
|
package/plugin/.mcp.json
CHANGED
|
@@ -46,6 +46,8 @@ existing=$(gh api "repos/<owner>/<repo>/issues/<prNumber>/comments" \
|
|
|
46
46
|
|
|
47
47
|
Match only comments carrying one of those markers — never every comment the loop user wrote — so an unrelated reply is never overwritten.
|
|
48
48
|
|
|
49
|
+
While a run is in flight, the comment carries a "new E2E run in progress" banner above the previous run's walkthrough. The PATCH replaces the whole body, banner included; never carry the banner or the previous walkthrough into the new body.
|
|
50
|
+
|
|
49
51
|
Report back: PR URL, whether an overflow comment was involved, and whether this was a fresh post or an update.
|
|
50
52
|
|
|
51
53
|
**Modes B/C (`render-for-new-pr` / `embed`)** — do not post, do not touch `gh`. Return the CLI output verbatim as your report:
|
package/plugin/hooks/README.md
CHANGED
|
@@ -47,6 +47,7 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
|
|
|
47
47
|
| `PostToolUse` (Bash) | `guardrail-record-comment-replies.sh` | record | an unresolved-thread fetch named review threads still awaiting an answer (classified by the `<!-- muggle-do:bot -->` marker, never the author login), a threaded reply the provider **confirmed** answered comments in one, or a `MUGGLE_REPLY_SKIP` marker deferred them | — | claim each thread and cover the comments answered, in the per-PR ledger beside the muggle-do slot |
|
|
48
48
|
| `PreToolUse` (Bash, `if` a command names `gh`/`glab`) | `guardrail-report-format.sh` | **enforce** | a `gh pr comment\|create\|edit` body — or a `gh api … issues/comments/<id>` PATCH editing one — reads like an E2E report but lacks the `build-pr-section` sentinel | — | **deny** — render via `muggle build-pr-section` instead |
|
|
49
49
|
| `PreToolUse` (muggle local execute/replay) | `guardrail-classify-gate.sh` | **enforce** | `muggle-test` is the skill in play and the target test case has no `pre-execution-classification` this session | — | **deny** — run Step 6f first (it calls `muggle-remote-test-script-list`, which is where the run learns the case has never passed) or record a legitimate skip via `MUGGLE_CLASSIFY_SKIP`. Scoped to `muggle-test`, so the single-target skills that legitimately skip classification are untouched; fails open when the test case can't be resolved |
|
|
50
|
+
| `PreToolUse` (muggle local execute/replay) | `guardrail-walkthrough-rerun.sh` | record | a browser run is about to start in a working tree (the tool call's `cwd`) whose branch has a PR, and that PR's walkthrough comment already shows a run or a skip | — | a detached job puts a "new E2E run in progress" banner, with its UTC start time, on top of the walkthrough the run will replace. The comment underneath is untouched, so the walkthrough check judges it as before; the run's own walkthrough replaces the whole body, banner included. A reserved placeholder or a comment already bannered is left alone |
|
|
50
51
|
| `Stop` | `guardrail-e2e-gate.sh` | **enforce** | unit tests passed this session, no E2E ran yet, and no skip was recorded | `autoE2ETest` | **block** the turn until E2E runs via `muggle-test` or a `MUGGLE_E2E_SKIP` marker records a legitimate skip (full message once, one-line reminders after; releases after 3 blocks). Quiet while a background acceptance-tester is in flight |
|
|
51
52
|
| `Stop` | `guardrail-terminal-gate.sh` | **enforce** | a PR went terminal this session and the next-options offer hasn't run since — an AskUserQuestion, or, while the session owns an open PR's watch slot, a closing message that asks the user | — | **block** the turn until the post-merge handoff runs (full message once, one-line reminders after; releases after 3 blocks; nothing but the offer resets the counter) |
|
|
52
53
|
| `Stop` | `guardrail-watch-gate.sh` | **enforce** | a PR opened this session that is still open and has no live watch — no session slot for it is terminal, stopped by its owner, or carries a `watch-heartbeat` touched within 15 minutes; a slot that is only seeded does not count | `autoWatchPR` | **block** the turn until the watch is armed per `muggle-pr-followup`'s `arm-watcher.md` or a `MUGGLE_WATCH_SKIP` marker records a legitimate skip (releases after 3 blocks). A PR clears once the session sees it go terminal or a provider lookup reports it merged or closed — what lets a PR whose slot post-merge cleanup deleted through. The lookup runs in a detached scan queued at turn end; a PR it has not reached yet still blocks, and one it could not reach fails open |
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"hooks": [
|
|
41
41
|
{
|
|
42
42
|
"type": "command",
|
|
43
|
-
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-classify-gate.sh
|
|
43
|
+
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-classify-gate.sh guardrail-walkthrough-rerun.sh",
|
|
44
44
|
"async": false,
|
|
45
45
|
"timeout": 10,
|
|
46
|
-
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-classify-gate.sh
|
|
46
|
+
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-classify-gate.sh guardrail-walkthrough-rerun.sh"
|
|
47
47
|
}
|
|
48
48
|
]
|
|
49
49
|
}
|
package/plugin/hooks/hooks.json
CHANGED
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"hooks": [
|
|
59
59
|
{
|
|
60
60
|
"type": "command",
|
|
61
|
-
"command": "set -- guardrail-classify-gate.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
|
|
61
|
+
"command": "set -- guardrail-dispatch.sh guardrail-classify-gate.sh guardrail-walkthrough-rerun.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
|
|
62
62
|
"async": false,
|
|
63
63
|
"timeout": 1
|
|
64
64
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -uo pipefail
|
|
3
|
+
|
|
4
|
+
# Walkthrough rerun notice (PreToolUse/muggle local execution tools).
|
|
5
|
+
# A browser run about to start on a working tree whose branch has a PR will
|
|
6
|
+
# replace that PR's walkthrough, so the comment gets a banner saying a new run
|
|
7
|
+
# is in progress before the run starts — never a decision, always {}. The
|
|
8
|
+
# provider calls run in a detached job, keyed on the tree the tool call names.
|
|
9
|
+
#
|
|
10
|
+
# The pre-filter re-states the execution tool names, like the classify gate's,
|
|
11
|
+
# so an unrelated payload never pays Node cold-start. `[-_]` because Codex
|
|
12
|
+
# reports an MCP tool with underscores where the server spells hyphens.
|
|
13
|
+
|
|
14
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
15
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
16
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
17
|
+
|
|
18
|
+
GUARDRAIL_SUBCOMMAND="walkthrough-rerun-notice"
|
|
19
|
+
|
|
20
|
+
guardrail_wants() {
|
|
21
|
+
guardrail_payload_matches 'muggle[-_]local[-_](execute[-_]test[-_]generation|execute[-_]replay)'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if guardrail_is_hook_script; then
|
|
25
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
26
|
+
fi
|
|
@@ -265,6 +265,7 @@ var GuardrailBackgroundJob = /* @__PURE__ */ ((GuardrailBackgroundJob2) => {
|
|
|
265
265
|
GuardrailBackgroundJob2["SettleBranchWalkthroughSkipped"] = "settle-branch-walkthrough-skipped";
|
|
266
266
|
GuardrailBackgroundJob2["SettleWalkthroughUnreasoned"] = "settle-walkthrough-unreasoned";
|
|
267
267
|
GuardrailBackgroundJob2["SettleWalkthroughNoAppLogicChange"] = "settle-walkthrough-no-app-logic-change";
|
|
268
|
+
GuardrailBackgroundJob2["NoteWalkthroughRerun"] = "note-walkthrough-rerun";
|
|
268
269
|
GuardrailBackgroundJob2["ScanWatchPrStates"] = "scan-watch-pr-states";
|
|
269
270
|
GuardrailBackgroundJob2["CommitDeferredState"] = "commit-deferred-state";
|
|
270
271
|
return GuardrailBackgroundJob2;
|
|
@@ -613,6 +614,9 @@ var WALKTHROUGH_SKIPPED_MARKER = "<!-- muggle-pr-walkthrough-status:skipped -->"
|
|
|
613
614
|
var WALKTHROUGH_COMMENT_HEADING = "### Muggle AI \u2014 PR visual walkthrough";
|
|
614
615
|
var REPORT_SENTINEL_TAG = new RegExp(`<!--\\s*${REPORT_SENTINEL}[^>]*-->\\s*`, "g");
|
|
615
616
|
var LAST_FULL_RUN_OPENING = "<details><summary>Last full E2E run on this PR</summary>";
|
|
617
|
+
var RERUN_NOTICE_OPENING = "<!-- muggle-pr-walkthrough-rerun -->";
|
|
618
|
+
var RERUN_NOTICE_CLOSING = "<!-- /muggle-pr-walkthrough-rerun -->";
|
|
619
|
+
var RERUN_NOTICE_BLOCK = new RegExp(`${RERUN_NOTICE_OPENING}[\\s\\S]*?${RERUN_NOTICE_CLOSING}\\s*`, "g");
|
|
616
620
|
var SHORT_SHA_LENGTH = 7;
|
|
617
621
|
var GH_COMMENT_TIMEOUT_MS = 1e4;
|
|
618
622
|
|
|
@@ -1772,12 +1776,28 @@ ${headline} Muggle verified \`${"NO_APP_LOGIC_CHANGE" /* NoAppLogicChange */}\`
|
|
|
1772
1776
|
}
|
|
1773
1777
|
function lastFullRunOf(body) {
|
|
1774
1778
|
const status = classifyComment(body);
|
|
1775
|
-
if (status === "reported" /* Reported */)
|
|
1779
|
+
if (status === "reported" /* Reported */) {
|
|
1780
|
+
return withoutRerunNotice(body).replace(REPORT_SENTINEL_TAG, "").trim();
|
|
1781
|
+
}
|
|
1776
1782
|
if (status !== "skipped" /* Skipped */) return null;
|
|
1777
1783
|
const start = body.indexOf(LAST_FULL_RUN_OPENING);
|
|
1778
1784
|
if (start === -1) return null;
|
|
1779
1785
|
return body.slice(start + LAST_FULL_RUN_OPENING.length).replace(/\s*<\/details>\s*$/, "").trim();
|
|
1780
1786
|
}
|
|
1787
|
+
var formatUtcMinute = (date) => `${date.toISOString().slice(0, 16).replace("T", " ")} UTC`;
|
|
1788
|
+
function hasRerunNotice(body) {
|
|
1789
|
+
return body.includes(RERUN_NOTICE_OPENING);
|
|
1790
|
+
}
|
|
1791
|
+
function withoutRerunNotice(body) {
|
|
1792
|
+
return body.replace(RERUN_NOTICE_BLOCK, "");
|
|
1793
|
+
}
|
|
1794
|
+
function withRerunNotice(body, startedAt) {
|
|
1795
|
+
return `${RERUN_NOTICE_OPENING}
|
|
1796
|
+
> **A new E2E run is in progress** \u2014 started ${formatUtcMinute(startedAt)}. The results below are from the previous run; this comment updates when the new run finishes.
|
|
1797
|
+
${RERUN_NOTICE_CLOSING}
|
|
1798
|
+
|
|
1799
|
+
` + withoutRerunNotice(body);
|
|
1800
|
+
}
|
|
1781
1801
|
function classifyComment(body) {
|
|
1782
1802
|
if (body.includes(REPORT_SENTINEL)) return "reported" /* Reported */;
|
|
1783
1803
|
if (!body.includes(WALKTHROUGH_SLOT_MARKER)) return "not-designated" /* NotDesignated */;
|
|
@@ -1797,11 +1817,11 @@ function walkthroughVerdict(bodies) {
|
|
|
1797
1817
|
function commentWithStatus(comments, status) {
|
|
1798
1818
|
return comments.find((comment) => classifyComment(comment.body) === status);
|
|
1799
1819
|
}
|
|
1820
|
+
function designatedComment(comments) {
|
|
1821
|
+
return comments.find((comment) => classifyComment(comment.body) !== "not-designated" /* NotDesignated */);
|
|
1822
|
+
}
|
|
1800
1823
|
function reserveComment(pr, comments, run) {
|
|
1801
|
-
|
|
1802
|
-
(comment) => classifyComment(comment.body) !== "not-designated" /* NotDesignated */
|
|
1803
|
-
);
|
|
1804
|
-
if (claimed) return false;
|
|
1824
|
+
if (designatedComment(comments)) return false;
|
|
1805
1825
|
return postPrComment(pr, renderReservedComment(), run);
|
|
1806
1826
|
}
|
|
1807
1827
|
function reserveWalkthroughComment(prUrl, run = defaultGhRunner) {
|
|
@@ -1837,13 +1857,22 @@ function settleWalkthroughCommentForNoAppLogicChange(prUrl, detail, run = defaul
|
|
|
1837
1857
|
if (!pr || !declared) return false;
|
|
1838
1858
|
const comments = listPrComments(pr, run);
|
|
1839
1859
|
if (comments === null) return false;
|
|
1840
|
-
const designated = comments
|
|
1841
|
-
(comment) => classifyComment(comment.body) !== "not-designated" /* NotDesignated */
|
|
1842
|
-
);
|
|
1860
|
+
const designated = designatedComment(comments);
|
|
1843
1861
|
const lastFullRun = designated ? lastFullRunOf(designated.body) : null;
|
|
1844
1862
|
const body = renderNoAppLogicChangeComment(declared, readPrHeadSha(pr, run), lastFullRun);
|
|
1845
1863
|
return designated ? patchPrComment(pr, designated.id, body, run) : postPrComment(pr, body, run);
|
|
1846
1864
|
}
|
|
1865
|
+
function noteWalkthroughRerunStarted(prUrl, run = defaultGhRunner, startedAt = /* @__PURE__ */ new Date()) {
|
|
1866
|
+
const pr = parsePrUrl(prUrl);
|
|
1867
|
+
if (!pr) return false;
|
|
1868
|
+
const comments = listPrComments(pr, run);
|
|
1869
|
+
if (comments === null) return false;
|
|
1870
|
+
const designated = designatedComment(comments);
|
|
1871
|
+
if (!designated) return false;
|
|
1872
|
+
if (classifyComment(designated.body) === "pending" /* Pending */) return false;
|
|
1873
|
+
if (hasRerunNotice(designated.body)) return false;
|
|
1874
|
+
return patchPrComment(pr, designated.id, withRerunNotice(designated.body, startedAt), run);
|
|
1875
|
+
}
|
|
1847
1876
|
function settleWalkthroughCommentAsUnreasoned(prUrl, run = defaultGhRunner) {
|
|
1848
1877
|
return settleWith(prUrl, renderUnreasonedSkipComment(), run);
|
|
1849
1878
|
}
|
|
@@ -2580,6 +2609,10 @@ function classifyGate() {
|
|
|
2580
2609
|
const reason = `Test case ${decision.testCaseId} has no pre-execution classification this session. Run muggle-test Step 6f for it first: classify replay-vs-regen per _shared/failure-mode-handling.md \xA7A, then emit one muggle-local-telemetry-event-emit with eventType "pre-execution-classification" for this test case. That step is what calls muggle-remote-test-script-list, which is the only place this run learns the test case has never passed or has failed repeatedly \u2014 cheap now, ~5 minutes of browser time to rediscover after the fact. If this execution genuinely has no classification step (a single user-picked target), say why and run \`echo "MUGGLE_CLASSIFY_SKIP: <reason>"\` \u2014 that records the skip for the rest of the session.`;
|
|
2581
2610
|
return denyTool(reason, host);
|
|
2582
2611
|
}
|
|
2612
|
+
function walkthroughRerunNotice() {
|
|
2613
|
+
startBackgroundJob("note-walkthrough-rerun" /* NoteWalkthroughRerun */, [], input.tool_input?.cwd ?? input.cwd);
|
|
2614
|
+
return "{}";
|
|
2615
|
+
}
|
|
2583
2616
|
function stageGate() {
|
|
2584
2617
|
const state = readState(sessionId);
|
|
2585
2618
|
const decision = stageGateDecision(state, unreadMandatoryStages(state));
|
|
@@ -2857,6 +2890,7 @@ var handlers = {
|
|
|
2857
2890
|
"record-stage-read": recordStageRead,
|
|
2858
2891
|
"record-stage-signals": recordStageSignals,
|
|
2859
2892
|
"classify-gate": classifyGate,
|
|
2893
|
+
"walkthrough-rerun-notice": walkthroughRerunNotice,
|
|
2860
2894
|
"stage-gate": stageGate,
|
|
2861
2895
|
"debug-path-gate": debugPathGate
|
|
2862
2896
|
};
|
|
@@ -2906,6 +2940,11 @@ function settleWalkthroughNoAppLogicChangeJob() {
|
|
|
2906
2940
|
if (prUrl && detail) settleWalkthroughCommentForNoAppLogicChange(prUrl, detail);
|
|
2907
2941
|
return "{}";
|
|
2908
2942
|
}
|
|
2943
|
+
function noteWalkthroughRerunJob() {
|
|
2944
|
+
const prUrl = defaultPrWalkthroughLookup.branchPrUrl();
|
|
2945
|
+
if (prUrl) noteWalkthroughRerunStarted(prUrl);
|
|
2946
|
+
return "{}";
|
|
2947
|
+
}
|
|
2909
2948
|
function scanWatchPrStatesJob() {
|
|
2910
2949
|
const scannedSessionId = jobArgs[0] ?? "unknown";
|
|
2911
2950
|
const state = readState(scannedSessionId);
|
|
@@ -2927,6 +2966,7 @@ var backgroundJobs = {
|
|
|
2927
2966
|
["settle-branch-walkthrough-skipped" /* SettleBranchWalkthroughSkipped */]: settleBranchWalkthroughSkippedJob,
|
|
2928
2967
|
["settle-walkthrough-unreasoned" /* SettleWalkthroughUnreasoned */]: settleWalkthroughUnreasonedJob,
|
|
2929
2968
|
["settle-walkthrough-no-app-logic-change" /* SettleWalkthroughNoAppLogicChange */]: settleWalkthroughNoAppLogicChangeJob,
|
|
2969
|
+
["note-walkthrough-rerun" /* NoteWalkthroughRerun */]: noteWalkthroughRerunJob,
|
|
2930
2970
|
["scan-watch-pr-states" /* ScanWatchPrStates */]: scanWatchPrStatesJob,
|
|
2931
2971
|
["commit-deferred-state" /* CommitDeferredState */]: commitDeferredStateJob
|
|
2932
2972
|
};
|
|
@@ -106,12 +106,14 @@ last_seen_file="${slot}/last_seen.json"
|
|
|
106
106
|
rebase_attempted=0
|
|
107
107
|
ci_attempted=0
|
|
108
108
|
blocked_digest_floor=""
|
|
109
|
+
rebase_budget_exhausted=0
|
|
109
110
|
while IFS= read -r evidence_line; do
|
|
110
111
|
evidence_line="${evidence_line%$'\r'}"
|
|
111
112
|
case "$evidence_line" in
|
|
112
113
|
REBASE_ATTEMPTED=*) rebase_attempted="${evidence_line#REBASE_ATTEMPTED=}" ;;
|
|
113
114
|
CI_ATTEMPTED=*) ci_attempted="${evidence_line#CI_ATTEMPTED=}" ;;
|
|
114
115
|
BLOCKED_CIDIGEST=*) blocked_digest_floor="${evidence_line#BLOCKED_CIDIGEST=}" ;;
|
|
116
|
+
REBASE_BUDGET_EXHAUSTED=*) rebase_budget_exhausted="${evidence_line#REBASE_BUDGET_EXHAUSTED=}" ;;
|
|
115
117
|
esac
|
|
116
118
|
done < <(node "${script_dir}/pr-watch-verdict.mjs" arm-floors --pr-key "${repo}#${pr_number}" \
|
|
117
119
|
--head "$head_sha" --rebase-key "$rebase_key" < "$last_seen_file" 2>/dev/null)
|
|
@@ -121,6 +123,15 @@ ci_red_floor=""
|
|
|
121
123
|
rebase_floor=""
|
|
122
124
|
[ -n "$rebase_due_key" ] && [ "$rebase_attempted" = "1" ] && rebase_floor="$rebase_due_key"
|
|
123
125
|
|
|
126
|
+
# A PR that spent its catch-up rebase budget is held for its owner whether or not
|
|
127
|
+
# the branch is stale yet: the tick refuses every rebase until maxCatchUpRebases
|
|
128
|
+
# is raised, so announcing one — here or on the loop's next base move — only asks
|
|
129
|
+
# the session for work the verdict turns down. The next arm reads a raised cap.
|
|
130
|
+
rebase_held=""
|
|
131
|
+
[ "$rebase_budget_exhausted" = "1" ] && rebase_held="1"
|
|
132
|
+
recorded_rebase_due_key="$rebase_due_key"
|
|
133
|
+
[ -n "$rebase_held" ] && recorded_rebase_due_key=""
|
|
134
|
+
|
|
124
135
|
thread_count=0
|
|
125
136
|
[ -n "$unresolved_threads" ] && thread_count=$(printf '%s' "$unresolved_threads" | tr ';' '\n' | grep -c .)
|
|
126
137
|
|
|
@@ -138,7 +149,9 @@ if [ -n "$ci_red_head" ]; then
|
|
|
138
149
|
fi
|
|
139
150
|
fi
|
|
140
151
|
if [ -n "$rebase_due_key" ]; then
|
|
141
|
-
if [ -n "$
|
|
152
|
+
if [ -n "$rebase_held" ]; then
|
|
153
|
+
echo "DRAIN branch stale at arm time — catch-up rebase budget spent (maxCatchUpRebases), held for the owner: no rebase to dispatch"
|
|
154
|
+
elif [ -n "$rebase_floor" ]; then
|
|
142
155
|
echo "DRAIN branch stale at arm time — a rebase already ran for key ${rebase_due_key}, floored"
|
|
143
156
|
else
|
|
144
157
|
echo "DRAIN branch stale at arm time — no rebase attempt recorded for key ${rebase_due_key}, not floored: dispatch rebase"
|
|
@@ -152,9 +165,10 @@ fi
|
|
|
152
165
|
printf 'CIRED="%s"\n' "$ci_red_floor"
|
|
153
166
|
printf 'REBASED="%s"\n' "$rebase_floor"
|
|
154
167
|
printf 'BLOCKED_CIDIGEST="%s"\n' "$blocked_digest_floor"
|
|
168
|
+
printf 'REBASE_HELD="%s"\n' "$rebase_held"
|
|
155
169
|
} > "${slot}/watch-watermark.env"
|
|
156
170
|
|
|
157
|
-
watch_record_due_work "$slot" "$head_sha" "$
|
|
171
|
+
watch_record_due_work "$slot" "$head_sha" "$recorded_rebase_due_key" "$ci_red_head"
|
|
158
172
|
|
|
159
173
|
# Claim the slot for this session. watcher_lease_is_foreign reads an absent
|
|
160
174
|
# owner.json as "not foreign", so a slot armed without one leases itself to a
|
|
@@ -55,6 +55,10 @@ echo "$$" > "${slot}/watch.pid"
|
|
|
55
55
|
started=$(date +%s)
|
|
56
56
|
fails=0
|
|
57
57
|
unseeded=0
|
|
58
|
+
# Set once the first iteration has run. Until then the window cannot roll the
|
|
59
|
+
# loop over, so a start-up slow enough to spend the whole window still gets one
|
|
60
|
+
# look at the PR rather than handing back a watch that never polled.
|
|
61
|
+
has_iterated=""
|
|
58
62
|
|
|
59
63
|
# In-memory floors, above the on-disk watermark. The watermark is advanced by
|
|
60
64
|
# the session after it handles a wave; these stop the loop re-reporting an event
|
|
@@ -105,10 +109,11 @@ while :; do
|
|
|
105
109
|
# the line is the owning session's cue to re-arm, and ending here is what
|
|
106
110
|
# frees the lease that re-arm needs. A loop that ran on past its monitor would
|
|
107
111
|
# keep that lease and heartbeat fresh while reporting to no one.
|
|
108
|
-
if watcher_window_elapsed "$started" "$(date +%s)"; then
|
|
112
|
+
if [ -n "$has_iterated" ] && watcher_window_elapsed "$started" "$(date +%s)"; then
|
|
109
113
|
echo "ROLLOVER pr=$pr_number monitor window of ${MUGGLE_PR_WATCH_MONITOR_WINDOW}s elapsed — re-arm to keep watching"
|
|
110
114
|
exit 0
|
|
111
115
|
fi
|
|
116
|
+
has_iterated=1
|
|
112
117
|
touch "${slot}/watch-heartbeat" 2>/dev/null
|
|
113
118
|
|
|
114
119
|
# No watermark yet means the arming session has not finished seeding. Wait
|
|
@@ -137,6 +142,7 @@ while :; do
|
|
|
137
142
|
watermark_ci_red=$(read_watermark_value CIRED)
|
|
138
143
|
watermark_rebase=$(read_watermark_value REBASED)
|
|
139
144
|
watermark_blocked_digest=$(read_watermark_value BLOCKED_CIDIGEST)
|
|
145
|
+
watermark_rebase_held=$(read_watermark_value REBASE_HELD)
|
|
140
146
|
|
|
141
147
|
state_line=$(watch_fetch_state "$repo" "$pr_number" "$slot" "$state_projection")
|
|
142
148
|
# One quick retry before counting a strike: a single flaky call should not
|
|
@@ -207,7 +213,11 @@ while :; do
|
|
|
207
213
|
fi
|
|
208
214
|
|
|
209
215
|
rebase_key="${head_sha}..${base_tip_sha}"
|
|
210
|
-
if [ "$
|
|
216
|
+
if [ "$watermark_rebase_held" = "1" ]; then
|
|
217
|
+
# The PR spent its catch-up rebase budget: however far the base moves, the
|
|
218
|
+
# tick refuses the rebase a wake would ask for, so nothing is due either.
|
|
219
|
+
due_rebase_key=""
|
|
220
|
+
elif [ "$rebase_key" = "$watermark_rebase" ] || [ "$rebase_key" = "$floor_rebase" ]; then
|
|
211
221
|
# Only a key already found due is ever floored, and the pair's standing
|
|
212
222
|
# cannot change until the head or the base moves, which mints a new key.
|
|
213
223
|
due_rebase_key="$rebase_key"
|
|
@@ -54,11 +54,12 @@ function isRebaseBudgetExhausted(lastSeenEntry, maxCatchUpRebases) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// src/pr-watch/armFloors.ts
|
|
57
|
-
function resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey) {
|
|
57
|
+
function resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey, maxCatchUpRebases) {
|
|
58
58
|
const blockedCiDigest = lastSeenEntry.blocked?.fingerprint?.ci_digest;
|
|
59
59
|
return {
|
|
60
60
|
isRebaseKeyAttempted: rebaseKey !== "" && isRebaseKeyAttempted(lastSeenEntry, rebaseKey),
|
|
61
61
|
isCiHeadAttempted: headSha !== "" && isCiHeadAttempted(lastSeenEntry, headSha),
|
|
62
|
+
isRebaseBudgetExhausted: isRebaseBudgetExhausted(lastSeenEntry, maxCatchUpRebases),
|
|
62
63
|
blockedCiDigest: typeof blockedCiDigest === "string" && !LINE_BREAK.test(blockedCiDigest) ? blockedCiDigest : ""
|
|
63
64
|
};
|
|
64
65
|
}
|
|
@@ -137,11 +138,12 @@ function runPrWatchVerdictCommand(commandLine, lastSeenJson, resolvePreferences)
|
|
|
137
138
|
const headSha = flags[HEAD_FLAG] ?? "";
|
|
138
139
|
const rebaseKey = flags[REBASE_KEY_FLAG] ?? "";
|
|
139
140
|
if (subcommand === "arm-floors" /* ArmFloors */) {
|
|
140
|
-
const evidence = resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey);
|
|
141
|
+
const evidence = resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey, resolvePreferences().maxCatchUpRebases);
|
|
141
142
|
return {
|
|
142
143
|
stdout: `REBASE_ATTEMPTED=${evidence.isRebaseKeyAttempted ? 1 : 0}
|
|
143
144
|
CI_ATTEMPTED=${evidence.isCiHeadAttempted ? 1 : 0}
|
|
144
145
|
BLOCKED_CIDIGEST=${evidence.blockedCiDigest}
|
|
146
|
+
REBASE_BUDGET_EXHAUSTED=${evidence.isRebaseBudgetExhausted ? 1 : 0}
|
|
145
147
|
`,
|
|
146
148
|
stderr: "",
|
|
147
149
|
exitCode: 0
|
|
@@ -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 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.
|
|
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. A PR that spent its catch-up rebase budget is the exception: its drain line says the rebase is `held for the owner`, and nothing is dispatched — the tick would refuse it — until the owner raises [`maxCatchUpRebases`](../muggle-preferences/preference-gates/maxCatchUpRebases.md). 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 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
|
|
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. Seed the rebase hold (`REBASE_HELD`) to `1` when `last_seen.json`'s `catch_up_rebases` has reached `maxCatchUpRebases` — the same check the tick's verdict blocks on — and empty otherwise: while it is set the loop raises no rebase wake on any base move. The script reads all four 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.
|
|
@@ -220,8 +220,9 @@ The watch loop's comparison floor — plain `KEY=VALUE` lines, one file per slot
|
|
|
220
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
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.
|
|
222
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.
|
|
223
|
+
- `REBASE_HELD` — `1` when the PR has spent its catch-up rebase budget (`catch_up_rebases` has reached [`maxCatchUpRebases`](../muggle-preferences/preference-gates/maxCatchUpRebases.md)), empty otherwise. While set, the loop raises no rebase wake and records no rebase as due however far the base moves: the tick's verdict refuses every rebase until the owner raises the cap, so a wake would only ask for work it turns down. Every arm recomputes it, so a raised cap lifts the hold at the next rollover or respawn.
|
|
223
224
|
|
|
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.
|
|
225
|
+
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, `REBASE_HELD` from the rebase budget) 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.
|
|
225
226
|
|
|
226
227
|
**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.
|
|
227
228
|
|