Skip to content

fix: keep CLI compaction on rotated context-engine sessions - #117250

Merged
steipete merged 1 commit into
mainfrom
codex/prod-wave-compaction-052208-2d45
Aug 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/prod-wave-compaction-052208-2d45

Conversation

@steipete

@steipete steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where CLI-backed sessions could ignore a rotated transcript when a shipped third-party context engine reported its successor through the deprecated sessionFile result. The queued compaction path validated and adopted that successor, but the CLI post-turn path only handled typed targets and session IDs, so maintenance and persisted resume state could remain attached to the old transcript.

Why This Change Was Made

Compaction successor interpretation now has one canonical internal owner shared by queued and CLI compaction. It preserves typed-target precedence, partial-target inheritance, legacy SQLite-marker and agent: key compatibility, and the invariant that a successor cannot change the active agent, session key, or store path. Native harness routing, context-engine hooks/auth/timeouts, checkpointing, cancellation precedence, and store mutation remain in their existing dispatchers.

User Impact

CLI sessions using context-engine plugins now continue on the correct compacted transcript, including plugins on the shipped deprecated successor contract. Invalid cross-agent, cross-key, cross-store, and conflicting-ID successors are rejected consistently in both compaction entrypoints.

Production delta: 193 additions / 234 deletions, net -41 lines. Tests are counted separately.

Evidence

  • Blacksmith Testbox tbx_01kyxxt18fvcapc39rzmjs047e: 169 focused tests passed (cli-compaction, compact.hooks, and compaction rotation).
  • Exact rebased head 0fbb55a36ca4eb6344be6df44fb7cfcb94ab0c1f: full pnpm check:changed passed, including formatting, oxlint, core/core-test tsgo, SDK API, deprecated API, plugin boundaries, dead exports, database-first, schema, and import-cycle guards.
  • Blacksmith focused and full-gate proof
  • Isolated autoreview: gpt-5.6-sol at xhigh, clean with no accepted/actionable findings.
  • Regression coverage adds CLI adoption for deprecated SQLite markers and session keys, plus conflicting-ID and cross-agent/key/store rejection.

Inspectable after-fix runtime proof

A trusted Blacksmith Testbox ran the real exported CLI lifecycle against an ephemeral SQLite session store and a context-engine implementation returning each shipped deprecated successor shape. The only redaction below is the random temporary directory. Run 30687019376, lease tbx_01kyxyqy2js4yynxcnzz0g4ct5, exit 0.

$ CI=1 node --import tsx compaction-successor-proof.ts
marker.reported = { sessionId: proof-marker-after, sessionFile: sqlite:main:proof-marker-after:<temp>/marker.sqlite }
marker.maintenance = { sessionId: proof-marker-after, sessionFile: sqlite:main:proof-marker-after:<temp>/marker.sqlite, sessionTarget: { agentId: main, sessionKey: agent:main:proof-marker, storePath: <temp>/marker.sqlite, sessionId: proof-marker-after } }
marker.returnedResume = { sessionId: proof-marker-after }
marker.persistedResume = { sessionId: proof-marker-after, compactionCount: 1, totalTokens: 100 }

sessionKey.reported = { sessionId: proof-session-key-after, sessionFile: agent:main:proof-session-key }
sessionKey.maintenance = { sessionId: proof-session-key-after, sessionFile: agent:main:proof-session-key, sessionTarget: { agentId: main, sessionKey: agent:main:proof-session-key, storePath: <temp>/session-key.sqlite, sessionId: proof-session-key-after } }
sessionKey.returnedResume = { sessionId: proof-session-key-after }
sessionKey.persistedResume = { sessionId: proof-session-key-after, totalTokens: 950 }

blacksmith run summary ... exit=0

This directly shows both deprecated result shapes reaching maintenance with the bound agentId / sessionKey / storePath, and the next persisted resume resolving to the successor session ID.

Direct upstream Codex contract proof

Personally inspected sibling openai/codex at 07490c75234ed3c63291a8eb7629f04f647038fa. Explicit app-server compaction remains native:

// codex-rs/app-server/src/request_processors/thread_processor.rs:1874-1877
let (_, thread) = self.load_thread(&thread_id).await?;
self.submit_core_op(request_id, thread.as_ref(), Op::Compact)
    .await
    .map_err(|err| internal_error(format!("failed to start compaction: {err}")))?;

