Skip to content

Wait for an ordered event before each absence check that slept - #5541

Merged
max-sixty merged 3 commits into
mainfrom
grind/absence-waits
Nov 5, 2026
Merged

max-sixty merged 3 commits into
mainfrom
grind/absence-waits

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Fifteen tests waited a fixed time, from 50 ms to 11 s, and then asserted that something had not happened: a receipt not sent, a probe not repeated, a pane not scrolled. On a slower machine the unwanted thing can land after the wait, and the test passes with the bug present. tests/AGENTS.md's "Absences", as #5522 rewrites it, says to wait instead for an event the page orders after the moment the unwanted thing would have happened, and then check that it is absent. Fourteen of these tests now do that, and the fifteenth drops its check, since nothing can produce what it checked for.

Test Waited Now waits for
test_render_read_state::test_modal_blocks_exposure_until_user_returns_to_threads 100 ms rendered, then round_trip: the read pass the resize set off has run, and any receipt it sent has come back
test_render_read_state::test_oversized_message_needs_contiguous_traversal 100 ms the same, after the scroll
test_render_read_state::test_a_page_seat_the_open_panel_stands_over_is_not_read 1.5 s the same, after the scroll
test_render_drawing::test_a_second_finger_takes_back_the_stroke_the_first_began 100 ms rendered: every repaint the release queued has run
test_render_floating_panel::test_writing_reaches_the_field_however_the_panel_stands 300 ms rendered: the resume has drawn what it decided
test_render_anchors::test_a_failed_deferred_hydration_waits_for_a_user_retry 250 ms the page's clock run a minute forward, past any backoff a retry would wait out, then rendered, with the page counting its own /api/deferred fetches
test_render_startup::test_slow_history_keeps_decisions_safe_and_status_honest[ready] 50 ms the planted fault's pageerror, then rendered
test_render_startup::test_user_view_context_waits_for_a_samples_viewport_allocation 11 s the page's clock run 11 s forward, then a check that the view restoring the frame is the only one sent since it went to zero
test_panes::test_reading_keys_follow_the_focused_pane_without_moving_its_sibling, first press 250 ms scroll_settled on the pane, then on the document
the same, second press 250 ms the same
test_freshness::test_status_changes_coalesce_behind_one_state_read, two waits 500 ms each the second freshness look asked after the change, which the page asks only once it has handled the first, with the page counting its own looks and state reads
test_changes_in_place::test_a_to_do_running_on_an_element_marks_it 300 ms told: the page has taken in the to-do
test_wait::test_the_stop_hook_watch_wakes_the_session_only_for_input 1 s two more passes of the watch over the pending input, with each pass's wait shortened to zero
test_site::test_a_page_that_starts_after_a_fault_takes_its_notice_back 3 s the page's clock stepped a second at a time, three times, each step taken with no probe round in flight, with the page counting the probe's own fetches
test_site::test_a_probe_in_flight_leaves_a_page_that_started_alone 2 s the page having handled the held probe round's answer
test_projected_data::test_data_written_while_a_fresh_revision_starts_shows_once_it_has_started (renamed from test_data_written_during_fresh_revision_startup_waits_for_activation) 100 ms nothing: the check is removed (below)

Four of these count requests in the page rather than through Playwright. A route handler's list and a request event reach Python on their own schedule, after the page's call, so a count read right after an ordered event could still be missing the request it is checking for.

