Repository navigation
Restart at the next prompt a page server another installed copy of Leaf started - #6765
Merged
Merged
Conversation
… the decision at the model tier
leaf-agent
previously approved these changes
Nov 22, 2026
…r", and its caller names the page
leaf-agent
approved these changes
Nov 22, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 23, 2026
…asks for (#6778) When a page's server restarts under a Leaf whose browser runtime differs, the open tab reloads itself (`reloadNow` in `layer-client.js`), and since #6765 that happens once per Leaf update for every page a session holds, often seconds after the user sent something from the tab. That reload dropped the user's place: a margin card or the panel's view closed under the reply being written in it, the panel's field lost focus and caret, a reader below a disclosure they had opened landed 1800px off, and the panel's Threads and On Me lists closed. Keys the user typed on with as the tab reloaded ran Leaf's single-key commands in the new document; probed at a key every 60ms, they opened another thread, showed Go-to hints and resolved a thread in the log, and a Space typed first scrolled the page and turned on design mode. Words typed as the server restarted put the browser's "Changes you made may not be saved" prompt in front of the reload. Every reload Leaf asks for now goes through `reloadDocument`, and the document writes, as it goes (`pagehide`), the one-use handoff a revision whose executable changed already used (`handOff` in `version.js`), so no second restore mechanism is added. What the handoff carries grows where the reload showed gaps: the reader a reply was written in (`readerOf`), so a reply typed in the panel's thread view comes back there rather than in the thread's margin card, and the panel's open list with its row and scroll (`captureCurrentLocation` in `floating-panel.js`). Keys typed through the reload go into the restored box. prepaint reads the handoff once for a reload of its own address (`lfStorage.handoff`), so the bootstrap knows before any module loads that a place is coming back. Until the new document has handed it back, no key is ready (`placeHandedBack`) and the held keys replay only afterwards, wherever focus is. Meanwhile a key the hold keeps, or a bare modifier such as a capital's Shift, is no input, so it doesn't stop the hand-back, while a key that acts, such as Tab or PageDown, does, and drops the held keys. Where the user was writing (`typing` in the handoff), a Space starts a held run as a letter does, and the hold takes keys whatever the single-key preference. `drafts.js` skips its leave prompt only for the `beforeunload` Leaf's reload raises (`takeLeafUnload`), so after a page's own prompt keeps the document, a later departure asks again. To weigh: the handoff and the panel's location also serve a revision's fresh document and a Back to a working place (`history.js`), so those now reopen a panel list and return a panel reply to the panel too. Ordinary loads keep counting held keys: probed against `main`, a load at a URL fragment and a Back to the page with keys typed during startup land and act the same; uncounting held keys there let an unsent comment's box reopen under the keys and lost some of them, so it applies only to Leaf's reloads. Still lost: a disclosure with no `id`, and focus on a widget's generated control with no `data-lf-carry`, since `carry.js` matches by authored id. Probed on `main` and here with `leaf-dev probe --base` on the real path: card reply, panel thread reply, panel page comment, passage comment, a just-sent reply in card or panel, Threads on a row, On Me scrolled, a scrolled reader with an open disclosure, and typing through the reload (a capital first, a Space first, into a passage comment, with single-key commands off) each come back as they stood, the typing cases also in Firefox; on `main` each lost its place. Three fresh-context reviews used the change and read the diff, and Tend's review found the Shift case; their findings are fixed here. Tests: `test_a_reload_into_another_runtime_keeps_the_user_where_they_were` (card, card at a version's address, panel), `..._keeps_the_panel_s_list_open` (Threads, On Me), `test_keys_typed_through_the_reload_go_into_the_reply_it_hands_back` (a capital first, a Space first, a passage comment, single-key commands off), `test_words_typed_as_the_server_restarts_go_with_the_reload_unasked` and `test_a_page_s_own_prompt_the_user_stays_at_leaves_leaf_asking_before_they_leave` fail without the change, except the passage-comment case, which guards a loss that depends on the replay's timing. The 24 startup key tests, the 28 tests that press Back, 27 revision-continuity tests, `pnpm run test:runtime` and `pnpm run check:browser` pass. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a session's prompt hook runs an installed copy of Leaf and a page the session holds is served by another installed copy, the hook now restarts that server under its own copy, at the same address, before the turn opens. A session moves to a newer copy at
/reload-plugins, a background job's wake or a resume, and until now its pages' servers kept the old copy until someone ranleaf server start, so the user's tab could draw what the agent'spage checknever checked.The hook reuses
leaf server start's test (nowhosting.other_serving_leaf), its check that this copy can serve the page, and its restart (hosting.restarting_server, which now takes the hook's deadline). A server a checkout started, and every server when the hook runs from a checkout, is left alone. A restart takes the old server down first, so it begins only while 5 s of the hook's 10 s deadline remain (reconnect.RESTART_NEEDS); later ones wait for the next prompt.Worth weighing:
leaf server start's is, so a session still on an older copy that takes a newer copy's page withleaf page claimmoves it back, where the older copy can serve it.server startrestart does today; this now happens once per update.The maintainer chose this on the Leaf page about keeping a session on one version of Leaf (open item
#12). A fresh-context reviewer read the diff; its findings are fixed. I didn't run the agent journey: it loads this tree with--plugin-dir, a checkout, where the new pass returns at once.Tests: new
test_a_prompt_restarts_only_a_server_another_installed_copy_started(model; removing any guard, the deadline margin or the serve-then-restart order fails it) andtest_a_prompt_restarts_a_server_another_installed_copy_started(journey, a real restart at the same URL), plus the serve-again,server start, session-lifecycle, server-lifetime and hook-import tests, all passing.