Automatic compaction remains inline before sampling:

// codex-rs/core/src/session/turn.rs:992-1012
maybe_run_previous_model_inline_compact(sess, turn_context, client_session, cancellation_token).await?;
let token_status = context_window_token_status(...).await;
if token_status.token_limit_reached {
    run_auto_compact(..., CompactionReason::ContextLimit, CompactionPhase::PreTurn).await?;
}

Therefore this PR does not alter thread/compact/start to Op::Compact, pre-sampling automatic compaction, or introduce a generic OAuth fallback.

AI-assisted: yes. I reviewed the implementation, contracts, and validation results.

@steipete
steipete marked this pull request as ready for review August 1, 2026 05:55
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 1, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 1, 2026, 2:01 AM ET / 06:01 UTC.

ClawSweeper review

What this changes

The branch moves context-engine compaction successor interpretation into one shared resolver so both CLI and queued compaction retain the correct rotated session transcript and reject binding changes.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

Keep this PR open for explicit maintainer handling. The patch consolidates two successor interpreters at the session-owner boundary and adds focused rejection coverage; I found no discrete source-level correctness defect. The maintainer label prevents automated cleanup, and the claimed Codex contract could not be independently inspected because the required sibling ../codex checkout is absent and GitHub DNS was unavailable.

Priority: P2
Reviewed head: 0fbb55a36ca4eb6344be6df44fb7cfcb94ab0c1f

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation and targeted coverage are coherent, but merge confidence is capped by missing inspectable real-behavior proof and the unavailable direct Codex contract check.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR body reports focused tests and a linked Testbox workflow, but no inspectable after-fix runtime transcript, terminal output, or redacted log was available to directly show legacy successor adoption; add one and update the PR body for automatic re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports focused tests and a linked Testbox workflow, but no inspectable after-fix runtime transcript, terminal output, or redacted log was available to directly show legacy successor adoption; add one and update the PR body for automatic re-review.
Evidence reviewed 6 items Current-main gap: The current CLI compaction path has its own resolver, while queued compaction separately interprets the context-engine successor; the proposed branch replaces both with the shared successor resolver and routes CLI maintenance through its resolved target.
Contract alignment: The context-engine contract explicitly prefers typed session targets while retaining raw successor fields as a named compatibility path for shipped engines that predate typed targets; the new helper retains that compatibility at the shared owner boundary.
Binding invariant: The new helper resolves legacy SQLite markers and session-key successors, then rejects any successor that changes the active agent, session key, or store path before callers persist it.
Findings None None.
Security None None.

How this fits together

Context-engine plugins compact agent transcripts and may return a successor identity. Both queued agent runs and the CLI post-turn path must validate that identity before maintenance and persisted resume state continue on the same agent, session key, and SQLite store.

flowchart LR
  A[CLI or queued compaction] --> B[Context-engine plugin result]
  B --> C[Shared successor resolver]
  C --> D[Agent session binding validation]
  D --> E[Context-engine maintenance]
  D --> F[Persisted resume state]
  E --> G[Next agent turn]
  F --> G
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports focused tests and a linked Testbox workflow, but no inspectable after-fix runtime transcript, terminal output, or redacted log was available to directly show legacy successor adoption; add one and update the PR body for automatic re-review.
  • Resolve merge risk (P1) - This changes the identity used for maintenance and resume persistence; an unhandled legacy successor shape could leave a session on the old transcript or reject a valid rotation.
  • Resolve merge risk (P1) - The PR body makes a Codex-runtime compatibility claim, but the required direct upstream source inspection was blocked by the missing ../codex checkout and unavailable GitHub DNS.
  • Complete next step (P2) - The protected maintainer label requires explicit maintainer handling, and this read-only review cannot independently validate the PR's direct Codex-runtime assertion.
Agent review details

Security

None.

PR surface

Source -41, Tests +203. Total +162 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 193 234 -41
Tests 1 203 0 +203
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 396 234 +162

Review metrics

Metric Value Why it matters
Successor ownership 1 shared resolver replaces 2 entrypoint-specific interpreters A single owner reduces drift between queued and CLI session-rotation behavior, but it now governs persisted session identity.

Merge-risk options

