carlos / platform Public

docs: review brief for the kept browser test flake fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7910cf1e6b0ae9322c1e531bd8cb27ca95ead82a parent d4f3fc8
1 file changed, +150 −0
  • docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-browser.md +150 −0

CI cancelled — superseded by a newer push — run details

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$'`.