fix(codex): settle compaction items when turns end #17265
main fromrefs/pull/17265/head·merged by juliusmarminge View on GitHubCodex can end a turn without sending item/completed for a context compaction. The unfinished item then keeps running after failure or Stop.
Track pending compaction IDs in each active Codex turn and settle them through the existing turn finalizer. Keep native start timestamps, use the turn's terminal time, and leave earlier completed compactions alone. Failed and stopped labels take precedence over token summaries in shared presentation.
Thanks to @luke2x for the original fix in #17265. The takeover preserves the contributor commits, merges current main, simplifies timestamp handling, and trims redundant tests.
Verification on head df5f1cf284, Linux / Node 24:
- Focused tests before → after: 384 → 375 across three existing suites. PR-added coverage shrinks from 13 cases across three changed test files to four cases across two files.
- With main's production code, the retained tests produce five expected failures; with this fix, all 375 pass. Replay cases cover native failure, native interruption, and Stop with an interrupt RPC error; each also preserves an earlier completed item and timestamps.
- Server and client-runtime typechecks pass. Targeted lint and formatting pass; two existing unused-binding warnings remain.
- One independent full-diff review round on Claude Opus 5.5 and Codex gpt-6-sol found no blocking issues. Broader web token-count presentation for other providers remains outside this Codex lifecycle fix.
Before/after test output. The proof exercises the public adapter replay and mobile presentation feed. An isolated Linux server and browser were started; an HTTP snapshot fixture was readable, but the browser attempt did not yield usable compaction visual evidence. No screenshot or authenticated live compaction is claimed.
Not verified: live Codex compaction, macOS, Windows, iOS, Android, or packaged Electron desktop. The adapter is shared by all clients and connection modes, with no wire change. Process death without a native terminal event or T3 Stop, and repair of historic stale items, remain outside scope. Server shards, lint, build/typecheck and package tests passed on the current head. Web CI failed, then failed again on one retry, in unchanged workflow-highlighting/attachment-preview tests with a browser connection-closed error (CI run). This remains a readiness blocker; maintainer review and visual verification are still needed. Unmerged.
Tests: Codex gpt-6-astra (high). Implementation: Codex gpt-6.1-sol (high). Reviews: Claude Opus 5.5 and Codex gpt-6-sol. Harnesses: Codex and Claude Code in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
cb98857Macroscope's review found this PR approvable — This is a focused Codex lifecycle bug fix that settles unfinished compaction items on terminal turns while preserving completed items and timestamps. The accompanying client change and regression tests are narrow, with no schema, default, deployment, security, or static-analysis impact.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.- Last reviewed commit: 52f7e70b7e77b050b90cb3a6f8d4ff243f2aae63
- Latest commit, not reviewed: cb988578183cb368a3ed65884e8b11bbbe401c3a
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
- ▶️ Resume reviews
- 🔍 Trigger review
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7b887113-f03c-421b-8abf-e630be676e95
📥 Commits
-
Reviewing files that changed from the base of the PR and between 0f64d43e5b39dc9de70e3463f85f3031c4583bb7 and 52f7e70b7e77b050b90cb3a6f8d4ff243f2aae63.
📒 Files selected for processing: 4
-
apps/mobile/src/lib/threadActivity.test.tsapps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tspackages/client-runtime/src/work-log/presentation.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
The Codex adapter tracks running compaction items and assigns terminal statuses and timestamps from provider events or turn finalization. Work-log and mobile summaries display distinct labels for failed, stopped, active, and completed compaction.
Changes: Compaction status handling
Layer / File(s) Summary Track and finalize compaction items
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsThe adapter tracks running compaction items, uses Codex timestamps, and emits terminal statuses when a turn ends. Replay tests cover failed and interrupted turns. Present compaction statuses
packages/client-runtime/src/work-log/presentation.ts,packages/client-runtime/src/work-log/presentation.test.ts,apps/mobile/src/lib/threadActivity.test.tsWork-log and mobile summaries distinguish failed, stopped, active, and completed compaction. Tests cover labels and token-count display. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant Codex as Codex notifications participant Adapter as CodexAdapterV2 participant Item as Compaction item Codex->>Adapter: Send compaction status and timestamp Adapter->>Item: Emit compaction update Codex->>Adapter: Send terminal turn status Adapter->>Item: Finalize running compaction itemSuggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
52f7e-
Compactions are settled on the covered turn-ending paths and display the appropriate status. No merge-blocking issue remains after normal checks.
Security architecture risk: 🔵 Low · up to
52f7e-
The change is narrowly scoped to compaction status, timestamps, and presentation. It adds no access or privileges, and the inspected paths preserve turn ownership and completed outcomes. Recovery after abrupt process termination remains unverified.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The inspected change affects compaction activity projections for existing root, subagent, and synthetic goal turns. No expansion into additional execution, credential, or network authority was identified in the base-to-head adapter change.
Trust Boundaries and Controls
- observed — Provider item identifiers are projected using the existing allocator and owning turn context. Finalization checks context identity rather than selecting another active turn, preserving the inspected per-turn ownership boundary.
Resilience and Maintainability Implications
- inferred — The live interruption fallback reaches the same finalization path after interruption errors or timeouts. This supports cleanup while the adapter remains alive, but does not establish recovery or durable projection repair after process termination.
-
Pre-merge checks:
4-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly identifies the Codex fix: settling compaction items when turns end. It is concise and follows the conventional commit format. Description check The description clearly explains the problem, implementation, scope, verification results, known limitations, CI status, and agent usage. It does not use the template headings exactly and does not inc… Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, scope, verification results, known limitations, CI status, and agent usage. It does not use the template headings exactly and does not include an explicit maintainer approval comment, but the content is otherwise complete and directly related to the change.
-
✨ Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
Additional Windows evidence for the stale compaction lifecycle addressed here, investigated via
t3 triageon 2026-10-11.Environment: T3 Code desktop nightly 0.0.46-nightly.20261011.2955; Windows 10.0.26220 x64; Codex CLI/app-server 0.162.1; gpt-6.1-sol with high reasoning effort.
The Codex app-server emitted
item/startedfor acontextCompactionat 01:29:23Z, then stalled without emittingitem/completedorturn/completed. The process stayed alive for approximately 55 minutes. With the user's approval, we terminated that specific shared app-server process to recover.Read-only inspection afterward confirmed:
Affected provider turn: interrupted completedAt: 2026-10-11T02:24:39.865Z Affected run: interrupted completedAt: 2026-10-11T02:24:39.882Z Original compaction item: running updatedAt: 2026-10-11T01:29:23.199Z completedAt: nullA replacement app-server subsequently resumed the persisted native thread. A fresh manual compaction completed at 02:27:05Z, and normal tool execution resumed. No database edits or source patches were applied. The original compaction item was still
runningwhen inspected after interruption.This is relevant to unfinished compaction items remaining running after a turn terminates. However, this case used process termination and T3's interruption finalization rather than a native Codex
turn/completednotification. Please consider whether this recovery path also needs coverage. I have not applied or tested this PR and am not claiming it handles that path or repairs previously saved rows. The underlying Codex hang is being reported separately as additional evidence on openai/codex#43062.Produced by Codex (GPT-6) via T3 triage; reviewed for redaction. No private prompts, workspace paths, credentials, or raw log attachments included.
juliusmarminge added labelsmacroscope-review
Note
Claude Opus 5.5 is responding on behalf of Luke.
@chitters2004 thanks for the trace. To answer the question about that recovery path: this PR does not cover it.
The adapter settles unfinished compaction items in the one place it ends a turn (
finalizeCodexTurn). That runs for a nativeturn/completedand for T3's Stop, including when the nativeturn/interruptfails or times out. In your case the app-server process was killed with neither, so the turn was finalized outside the adapter and the item would still be leftrunningwith this change.I've added that limit to the description. It reads to me as the same symptom from a second cause, so I've kept it out of this PR rather than widen it; happy to follow up separately if a maintainer wants it handled here.
Note
Written by gpt 6.1 sol on behalf of Luke
Resolved the conflicts with
main; latest head is52f7e70b7e. Compaction settlement when a turn ends is retained alongside the newer Codex approval handling and shared token-count helper. Failed/stopped labels are preserved.Verification: 378/378 tests passed across
CodexAdapterV2.test.ts, client-runtimework-log/presentation.test.ts, and mobilethreadActivity.test.ts; server and client-runtime typechecks and formatting passed. Focused lint had no errors (the adapter reported two unused-variable warnings). The pushed head also merges cleanly againstmainat340ee237bf. CI is rerunning on the merge commits.Note
Written by deepseek v4.1 flash 1017 on behalf of luke.
Updated this branch with the latest
main. It was 24 commits behind, so I mergedmainintofix/codex-compaction-terminal-state, which brings the PR fully up to date. The merge was clean with no conflicts, and the PR diff is otherwise unchanged. CI will re-run against the new base.juliusmarminge assignedjuliusmarminge
Taking over this one as maintainer for batch codex-05. I will preserve author credit, rebuild the focused compaction lifecycle fix against current main, and run separate regression, implementation, and adversarial review passes. This will remain unmerged.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
🟡 Medium
Adapters/CodexAdapterV2.ts:5194File-change approval requests with blank or absent
reasonandgrantRootare emitted without the affected paths or operations, so users must approve edits or deletions without seeing what will change.FileChangeRequestApprovalParamshas nofileChanges, and this call builds the prompt only frompayload; preserve the per-item changes captured fromitem/startedand pass them tocodexFileChangeApprovalPrompt.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts around line 5194: File-change approval requests with blank or absent `reason` and `grantRoot` are emitted without the affected paths or operations, so users must approve edits or deletions without seeing what will change. `FileChangeRequestApprovalParams` has no `fileChanges`, and this call builds the prompt only from `payload`; preserve the per-item changes captured from `item/started` and pass them to `codexFileChangeApprovalPrompt`.juliusmarminge merged thisccae51a
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed