Skip to content

feat(codex): give a codex session compaction, manual and automatic - #11944

Merged
bolichen97 merged 1 commit into
mainfrom
fix/codex-compaction
Sep 19, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/codex-compaction

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

A codex session never compacts. The user reported it twice over:

The codex backend manages compaction automatically — it summarizes the conversation on its own as context fills, so manual /compact isn't needed (and isn't supported) here. Codex manual compaction isn't allowed? I also noticed that auto compaction isn't allowed either.

Both halves are real. /compact is 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_COMPACT gates the manual command, and Crew's automatic compaction reads the same set through session_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.

Question Answer off the wire
Is compact offered? Yes — available_commands_update lists it, "Summarize conversation to avoid hitting the context limit"
Inline or async? Inline — the session/prompt response comes after the compaction, stopReason: end_turn
How is it reported? A marked tool-call pair: tool_call in_progress → tool_call_update completed, both _meta.contextCompaction
Is there a failed status? No — an errored compaction leaves the prompt unanswered (240s, no reply)
Does codex auto-compact itself? Only with model_auto_compact_token_limit set. Without it, 50k tokens over three turns compacted zero times

So codex joins both sets, and parse_codex_compaction_update turns that marked pair into the EVENT_COMPACTION_STATUS kiro-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. AcpSessionHandle is the one that runs: #11267 moved codex onto AcpRuntime, so wiring only AcpClient would have fixed nothing.

One more arm had to move. _compact_in_place fell 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 on ACP_BACKENDS_INLINE_COMPACTION membership, 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 runCompact never resolves, so the session/prompt request goes unanswered and a consumer that entered a compacting state would never leave it. _settle_codex_compaction closes that out at the turn's terminal and reports failed, not the completed the 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_refuses and test_a_non_inline_harness_keeps_its_asynchronous_wait pin both directions.

Tests

test/test_codex_compaction.py, 71 tests. The great majority fail on this branch's base.

Group What it locks in
Membership codex in both sets, inline stays a subset, no other harness gained anything
parse_codex_compaction_update the captured pair classifies; a replayed history frame does not; the marker decides, not the title; no failed is invented
AcpClient / AcpSessionHandle the pair becomes the shared event, a terminal without a start is ignored, a non-inline harness is never asked, no failure budget on a guess
Real frame handler a live AcpSessionHandle fed the captured frames emits the status and keeps the tool-call rows
Both gates manual and automatic both stop refusing codex; both still refuse KAS
In-place arm a statusless inline turn recycles instead of waiting; kiro-cli keeps its wait; the arm is selected by capability, asserted over the parsed AST so a comment cannot satisfy it
Dangling started settles as failed on both transports, never completed, on every stop reason; no-op when idle; disarmed by a real terminal; no failure budget; no retry promise; wired at the choke point

Manual verification

The capture IS the manual verification. codex-acp 1.11.0 was driven over stdio with a scratch CODEX_HOME and 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 read started/completed from the first two and started alone 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 --user gives Operation not permitted, systemd-run --user gives Failed to connect to bus: Permission denied — so driving Crew's own AcpRuntime against the real adapter dies before initialize. What is covered instead: a real AcpSessionHandle over a real AcpRuntime is fed the captured frames and asserted to emit the status while keeping the tool-call rows, with the meter drop asserted as context_pct_unknown. What is not covered is the browser rendering the notice. That needs one /compact in 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested review from a team and chenmingwei23 September 19, 2026 05:13
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 19, 2026
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 006d73f881ac38b9d26b5914f7bcb86a9c94bff3 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 006d73f

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 006d73f881ac38b9d26b5914f7bcb86a9c94bff3: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 006d73f881ac38b9d26b5914f7bcb86a9c94bff3 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify one dashboard /compact on a sandbox-capable host — the browser-rendered notice is the gap the description itself names as untested.

[DESIGN-REVIEWED] 006d73f

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 006d73f881ac38b9d26b5914f7bcb86a9c94bff3 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

One /compact from the dashboard on a sandbox-capable host — the codex-acp 1.11.0 wire claims rest on the author's own capture, and the rendered notice is untested.

What this change ships

Inventory (8 items) — 8 justified

Intent: FIX — a codex session never compacts (manual /compact refused, threshold compaction declined), so long chats grow until the session is recycled and lost.

  1. Manual /compact on a codex session now runs (dashboard and all messaging surfaces) instead of being refused — justified
  2. Crew's threshold compaction now compacts a codex session instead of declining and recycling it — justified
  3. Codex compaction now shows as the standard started/completed status (notice, context-meter reset) — justified
  4. An errored codex compaction now reports "failed" at turn end instead of nothing — justified
  5. Inline-compaction backends (claude too) now recycle a statusless compaction turn immediately instead of holding the turn semaphore for the whole result budget — justified
  6. New exported parser parse_codex_compaction_update — justified (2 consumers counted: AcpClient._codex_compaction_event, AcpSessionHandle._codex_compaction_event)
  7. The dormant AcpClient transport carries the same translation as the live AcpRuntime path — justified (harness-parity H6: "Both drivers answer from the table, not one of them")
  8. Spec rows in agent-host-contract, providers, session updated in the same commit — justified (AGENTS.md mandate)

Rewritten membership pins (test_membership_is_kiro_and_claude_only, the ACP_BACKENDS_INLINE_COMPACTION comment) each licensed their own edit — "Opting a harness in is a deliberate edit with evidence (H6)" — and the PR supplies the evidence and declares the change. Sibling harnesses (pi, opencode, goose) left outside the sets are documented conservative exclusions on base and explicitly deferred in the test docstrings.

[FIRST-PRINCIPLES-REVIEWED] 006d73f

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 006d73f881ac38b9d26b5914f7bcb86a9c94bff3 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 006d73f

Verdict parsed from the review's SHA-scoped output markers for commit 006d73f881ac38b9d26b5914f7bcb86a9c94bff3.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 006d73f881ac38b9d26b5914f7bcb86a9c94bff3: <one-sentence reason>

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.
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 19, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 new status is None and not capabilities_of(...).compacts_inline arm is fail-safe. An inline harness that produces no terminal falls through to status != "completed" → RuntimeError → _recycle_held, i.e. the existing safe recycle rather than silent context loss; a non-inline harness keeps its async wait_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, and capabilities_of falls back to UNKNOWN_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_COMPACTION gain ACP_BACKEND_CODEX, a backend constant rather than a model id. I checked the whole diff for a hardcoded claude-* / gpt-* / opus* default or fallback: none.
  • src/kiro_crew/acp/_dispatch.py plus client.py / session_handle.py — parse_codex_compaction_update keys on the _meta.contextCompaction marker and frame kind rather than the title (so a title reword cannot break it), _settle_codex_compaction synthesizes failed on a dangling started without resetting the meter or arming the post-failure budget, and _codex_compaction_pending is reset in every per-turn init path.

Non-blocking, no action required:

  1. The codex/claude wire claims in docs/system-specs/modules/agent-host-contract.md (codex-acp 1.11.0's _meta.contextCompaction marker, "no failed status", native auto-compaction being conditional on model_auto_compact_token_limit) rest on your own stdio capture rather than a checked-in fixture. test/test_codex_compaction.py hardcodes 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 /compact once 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 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: readiness gate passed

@bolichen97
bolichen97 merged commit d92b8c4 into main Sep 19, 2026
126 of 133 checks passed
@bolichen97
bolichen97 deleted the fix/codex-compaction branch September 19, 2026 19:36
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 19, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…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>
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.

3 participants