Skip to content

Move Codex's pointer confirmation, the delivery ack and the work fold to their owners, ending two backward imports - #7217

Merged
max-sixty merged 3 commits into
mainfrom
agent-ac1a006bfc0dc0986
Nov 26, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-ac1a006bfc0dc0986

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Ends two of src/leaf's seven allowed backward imports, agents.delivery -> serving.served_state.context and records.page_view -> agents.delivery, and most of the import cycle among codex, codex_state, delivery, presence and thread in agents. Each piece moves to the module that owns its fact:

  • confirm_codex_pointer moves from codex_state into codex, beside the Codex delivery record it confirms. codex_state keeps the record paths and the turn observation that codex reads from below.
  • receive_delivery and cmd_delivery_ack move to a new commands/delivery_ack.py. They pick a transport by the harness's adapter, Codex's record or the plain page receipts, so they sit above both, as the hooks' branch on the same fact already does in commands. delivery now takes receipt for every harness without naming one.
  • The page's work fold moves from serving/served_state/work.py to records/work_state.py; its header already said every transport reads it. presence.read_work reads 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_data takes that WorkState rather than reading it again.
  • PageView.responses, page_view's only import of agents, had no caller and goes.

One behaviour differs, on an error path: deliverable() on a page with no revision and an unparseable layer.json used to raise ValueError, because read_page read the registry eagerly; read_work doesn't read the registry, so it returns. That is what PageRead.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, is presence.nudge_interrupted, which the next PR moves to serving/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 so leaf delivery ack and leaf page list load no more than before.

Tests: lint-imports, pre-commit, and 897 covering model tests, among them test_hook_registration, test_hooks, test_forks, test_codex_adapter and test_receipts.

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

…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.
@max-sixty
max-sixty merged commit cd25caf into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-ac1a006bfc0dc0986 branch November 26, 2026 04:31
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_
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