Repository navigation
Serve a page with the Leaf that runs server start - #5977
Merged
Merged
Conversation
`server start` handed back any server already running for the page, whichever Leaf started it. A server keeps the Leaf it started under, and markup and layout contracts move between commits with no protocol bump, so an agent could hand the user a URL served by a Leaf other than the one whose `page check` it read. Of the 37 page servers running on the maintainer's Mac on 14 November, 17 ran a checkout since deleted (one answered its page with a 500), 8 a checkout since moved to another commit, and 4 an older plugin install. `server start` now takes the page as before, then restarts a running server whose recorded Leaf differs in path or commit, through the restart `page init` uses (`hosting.restarting_server`), so the URL stays and open tabs reconnect. Before it takes the page, it checks that this Leaf can serve it (`http.page_endpoint`), so a refusal leaves the page with its owner and the other Leaf serving it. Uncommitted edits don't count, since the record can't say whether they changed after the server started. Hooks, the watch and other revivals still hand back whatever server they find, since the process reviving a page may run an older Leaf than its server. Codex's review of a first version, which stopped the other Leaf's server with `cmd_stop` inside `cmd_serve`, found that a start failing after the stop left the service disabled for good, since `cmd_stop` records the service as unwanted. Test: `test_a_start_serves_the_page_with_its_own_leaf` checks that a start keeps this Leaf's own server, restarts another's at the same URL, and leaves another's serving when this Leaf can't serve the page.
leaf-agent
approved these changes
Nov 14, 2026
leaf-agent
added a commit
that referenced
this pull request
Nov 21, 2026
…est_a_start_serves_the_page_with_its_own_leaf (#6668) `test_a_start_serves_the_page_with_its_own_leaf` deleted `layer.json` and then wrote its replacement while the replaced server was still running. The server's row publisher refreshes about every two seconds. When a refresh landed inside that gap, [`read_page_registry`'s `compose`](https://github.com/max-sixty/leaf/blob/656c4c5e6f0ca48a028b1fc403a07eb7b191ac5d/src/leaf/registry/storage.py#L253-L258) read the layer through `load_registry`, then found no record and failed `assert record is not None`. A failed refresh exits the server ([`RowPublisher.run`](https://github.com/max-sixty/leaf/blob/656c4c5e6f0ca48a028b1fc403a07eb7b191ac5d/src/leaf/server_rows.py#L146-L161)), so `running_server` found no server at line 1028. `LAYER.write` already replaces the file atomically, the way `page init` writes it, so the test now rewrites the record without deleting it first. The test still covers what it set out to: a server over a layer selecting an unknown package. An `absent` package is reported as an activation error and does not crash the server. Evidence, all from macOS `ci` dispatches of this test alone (`--workers 3 --load 2`): - **Before:** on a probe branch at the base, 3 of 36 copies failed ([run 44925710678](https://github.com/max-sixty/leaf/actions/runs/44925710678)). Each failing server's own log ends in the `compose` assertion traceback above. An earlier probe also failed 2 of 36 with the lease released and the port refusing connections ([run 44924777467](https://github.com/max-sixty/leaf/actions/runs/44924777467)). - **After:** this branch passed 54 of 54 ([run 44926717612](https://github.com/max-sixty/leaf/actions/runs/44926717612)). The test came in with #5977. <details><summary>Left as is</summary> `compose` reads the layer record twice, so a record deleted between those reads crashes the serving process. In Leaf itself the record changes only through `page init`, which restarts the server and replaces the file atomically (`served_state/reading.py`, `held_page_reading`). That makes this window reachable only by deleting `layer.json` by hand under a live server. This PR changes only the test. </details> Closes #6665 — automated triage Co-authored-by: leaf-agent <[email protected]>
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.
leaf server starthanded back any server already running for the page, whichever Leaf started it, so an agent could give the user a URL served by a Leaf other than the one whosepage checkit read. Of the 37 page servers running on Max's Mac today, 17 ran a checkout since deleted (one answered its page with a 500), 8 a checkout since moved to another commit, and 4 an older plugin install.server startnow restarts such a server under its own Leaf at the same URL, through the restartpage initalready uses (hosting.restarting_server). Before taking the page it checks that its Leaf can serve it, so a refusal leaves the page as it was.Worth weighing: another Leaf means another path or commit; uncommitted edits in the same checkout don't trigger a restart. Revivals from hooks or the watch still keep whatever server they find, and a watch from an older checkout can still revive a server that died under its own Leaf. That was already the case before this change.
Max asked for the design; Codex reviewed two rounds. Test:
test_a_start_serves_the_page_with_its_own_leaf, plus the server start, claim, wait and preview tests.