docs: review brief for the demo claim stage-hold flake fix
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+191
−0
docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-stage-hold.md+191 −0
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-stage-hold.md b/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-stage-hold.md| new file mode 100644 |
| index 000000000..bfc589c4f |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-claim-stage-hold.md |
| @@ -0,0 +1,191 @@ |
| +# Review brief: demo claim stage-hold flake, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `flake-demo-claim-stage-hold`, fix commit |
| +f1193adc2653e12dc8cab648d9fc0d3a84dbe99e, golden commit |
| +9ced5534862463871a92ca667cfc750120f54221. |
| +Under review: the diff `origin/main..flake-demo-claim-stage-hold` (base |
| +365a79ca). Changed files: |
| + |
| +- `internal/console/static/demo_claim.js` (product JS, +7 lines) |
| +- `internal/console/testdata/demo_claim_layout.mjs` (`watchClaimCSP`) |
| +- `internal/console/testdata/demo_claim_browser.mjs` |
| +- `internal/console/demo_claim_footer_test.go` (eight page digests) |
| + |
| +This brief is the only other file. Authority: `demo_claim.js` as merged |
| +on main (its hold rule, below). The fix must not change what users see |
| +or the page's timing, and it must not weaken 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 and its history |
| + |
| +CI, 2026-11-19, branch `flake-lease-teardown`, shard internal_console@16: |
| + |
| +``` |
| +TestDemoClaimUXHeadlessFast390 |
| +AssertionError: [{"stage":1,"time":95.1},{"stage":2,"time":734},{"stage":3,"time":1411.7},{"stage":4,"time":2107.1}] |
| + at runUX (internal/console/testdata/demo_claim_browser.mjs:180) assert(b.time-a.time >= heldAtLeast) |
| +``` |
| + |
| +Stage 1 to 2 measured 638.9 ms against `heldAtLeast = 640`. The same |
| +check had already failed at 649.8 ms and 648.5 ms (2026-11-11, #897), and |
| +at 644.9 ms and 648.4 ms for stage 1 (2026-11-10/11). Each time the slack |
| +was widened (to 10 ms) or stage 1 was given a domInteractive / |
| +first-paint correction. |
| + |
| +## Why the observer's clock was wrong |
| + |
| +The test timed each stage with a MutationObserver on `data-stage` / |
| +`data-state` and took `performance.now()` inside the callback. That is |
| +when the callback ran, not when the page started holding the stage. The |
| +page's hold starts after a double `requestAnimationFrame` that follows |
| +the DOM change (`since`, `demo_claim.js:262`; stage 1 at `:357`), and |
| +the callback runs at the microtask checkpoint of the task that changed |
| +the DOM. Neither end is the page's clock, and the gap between them |
| +depends on frame timing and load. So a stage the page held for 650 ms |
| +can measure short by an arbitrary amount on a loaded worker, and no |
| +slack is the right size. |
| + |
| +## The page's real hold rule |
| + |
| +From `demo_claim.js`: |
| + |
| +- `minimum = 650` (`:8`). |
| +- Stage 1 (server-painted): after the first double rAF, `since` is set |
| + and the first poll is armed for `minimum` (`:357`). |
| +- `hold()` (`:154`) waits `max(0, minimum - (now - since))`, so it ends |
| + no sooner than `since + 650` by the page's clock, less what setTimeout |
| + drops (below). |
| +- `advance(target)` (`:264-267`) runs `await hold(); await setStage(stage + 1)` |
| + per step. So each stage shows at `max(since + 650, when the poll |
| + answered)`: the server answer can make a hold longer, never shorter. |
| +- `setStage` (`:245`) changes the DOM, waits a double rAF, then sets |
| + `since` for the new stage (`:262`). |
| +- Stage 3 to claimed: `await hold(); await finish(result)` (`:329`). |
| + `finish` fetches the page, then shows the claimed state. |
| +- Stopping/aborted: `await hold()` then the failure view (`:315`). |
| + |
| +## The fix |
| + |
| +- `demo_claim.js:158` adds `held()`, which writes |
| + `data-stage-held="<stage left> <since> <performance.now()>"` on |
| + `#claim-progress`. It is called at the top of `setStage` (`:246`, before |
| + any DOM change for the new stage), in `finish` just before the claimed |
| + state is shown (`:291`, same task as `claim.dataset.state = "claimed"`), |
| + and on the stopping/aborted path after its hold (`:316`). It reads two |
| + clocks and writes one attribute. Nothing styles or reads |
| + `data-stage-held`. It does not touch `since`, `hold()` or any timer. |
| +- `demo_claim_layout.mjs` (`watchClaimCSP`): the observer now records only |
| + the order of the stages shown (`window.claimStages`). A second observer |
| + on `#claim-progress` for `data-stage-held` collects each page-recorded |
| + hold into `window.claimHolds` (`:89-93`). The domInteractive / |
| + first-paint heuristic is gone. The blank-frame counter is unchanged. |
| +- `demo_claim_browser.mjs`: `assertHeld()` (`:24`) checks that stages 1, |
| + 2, 3, 4 were shown in order and that the page-recorded hold of each of |
| + stages 1 to 3 is `>= heldAtLeast`. Both callers (the fast scene, `:195`, |
| + and every `liveMotion` variant, `:245`) use it. |
| +- `heldAtLeast = 650 - 1 - 0.2` (`:20`). The 1 ms: `setTimeout` takes a |
| + WebIDL `long`, so the fractional delay `hold()` asks for is truncated |
| + (under 1 ms lost). The 0.2 ms: Chromium coarsens `performance.now()` to |
| + 100 µs with jitter on a page that is not cross-origin isolated (the |
| + console sends no COOP/COEP), so each reading is off by under 0.1 ms. |
| + `since` is both the hold's base and the recorded start, so its error |
| + cancels. The reading inside `hold()` and the recorded end do not. The |
| + bound is: recorded hold > 649 - e(hold read) + e(end read) > 648.8. |
| +- The working-button hold (`:213-223`) keeps its check. It does not have |
| + the observer's weakness: the test reads `performance.now()` in the page |
| + before `requestSubmit()` and again inside the overridden `submit`, so the |
| + two readings bracket a whole-number `wait(650)` plus a double rAF. It |
| + now uses the tighter `heldAtLeast` (648.8 instead of 640). |
| +- `demo_claim_footer_test.go`: `TestDemoClaimFooterAbsentKeepsOldBytes` |
| + pins the sha256 of eight rendered claim pages. The pages link the |
| + script by a content-hashed path (`assetURL`, `assets.go:67`), so the |
| + new script moved all eight. I rendered the eight pages with main's |
| + script and with this one (throwaway test, deleted). After replacing |
| + `static/<hash>/demo_claim.js` with a placeholder, each pair is |
| + byte-identical. The only difference is `167c6323732b` to `abd45e02c318`. |
| + The new digests are the ones the failing test printed. No other file |
| + pins the old hash or digests. |
| + |
| +## Evidence (docs-t1, Chromium 151.0.7922.173, node v24.19.0, load about 40 on 16 cores) |
| + |
| +- Mutation: `minimum = 600` in `demo_claim.js` (reverted). Fast390 fails: |
| + holds 622.7, 601.7, 611.3 ms. |
| +- Mutation: `await hold()` removed from `advance` (reverted). Fast390 |
| + fails: stage 2 held 0 ms. |
| +- After, at f1193adc: `go test ./internal/console -run 'TestDemoClaim|TestDemoSpentToken|TestAppSource' -count=3 -timeout 40m -v`. |
| + Rounds 1 and 2 passed every browser test: UX (Headless, Fast390/1280, |
| + four Motion), BrowserHeadless, SpentTokenBrowserHeadless, KeptHeadless, |
| + SelectStepUpHeadless, AppSourceHeadless, CountdownBrowser. Round 3 |
| + passed all the non-UX browser tests (each 3/3), then the package hit its |
| + 40-minute timeout in `TestDemoClaimUXRetryRemainsClosed` on a machine at |
| + load 40 on 16 cores. That was a timeout, not an assertion. |
| + `TestDemoClaimFooterAbsentKeepsOldBytes` failed in every round: that is |
| + the digest golden above, fixed in 9ced5534. |
| +- After, at 9ced5534: `go test ./internal/console -run 'TestDemoClaimUX|TestDemoSpentToken|TestDemoClaimFooter' -count=1 -timeout 30m -v` |
| + gave `ok ... 144.430s`, with every UX browser test, the spent-token |
| + browser test and all eight footer tests PASS. So each UX browser test has |
| + passed three times. |
| +- Census and code-health do not read these files (no references in |
| + `internal/provision` census tests, `internal/codehealth` or |
| + `.amadan/code-health.tsv`), so I did not run them. |
| + |
| +## What to check |
| + |
| +1. Production behaviour unchanged: is there any path where `held()` can |
| + throw, run before `progress`/`since` exist, change a timer, or alter |
| + layout or style? Does any CSS or JS select on `#claim-progress` |
| + attributes so that a new `data-*` attribute matters? Does any golden or |
| + snapshot include runtime attributes of `#claim-progress`? |
| +2. Is `data-stage-held`'s start the same `since` that `hold()` used for |
| + that stage, and its end no earlier than the moment the next state |
| + shows? Check all three call sites. In `finish`, `held()` (`:291`) comes |
| + after the last `throw` (`:282`) and after a few DOM writes in the same |
| + task (`:284-290`), with no paint between them and the claimed state |
| + (`:294`); a failed `finish` is retried by the next poll and records |
| + nothing until it succeeds. Confirm. |
| +3. Does the assertion still fail for a page that skips or shortens its |
| + hold? Think of variants other than the two mutations above: `held()` |
| + removed (holds missing), hold awaited without `await`, `since` reset |
| + late. |
| +4. Is the 0.2 ms coarsening allowance right for this Chromium, and is the |
| + truncation argument right (fraction of a `long` delay)? Can a DOM timer |
| + fire early relative to `performance.now()`? |
| +5. Can the `data-stage-held` observer miss a write (two writes before one |
| + callback)? If it did, the test fails rather than passes; confirm. |
| +6. Is any timing check left on the observer's clock, or on node's clock in |
| + a way that can fail under load? Known and left as is: the |
| + `button submitted before 650ms` check (`demo_claim_browser.mjs:221`) |
| + waits 500 ms in node and expects no submit yet. Under heavy load it can |
| + only fail falsely, not pass falsely. Say whether it should change in |
| + this branch. |
| +7. `minimum` is written twice: page (`demo_claim.js:8`) and test |
| + (`demo_claim_browser.mjs:19`). Acceptable, or should the test read it |
| + from the page? |
| + |
| +## 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 'TestDemoClaimUXHeadlessFast'`. |