Skip to content

Keep a gesture sent as the tab closes - #5062

Merged
leaf-agent merged 3 commits into
mainfrom
playground-saved-choices
Nov 2, 2026
Merged

leaf-agent merged 3 commits into
mainfrom
playground-saved-choices

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Closing a Firefox tab right after typing in a playground lost the edit in 3 of 8 closes. The playground records an unrecorded edit when the page leaves, which in Firefox is pagehide, and the event post was an ordinary request, which the browser cancels along with the document. Any gesture still on its way when a tab closed, such as a reply sent a moment before, could be lost the same way.

An earlier test of a keepalive post (#4845) set it only while the document was hidden and concluded keepalive didn't help. Firefox fires pagehide while the document still reads visible, so the post that mattered never had it. One traced close: beforeunload, pagehide, the post (document visible), visibilitychange to hidden, unload.

The change

  • browser/runtime/layer-client.js, postEvent: every event goes out with keepalive when its body is under 60,000 bytes. A page may keep only 64 KiB of keepalive bodies in flight, and the browser refuses a request past that, so a longer message goes out as an ordinary request.
  • browser/runtime/interaction-log.js: the interaction log shares that budget. Its routine uploads drop keepalive, since its closeout already sends queued entries again. The closeout is one batch of up to 32,000 bytes. In Firefox it runs before the playground's edit and could otherwise use up the room the edit needs.

Testing

  • tests/runtime/event-post.test.mjs: a gesture's post asks for keepalive, and a body over the limit, counted in bytes rather than characters, goes out without it. Removing keepalive, setting it unconditionally, or counting characters each fails the test.
  • No browser test covers the close itself. Neither engine fails it deterministically without depending on how Playwright intercepts requests.
  • Measured with a journey that opens a second tab, types, closes the tab and reads the edit back from the first tab, eight closes per arm: Firefox kept 5 of 8 before and 8 of 8 after, and Chromium kept 8 of 8 in both. Event-post round-trip medians stayed at 10–15 ms in both engines.
  • pnpm run test:runtime, pnpm run check:browser, pre-commit on the changed files, the playground's leave test, and the interaction-log browser tests in test_render_application_boundary.py pass.
  • Two Codex (gpt-6-astra) reviews. Their findings are fixed: the closeout's size, the test's claim and byte counting, and two comments. The one exception is below.

Left open

A gesture queued behind one still in flight when the tab closes is still never sent, because delivery.js sends gestures one at a time. That takes two gestures and a close within one server round trip. Sending the queue all at once as the page leaves would let gestures arrive out of order.

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

Closing a Firefox tab right after typing in a playground lost the edit in
3 of 8 closes. The playground records an unrecorded edit when the page
leaves, Firefox's leave event being `pagehide`, and the event post was an
ordinary request, which the browser cancels with the document. Any gesture
still on its way when a tab closed, such as a reply sent a moment before,
could go the same way.

An earlier test of a `keepalive` post set it only while the document was
hidden, and concluded keepalive didn't help. Firefox fires `pagehide` while
the document still reads `visible`, so the post that mattered never had it.
A trace of one close: beforeunload, pagehide, the post (document visible),
visibilitychange to hidden, unload.

`postEvent` now sends every event with `keepalive` when its body is under
60,000 bytes; a page may keep only 64 KiB of keepalive bodies in flight, so
a longer message goes out as an ordinary request. The interaction log shares
that budget: its routine uploads drop `keepalive`, since its closeout sends
queued entries again, and the closeout shrinks to one batch of up to 32,000
bytes. In Firefox it runs before the playground's edit and could otherwise
leave no room for it.

Behavior the tests now protect: a gesture's post asks the browser to carry
it past the page, and a body over the limit, counted in bytes, goes out
without that (`tests/runtime/event-post.test.mjs`). No browser test covers
the close itself: neither engine fails it deterministically without
depending on how Playwright intercepts requests.

Measured with a journey that opens a second tab, types, closes it and reads
the edit from the first tab: Firefox kept 5 of 8 before and 8 of 8 after,
Chromium 8 of 8 in both. Event-post round trips stayed at 10-15 ms median in
both engines. A gesture queued behind one still in flight when the tab
closes is still never sent.
leaf-agent
leaf-agent previously approved these changes Nov 2, 2026
# Conflicts:
#	dist/kernel/kernel.json
@leaf-agent
leaf-agent merged commit 7259dd2 into main Nov 2, 2026
4 of 5 checks passed
@leaf-agent
leaf-agent deleted the playground-saved-choices branch November 2, 2026 07:27
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