Skip to content

Serve a page with the Leaf that runs server start - #5977

Merged
max-sixty merged 2 commits into
mainfrom
diagnose-thin-playground
Nov 16, 2026
Merged

max-sixty merged 2 commits into
mainfrom
diagnose-thin-playground

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

leaf server start handed 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 whose page check it 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 start now restarts such a server under its own Leaf at the same URL, through the restart page init already 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.

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

`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.
@max-sixty
max-sixty merged commit 17948f1 into main Nov 16, 2026
5 checks passed
@max-sixty
max-sixty deleted the diagnose-thin-playground branch November 16, 2026 08:40
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]>
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