Repository navigation
fix(codex): avoid repeated host compaction on native turns - #175256
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. What this changesThis PR defers host transcript compaction until a fresh Codex thread needs bounded history. Example: An ordinary Codex turn has an oversized host transcript mirror.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR implements the approved lazy-seeding direction, addresses repeated Codex host compaction, and has no actionable introduced defects after review. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherOpenClaw stores conversation history independently of Codex native threads; the host prepares bounded history for fresh threads while Codex owns native compaction. flowchart TD
A[Admitted conversation turn] --> B[Codex thread lifecycle]
B --> C[Reuse healthy native thread]
B --> D[Prepare fresh history seed]
D --> E[Host compaction when needed]
E --> F[Atomic transcript and accounting writer]
D --> G[Bounded native history injection]
F --> G
Technical reviewBest possible solution: Keep host summarization at fresh-seed consumption, preserving native reuse, atomic accounting, active input, and explicit context-engine ownership. Do we have a high-confidence way to reproduce the issue? Current main evaluates host transcript byte pressure independently of native compaction, explaining repeated summaries; the supplied before/after runtime campaigns corroborate that path. Is this the best way to solve the issue? Moving the guard to fresh-seed consumption addresses its original bootstrap purpose and reuses the existing compactor and atomic writer without competing persistence ownership. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 08b19021512e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +98, Tests -115, Docs -1, Generated 0. Total -18 across 36 files. Added test files: 1. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (7 earlier review cycles)
Reviewed October 17, 2026, 1:23 PM ET / 17:23 UTC (Revision 8). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
|
Landed in 6db8577.
Thanks @scotthuang for the #158044 diagnosis that led here. |
Related: #158044, #126171, #115514, #167916
What Problem This Solves
Fixes repeated host summarization on ordinary Codex turns, including the turn after native
/compact, when OpenClaw's transcript mirror exceeds its byte limit.User Impact
Healthy native Codex threads continue without a host byte-summary request or a following native compaction. OpenClaw bounds the mirror only when it must seed a fresh native thread, attempting one host compaction only if the bounded seed would omit history not already covered by a host summary. The full stored transcript remains available to history, search, export, backups, cold storage, and memory indexing.
Native rollout-size/token fuses, manual native compaction, built-in/CLI behavior, and explicit context-engine ownership are preserved. Fresh seeds can still omit oversized history after the single attempt; an existing bounded-context notice tells the user when history is omitted. This does not add a native SQLite replay boundary or change
memoryFlush.forceFlushTranscriptBytes(#126171).Why This Change Was Made
The guard introduced in #115514 protects fresh-thread bootstrap size, but ran on every turn. Native compaction deliberately produces a display-only note, not a host compaction boundary, so it cannot clear that trigger. The bound and conditional host compaction now live at fresh-thread seed consumption instead. Thanks to @scotthuang for diagnosing the repeated post-
/compactwork in #158044; this implements the maintainer's lazy-seed direction, not host-first manual compaction.Removed: the Codex byte-preflight branch, its private WeakMap authority/claim module, projected compaction configuration, queued special-authority handling, post-maintenance latch callback, byte-triggered native follow-up, and tests of those retired paths. Owning engines retain engine-first compaction and their native follow-up. The existing compactor and atomic summary/count writer are reused; #167916's bounded summarization remains unchanged.
Accepted compatibility boundary: Ayaan, the SDK and security owner, approved the optional additive
AgentHarnessHostCapabilities.prepareBoundedSeed({ assertCurrent, signal, tokenBudget? }): Promise<readonly AgentMessage[]>capability on 2026-10-17, including the narrowing-only delivery allowance. The host captures session, configuration, source, byte budget, cancellation, and writer fences; callers cannot select another target or widen the captured token budget. Older hosts keep bounded selection without a plugin-side summary request. Explicit context engines retain their projections. The required main integration now supplies the canonical nullable-latch writer contract unchanged: seed commits pass explicitnullto clear prior suppression. No schema, stored-row shape, external protocol, or config key changes. Stored Codex latches are ignored on ordinary turns; non-Codex latch behavior is retained.Evidence
Complete: 57 paired result rows, seven reduced paid-confirmation turns, and supporting manual-compaction/harness-switch campaigns. The final report records no unresolved regressions or coverage gaps. Full local evidence is retained in
codex-mirror-lazy-seed/results.mdandresults.json; private transcript contents and credentials are not published here.BEFORE executed
7bfde4923e84f67e2961ea24d6a6fb6108680a03; AFTER executeddf4c0017e1a8c4971afd8b0819e29923242ba970. Final head7083100abbdcc77bb9a28ac1afc41e647e299eadis production-identical to df4c:git diff df4c0017 7083100a --statcontains onlyhost-seed.test.ts | 12(11 additions, one deletion) for its test-table type. The 67 incoming main commits changed none of the seed/compactor/writer/maintenance/harness-capability owners, so the same BEFORE remains applicable. The OpenShell config fingerprint conflict was regenerated canonically.Paired runtime results
“Op” means a committed host compaction; “calls” means summary-provider requests within that operation. Native history injection is not native compaction.
Supporting recorded-head campaigns also exercised real native
/compactfollowed by a normal turn, built-in/CLI harness switching, and an owning context engine's engine-first compaction plus native follow-up. Their head identities remain explicit in the full report; they are not mislabeled as current-head executions. The final focused batch passed 74 tests in three owner files, with Oxfmt/Oxlint and independent P0/P1 review clean; the main-integration batch separately passed 136 tests in five files.Five-repeat latency
Wall times include CLI startup through terminal reply. These are loopback comparisons, not a promise of a fixed live-provider speedup.
Real-provider confirmation
Each rotation entry below is one measured turn. Inputs are provider-reported totals across summary and native requests; model names are redacted as A/B/C. All six rotation turns recalled all three facts with zero errors and zero native
thread/compact/startrequests.The seventh confirmation turn was BEFORE model-A ordinary maintenance: 35,518 input tokens and two summary calls. Earlier full three-model campaigns remain supporting evidence. Final confirmation used 286,083 input tokens against a 286,841 forecast; the whole paid campaign used 3,593,931 input / 26,838 output tokens / 280 requests, below the approved 3,650,000-input cap. Credentials were removed.
Authority, compatibility, and limitations
nativeSyncAfterHostflag also counts expected injection; it does not meanthread/compact/start.Exact-head CI is green. The final build, proof identity, budget ledger, and cleanup receipts are recorded; merge remains gated on ClawSweeper's exact-head readiness.
pr-simplifyagainst merge base0b64fd18fcdccfa5ef3a1837909e7321ebcbca50: production +460/-362 (+98); tests +487/-602 (-115); docs including generated fingerprints +43/-44 (-1). Total: 36 files, +990/-1008, net -18 lines. No coverage was cut.The remaining production increase is 295 lines of host-owned seed preparation (authority/cancellation, retained-input budgeting, media costs, summary reservation and atomic persistence), plus 62 net lines of SDK/injection/notice integration, offset by 259 removed lines of eager preflight and private claim machinery. Shared bounds have distinct jobs: avoid restoring discarded media, account for actual media/active input, then reserve notice/summary only when needed. Non-Codex and owning-engine contracts remain intact.
Merge danger: two-way door. Reverting restores eager host byte preflight; any summaries already appended remain valid existing-format transcript events. The main risk is incorrect fresh-thread seed selection or source/writer handoff for Codex sessions with the byte guard enabled. Healthy native reuse and explicit engine ownership are protected separately. No operator Gateway or operator state was touched.