Repository navigation
fix(codex): prevent stale compaction after session rollover - #138767
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 9:58 PM ET / September 5, 2026, 01:58 UTC. ClawSweeper reviewWhat this changesMakes Codex session-to-thread lookups retain generation checks, preventing queued compaction from acting after session rollover while preserving cancellation results and adding regression coverage. Merge readiness✅ Ready for maintainer review Keep open: current main still contains the readable-binding bypass, and the merged predecessor-recovery work does not cover this admission case. No blocking correctness defect was found in the proposed patch. Priority: P2 Review scores
Verification
How this fits togetherThe Codex plugin maps OpenClaw sessions to saved Codex conversations. Compaction and related operations resolve that mapping, wait for thread ownership, and send requests to Codex app-server. flowchart TD
A[Session action] --> D[Resolve generation and thread]
B[Canonical session row] --> D
C[Saved native binding] --> D
D --> E[Wait for thread ownership]
E --> F{Generation still current?}
F -->|Yes| G[Codex request and guarded writes]
F -->|No| H[Reject without changing successor]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +19, Tests +173. Total +192 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep generation validation in the shared binding owner rather than adding a compaction-only guard or setting; the small production increase supplies the missing authority capture and preserves the narrow cancellation boundary. Do we have a high-confidence way to reproduce the issue? Yes, from source: hold the native-thread queue, admit compaction with a readable binding, rotate the canonical session row, then release the queue. Current main retains a no-op generation assertion; the added regression exercises this sequence, but this reviewer did not execute it. Is this the best way to solve the issue? Yes—the canonical session row already records the required lineage, and composing its exact generation pair with caller authority repairs shared resolver consumers without another store, public API, or option. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cfc6534da8c3. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…8767) Fix stale Codex compaction after durable same-key session rollover by carrying canonical session-generation authority through binding resolution and final transport writes. - share the exact `(sessionId, previousSessionId)` fence across readable-binding resolution and generation reclaim - preserve caller-owned ephemeral authority, successor adoption, and narrow resolver-cancellation behavior - prove the stale generation makes zero Codex protocol calls while the successor resumes and compacts the same real native thread Validation: focused 126/126, reviewed owner/sibling surface 716/716, `check:changed`, exact-head hosted CI, local and hosted ClawSweeper, scoped-clean autoreview, and live Codex rollover proof `run_84742ba57fbd`. Related: openclaw#138473
Related: #138473
What Problem This Solves
Fixes an issue where a queued Codex compaction admitted under one durable session generation could continue after the same session key rolled over to a successor generation. An already-readable native binding bypassed the durable-row generation fence, so stale work could acquire a client or write after ownership had moved.
Why This Change Was Made
Codex binding resolution now captures tri-state authority from the canonical session row: a current durable row composes an exact
(sessionId, previousSessionId)host assertion with the caller assertion, no row remains scoped ephemeral, and mismatched or unreadable authority fails closed. Reclaim and ordinary resolution share that prepared capture without persisting authority.Compaction now resolves the binding once before client selection and narrowly converts only resolver-time cancellation into the existing compaction result. The merged pre-write rejection, ambiguous-write retirement, watcher, cleanup, and finalization paths remain unchanged.
User Impact
Queued Codex compaction can no longer act through a stale native-thread binding after same-key session rollover. The successor generation can adopt the existing native thread without a stale client acquisition or write from its predecessor.
Evidence
c26e46b2f87ad50d2f655e44975eafc8d394527ffrom fix(codex): preserve native threads after interrupted compaction #138473 is an ancestor. Its full tree differs from merged headf4e1c96807f704cbe8de4276144b52001cbf4183because the squash used a newer main base, while all four files changed here were byte-identical.run-attempt.native-hook-relay.test.ts:466failure reproduces unchanged on the untouched squash at https://crabbox.openclaw.ai/portal/runs/run_6ceeac0e7995.node scripts/check-changed.mjspassed, including extension production/test type checks, oxlint, formatting, boundary, cycle, and dead-export checks.f44a3ffaa5831ccaf157f5fb9e751cab34a02298, temporary harness SHA-25605332255d95da7adf8bc9b4906844a4fe36274d41ebed91446be53f6fb2d1fc6, providerhetzner, and real Codex app-server0.153.0over stdio. The queued stale generation failed withCodex session generation is no longer current, zero client-factory calls, zero protocol methods, and its binding intact. The successor adopted the same native thread, acquired one client, sentthread/resumethenthread/compact/start, observed matching compaction and turn completion, returnedok=true,compacted=true,completed=true, and became the binding owner. The live harness passed 1/1 and the task-owned lease was released.openai/codexcommit3921a30d6b11218883e5bb81a48082095cf79b7c; inspectedcodex-rs/app-server/src/request_processors/thread_processor.rs:762-770,2371-2383,codex-rs/core/src/tasks/compact.rs:19-85,codex-rs/core/src/compact.rs:185-245,290-320, andcodex-rs/core/src/tasks/mod.rs:512-630,903-1005.session-binding.ts+14,compact.ts+5), reduced from the earlier +26 shape. The remaining growth is the single canonical durable-row tri-state/exact-pair fence shared by resolution and reclaim, plus the deliberately narrow resolver-abort boundary. Further compression would duplicate authority policy, weaken the exact-pair fence or public rollback semantics, or broaden cancellation normalization.Local ClawSweeper completed on exact range
7b1795acc6783273c4218a511011bc1f7f13bd65..f44a3ffaa5831ccaf157f5fb9e751cab34a02298after using an isolated authenticated reviewer home. It found no code defect, cleared security, judged the shared-owner fix correct, and requested the live final-effect proof recorded above. Hosted ClawSweeper then reviewed the same exact head with no findings and no before-merge actions: #138767 (comment). Hosted CI is green at that SHA. Fresh generic autoreview also completed on exact commitf44a3ffaa5831ccaf157f5fb9e751cab34a02298: scoped clean, no P0/P1 findings, patch correct at 0.93 confidence.Agent Transcript
Redacted codex session transcript: fix(codex): fence current bindings against host rollover