Merge remote-tracking branch 'origin/main' into race-activator-1249
3 files changed,
+200
−0
docs/superpowers/reviews/FINDINGS-flake-demo-claim-browser.md+31 −0docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-browser.md+150 −0internal/console/testdata/demo_claim_kept_browser.mjs+19 −0
diff --git a/docs/superpowers/reviews/FINDINGS-flake-demo-claim-browser.md b/docs/superpowers/reviews/FINDINGS-flake-demo-claim-browser.md| new file mode 100644 |
| index 000000000..6d84c81f7 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/FINDINGS-flake-demo-claim-browser.md |
| @@ -0,0 +1,31 @@ |
| +Reviewed `7910cf1e6b0ae9322c1e531bd8cb27ca95ead82a` against `origin/main` (`12158f40fdafa2b08a0ee747059289c39d09bace`), round 1. The diff contains only the browser-test change and its review brief. |
| + |
| +**P1: none. P2: none.** |
| + |
| +**P3 — The sibling scripts retain the navigation race.** |
| +Invariant: assertions must run against the intended document after navigation. |
| + |
| +- [demo_claim_browser.mjs:80](/home/paulca/amadan.net/carlos/platform-flake-browser/internal/console/testdata/demo_claim_browser.mjs:80) polls across the token shell’s replacement. Its reloads at lines 184–185 and 240–241 immediately poll a condition already satisfied by the outgoing document. |
| +- [demo_claim_resume_browser.mjs:164](/home/paulca/amadan.net/carlos/platform-flake-browser/internal/console/testdata/demo_claim_resume_browser.mjs:164) navigates between pages with the same radio-selector condition, then immediately polls it. Lines 200–201 also poll across the submission and resume navigation chain. |
| + |
| +These can fail during document replacement or accept the outgoing document and run subsequent assertions too early. In a follow-up, add passive navigation waits matched to each flow before polling. The resume flow needs to account for its intermediate documents. These are existing, out-of-scope issues, as the brief specifies. |
| + |
| +The requested checks: |
| + |
| +1. **The new waits leave no CDP command in either identified navigation window.** [demo_claim_kept_browser.mjs:56](/home/paulca/amadan.net/carlos/platform-flake-browser/internal/console/testdata/demo_claim_kept_browser.mjs:56) only checks the event array and awaits timers. Both navigation calls immediately await it. The live-mode `shot()` and completion fetch occur after the second commit, at lines 93–94. Reload assertions and the settled screenshot likewise follow the reload commit. There is no retry or suppression of a failed command. |
| + |
| +2. **The event and filtering are appropriate.** The handler checks the attached session and excludes child frames. CDP defines `Frame.url` without its fragment and distinguishes document navigation from same-document navigation, so the expected URLs are correct without additional stripping. See [https://raw.githubusercontent.com/ChromeDevTools/devtools-protocol/master/pdl/domains/Page.pdl](https://raw.githubusercontent.com/ChromeDevTools/devtools-protocol/master/pdl/domains/Page.pdl). |
| + |
| + Chromium updates the renderer connection before committing navigation and resumes queued commands against that connection. This supports using the event as the boundary for subsequent evaluations across a renderer swap; flattening does not pin the session to the outgoing renderer. The event does not mean the DOM is ready, which is why retaining `until()` matters. See [https://raw.githubusercontent.com/chromium/chromium/main/content/browser/devtools/render_frame_devtools_agent_host.cc](https://raw.githubusercontent.com/chromium/chromium/main/content/browser/devtools/render_frame_devtools_agent_host.cc). |
| + |
| +3. **The strict sequence fits these fixtures.** The script never traverses history, so it does not trigger a back-forward-cache restoration. `history.replaceState()` does not add a document commit. The previous scene’s expected commits have already been received before the next snapshot. The live completion fetch updates server state and the page updates its DOM; neither adds a navigation. I found no legitimate extra commit that this assertion would reject in the current flow. |
| + |
| +4. **Both navigation sites in the kept script are covered.** Its only explicit navigation operations are the initial `Page.navigate` and `Page.reload`; both now wait. The shell’s implicit replacement is covered by expecting two initial commits. |
| + |
| +5. **The existing proof is preserved.** [demo_claim_kept_browser.mjs:96](/home/paulca/amadan.net/carlos/platform-flake-browser/internal/console/testdata/demo_claim_kept_browser.mjs:96) retains the reveal count, fragment and history checks, token absence, cookie scope, settled reload, and CSP assertions. The reload check is stronger because it can no longer succeed on the outgoing document. |
| + |
| +6. **The proposed cause is credible, but the exact failed command remains unproven.** The first scene is live. Its shell delay, staged completion holds and celebration precede reload, supporting the conclusion that the 3.61-second failure happened earlier. The local 4.7-second measurement alone would not establish CI timing. Chromium also explicitly emits this error for outstanding JavaScript-executing commands during renderer replacement, matching the proposed mechanism. See [https://raw.githubusercontent.com/chromium/chromium/main/content/browser/devtools/devtools_session.cc](https://raw.githubusercontent.com/chromium/chromium/main/content/browser/devtools/devtools_session.cc). Unexpected target closure remains another possible source; this change correctly leaves such failures visible. |
| + |
| +Validation was static inspection and Chromium source verification. I did not run tests in this read-only environment or independently reproduce the reported failure. No files were changed. |
| + |
| +**READY** |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-browser.md b/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-browser.md| new file mode 100644 |
| index 000000000..ec3c38ead |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-browser.md |
| @@ -0,0 +1,150 @@ |
| +# Review brief: flake fix for TestDemoClaimKeptHeadless, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `flake-demo-claim-browser`, fix commit |
| +d4f3fc8d394e26ae474ef9944f8a2c2dce6cbc6f. |
| +Under review: the diff `origin/main..flake-demo-claim-browser` (base |
| +12158f40). The only code change is |
| +`internal/console/testdata/demo_claim_kept_browser.mjs`; this brief is |
| +the other file. |
| +Authorities: the kept-link behaviour as merged on main in ce7576a6 |
| +(`internal/console/demo_claim_kept.go`, `internal/console/static/demo_claim.js`). |
| +The fix must not change product code or what the test proves. |
| + |
| +You are an independent reviewer. Read this brief, then the code it |
| +names, and check every claim against that code. |
| + |
| +## The failure |
| + |
| +Main CI at 0acb2767 (2026-11-19, shard internal_console@4) failed once |
| +and passed on rerun: |
| + |
| +``` |
| +--- FAIL: TestDemoClaimKeptHeadless (3.61s) |
| + demo_claim_kept_browser_test.go:62: kept browser: exit status 1 |
| + AssertionError [ERR_ASSERTION]: {"code":-32000,"message":"Inspected target navigated or closed"} |
| +``` |
| + |
| +The assertion is the `message.error === undefined` check in `call()`, |
| +so a CDP command came back with that error. The CI excerpt has no |
| +stack, so it does not name the step. |
| + |
| +## Root cause (claimed) |
| + |
| +The test drives Chromium over CDP through |
| +`internal/console/testdata/demo_claim_kept_browser.mjs`. Each scene opens |
| +`/demo/claim/kept#k=<token>`. That page is a shell. `demo_claim.js` clears |
| +the fragment with `history.replaceState` (same document), POSTs the token, |
| +waits at least 650 ms, then calls `location.replace("/demo/claim")`, which |
| +is a second cross-document navigation the script does not trigger. |
| + |
| +Before the fix, the script started `until()` straight after |
| +`Page.navigate`. That polls `Runtime.evaluate` every 100 ms on the shell |
| +while the shell navigates away. A command that reaches the outgoing |
| +document as the new one commits gets -32000 "Inspected target navigated |
| +or closed". |
| + |
| +Timing evidence that this is the step CI hit, not the reload: a local |
| +timeline run (temporary logging, since reverted) showed the shell's |
| +replace committing about 1.1 s after the script starts and scene 1's |
| +`Page.reload` at about 4.7 s. The CI failure came 3.61 s into the whole Go |
| +test, and that time also covers building eight fixtures and launching |
| +Chromium. So it failed in scene 1, before any reload. Within that time, |
| +the shell's `location.replace` is the only navigation that commands were |
| +polled across. |
| + |
| +The second race has the same shape. `Page.reload` answers before its |
| +navigation commits, and the settled `until()` condition |
| +(`readyState === "complete" && state === "claimed"`) is already true on |
| +the outgoing page. So the first poll could fail the same way, or pass on |
| +the old document. Only the 1800 ms sleep then kept the following |
| +assertions on the new document. Locally the reload committed 8 to 50 ms |
| +after `Page.reload` returned. I did not see an old-document pass in |
| +practice. |
| + |
| +## The fix |
| + |
| +- Record every main-frame `Page.frameNavigated` for our session, with the |
| + URL and no fragment, in `commits`. |
| +- `committed(since, urls)` waits, sending no CDP commands, until the |
| + expected number of commits has arrived after `since`. It is bounded by |
| + 150 × 100 ms, the same as `until()`. It then asserts with `deepEqual` |
| + that the commits are exactly the expected URLs. |
| +- After `Page.navigate`: expect `[origin/demo/claim/kept, origin/demo/claim]`. |
| + After `Page.reload`: expect `[origin/demo/claim]`. Then the existing |
| + `until()` calls and assertions run unchanged. |
| + |
| +No assertion was removed or loosened. The navigation order is now |
| +asserted where it was only implied before. There are no sleeps and no |
| +retries of the failing command. |
| + |
| +## Reproduction (docs-t1, Chromium 151.0.7922.173, node v24.19.0, load 30 to 128 on 16 cores) |
| + |
| +- Before, plain: `go test ./internal/console -run 'TestDemoClaimKept' -count=50` |
| + hit the 10-minute default timeout after about 10 iterations. Each |
| + browser run takes about 45 s. The output had no `--- FAIL` line for the |
| + browser test; it ended in `panic: test timed out after 10m0s`. |
| +- Before, stress (temporary edit, reverted): `until()` polled every 1 ms |
| + with the same 15 s budget, `STRESS_POLL=1 go test ./internal/console -run '^TestDemoClaimKeptHeadless$' -count=6 -v`: |
| + 6/6 PASS. Plus 3/3 PASS with `--enable-features=RenderDocument:level/all-frames`. |
| + A first stress attempt at 0 ms with 150 iterations failed 6/6, but only |
| + because 150 immediate polls ran out before the page was ready |
| + (`browser_condition_timeout`). That was an artifact of the stress |
| + variant, not the CDP error, and it is not counted. |
| +- So the -32000 never reproduced locally: 0 in about 21 valid runs. This |
| + Chromium answers commands across these navigations without error. |
| + CI's runners supply their own Chromium (`.amadan/ci.d` installs none; |
| + the test skips when `chromium` is not on PATH), and its version and |
| + features are unknown here. |
| +- After: `go test ./internal/console -run '^TestDemoClaimKeptHeadless$' -count=10 -timeout 20m -v` |
| + gave 10/10 `--- PASS` (44.6 to 52.1 s each), `ok ... 470.888s`. |
| + |
| +## What to check |
| + |
| +1. Does `committed()` really keep every CDP command away from a document |
| + that is being replaced? Is there any command between `Page.navigate`'s |
| + response and the second commit, or between `Page.reload`'s response |
| + and its commit? Look at `shot()` and the live-mode `fetch` evaluate. |
| +2. Is `Page.frameNavigated` (main frame, `parentId` absent, matching |
| + `sessionId`) the right signal? Once it has arrived, are later |
| + `Runtime.evaluate` calls guaranteed to reach the new document, given |
| + flattened sessions across a RenderFrameHost swap? |
| +3. Can `commits` see a stray main-frame commit the test does not expect |
| + (bfcache restore, `pageshow` persisted path, a previous scene's late |
| + event)? Would the strict `deepEqual` then turn a pass into a new flake, |
| + or is a strict sequence the correct thing to assert here? |
| +4. Is anything left in this script that navigates and then polls without |
| + waiting? The sibling scripts (`demo_claim_browser.mjs`, |
| + `demo_claim_resume_browser.mjs`) share the `until()` pattern. Say |
| + whether they carry the same race. They are out of scope for this |
| + change, so report them as P3 follow-ups, not blockers. |
| +5. Does the test still prove everything it proved before: reveal once, |
| + settled reload, cleared fragments, scoped cookies, zero CSP |
| + violations? |
| +6. Is the root-cause argument (the 3.61 s timing and the step order) |
| + sound? Is there a simpler explanation the fix would miss? |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| + Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for |
| + another round. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Do not |
| +raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3. Each gives the problem, the evidence |
| +(file:line, verified), the failure scenario and a concrete fix. End with |
| +exactly one verdict: |
| + |
| +- **READY**: no P1 and no P2. |
| +- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another |
| + round. |
| +- **NOT READY**: one or more P1s, listed. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of |
| +your own. Do not run the full test suites. If you run anything, run only |
| +`go test ./internal/console -run '^TestDemoClaimKeptHeadless$'`. |
diff --git a/internal/console/testdata/demo_claim_kept_browser.mjs b/internal/console/testdata/demo_claim_kept_browser.mjs| index e270fbe9c..ed6176671 100644 |
| --- a/internal/console/testdata/demo_claim_kept_browser.mjs |
| +++ b/internal/console/testdata/demo_claim_kept_browser.mjs |
| @@ -12,6 +12,8 @@ const chrome = spawn(binary, ['--headless', '--no-sandbox', '--disable-gpu', |
| let sequence = 0, buffered = '', session; |
| const pending = new Map(); |
| const violations = []; |
| +// Every document the tab's main frame commits, in order (fragment excluded). |
| +const commits = []; |
| chrome.stdio[4].on('data', bytes => { |
| buffered += bytes.toString(); |
| let end; |
| @@ -19,6 +21,7 @@ chrome.stdio[4].on('data', bytes => { |
| const message = JSON.parse(buffered.slice(0, end)); |
| buffered = buffered.slice(end + 1); |
| if (message.method === 'Runtime.bindingCalled' && message.params.name === 'keptCSP') violations.push(message.params.payload); |
| + if (message.method === 'Page.frameNavigated' && message.sessionId === session && !message.params.frame.parentId) commits.push(message.params.frame.url); |
| const resolve = pending.get(message.id); |
| if (resolve) { pending.delete(message.id); resolve(message); } |
| } |
| @@ -43,6 +46,17 @@ async function until(expression) { |
| } |
| throw Error('browser_condition_timeout: ' + await evaluate('JSON.stringify({text:document.body.innerText,email:document.getElementById("email")?.value,focus:document.activeElement.tagName,valid:document.querySelector("form")?.checkValidity()})')); |
| } |
| +// The kept shell replaces itself with /demo/claim once its exchange lands, |
| +// and Page.reload answers before its navigation commits. A command that |
| +// reaches the outgoing document as the next one commits fails with -32000 |
| +// "Inspected target navigated or closed" (main CI, 2026-11-19), and a |
| +// condition polled too soon can pass on the outgoing page. So a step that |
| +// navigates waits, sending nothing, until the main frame has committed |
| +// exactly the documents it expects, and only then polls the page. |
| +async function committed(since, urls) { |
| + for (let i = 0; i < 150 && commits.length - since < urls.length; i++) await new Promise(resolve => setTimeout(resolve, 100)); |
| + assert.deepEqual(commits.slice(since), urls); |
| +} |
| const timer = setTimeout(() => { chrome.kill('SIGKILL'); process.exitCode = 1; }, 170000); |
| try { |
| @@ -70,7 +84,10 @@ try { |
| await call('Network.clearBrowserCookies'); |
| await call('Emulation.setDeviceMetricsOverride', {width:scene.Width,height:900,deviceScaleFactor:1,mobile:false}); |
| await call('Emulation.setEmulatedMedia',{features:[{name:'prefers-color-scheme',value:scene.Theme},{name:'prefers-reduced-motion',value:'no-preference'}]}); |
| + const origin = new URL(scene.URL).origin; |
| + let since = commits.length; |
| await call('Page.navigate',{url:scene.URL}); |
| + await committed(since,[origin+'/demo/claim/kept',origin+'/demo/claim']); |
| if (scene.Mode === 'live') { |
| await until('location.hash === "" && document.getElementById("claim")?.dataset.state === "claiming"'); |
| await shot(scene,'progress'); |
| @@ -90,7 +107,9 @@ try { |
| assert(cookies.every(cookie => cookie.name !== 'carlos_console_session')); |
| const statusCookie = cookies.find(cookie => cookie.name === 'carlos_demo_claim_flow'); |
| assert(statusCookie?.httpOnly && statusCookie.secure && statusCookie.path === '/demo/claim'); |
| + since = commits.length; |
| await call('Page.reload',{ignoreCache:true}); |
| + await committed(since,[origin+'/demo/claim']); |
| await until('document.readyState === "complete" && document.getElementById("claim")?.dataset.state === "claimed"'); |
| await new Promise(resolve => setTimeout(resolve,1800)); |
| assert.equal(await evaluate('window.keptReveals'),0); |