Repository navigation
feat(codex): give a codex session compaction, manual and automatic - #11944
Conversation
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify one dashboard [DESIGN-REVIEWED] 006d73f |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS One What this change shipsInventory (8 items) — 8 justifiedIntent: FIX — a codex session never compacts (manual
Rewritten membership pins ( [FIRST-PRINCIPLES-REVIEWED] 006d73f |
Opus 4.8 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
A codex session got no compaction at all. codex sat outside ACP_BACKENDS_COMPACT, and that one membership answers both entry points -- the manual /compact command and Crew's own threshold compaction -- so the automatic path declined with "compact_unsupported" and the context grew until the session was recycled. The refusal a user saw said the backend "manages compaction automatically", which was a claim about codex nothing had checked. A capture off codex-acp 1.11.0, driven over stdio, settles it: "compact" is advertised in available_commands_update, the /compact prompt is answered only once the compaction is done, and the compaction is reported as a tool_call pair marked _meta.contextCompaction. codex's native auto-compaction is real but conditional on the operator's model_auto_compact_token_limit -- with the limit absent, a session held at 50k tokens across three turns compacted not once -- so Crew's own threshold compaction is turned on for codex rather than delegated to the harness. parse_codex_compaction_update translates that marked pair into the EVENT_COMPACTION_STATUS vocabulary kiro-cli, KAS and claude already produce, on both ACP transports, so the dashboard, the messaging surfaces and wait_for_compaction all work with no per-surface change. The in-place autocompact arm stops awaiting an asynchronous status an inline harness never sends; that arm is selected by ACP_BACKENDS_INLINE_COMPACTION membership, so the next harness to demonstrate inline compaction inherits it by joining the set.
f04d062 to
006d73f
Compare
buluoray
left a comment
There was a problem hiding this comment.
Reviewed at head 006d73f881ac38b9d26b5914f7bcb86a9c94bff3. No blocking findings — approving.
Verified against source rather than the description:
src/kiro_crew/session_compaction.py_compact_in_place— the newstatus is None and not capabilities_of(...).compacts_inlinearm is fail-safe. An inline harness that produces no terminal falls through tostatus != "completed"→RuntimeError→_recycle_held, i.e. the existing safe recycle rather than silent context loss; a non-inline harness keeps its asyncwait_for_compaction. No trigger or threshold logic changed, so there is no new loop shape to worry about.src/kiro_crew/agent_sdk/capabilities.py—compacts_inline = backend in ACP_BACKENDS_INLINE_COMPACTION, andcapabilities_offalls back toUNKNOWN_BACKEND_CAPABILITIES(compacts_inline=False). Every gate is positive set membership, never the absence of another harness.src/kiro_crew/agent_sdk/backends.py—ACP_BACKENDS_COMPACT/ACP_BACKENDS_INLINE_COMPACTIONgainACP_BACKEND_CODEX, a backend constant rather than a model id. I checked the whole diff for a hardcodedclaude-*/gpt-*/opus*default or fallback: none.src/kiro_crew/acp/_dispatch.pyplusclient.py/session_handle.py—parse_codex_compaction_updatekeys on the_meta.contextCompactionmarker and frame kind rather than the title (so a title reword cannot break it),_settle_codex_compactionsynthesizesfailedon a danglingstartedwithout resetting the meter or arming the post-failure budget, and_codex_compaction_pendingis reset in every per-turn init path.
Non-blocking, no action required:
- The codex/claude wire claims in
docs/system-specs/modules/agent-host-contract.md(codex-acp 1.11.0's_meta.contextCompactionmarker, "no failed status", native auto-compaction being conditional onmodel_auto_compact_token_limit) rest on your own stdio capture rather than a checked-in fixture.test/test_codex_compaction.pyhardcodes the captured frame dicts instead of replaying a recorded.jsonl, so nothing reddens if codex-acp changes shape. Worth a fixture later; not a defect now. This is the same thing both advisory lanes land on, alongside their one ask: run a real dashboard/compactonce on a sandbox-capable host, since the browser-rendered notice is the untested surface.
Bot verdicts on this SHA: GPT 5.6 no blocking findings, Opus 4.8 no findings, Design PASS, First Principles PASS (8/8 inventory items justified).
bolichen97
left a comment
There was a problem hiding this comment.
Approved: readiness gate passed
…irodotdev#11944) A codex session got no compaction at all. codex sat outside ACP_BACKENDS_COMPACT, and that one membership answers both entry points -- the manual /compact command and Crew's own threshold compaction -- so the automatic path declined with "compact_unsupported" and the context grew until the session was recycled. The refusal a user saw said the backend "manages compaction automatically", which was a claim about codex nothing had checked. A capture off codex-acp 1.11.0, driven over stdio, settles it: "compact" is advertised in available_commands_update, the /compact prompt is answered only once the compaction is done, and the compaction is reported as a tool_call pair marked _meta.contextCompaction. codex's native auto-compaction is real but conditional on the operator's model_auto_compact_token_limit -- with the limit absent, a session held at 50k tokens across three turns compacted not once -- so Crew's own threshold compaction is turned on for codex rather than delegated to the harness. parse_codex_compaction_update translates that marked pair into the EVENT_COMPACTION_STATUS vocabulary kiro-cli, KAS and claude already produce, on both ACP transports, so the dashboard, the messaging surfaces and wait_for_compaction all work with no per-surface change. The in-place autocompact arm stops awaiting an asynchronous status an inline harness never sends; that arm is selected by ACP_BACKENDS_INLINE_COMPACTION membership, so the next harness to demonstrate inline compaction inherits it by joining the set. Co-authored-by: zejiangg <zejiangg@amazon.com>
Problem / Motivation
A codex session never compacts. The user reported it twice over:
Both halves are real.
/compactis refused, and Crew's own threshold compaction is skipped too. The message the user got is also wrong: nothing had checked whether codex manages compaction on its own.Why it matters
Context grows with nothing to trim it. A long codex chat runs to the recycle threshold and the session is thrown away, which loses the conversation. Every other selectable backend has a way out.
What changed (motivation → approach → change)
One membership answers both entry points.
ACP_BACKENDS_COMPACTgates the manual command, and Crew's automatic compaction reads the same set throughsession_compaction._compact_unsupported_backend. codex was not in it, so both declined.I drove codex-acp 1.11.0 over stdio and read the wire instead of the docs.
compactoffered?available_commands_updatelists it, "Summarize conversation to avoid hitting the context limit"session/promptresponse comes after the compaction,stopReason: end_turntool_callin_progress→tool_call_updatecompleted, both_meta.contextCompactionfailedstatus?model_auto_compact_token_limitset. Without it, 50k tokens over three turns compacted zero timesSo codex joins both sets, and
parse_codex_compaction_updateturns that marked pair into theEVENT_COMPACTION_STATUSkiro-cli, KAS and claude already produce. That is the whole trick: every consumer — the dashboard notice, the context meter, ten messaging surfaces,wait_for_compaction— already handles that event, so none of them needed a codex arm.The translation sits on both ACP transports.
AcpSessionHandleis the one that runs: #11267 moved codex ontoAcpRuntime, so wiring onlyAcpClientwould have fixed nothing.One more arm had to move.
_compact_in_placefell back to awaiting an async status when the turn carried none. An inline harness never sends one, so that spent the whole result budget holding the session's turn semaphore and then recycled anyway. It is now gated onACP_BACKENDS_INLINE_COMPACTIONmembership, never on codex's name, so the next harness that demonstrates inline compaction inherits it by joining the set.The user-facing text is untouched and is now true: it only appears for a backend that really is outside the set.
One more frame does not exist, and that needed its own answer. A compaction that ERRORS reports nothing: the adapter's
runCompactnever resolves, so thesession/promptrequest goes unanswered and a consumer that entered a compacting state would never leave it._settle_codex_compactioncloses that out at the turn's terminal and reportsfailed, not thecompletedthe claude twin synthesizes — codex sends its terminal for a manual and a native compaction alike, so a missing one is evidence the compaction did not finish. It resets no counters, arms no failure budget, and promises no retry.Backwards compatibility
Compatible. Three one-line membership adds and one new translation. Every gate reads the same sets it read before, and a harness outside them behaves exactly as it does today —
test_a_non_member_still_refusesandtest_a_non_inline_harness_keeps_its_asynchronous_waitpin both directions.Tests
test/test_codex_compaction.py, 71 tests. The great majority fail on this branch's base.parse_codex_compaction_updatefailedis inventedAcpClient/AcpSessionHandleAcpSessionHandlefed the captured frames emits the status and keeps the tool-call rowsstartedfailedon both transports, nevercompleted, on every stop reason; no-op when idle; disarmed by a real terminal; no failure budget; no retry promise; wired at the choke pointManual verification
The capture IS the manual verification. codex-acp 1.11.0 was driven over stdio with a scratch
CODEX_HOMEand a local stub model provider, so no host credential was involved. Three runs: a successful/compact, a failing one, and three ordinary turns with auto-compaction armed. The parser was replayed over all three raw frame logs and readstarted/completedfrom the first two andstartedalone from the failing one.One residual, and it is about this host rather than the change. Crew refuses to spawn codex where there is no sandbox backend, by design, because the credential mask is the compensating control for an enforced permission route. This box has none —
unshare --usergivesOperation not permitted,systemd-run --usergivesFailed to connect to bus: Permission denied— so driving Crew's ownAcpRuntimeagainst the real adapter dies beforeinitialize. What is covered instead: a realAcpSessionHandleover a realAcpRuntimeis fed the captured frames and asserted to emit the status while keeping the tool-call rows, with the meter drop asserted ascontext_pct_unknown. What is not covered is the browser rendering the notice. That needs one/compactin the dashboard on a host with a working sandbox.Related Issues
no linked issue: reported directly by a user in chat, not filed. #11267 and #8294 are named above as base changes this builds on, not as issues to close.
Pattern harvest
Rule candidate: review-prompt
Pattern: a user-facing message that asserts a third party's behaviour, on a code path that never observed it. The refusal text claimed codex "manages compaction automatically" while the capability set said only that Crew would not try. Prefer wording that states what this code does.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)