Skip to content

Split the page server's records from its process's lifetime - #7208

Merged
max-sixty merged 5 commits into
mainfrom
agent-abdfa171d01898cfc
Nov 26, 2026
Merged

max-sixty merged 5 commits into
mainfrom
agent-abdfa171d01898cfc

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

agents/server.py mixed the page server's records with the serving process's lifetime, and sat in agents only because presence reads running_server. That forced page check's source_advice (in records) to import upward for other_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 to base/server.py with their generated record_types.pyi; other_serving_leaf moves to source/layer.py beside running_leaf and payload_provenance, which it compares; and exit_serving, exit_serving_on_signals, stop_when_service_ends and _follow_copy move to serving/server_lifetime.py, which only pages/hosting and serving/server_rows import. agents/server.py is deleted, and every caller in src, tests, dev and worker moves 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 importing codex lazily said "every hook loads this module", which no longer holds, so it now names hosting as the path that brings the module into processes that never serve. Worth a look: the agents, serving and source/layer.py headers, and hosting now importing source.layer at module level (about 2 ms of a 70 ms import).

import-linter's allowances on main go from 10 to 9.

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

`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
leaf-agent previously approved these changes Nov 26, 2026
# Conflicts:
#	.config/importlinter.ini
#	dev/leaf_dev/commands/journey/_claude_code.py
leaf-agent
leaf-agent previously approved these changes Nov 26, 2026
# Conflicts:
#	tests/journeys/test_render_controls.py
@max-sixty
max-sixty merged commit eb4fce8 into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-abdfa171d01898cfc branch November 26, 2026 03:02
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_
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