Maintainer options:

  1. Prove legacy successor adoption before merge (recommended)
    Add a redacted runtime transcript or Testbox artifact showing that a deprecated marker/session-key successor updates both maintenance and persisted CLI resume state without crossing the active binding.
  2. Accept the focused-test evidence
    A maintainer may accept the existing focused regression suite and CI evidence while explicitly owning the remaining uninspected runtime-proof and Codex-contract risk.

Technical review

Best possible solution:

Retain one canonical successor resolver, then complete direct Codex-source verification and publish a redacted after-fix CLI/Testbox transcript showing a deprecated successor rotates maintenance and persisted resume state to the new transcript.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: current main has separate CLI and queued successor handling, while the new focused cases exercise the missing CLI compatibility path and invalid binding variants. No local test was run because this review is read-only.

Is this the best way to solve the issue?

Yes, conditionally: centralizing successor interpretation at the shared session-target boundary is the narrowest maintainable repair, provided direct Codex contract inspection and after-fix runtime proof confirm the stated compatibility claim.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1f40646f7e05.

Labels

Label changes:

  • add P2: This is a bounded repair for compaction and persisted-resume behavior rather than an emergency runtime outage.
  • add merge-risk: 🚨 session-state: The branch changes how compaction successors are validated and recorded for later session maintenance and resume.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports focused tests and a linked Testbox workflow, but no inspectable after-fix runtime transcript, terminal output, or redacted log was available to directly show legacy successor adoption; add one and update the PR body for automatic re-review.

Label justifications:

  • P2: This is a bounded repair for compaction and persisted-resume behavior rather than an emergency runtime outage.
  • merge-risk: 🚨 session-state: The branch changes how compaction successors are validated and recorded for later session maintenance and resume.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports focused tests and a linked Testbox workflow, but no inspectable after-fix runtime transcript, terminal output, or redacted log was available to directly show legacy successor adoption; add one and update the PR body for automatic re-review.

Evidence

What I checked:

  • Current-main gap: The current CLI compaction path has its own resolver, while queued compaction separately interprets the context-engine successor; the proposed branch replaces both with the shared successor resolver and routes CLI maintenance through its resolved target. (src/agents/command/cli-compaction.ts:256, 0fbb55a36ca4)
  • Contract alignment: The context-engine contract explicitly prefers typed session targets while retaining raw successor fields as a named compatibility path for shipped engines that predate typed targets; the new helper retains that compatibility at the shared owner boundary. (src/context-engine/types.ts:112, 1f40646f7e05)
  • Binding invariant: The new helper resolves legacy SQLite markers and session-key successors, then rejects any successor that changes the active agent, session key, or store path before callers persist it. (src/agents/embedded-agent-runner/compaction-successor.ts:142, 0fbb55a36ca4)
  • Regression coverage: The branch adds CLI scenarios for deprecated SQLite-marker successors plus conflicting identity and cross-agent/key/store rejection, covering the compatibility and state-safety boundaries introduced by the shared resolver. (src/agents/command/cli-compaction.test.ts:457, 0fbb55a36ca4)
  • Area provenance: The current CLI, queued-compaction, and session-target paths were most recently carried together by the agent-roster repair, making its author the strongest current-main routing candidate for this subsystem. (src/agents/command/cli-compaction.ts:256, af687f920f61)
  • Codex dependency gate unavailable: Repository policy requires direct inspection of sibling Codex source for a Codex-related verdict or proof-sufficiency claim. The required sibling checkout is absent, and attempts to inspect/fetch promisor objects or GitHub proof artifacts failed because GitHub DNS could not resolve.

Likely related people:

  • Jason (Json): Current-main blame and the latest available history connect the CLI compaction, queued compaction, and session-target resolver surfaces to the same recent repair. (role: recent area contributor; confidence: medium; commits: af687f920f61; files: src/agents/command/cli-compaction.ts, src/agents/embedded-agent-runner/compact.queued.ts, src/agents/run-session-target.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add a redacted after-fix CLI/Testbox transcript proving deprecated successor adoption through maintenance and persisted resume state.
  • Have a maintainer or reviewer inspect the required sibling Codex source before relying on the PR's Codex compatibility statement.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 4caff51 into main Aug 1, 2026
190 of 202 checks passed
@steipete
steipete deleted the codex/prod-wave-compaction-052208-2d45 branch August 1, 2026 06:07
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant