Repository navigation
fix(agents): serialize native compaction with session writers - #135441
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 10:56 AM ET / 14:56 UTC. ClawSweeper reviewWhat this changesThe PR serializes native Merge readinessKeep open. The PR provides a focused repair for the active-writer compaction race, with no introduced correctness or security defect found; current-main source could not be independently loaded from the unavailable promisor remote. Priority: P1 Review scores
Verification
How this fits togetherNative compaction asks the Codex runtime to persist a shorter conversation transcript. It shares the session’s execution lanes with ordinary agent turns so transcript writes and compaction cannot overlap. flowchart LR
Command[Manual compact command] --> Target[Durable session target]
Writer[Active agent writer] --> SessionLane[Session lane]
Target --> SessionLane
SessionLane --> GlobalLane[Global execution lane]
GlobalLane --> ClaimCheck[Writer claim check]
ClaimCheck --> Native[Native compaction]
Native --> Transcript[Persisted compacted transcript]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +48, Tests +150. Total +198 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the shared session-then-global lane wrapper with its immediate durable claim revalidation for both native execution paths. Do we have a high-confidence way to reproduce the issue? No current-main reproduction was run locally; the exact-head source and supplied before/after real-runtime trace provide a clear reproduction and recovery scenario. Is this the best way to solve the issue? Yes. It reuses the normal embedded-run lane order and verifies the durable writer claim immediately before either native execution path can modify the transcript. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4adab7342dd8. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
01da97e to
7763d98
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Addressed all rank-up moves on
|
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞👀 Re-review progress:
|
|
Thanks @jjjhenriksen! Proof: A real managed Codex writer ran a command while native compaction was requested. The writer completed before compaction started, compaction completed, both transcript markers persisted, and a separate turn recalled them.
Landed: e571ea3 Source: 64c0b97 |
…aw#135441) ## What Problem This Solves Primary native compaction could start while the same OpenClaw session still owned an active writer. Codex treats manual compaction as a turn-like task and replaces an active task, so the overlap could interrupt the user turn and strand compaction before its terminal item. ## Why This Change Was Made The host compaction coordinator now admits primary native harness and native CLI control operations through the existing per-session and global lanes. It revalidates the Codex session owner after admission. Direct compaction for callers that already own a lane remains unchanged. The contributor's client-router wait, extra timeout, and duplicate rejection test were removed. A route can end before OpenClaw finishes its transcript checkpoint, so route lifetime was not the writer ownership boundary. ## User Impact Codex-backed turns finish and persist before queued native compaction starts. The change does not add configuration, retries, timeouts, locks, or compaction policy. ## Evidence - Current-main red at `d49fd235bfcc4e0ed94b09d13c7b7a6060908d5c`: the compaction request preceded writer completion, Codex interrupted the writer, and the compaction item did not complete. - Exact-head green at `64c0b970febf7dadb4814e10d24632e6e5d6ee92`: writer command completed, writer turn completed, compaction request started, and the context-compaction item completed in that order. - Transcript proof: both unique markers remained after compaction, and a separate follow-up turn recalled them. - Regression proof: the native CLI ownership test fails on pre-repair head `250755ad0768f80197b2d87d1690c6bc1703fbcb` because compaction starts after the writer claim changes; it passes on this head without starting native I/O. - Focused tests: all 173 compaction owner tests passed. - Focused lint, format, and `git diff --check` passed. ### Real runtime order | Baseline | Exact head | | --- | --- | | writer start → command start → compaction request → writer interrupted → compaction item start | writer start → command start → command complete → writer complete → compaction request → compaction item start → compaction item complete | ### Redacted event trace ```text baseline d49fd23 01 writer_turn_started 02 writer_command_started 03 compaction_trigger 04 compaction_request firstTurnCompleted=false 05 writer_turn_completed status=interrupted 06 compaction_item_started -- compaction_item_completed missing exact head 64c0b97 01 writer_turn_started 02 writer_command_started 03 compaction_trigger 04 writer_command_completed 05 writer_turn_completed status=completed 06 compaction_request firstTurnCompleted=true 07 compaction_item_started 08 compaction_item_completed ``` Exact-head assertions: writer terminal `ok`; compaction `ok`; completion marker present; input and completion markers persisted; separate recall turn terminal `ok`; recall returned `WRITER_RECALL_OK`. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Primary native compaction could start while the same OpenClaw session still owned an active writer. Codex treats manual compaction as a turn-like task and replaces an active task, so the overlap could interrupt the user turn and strand compaction before its terminal item.
Why This Change Was Made
The host compaction coordinator now admits primary native harness and native CLI control operations through the existing per-session and global lanes. It revalidates the Codex session owner after admission. Direct compaction for callers that already own a lane remains unchanged.
The contributor's client-router wait, extra timeout, and duplicate rejection test were removed. A route can end before OpenClaw finishes its transcript checkpoint, so route lifetime was not the writer ownership boundary.
User Impact
Codex-backed turns finish and persist before queued native compaction starts. The change does not add configuration, retries, timeouts, locks, or compaction policy.
Evidence
0fafd993b4f93af51037dd9e29f69fcb94479a6e: the compaction request preceded writer completion, Codex interrupted the writer, and the compaction item did not complete.64c0b970febf7dadb4814e10d24632e6e5d6ee92: writer command completed, writer turn completed, compaction request started, and the context-compaction item completed in that order.250755ad0768f80197b2d87d1690c6bc1703fbcbbecause compaction starts after the writer claim changes; it passes on this head without starting native I/O.git diff --checkpassed.Real runtime order
Redacted event trace
Exact-head assertions: writer terminal
ok; compactionok; completion marker present; input and completion markers persisted; separate recall turn terminalok; recall returnedWRITER_RECALL_OK.