Skip to content

Start a reload from the drafts its page still had waiting, so words typed on arrival stand - #6399

Merged
max-sixty merged 6 commits into
mainfrom
agent-a4e817d30564068e6
Nov 18, 2026
Merged

max-sixty merged 6 commits into
mainfrom
agent-a4e817d30564068e6

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Refs #6392

Words typed just after a reload could be replaced by the page the user left. A reload while a draft write was still out was served the older generation the server held, and the departing page resent the newest words on pagehide. Where the resend landed first, the server refused the reload's write over the older generation and answered with the resend's words, which the reload took for another tab's, so the words typed after the reload went. That is the nightly macOS failure of test_a_kept_draft_and_an_input_method_reach_the_editor_as_it_loads ("typed words left the screen"). This branch first made that test wait for the write before reloading; it now fixes the runtime, and the test presses as a fast user would again.

The change

On pagehide, the page also leaves in the tab's session store, for each draft, the generations its writes that may still land carry or name, and its copy of a draft still waiting (browser/runtime/drafts.js). A reload takes them before it hears the drafts it was served (takeWaitingDrafts):

  • It starts from the copy, so the newest words show at once.
  • The words it has yet to send go over any of those generations, whichever lands and when (superseded). Words another tab or device wrote still win, by the rules every reading follows.
  • It stops counting them once it hears the server take a write of a generation outside the set, since those writes can then land only into an empty slot. Until then a further reload hands them on.
  • A generation the page was still sending hands on its generations but not its copy, since only the server's answer says whether the log took those words; the reload shows what it was served.
  • A settled copy comes across too, so words sent just before a reload no longer show in its box as the earlier generation the server still held.

