Repository navigation
Split the page server's records from its process's lifetime - #7208
Merged
Merged
Conversation
`agents/server.py` held two things: the page server's records and their readings, and the serving process's lifetime. It stood in `agents` only because `presence` reads `running_server`, so `page check`'s `source_advice` in `records` imported upward from it, through one of import-linter's allowances. - The records move to `base/server.py`: `SERVICE`, `ACCESS`, `read_service`/`write_service`, `running_server`, `page_access`, `host_key`, `page_origin`/`page_url`, `preview_metadata`, `served_lifetime` and `loopback_only`. They import only `base`, as the server's row in `base/rows.py` already does. The generated `record_types.pyi` that types them moves beside them. - `other_serving_leaf` moves to `source/layer.py`, beside `running_leaf` and `payload_provenance`, which it compares. - The lifetime moves to `serving/server_lifetime.py`: `exit_serving`, `exit_serving_on_signals`, `stop_when_service_ends` and `_follow_copy`. Only `pages/hosting` and `serving/server_rows` import it. `agents/server.py` is gone. Every caller in `src`, `tests`, `dev` and `worker` imports from the new homes, prose references name them, and the `agents` and `serving` package headers say what each now holds. `_follow_copy`'s reason for importing `codex` lazily now names `hosting` rather than every hook, since hooks no longer load the lifetime code unless they load `hosting`. import-linter's allowances on main go from 13 to 12.
leaf-agent
previously approved these changes
Nov 26, 2026
# Conflicts: # .config/importlinter.ini # dev/leaf_dev/commands/journey/_claude_code.py
leaf-agent
previously approved these changes
Nov 26, 2026
# Conflicts: # tests/journeys/test_render_controls.py
# Conflicts: # .config/importlinter.ini
leaf-agent
approved these changes
Nov 26, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…ke rule beside delivery, ending agents' last cycle (#7222) Ends two of `src/leaf`'s remaining backward imports, `agents.codex_adapter -> commands.session` and `agents.presence -> commands.session`, and the last edge of the import cycle among `codex`, `codex_state`, `delivery`, `presence` and `thread`, which leaves `agents` without a cycle. - **The Codex adapter's process** (`run_adapter` and `_hand_over`, its handover to a newer installed copy) moves from `agents/codex_adapter.py` to a new `commands/codex_run.py`, named for `leaf codex run`. It runs the session watch (`session.Watch`, `read_watch_pass`), as `leaf wait` and the hooks' between-turns watch do, and the watch can't sit below `pages` because it revives dead servers through `hosting`. `codex_adapter` keeps what the loop drives and other processes read: the transports, `TaskConnection`, the lease record and `preparing_adapter`, as #7208 split the page server's records from its process. `capture_batch` now takes the page's transaction and batch, so nothing in `agents` reads the watch's tick. - **The nudges.** `presence.nudge_interrupted` moves to `serving/server_rows.py`, its only caller. `wake_inputs`, the rule for which deliverable input wakes a session, which the between-turns watch, `nudge_pending` and `nudge_interrupted` all apply, moves beside `delivery.deliverable`. It now takes the work reading `deliverable` already holds, so a nudge or a watch pass folds the page once where it folded it twice. Behaviour is unchanged apart from that second fold going. To weigh: `_offer_queued_delivery` and `_start_adapter` lost their underscores, since `codex_run` now calls them across modules. This is one of the cuts the maintainer asked for to end `src/leaf`'s backward imports and the cycles inside its packages. Codex reviewed it and found no regression; its findings on where code reads the watch's tick and on stale pointers are folded in. It also reproduced a pre-existing bug, advice waking a session after its only actionable input was answered, which gets its own PR. Tests: `lint-imports`, pre-commit, and 482 covering model tests (the adapter, App Server, hooks, wait, native watch, delivery, receipts, stop guard, server lifetime, handover pass, hook registration and session lifecycle). The edited journey files compile but weren't run here; CI runs them. > _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.
agents/server.pymixed the page server's records with the serving process's lifetime, and sat inagentsonly becausepresencereadsrunning_server. That forcedpage check'ssource_advice(inrecords) to import upward forother_serving_leaf. This splits the module by concern: the records and their readings (SERVICE,ACCESS,running_server,page_access,host_key, the URL helpers,served_lifetime,loopback_only,preview_metadata) move tobase/server.pywith their generatedrecord_types.pyi;other_serving_leafmoves tosource/layer.pybesiderunning_leafandpayload_provenance, which it compares; andexit_serving,exit_serving_on_signals,stop_when_service_endsand_follow_copymove toserving/server_lifetime.py, which onlypages/hostingandserving/server_rowsimport.agents/server.pyis deleted, and every caller insrc,tests,devandworkermoves to the new homes, with no re-exports.The moved code is byte-identical apart from imports and one docstring:
_follow_copy's reason for importingcodexlazily said "every hook loads this module", which no longer holds, so it now nameshostingas the path that brings the module into processes that never serve. Worth a look: theagents,servingandsource/layer.pyheaders, andhostingnow importingsource.layerat module level (about 2 ms of a 70 ms import).import-linter's allowances on
maingo from 10 to 9.