Skip to content

refactor(codex, agent): split the module, no behaviour change - #65

Merged
blockmandev merged 3 commits into
mainfrom
refactor/codex-agent-mod
Oct 24, 2026
Merged

blockmandev merged 3 commits into
mainfrom
refactor/codex-agent-mod

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Behaviour-preserving split answering the code-auditor findings on src/agent/codex.rs (2183 lines; Reading::line complexity 30 / 145 lines; a 114-line test) and src/agent/mod.rs (1307 lines; budget_for_spawn 101 lines).

Commits

  1. Pins, on the original code — src/agent/codex/pinned_tests.rs: 60 real and broken codex exec --json lines read on both routes (every Wire variant and item type, malformed lines), 7 whole turns, the argv + environment of 11 spawn configurations (own route fresh/resumed, every permission mode, bridged fresh/resumed, a Windows server path), the 14 MODEL_ONLY_OVERRIDES, mcp_config, and a turn whose binary is missing. src/agent/budget_pinned_tests.rs: budget_for_spawn at every size around its limits, priority order, both cut floors (100/120), char boundaries, and the exact spill notice. Every expectation was produced by the original code.
  2. Pins restructured (tables lifted out so no pin fn passes 100 lines), proven again on the original code: 18 passed; 0 failed; ... 2318 filtered out.
  3. The split.

Layout

file lines
agent/mod.rs (AgentEvent, TurnOutcome, quota status, AgentError) 294
agent/backend.rs (trait + Box forwarding) 552
agent/handover.rs 230
agent/spawn_budget.rs 299
agent/codex/mod.rs 647
agent/codex/argv.rs 265
agent/codex/bridged.rs 111
agent/codex/wire.rs 396
agent/codex/tests.rs / wire_tests.rs / pinned_tests.rs 730 / 191 / 963

Everything is re-exported at its old path; no caller changed. MAX_UNWIRED stays 41 (is_limit_status stays in mod.rs so it is not re-exported by name, which would have hidden that it is still unwired).

Checks

cargo fmt --all -- --check, cargo clippy --all-targets -q -- -D warnings, cargo test -q: lib 2318 -> 2336 (2326 passed, 10 ignored), 59 bin. The static auditor reports no function over 100 lines or complexity 20 in the touched files.

… the split

60 real and broken `codex exec --json` lines read on both routes, 7 whole
turns, the argv and environment of 11 spawn configurations, the bridged
registration, mcp_config and a turn that cannot start; budget_for_spawn at
every size around its limits, its priority order, both cut floors and the
spill notice. Every expectation was produced by the code as it stands.
Same expectations, same assertions: the whole-turn cases and readings
become consts, and the spawn pin builds its configurations and its two
routes' expected argv in helpers, so no pin function passes 100 lines.
The argv helper is renamed `reported`, which no other module defines.
codex.rs becomes src/agent/codex/: mod.rs (the backend and its settings),
argv.rs (both routes' commands, MODEL_ONLY_OVERRIDES, the bridge
registration), bridged.rs (run_bridged), wire.rs (the --json wire types
and Reading). Reading::line is one match that hands each variant to a
helper; the long bridged-turn test is backed by setup and event helpers
with the same assertions. Tests split into codex/tests.rs and
codex/wire_tests.rs, declared #[cfg(test)].

agent/mod.rs keeps AgentEvent, TurnOutcome, the quota status and
AgentError; the trait and its Box forwarding move to backend.rs, the
handover classifiers to handover.rs, budget_for_spawn to spawn_budget.rs
as named steps (by_priority, is_high_priority, Kept::take). Everything is
re-exported at its old path. Docs that named codex.rs or agent/mod.rs
now name the new files.

The pins of the two commits before pass unchanged; MAX_UNWIRED stays 41.
@blockmandev
blockmandev merged commit bcc8770 into main Oct 24, 2026
12 checks passed
@blockmandev
blockmandev deleted the refactor/codex-agent-mod branch November 15, 2026 20:29
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.

1 participant