Repository navigation
Move Codex's pointer confirmation, the delivery ack and the work fold to their owners, ending two backward imports - #7217
Merged
Merged
Conversation
…ward imports A refactor: behaviour is unchanged. - `confirm_codex_pointer` moves from `codex_state` to `codex`, beside `accept_codex_delivery` and the delivery record it reads. `codex_state` keeps the record paths and the turn observation `codex` reads, and no longer imports `codex` or `delivery`. - The body of `leaf delivery ack` (`receive_delivery`, `cmd_delivery_ack`) moves from `delivery` to a new `commands/delivery_ack.py`. Its branch on `Harness.adapter` chooses between Codex's delivery record and the page receipts, so it sits above both, as the hooks' branch on the same fact does (`hooks.offer_at_step`). `delivery` holds receipt for every harness without naming one, and no longer imports `codex_state`. - `serving/served_state/work.py` moves to `records/work_state.py`. It folds the log, the live revision and presence into the agent's work, imports only `base`, `log` and `records`, and its header already said every transport reads it. `presence.read_work(page_dir, events)` reads that work from a page directory: the same revision, revisions, presence, live stream and clock reach `work_state` as through `read_page(...).work`, without the served page's registry, descriptor and versions. Delivery, `commands.session`, `commands.hook_transport` and the website, which took only `.work` from `read_page`, call it, and `current_responses` takes a `WorkState` rather than a `PageRead`. `delivery` no longer imports `serving`, and the Stop hook no longer loads `served_state.context`. - `PageView.responses`, `InitialPageView.responses` and the test `ModelPage.responses` go. Nothing has called them since #1327 removed requests, and `PageView.responses` was `page_view`'s only import of `agents`. The import-linter allowances `agents.delivery -> serving.served_state.context` and `records.page_view -> agents.delivery` go. The cycle among `codex`, `codex_state`, `delivery`, `presence` and `thread` is now `delivery` and `presence` alone, closed by `presence.nudge_interrupted`'s import of `delivery.deliverable`. Tests move to the new homes. `test_hook_registration`'s Stop case checks that the hook read a page by `records.work_state`, which reading the page's work loads, since the hook no longer imports `served_state.context`.
… used Follows the previous commit, from its review. - `delivery.batch_data` takes the page's work (`work`) rather than its response map (`responses`), and reads the work only where its caller hasn't. The hooks' `read_plans`, `codex.append_batch` and `forks._thread_data` already hold or read it, and pass it, so a batch holding an action no longer reads the page's work twice, and `read_plans` drops its copy of `current_responses`' comprehension. - `presence` imports `records.work_state` inside `read_work`, so a reader of presence alone, such as `leaf page list`, loads none of the fold. `test_hook_registration`'s Stop case checks that `presence.read_work` imported the fold, which only a read of the page's work does. - `commands.delivery_ack` imports `codex` only for an adapter session's pointer, so `leaf delivery ack` elsewhere, an unknown id included, loads neither the Codex transport nor its App Server exit handler. - Headers: `delivery_ack` names `receive_held` and `receive_batch` for the hooks' and Codex's provider receipts, `served_state/queues.py` names `work_state.served_workflows`, and `PageRead.layer` no longer names delivery among the readers that never serve the page. One behaviour differs from before the previous commit, and stays: the work's readers no longer read the page's registry, which the work fold never used. So on a page with no revision whose `layer.json` doesn't parse, `deliverable` and every other `read_work` caller return their reading where `read_page` raised `ValueError`, as `PageRead.layer` intends for a reader that never serves the page. The rest is a refactor, with behaviour unchanged.
leaf-agent
approved these changes
Nov 26, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…a cycle (#7230) import-linter's layers contract checks only the imports between `src/leaf`'s eight packages, so the modules inside a package could import each other in a cycle, and six groups did. The cuts that ended them have landed (#7216, #7217, #7218, #7222, #7224). This adds import-linter's own `acyclic_siblings` contract over every package (`ancestors = leaf.*`). It recurses into subpackages such as `served_state` and `render_gate`, so a new cycle fails pre-commit as an upward import does, naming the import that closes it. A planted deferred import from `presence` into `delivery`, and one from `served_state.context` into `served_state.page`, each fail the contract; the tree as it stands passes. The config's header now says how to fix a cycle, and that a deferred import counts like any other, so deferring one ends no cycle; `src/AGENTS.md` states the rule beside the layering one. The maintainer asked for the cycles inside `agents` to be broken; this widens that to every package and keeps them broken. The two allowances the layers contract still lists are cut by #7223 and the PR after it. Tests: `lint-imports` (both contracts), pre-commit, and the two planted cycles above. > _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.
Ends two of
src/leaf's seven allowed backward imports,agents.delivery -> serving.served_state.contextandrecords.page_view -> agents.delivery, and most of the import cycle amongcodex,codex_state,delivery,presenceandthreadinagents. Each piece moves to the module that owns its fact:confirm_codex_pointermoves fromcodex_stateintocodex, beside the Codex delivery record it confirms.codex_statekeeps the record paths and the turn observation thatcodexreads from below.receive_deliveryandcmd_delivery_ackmove to a newcommands/delivery_ack.py. They pick a transport by the harness'sadapter, Codex's record or the plain page receipts, so they sit above both, as the hooks' branch on the same fact already does incommands.deliverynow takes receipt for every harness without naming one.serving/served_state/work.pytorecords/work_state.py; its header already said every transport reads it.presence.read_workreads it for delivery and for the commands, hooks and website code that read nothing else of the served page, so one function reads the live work outside the served state.batch_datatakes thatWorkStaterather than reading it again.PageView.responses,page_view's only import ofagents, had no caller and goes.One behaviour differs, on an error path:
deliverable()on a page with no revision and an unparseablelayer.jsonused to raiseValueError, becauseread_pageread the registry eagerly;read_workdoesn't read the registry, so it returns. That is whatPageRead.layer's docstring already asked of a reader that never serves the page. Serving such a page still raises.The cycle's last edge,
presence -> delivery, ispresence.nudge_interrupted, which the next PR moves toserving/server_rows.py, its only caller.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 its findings are folded in, among them two imports kept deferred soleaf delivery ackandleaf page listload no more than before.Tests:
lint-imports, pre-commit, and 897 covering model tests, among themtest_hook_registration,test_hooks,test_forks,test_codex_adapterandtest_receipts.