Only a reload takes what was left, and only once. A return through history can come long after the writes landed, and the server keeps no record of words put away since, so a replay then would stand them up again (the failure that closed #6221). browser/runtime/storage.js now says the tab holds unsent words only from a page to its reload.

What it leaves

The server's draft store forgets settlements: write_draft takes any write into an empty slot, so a write that arrives after its generation was put away stands it up again. The handoff adds one such path: if another tab puts the draft away during the reload, after the departing page's resend has landed, the reload's replay brings the words back. The same already happens without a reload, for a write whose answer was lost and which a look retries after another tab put it away. Closing both needs the store to remember the generations it settled, as the log remembers the sent ones; this change doesn't attempt that. The drafts.js header now says the server takes a write "only over one it names or over none".

Tests

Five tests in tests/browser/drafts/test_shared_drafts.py hold the departing page's writes and the reload's writes and reads with page.route. Chromium's routes don't see the keepalive resend, which lands as the page goes; Firefox's do, so the three tests that need the resend to land late run in Firefox. Each reload runs inside restarting, since Firefox warns of every module load a reload cuts short, such as the view checks a page imports after it presents; that helper's docstring now names a reload.

Test Order it forces Base drafts.js
…stand_over_the_resend_of_the_page_it_left (Chromium) resend lands, then the reload's writes server ends "Kept"; watch: "K words" left the screen
…stand_however_late_the_page_it_left_writes (Firefox) the write that was out lands, the reload's first write is refused over it, the resend lands, then the reload's next write no reload write to order
…stand_over_the_send_it_cut_short (Firefox) a send cut short by the reload, a second reload, then the resend server ends "Kept"
…stand_over_a_resend_landing_after_a_rewrite (Firefox) a send cut short, the server loses its drafts and the reload writes "K" back, then the resend server ends "Kept"
test_words_sent_just_before_a_reload_do_not_come_back_with_it (Chromium) a send answered just before the reload box shows "K" on arrival

All five pass with the change. The three Firefox tests also fail against this PR's earlier unpushed revisions, whose gaps an independent review found. The original test passes under taskpolicy -b with --cpu-throttle 8. pnpm run test:runtime and pnpm run check pass.

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

…hat restores it

The reloaded document is served the drafts the server holds. With the last keystrokes' write still in flight, it landed after the words typed on arrival and replaced them, which failed the macOS nightly. Refs #6392.
leaf-agent
leaf-agent previously approved these changes Nov 18, 2026
…yped on arrival stand

A reload while a draft write was still out was served the older generation the
server held, and the page it replaced resent the newest words on `pagehide`.
Where the resend landed first, the server refused the reload's write over the
older generation and answered with the resend's words, which the reload took
for another tab's: the words typed after the reload went. This is the nightly
macOS failure of
`test_a_kept_draft_and_an_input_method_reach_the_editor_as_it_loads` (#6392),
whose earlier fix on this branch only waited for the write before reloading;
the test presses as a fast user would again.

The page now also leaves in the tab store, for each draft, the generations its
writes that may still land carry or name, and its copy of a draft still
waiting. A reload takes them before hearing the drafts it was served. It shows
the newest words at once, and the words it has yet to send go over any of
those generations, whichever lands and when, until the server takes a write of
a generation outside them; a further reload hands them on until then. A
generation the page was still sending hands on its generations but not its
copy, since only the server's answer says whether the log took those words. A
settled copy comes across too, so words sent just before a reload no longer
show in its box as the earlier generation the server still held. Only a
reload takes what was left, once: a later arrival could replay words put away
elsewhere since, which the server keeps no record of (the failure that closed
#6221).

Left open: the server takes any write into an empty slot, so a Cancel in
another tab during the reload, after the departing page's resend lands, comes
back with the reload's replay, as a retried write already could. Closing it
needs the store to remember the generations it settled.

Independent review (Codex, four passes) found three orders the first versions
lost words in: the reload stopped counting the departing page's writes after
the server's first answer, a send cut short by the reload handed on nothing
(and a second reload dropped what the first inherited), and an accepted
rewrite of an existing generation retired the set too early. Each has a test.

Tests, against the base runtime and with this change:
- resend lands first (Chromium): server ends "Kept", watch reports "K words"
  left the screen; passes.
- Codex's late-resend order (Firefox, whose routes hold the keepalive resend
  that Chromium's don't see): no reload write to order; passes.
- send cut short, two reloads (Firefox): server ends "Kept"; passes.
- server loses its drafts mid-window (Firefox): server ends "Kept"; passes.
- send answered just before the reload (Chromium): box shows "K" on arrival;
  passes.
The original test also passes under `taskpolicy -b` with `--cpu-throttle 8`.
@max-sixty max-sixty changed the title test: wait for the kept draft to reach the server before reloading Start a reload from the drafts its page still had waiting, so words typed on arrival stand Nov 18, 2026

@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.

The three Firefox tests often error at teardown on this head. On a Linux runner I ran the selection three times, and …however_late…, …cut_short… and …after_a_rewrite… errored in 5 of the 9 runs, each time on a Firefox console warning such as Loading failed for the module with source "…/runtime/time-axis.js" (also checks/view.js, checks/words.js, runtime/user-view.js). Every test body passed. These tests reload as soon as wait_until_ready returns, while Firefox is still loading the page's lazy modules, and the harness fails a test on the warning that a cut-short module load leaves. #5883 and #6392 already track this warning as a rare one-off. These three tests make it likely on every run that includes them, so they would bring that intermittent red into the PR test job and the nightly. See the inline comment.

The server's draft store forgetting settlements ("What it leaves") has no issue I could find, and this change adds a path into it. An issue that names both paths (the lost-answer retry and the reload replay after another tab puts the draft away) would let whoever fixes it find the whole problem.

…'s cut-short module loads

The review bot ran the three Firefox reload tests three times on a Linux
runner: in 5 of 9 runs they errored at teardown on Firefox's warning
`Loading failed for the module with source …` (user-view.js, checks/view.js,
checks/words.js, time-axis.js). Each test reloads as soon as
`wait_until_ready` returns, while the page is still importing the view checks
it loads after presenting, and Firefox warns of every module load a
navigation cuts short. Holding `runtime/user-view.js` across a reload
reproduces it on every run, and wrapping the reload in `restarting` drops it.

`restarting` already holds that the complaints of a document the test
replaces belong to the replacement rather than to a wording list; its
docstring now names a reload beside a server or layer replacement.
…in the list

`test_words_typed_on_a_reload_stand_however_late_the_page_it_left_writes`
failed on the PR's Linux runner with more draft writes held than the three it
unpacked by position: the departing page's write, its resend and the reload's
first write. Locally the route holds exactly those three, including on
efficiency cores beside the other four tests, so the extra write's source is
unconfirmed; a second document in the tab, such as a startup recovery reload
on a cold Firefox, would add one.

The reload tests now key each held write by its words, marking a page's resend
as it goes by the generations it names (`_says`), and land every write of a
role in the order the pages sent it. The words typed on arrival go in as one
input, so the reload writes them as one generation. Against the runtime
revisions the review cases caught, each Firefox test still fails: the late
resend ends with the server holding "Kept" for "Kept words", and the cut-short
send and the rewrite each end with "Kept" for "K words".
@max-sixty
max-sixty merged commit d2195ff into main Nov 18, 2026
5 checks passed
@max-sixty
max-sixty deleted the agent-a4e817d30564068e6 branch November 18, 2026 20:49
max-sixty added a commit that referenced this pull request Nov 19, 2026
…ting (#6428)

A reload asks for its document before the page it replaces goes away.
Where that page then hears the server take its last draft write, it
holds the draft as durable, and #6399's handoff leaves the reload only
drafts still waiting, so the reload shows the older generation it was
served until its first look. Words typed on arrival go over that older
generation and are replaced by the departing page's words. This is the
flake in `test_held_keys_stand_beside_a_saved_draft` ("H" for "Half a
thought", 2 of 13 runs under `-n 3` on a loaded Mac, with #6399 in).

The page now leaves its durable copies in the tab too, still marked
durable so the reload doesn't write them again; a served generation
older than a copy gives way to it by version in `hearReading`, as for
any reading.
`test_words_typed_on_a_reload_stand_over_a_write_taken_as_it_was_served`
serves the reload a document fetched before the write lands and fails on
main. The saved-draft test drops the wait-for-save step #6416 added; its
selection passed 8 of 8 runs.

To weigh: a store that went back as the page reloaded (a server
restarting from an older copy) isn't heard by the reload, so a durable
copy shows words the server lost and isn't written back; main drops
them. A Codex review found that taking the copies' versions as the
reload's heard store version, which would catch that, suppresses reads
of other drafts, so it's left out. Codex also confirmed a pre-existing
flaw this doesn't touch: recovery after a rollback writes the tab's
words over a generation another device wrote after the rollback.

`pnpm run check` and `pnpm run test:runtime` fail on main at the moment
in `anchor-placement.js`, from #6417; this change doesn't touch it.

Found while following up the saved-draft flake from #6383.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 19, 2026
…raft's version counts (#6441)

On leaf.page a draft write was answered before anything outside the
container held it, and every release started a new drafts store. The
browser guessed when the store had gone back by comparing a version
counter that restarts with each store, and the guess misfired: a reload
after a new store re-sent its words in a loop (1,903 requests in 3 s, on
`main` since #6399), a hidden tab could clear a draft once another
device's writes carried the counter past what it had heard, and a
detected restore wrote over another device's later words.

This removes the doubt rather than guessing better. leaf.page answers a
draft write only once the session's Durable Object holds it, through a
drafts-only operation that takes a write only over the version it
replaces. No page commit carries drafts, so a late commit can't put an
older store back, and a sleeping session serves the stored drafts in
place of the ones its last commit captured. `drafts.json` carries a
store id, which every reading and write answer names, and `drafts.js`
orders versions only within one store; a tab meeting a new store writes
its words where that store holds nothing for their draft. The counter
guess (`restoring`, `restores`, the floor in `lookForDrafts`, the
`restored` branch) and the stop handler's `save_drafts` are deleted.

It also adds a sentence to `SOUL.md`: Leaf drops typed words only when
it knows they're unwanted, and otherwise keeps them where the user can
find them. In a temporary A/B, maintainer agents given it kept both
tabs' words in a refused-write case in 4 of 5 runs, against 1 of 5
without it.

To weigh: a draft write on leaf.page now waits on a round trip to the
Durable Object, measured only against the loopback double (median 1.2 ms
against 0.7 ms). A write another tab beat still drops the refused tab's
words, and a release still starts each visitor's drafts over, as it does
their threads; both are left for later changes.

max-sixty asked for the fix; Codex reviewed the build; its finding that
a late save could overwrite a newer one is folded in as the
compare-and-swap above.

Tests: new process, website-server, browser and worker tests each fail
on a revert of their fix; `pnpm run check`, `pnpm run test:runtime` and
focused suites pass.

> _This was written by Claude Code on behalf of max-sixty_
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