Three of the waits needed more than an ordered event:

  • The started-page probe test. The supervisor sets the timer for its next round only once the last round's answer lands, so a clock run while a round is in flight fires nothing. The test therefore waits until no round is in flight and steps the clock a second at a time, waiting out any round each step starts. It throws its planted fault from a DOMContentLoaded listener, because a timer's callback under Playwright's installed clock throws without firing the page's error event (measured: the callback ran, the page's error listeners saw nothing, and data-lf-startup-error stayed unset), and the supervisor would never start. The test first checks that the supervisor recorded the fault in data-lf-startup-error.
  • Both probe tests count only the supervisor's probe, which asks for registry.json past the cache. The runtime's own read of the same address used to count too, so handled >= 1 could hold before the held round was answered. Each probe also carries a Leaf-Test-Probe header, so the in-flight test's route holds the probe alone; the runtime's read goes through, and the page comes up on its own rather than through a planted data-lf-upgraded.
  • The deferred-hydration test runs the page's clock forward, since rendered doesn't wait for a timer and a retry on a backoff would come after it.

The projected-data test checked, 100 ms after writing data during a fresh revision document's startup, that the update had not painted. That guarded a newer source reading painting into a document that was still activating, a case from before #666, when an activation could hold the page while the new document was already mounted. Since #666 a revision that changes the page's code starts a fresh document. The test holds that document's registry.json for all of startup, and widgets import their modules only after it arrives (widget-loader.js), so no widget exists to paint the update. No product change short of drawing widgets before their registry can bring the case back. The checks after the release stay: the update shows, and so does the new revision's text.

Controls

For each test, a throwaway product change made the unwanted thing happen, and the converted check caught it. Each browser test ran four ways: as is and with the change, at CPU 1x and at --cpu-throttle 10. As is, every run passed; with the change, every run failed at the converted check. None of the changes is committed.

Test Change
modal thread/read.js reads a message under an open modal
oversized message thread/read.js takes any traversal as contiguous
page seat under the panel thread/read.js measures the message without the panel's clip
second finger drawing.js keeps the stroke when it is dropped
resume drafts.js reports the writing place unavailable after resuming it
deferred hydration lf-diff.js retries a failed load on the next task, and separately on a 1.5 s backoff
post-upgrade fault prepaint.js marks a startup error, a task later, for an error after upgrade
sample viewport user-view.js reports a zero-sized view
panes, first press the d key also scrolls the sibling pane two frames later
panes, second press the d key scrolls the focused pane a further 40 px two frames later
freshness state-feed.js asks again while a read is in flight
to-do margin-bars.js marks a to-do's target before it is running
stop-hook watch session.py wakes on the second pass over pending input (a model test, so no throttle)
started page's probe bootstrap.js drops both of the probe's started checks; over the clock's three steps the count rose from 1 to 4 at 1x and from 2 to 5 at 10x
in-flight round bootstrap.js acts on a round's answer after the page started; a second document, ?_leaf-recovered=, was requested

What ran

Each touched test as is and with its change, at CPU 1x and 10x, one at a time (uv run --frozen pytest <test> -n0 -q, then with --cpu-throttle 10), from scripts that applied and restored each change, and the projected-data test as is at both. Every touched test together at 51e0bf3, with -n 2: 19 passed; the four tests changed since then each passed as is at 1x and 10x, and the freshness and projected-data tests again at 1x after the last change. Not run: Firefox or WebKit, and the rest of each test file.

The sleeps removed total about 21 s, 11 s of it in the sample-viewport test; the deferred-hydration test's minute of clock adds about 3 s.

The rule is #5522; #5523 holds the fixes to the scaling checks and the playground wait.

This was written by Claude Code on behalf of max-sixty

Fifteen tests slept a fixed time, from 50 ms to 11 s, and then asserted that
something had not happened: a read receipt, a repeated probe, a retried fetch, a
scrolled pane. On a slower machine the unwanted thing can land after the sleep,
and the test passes with the bug present. Each now waits for an event the page
orders after the moment the unwanted thing would have happened (tests/AGENTS.md,
"Absences"): `rendered`, `round_trip`, `told`, `scroll_settled`, a `pageerror`,
a later request of the same kind, the page's clock run forward, or, in the
stop-hook watch's model test, two more passes of the watch.

Three tests count requests in the page instead of through Playwright, whose
route and request events reach Python on their own schedule after the page's
call, so a count read after an ordered event could still miss the request.

The started-page probe test planted its fault from a timer. Under the clock
this change installs there, a timer's callback throws without firing the page's
`error` event, so the supervisor never started and the test passed whatever the
probe did. A `DOMContentLoaded` listener throws the fault now, and the test
first checks that the supervisor recorded it.

Each test ran as is and with a throwaway product change that makes the
unwanted thing happen, at CPU 1x and, for browser tests, at --cpu-throttle 10.
As is, every run passed. Mutated, every run failed at the converted check,
except the projected-data test: a widget draws data only after the page's
registry loads, which the test holds through all of startup, so no plausible
change paints the update in that window. Its observer records any such paint
for the whole hold, where the sleep sampled 100 ms of it.

Co-authored-by: Claude Opus 5.5 <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In test_a_probe_in_flight_leaves_a_page_that_started_alone, the new wait can be met by the runtime's own registry.json read rather than the held probe round, which would leave the absence check unordered again (inline).

Comment thread tests/journeys/test_site.py Resolved
max-sixty added a commit that referenced this pull request Nov 5, 2026
…ine ten times slower (#5523)

Max's rule is that every test still passes on a machine ten times slower
than the one
it was set on (#5522). Two places this changes broke it.

**The scaling journeys' noise floors were milliseconds.** `exponent`
leaves out a size
whose growth above BASE is under a floor, 10 ms (50 ms for the server's
time to answer).
On a slower machine every reading grows and the noise with it, so more
sizes clear a
fixed floor and noise gets fitted; on a faster one, real growth falls
under it. A floor
is now a share of a reading from the same run: the BASE page's load for
the browser's
costs (`scaling.floors`, 5%, and 25% for the server's time to answer),
and each
server path's own reading on the BASE page (`server_scaling.floors`), so
a cheap path
isn't judged against a dearer one's fixed work. On this Mac the
browser's come to 8-10 ms
and 39-52 ms. The event answer's size stays 10 KB, since no machine's
speed changes it.
`exponent` takes the floor from its caller.

On the growth test's readings of all four pages, scaled as a machine 10
times faster or
slower would scale them, the ms floors fit different sizes to different
exponents at
each speed (asks' click: none, 0.89 over two sizes, 0.67 over three),
and the new floors
fit the same sizes to the same exponent at every speed.

**The browser growth test's time.** With the suite's health sensors, the
growth test's
document page took 1,203 s on CI's daily run, and at CPU rate 10 the
document and asks
pages ran past the 1,800 s per-test limit. #5515 has since moved the
test onto
`browser.unwatched`, as this branch also did, so that part merged
without a change here.
On the merged head, the growth test's logic at CPU rate 10 passes the
document page in
199 s. The per-test limit stays at 1,800 s.

**The playground leave test waited a fixed second.** After two reloads
it waited
1,000 ms for a leaving document's post, then read the log to check that
leaving recorded
nothing. On a slower machine that post could land after the read, and
the test would
pass without checking. It now leaves one real edit for a third reload
and waits for that
edit's record, which arrives after anything the two reloads' leaving
documents posted,
then checks that it is the only new record. With leaving changed to
record the drawn
default, the test fails (7 records where 5 belong); restored, it passes,
also at
`--cpu-throttle 10`.

The other deadlines leave at least ten times their work's normal
duration and are
unchanged: `SERVED_TIMEOUT_MS` (120 s) bounds one probe or request;
`STATED_TIMEOUT`
(120 s) bounds a server start or a short subprocess;
`HANDOVER_DEADLINE_MS` (240 s)
bounds a corpus handover of 16-18 s; and the lease holder's 60 s in
`test_interact_server.py` outlives a nested run that takes 1 s here and
1.9 s on CI.

The scaling journeys are the daily gate on the costs #5194 tracks.

## Checks run

- `uv run pytest tests/journeys/test_scaling.py -n 2`: all four pages
pass, 115-131 s
  each.
- `uv run pytest tests/journeys/test_server_scaling.py -n 2`: eight
pass, and `cards`,
marked `xfail` because its exponent fits 1.3-1.6 from run to run, passed
this run.
- The server test's measurement three more times on all nine pages: each
run fitted 40
of 48 paths, where a floor of the BASE page's paths together fitted 20
or 21 of the
same readings. Outside `cards` the largest exponents were 1.25, 1.11 and
1.13, and
`cards`' `delivery` fitted 1.49, 1.51 and 1.47 under either floor.
Unfitted are the
`revisions` page's five paths, which stay flat as versions accumulate,
and `activate`
  on `threads`, `messages` and `batch`.
- The growth test's logic at CPU rate 10, outside pytest
(`.tmp/review/growth_check.py`
in the worktree), on document and asks: both pass, in 196 s and 254 s.
Rerun on
  document after merging main (4130d3e): passes in 199 s.
- After merging main, `uv run --frozen pytest
tests/journeys/test_scaling.py -n 2`: all
  four pages pass, in 250 s.
- The same with 100 ms of busy work at the 256 page added to each press,
key and wheel
step, scaled with the square of the page's size, at rate 1: click, key
and scroll fail
  on prose and document.
- The growth test's dumped readings from all four pages, watched and
unwatched, with
every duration scaled by 0.1 and by 10: the share floors fit the same
sizes and
  exponents at each scale; the ms floors didn't.
-
`test_a_playground_records_an_edit_made_while_loading_or_as_the_page_leaves`:
fails
with leaving recording the drawn default, passes restored, and passes
with
  `--cpu-throttle 10`. `test_a_wait_takes_the_suites_deadline` passes.
- `pre-commit run --files` on the changed files.

## Not covered

`--cpu-throttle` and CDP's `Emulation.setCPUThrottlingRate` slow only
Chromium's
renderer. Page building, the server, Python and Playwright's driver ran
at full speed in
the rate-10 runs, so those runs don't show how the server's time to
answer, or a
journey's setup, behaves on a machine ten times slower. `--cpu-throttle`
also doesn't
reach a page from `browser.unwatched`, so the rate-10 runs of the growth
test wrapped
the tab themselves.

The rule this follows is in #5522, and the fixed waits before absence
assertions are in
#5541.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
max-sixty and others added 2 commits November 5, 2026 13:29
The probe tests counted every `registry.json` fetch, and the runtime's own read
of the registry is one, so the in-flight round test's `handled >= 1` held
before the round it waits on was answered. `COUNT_PROBES` now counts only the
probe, which asks past the cache, and names each probe in a header so the route
holds the probe alone. The runtime's read goes through and the page comes up on
its own, so the test no longer plants `data-lf-upgraded`.

The supervisor sets the timer for its next round only once the last round's
answer lands, so a clock run while a round is in flight fired nothing, and the
started-page test passed with a probe that ignored `started`. The test now
waits until no round is in flight, then steps the clock a second at a time,
waiting out any round each step starts.

`rendered` doesn't wait for a timer, so a retry on a 1.5 s backoff passed the
deferred-hydration test at 1x. The test now installs the page's clock and runs
it a minute forward before it counts.

The freshness test read the route's list of held state reads after an ordered
event, which reaches Python on its own schedule. It now counts looks and state
reads in the page, and waits for the second look asked after a change, which
the page asks only once it has handled the first.

The projected-data test drops its check that data didn't paint during the
fresh document's startup. The test holds the revision's registry for all of
startup, and widgets import their modules only after it arrives, so no product
change can paint in that window; the checks after the release stay.

Each fixed test fails with its planted defect at CPU 1x and --cpu-throttle 10,
and passes as is at both.

Co-authored-by: Claude Opus 5.5 <[email protected]>
…tup data test

The freshness test took its baseline of state reads from the page's count less
the route's list of held reads. It now reads the page's count before installing
the route, so every comparison is between the page's own counts.

The projected-data test no longer checks that data stays unpainted during the
fresh document's startup, only that it shows once the page has started, so its
name says that.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review November 5, 2026 21:55
@max-sixty
max-sixty merged commit 0eb1a7f into main Nov 5, 2026
6 checks passed
@max-sixty
max-sixty deleted the grind/absence-waits branch November 5, 2026 22:14
max-sixty added a commit that referenced this pull request Nov 5, 2026
…one by a benchmark (#5522)

`tests/AGENTS.md` held functional tests to giving the same result when
the system runs
ten times slower, and sent performance to be tested "separately, under
controlled
conditions". Max's rules now cover every test: "we should never have the
timings be a
test, we should have a rule that running on a 10x slower machine still
passes", and "we
should never pass/fail based on benchmark results".

The section "Functional results do not depend on execution speed"
becomes "Results do not
depend on execution speed", and says:

- every test, fixtures and watches included, gives the same result on a
machine ten times
slower than the one it was written on, since CI's runner and a host
running other
  sessions' suites are both slower than an idle development machine;
- so no test asserts a duration, and no test passes or fails on a
benchmark's reading: a
benchmark reports its readings (`leaf-dev scaling`, charted daily), and
a reader judges
  them;
- `--cpu-throttle 10` checks a test against the rule; it slows only
Chromium's renderer,
  not the server, Python or the driver, and doesn't reach a page from
  `browser.unwatched`;
- each operation that could hang gets a deadline at least ten times the
longest it takes
on CI's runner, whose `test` job records each test's time in its junit
results
  (`leaf-dev suite-profile`).

"Absences" now says how to assert that something didn't happen, the
commonest violation:
wait for a later event ordered after the moment the forbidden behavior
would have
happened, then check it is absent. It names the events the suite already
waits on: the
page's sends coming back (`round_trip`), the page taking in what the
server holds
(`told`), the shared clock's next tick (`ticked`), and a later gesture
of the same kind.
"Wait for the operation's own completion signal" already covers a fixed
wait before an
assertion that something happened.

Three other places follow:

- `test_a_wait_takes_the_suites_deadline` called a sleep "an absence
window"; it now says
a sleep bounds nothing and points at "Absences". Its check never read
sleeps, so only
  the docstring changes.
- `faulthandler_timeout`'s comment in `pyproject.toml` said the slowest
test takes under
three minutes on CI. On the 2026-11-05 nightly, sixteen tests took
longer than 180 s,
the slowest 1,614 s. Max decided the half-hour limit stays a guard
against a hang,
outside the ten-times rule, and the comment now says so. The limit
itself is unchanged.
- "Races" said `--cpu-throttle` slows every page the browser fixtures
open; it now says
the pages the `browser` fixture watches. The two comments that cite the
section by
  heading follow its new name.

`dev/AGENTS.md` says nothing about timing; `leaf-dev scaling`'s own
header owns how it
measures. No eval was run on this wording.

Related: #5563 took the daily growth tests' pass/fail out, so nothing
gates on a benchmark's reading; #5523 holds the playground wait and the
scaling changes, and #5541 the fixed
waits before absence assertions.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 6, 2026
…sts' absence checks (#5603)

Four tests in `tests/browser/startup/test_freshness.py` slept for a
fixed time and then checked that something had not happened: the page
asking for state, reloading, or looking for news while hidden. On a slow
machine the unwanted request or reload can arrive after the sleep, so
the test passes with the bug present. That breaks the rule in
`tests/AGENTS.md`, "Absences", and #5541's sweep missed this file. Each
check now waits for something the page itself does after the moment it
would have misbehaved. The page counts its own requests (`COUNT_ASKS`,
moved to the top of the file). Each rewritten check failed with the bug
it guards against planted in `browser/runtime/state-feed.js`, and all
twelve tests in the file pass without it.

| Test | Slept | Now waits for | Planted fault it caught |
|---|---|---|---|
| `test_a_quiet_page_reads_only_freshness_and_hears_changes` | 3 s | a
round of the shared clock, then a freshness check the page finished |
the clock asking for state every round (`asks = true \|\| …`) |
| `test_a_durable_server_restart_keeps_the_current_editor` | 500 ms |
the page's next freshness check after the one that saw the new server,
or a reloaded document, whichever comes first | a reload 100 ms after
seeing the new server |
| `test_a_hidden_page_stops_its_freshness_reads_until_it_is_visible` |
500 ms | a round of the shared clock; it now also checks that no
freshness request was sent after the page hid | a hidden page that keeps
checking (`stopListening` not called) |
| `test_a_page_whose_read_failed_asks_again_on_its_own` | 1 s | eight
freshness checks; it then allows one state read per round of the clock,
timed by the page's own clock, plus one | every check asking for state
(`if (true) item(observed)`), which made 9 reads in about 2 s |

`ran_its_clock` has the page set a timer one interval of the shared
clock long (`TICK_MS`, plus 500 ms). The browser fires timers in
deadline order, so the clock's next round and any freshness check still
scheduled run before it, however slowly the machine runs them. A fixed
sleep, by contrast, runs on the test's clock, which knows nothing about
the page's timers. `TICK_MS` is copied from `state-feed.js`, and a
comment says so.

The 100 ms sleep before the hidden-page test writes its news is left in
place: it is setup, not a check that something stayed absent.

Co-authored-by: leaf-agent <[email protected]>
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.

2 participants