Skip to content

Make the paced-reveal check observe every redraw, not sample on a timer - #718

Merged
neuromechanist merged 7 commits into
developfrom
feature/issue-691-paced-reveal-flaky
Nov 11, 2026
Merged

neuromechanist merged 7 commits into
developfrom
feature/issue-691-paced-reveal-flaky

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

frontend/browser-harness/paced-reveal-check.mjs failed on the CI runner with "the reader saw the reply grow through 3 different lengths" (#691). This makes the check observe every redraw and removes the dependence on runner speed, without touching frontend/osa-chat-widget.js, the REVEAL_* constants, or the threshold of 4 distinct lengths.

Root cause, with evidence

The first hypothesis was that the 25 ms timer sampler undercounts redraws on a starved main thread. The reproduction shows that this is true but is the minor cause. The main cause is in the widget's design: the reveal is a deadline (REVEAL_LAG_MS 500), so a tick that runs late draws a bigger slice to keep to it. On a starved runner the widget itself draws fewer, larger steps, and nothing that counts lengths can count steps that were not taken.

  • CI run 42951835425 (PR feat: import a chat notebook as a named tab and notebook tabs (E4.2, E4.4) #690/Notebook bridge: import a notebook from the chat as a new tab #673 branch, Frontend Tests, "Check the paced reveal in headless Chrome"): stall 150, distinctLengths 3, redraws 5, p50 = p75 = p100 = 1881 ms. On a quiet run the same reply draws 7 lengths in 9 redraws (2 of the redraws are not the reply: the user message and the final one). 5 redraws is consistent with 3 reply draws, so the sampler and the widget agree here as far as the log shows.
  • Reproduction (page stalled on purpose, the unmodified measurement): a MutationObserver recording the length at every redraw reported the same numbers as the sampler (observed 3, sampled 3, redraws 5) in the runs below. The widget drew [7, 344, 888] characters, one slice 200 to 250 ms after the previous one (a late tick drawing a bigger slice), in the same shape as the CI log. The mechanism (a late tick drawing a bigger slice) is shown with five 300 ms stalls; five 150 ms stalls do not reproduce the CI numbers (5 lengths, passes), so the exact stall pattern on the CI runner is unknown. The fix does not depend on it: the forgiving clock removes lateness whatever its source.
  • The sampler also undercounts in a minority of runs (at 50x throttling: observed 4, sampled 3, in 2 of the roughly 12 runs that printed both), so recording at every redraw is still right, and is done here. It is not sufficient alone: at 50x the observer alone still passed only 2 of 6.
  • The only logged instance of this assertion failing is run 42951835425. gh run list --workflow Tests --status failure --limit 200 (102 failed runs, back to 2025-12-23) plus gh run view --log-failed on each found the assertion text in two other runs (36784174307, 36574519801), both of which passed it ("grew through 5 / 6 different lengths") and failed on other checks.

Changes

  1. Opt-in reproduction switches (commit 1, no behaviour change unset): PACED_REVEAL_CPU_THROTTLE=<rate> (CDP Emulation.setCPUThrottlingRate) and later PACED_REVEAL_STALL_MS=<ms> (the page's main thread blocked that long five times from 90 ms after the first text, 240 ms apart, a deterministic stand-in for a busy neighbour).
  2. Observation: a MutationObserver (childList, subtree, characterData) on .osa-chat-messages records [performance.now(), reply text length, code block lengths, sources, forgiven] at every redraw, in the page. distinctLengths, p25/p50/p75/p100, the code-block and sources checks are derived from those records. The 25 ms sampler stays for stall and for the end-of-reply detection.
  3. Driving the reveal clock (the brief's fallback, because observation alone cannot make the count independent of runner speed): inside the page, each timer the widget sets that fires late moves the widget's clock back by how late it was, so the widget sees every tick on time, as on a quiet machine. The timers are still the browser's, the draws are still the widget's own code; the check's own measurements use the original clock. The total lateness in the reveal window (lateTicks) is added to the stall-stretched time bounds (stall = max(worst late sample, lateTicks), same cap), because a reveal whose ticks were late takes that much longer in real time. PACED_REVEAL_REAL_CLOCK=1 turns the clock adjustment off, which is how the failure is reproduced.
  4. README paragraph and the file header updated.

Every assertion and control is kept: threshold 4, burst, silence, fresh conversation, reduced-motion comparison, code block drawn whole, no early sources, stall-stretched bounds.

Evidence

Pre-fix is the unmodified measurement (commit 1 plus the stall switch applied to it); post-fix is this branch. Each is a loop of the check in headless Chrome 157 on a 10-core Mac.

Condition Pre-fix Post-fix
Quiet, 20 runs not looped (the unmodified check passed the runs seen) 20/20
20 busy yes processes on 10 cores, 20 runs 20/20 20/20
CPU throttling 8x, 20 runs 20/20 20/20
CPU throttling 50x, 20 runs 6/20 20/20
Main thread blocked 300 ms five times (PACED_REVEAL_STALL_MS=300), 20 runs 0/20 ("grow through 3 different lengths", redraws 5, as in CI) 20/20 (5 lengths, 7 redraws)
Blocked 150 ms five times, 6 runs 6/6 (5 lengths; measured with the observer and the clock left alone) 6/6 (7 lengths)

CPU load and 4x to 8x throttling alone do not reproduce the failure here: they slow the page evenly, and a tick-by-tick reveal still draws 5 or more steps. What reproduces it is the page stopping for 150 ms or more, so that is what the deterministic switch does.

Commands run

  • bun install: 11 packages installed.
  • bun frontend/browser-harness/paced-reveal-check.mjs: all checks passed (7 lengths, 9 redraws, stall 17).
  • 20-run loops as in the table (pass/fail counts as shown).
  • uv run pytest tests/test_frontend/test_embed_snippet_hygiene.py -q --no-cov: 17 passed.
  • bun frontend/test-widget-paced-streaming.js: 373 checks, 0 failed.
  • gh run list --workflow Tests --status failure --limit 200 and gh run view <id> --log-failed | grep: see above.

No new test file, so no workflow change. frontend/osa-chat-widget.js is unchanged; the evidence shows no widget defect (the coalescing on a late tick is the designed deadline behaviour).

Closes #691

Design note: CI now runs the widget with an adjusted clock, so late-tick coalescing (fewer, larger steps by design, REVEAL_LAG_MS) is intentionally not tested by this check. With the widget's pacing forced off the check still fails, with and without a stall, so it keeps its teeth.

…a starved runner (#691)

Opt-in CDP Emulation.setCPUThrottlingRate on the measured page; unset it is a no-op. Tested: at 50x the unmodified check fails 'grow through 3 different lengths' with redraws 5, as in CI run 42951835425.
…tick against the widget (#691)

Lengths, quartile times, code blocks and sources are read from a MutationObserver
on the messages container, timestamped in the page; the 25 ms sampler stays for
stall and the end of the reply. The widget's own timers move its clock back by how
late they fired, so a starved runner still sees every tick on time; the lateness
is added to the stall-stretched bounds. The threshold of 4 lengths is unchanged.
Tested: 20/20 unthrottled, 20/20 under 20 busy processes, 20/20 at 8x and 50x CPU
throttling, 20/20 with 300 ms stalls (the unmodified check: 0/20).
…tarvation switches (#691)

Docs only; the README commands were run.
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://feature-issue-691-paced-reve-demo.osc.earth
Branch feature/issue-691-paced-reveal-flaky
Commit e7c1828

This preview will be updated automatically when you push new commits.

…observer record, fix the env switch (#691)

Tested: check passes by default and 5/5 under PACED_REVEAL_STALL_MS=300; fails with PACED_REVEAL_REAL_CLOCK=1 at 300 ms.
@neuromechanist

Copy link
Copy Markdown
Member Author

Review round 1, outcomes (fix commits on this branch):

  • Shifted clock not monotone (important): fixed. The shifted performance.now now returns lastReported = Math.max(lastReported, now() - forgiven). Tested: the check passes by default and 5/5 with PACED_REVEAL_STALL_MS=300, and still fails (3 runs) with PACED_REVEAL_REAL_CLOCK=1 at 300 ms.
  • Stale quartile comment (important): fixed, reworded to refer to the redraw records and a late tick drawing a big slice.
  • Root cause stronger than the evidence (important, PR body): fixed in the PR body. It now says the mechanism is shown at 300 ms x5, that 150 ms x5 does not reproduce the CI numbers, and that the CI runner's exact stall pattern is unknown; the "sampler saw every draw" claim is softened.
  • Crash when the observer records nothing (suggestion): fixed. summarize returns null when there are no non-empty redraws or no arrivals, and check() reports "the observer recorded the reply being drawn" and returns early for both the paced and reduced-motion runs.
  • PACED_REVEAL_REAL_CLOCK=0 treated as set, spacing slip (suggestion): fixed. const FORGIVE_LATE_TICKS = process.env.PACED_REVEAL_REAL_CLOCK !== '1';.
  • README wording (suggestion): fixed. It says "five 300 ms stalls", explains PACED_REVEAL_STALL_MS (five blocks, 240 ms apart, from 90 ms after the first text), and annotates the CPU_THROTTLE line. Docs only, not run. I did not re-measure the 50x failure rate (14/20 is from the PR body); 6 local runs at 50x with the adjusted clock all passed.
  • Design tradeoff to record (suggestion): no code change; added the explicit sentence that late-tick coalescing is intentionally not tested, to the file header, the README and the PR body.

Note: Biome with no repo config reports pre-existing formatting and an unused error variable in finally; those are untouched lines and not changed here.

…urn field (#691); tested: check passes, stall reproduction still fails as documented
@neuromechanist

Copy link
Copy Markdown
Member Author

Review round 2 outcomes (commit fc504c1):

  • Header comment says 150 ms stalls reproduce the failure (paced-reveal-check.mjs, line 23): fixed. It now says a few hundred ms (five 300 ms stalls reproduced it; 150 ms ones did not), matching the README.
  • STALL_MS comment overstates CPU_THROTTLE (line 151): fixed. It now names PACED_REVEAL_REAL_CLOCK=1 with PACED_REVEAL_STALL_MS=300 as the deterministic reproduction, and CPU_THROTTLE at about 50x as failing only some runs (4x to 8x does not fail).
  • Unexplained diagnostic fields (line 311): fixed. sampledLengths has a comment saying it is printed for comparison with distinctLengths and is not asserted; forgiven is dropped from the MEASURE return value (it is still used inside the page for the per-snapshot value and the stall).

Tested: bun frontend/browser-harness/paced-reveal-check.mjs passes, and with PACED_REVEAL_STALL_MS=300 it passes; with PACED_REVEAL_REAL_CLOCK=1 PACED_REVEAL_STALL_MS=300 it fails as the README documents. Comments and one removed field only; no behavior change.

@neuromechanist
neuromechanist merged commit bd819d0 into develop Nov 11, 2026
8 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-691-paced-reveal-flaky branch November 11, 2026 13:29
@neuromechanist

Copy link
Copy Markdown
Member Author

PM verdict: ready and merged. Every criterion met (root cause with evidence and reproduction, observer-based lengths plus the forgiving clock fallback with explanation, threshold 4 and all controls kept, 20-run stability tables, README and header updated, hygiene test passes, widget unchanged). All review findings from rounds 1 and 2 have outcomes. After updating the branch, Lint, Test (3.11), Test (3.12), Frontend Tests and deploy all passed; Integration Tests skipped. Squash-merged; #691 closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant