Repository navigation
fix(codex): avoid repeated host compaction after manual compact - #158044
scotthuang wants to merge 15 commits into
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: blocked before merge. What this changesThis PR applies the host transcript byte guard before manual Codex compaction and preserves committed accounting when native compaction fails. Example: Manually compact a Codex session whose host transcript occupies 21,224,992 bytes.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial Merge readiness⛔ Blocked before merge - 3 items remain This PR still addresses a distinct manual-compaction problem, and the previous navigation finding is resolved; product direction, SDK scope, and an unclassified CI failure remain unsettled. Priority: P1 Decision needed
Before merge
FindingsNone. Agent review detailsHow this fits togetherThe shared compaction owner receives manual or ordinary-turn requests, coordinates OpenClaw's SQLite transcript separately from Codex's native history, and publishes accounting and client notifications. flowchart TD
A[Manual compaction request] --> B[Check host byte budget and latch]
B --> C[Host semantic compaction when needed]
C --> D[Commit boundary count and latch]
D --> E[Native Codex compaction]
B --> E
E --> F[Publish committed host change and native outcome]
Technical reviewBest possible solution: Retain shared host accounting, keep receipt callbacks internal, and explicitly settle the host-first manual timing contract. Do we have a high-confidence way to reproduce the issue? Current main leaves native manual compaction separate from the host byte guard, so an oversized mirror without valid suppression can trigger host compaction on the next turn; historical operator evidence corroborates this path. Is this the best way to solve the issue? Sharing the existing byte guard and accounting owner is appropriate, and navigation protection is restored, but manual timing and exposure of internal receipt callbacks still need owner direction. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 799b7a347c50. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +344, Tests +906, Docs +24, Other -1. Total +1273 across 35 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel 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 (12 earlier review cycles; latest 8 shown)
Reviewed October 12, 2026, 11:59 PM ET / October 13, 2026, 03:59 UTC (Revision 13). |
5482714 to
ff85341
Compare
ff85341 to
51b023f
Compare
|
Maintainer decision (Ayaan): instead of host-first manual compaction, Codex sessions will stop running the host summarizer on transcript-byte growth; the transcript copy is bounded only when a fresh native thread is seeded, with at most one host summary at that moment. This PR will be superseded by that change (credit to @scotthuang for the diagnosis); I'll link it 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-`/compact` work in #158044; this implements the maintainer's [lazy-seed direction](#158044 (comment)), 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 explicit `null` to 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.md` and `results.json`; private transcript contents and credentials are not published here. BEFORE executed `7bfde4923e84f67e2961ea24d6a6fb6108680a03`; AFTER executed `df4c0017e1a8c4971afd8b0819e29923242ba970`. Final head `7083100abbdcc77bb9a28ac1afc41e647e299ead` is **production-identical to df4c**: `git diff df4c001 7083100 --stat` contains only `host-seed.test.ts | 12` (11 additions, one deletion) for its test-table type. The [67 incoming main commits](7bfde49...0b64fd1) 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. | Scenario | Repeats | BEFORE host ops / calls | AFTER host ops / calls | Result | |---|---:|---:|---:|---| | Oversized ordinary turn | 5 | 1 / 1 | 0 / 0 | All three historical facts retained | | Below-budget control | 5 | 0 / 0 | 0 / 0 | All three facts retained | | Fresh rotation at final history allowance | 2 | 0 / 0 | 1 / 2 | 73,678-byte seed; all three facts retained | | Subsequent rotation with covering summary | 2 | 0 / 0 | 0 / 0 | No repeat host summary; all three facts retained | | 8 KiB refresh, compaction disabled | 2 | 0 / 0 | 0 / 0 | 20,459 / 20,463-byte seeds retain the active 17,862-byte exchange and task once; older facts omitted with the native-seed notice | | Same refresh, compaction enabled | 1 paired, plus 2 repair-proof repeats | 1 / 1 | 1 / 1 | 22,222-byte seed; active exchange and all three facts retained | | Forced-cold upgrade, first next turn | 2 | 1 / 2 | 1 / 1 | 1,744-byte seed contains persisted summary; settings/auth/history and all facts retained | | Same upgrade, second next turn | 2 | 1 / 2 | 0 / 0 | Warm native reuse, no repeat host maintenance | | High-byte-cap but token-bounded upgrade | 1 | 0 / 0 | 1 / 2, then 0 / 0 | Deliberately not a below-all-budgets control; all facts retained | Supporting recorded-head campaigns also exercised real native `/compact` followed 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. | Cell | BEFORE median [min–max], ms | AFTER median [min–max], ms | |---|---:|---:| | Oversized ordinary turn, n=5 each | 1,714.492 [1,683.089–1,792.939] | 1,484.624 [1,462.629–1,495.408] | | Control, n=5 each | 1,492.385 [1,463.280–1,495.413] | 1,523.846 [1,478.522–1,551.325] | ### 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/start` requests. | Model | Summary calls BEFORE → AFTER | Input tokens BEFORE → AFTER | Wall ms BEFORE → AFTER | AFTER seed bytes | |---|---:|---:|---:|---:| | A | 2 → 1 | 41,896 → 41,700 | 10,284.090 → 9,766.600 | 67,614 | | B | 2 → 1 | 41,855 → 41,602 | 12,733.944 → 11,388.505 | 67,174 | | C | 2 → 1 | 41,873 → 41,639 | 12,074.490 → 11,443.134 | 67,368 | 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 - The task-owned observer exercised the real host compactor, atomic persistence, and stock native injection: one host operation, two summary calls, nine injected items / 73,678 bytes, and **zero native compaction RPCs**. The report's legacy `nativeSyncAfterHost` flag also counts expected injection; it does not mean `thread/compact/start`. - Retained callbacks after completed-source retirement and after public reset rejected with zero additional summary/native effects; transcript-plus-entry hashes stayed identical. Reset during prepared seeding produced zero stale injections; the next turn was healthy with neither old-thread reuse nor stale seed markers. Public reset retires both source and writer; isolated writer-only reassignment is additionally covered by the owner regression. - E2E exposed and repaired two real defects: an oversized tail crowded out a fitting persisted summary, and the compactor's default kept tail exceeded the final seed allowance. The seed now reserves a fitting summary and gives the existing compactor the matching retention budget. Negative owner tests fail before these repairs. - The upgrade is explicitly **forced-cold**: native 0.160.0→0.162.0 changes runtime/policy identity. This is not presented as a warm-binding migration. Saved operator settings, authentication, logical history, and real pre-existing latch state were checked. - The existing [160,000-CJK-weighted-character summary input cap](https://github.com/openclaw/openclaw/blob/0b64fd18fcdccfa5ef3a1837909e7321ebcbca50/packages/agent-core/src/harness/compaction/utils.ts#L393) samples oversized histories and marks gaps. This PR does not promise lossless summaries or hide that pre-existing limitation. - With compaction disabled, the configured cap still omits older historical facts with a notice; no-cap defaults and the full saved record are unchanged. In the disabled 8 KiB case, BEFORE recalled three old facts and AFTER recalled none, while preserving the active task/exchange. That is the explicit configured-bound behavior, not an inherited-loss claim. - Cleanup removed 98 receipt-owned temporary roots, deferred none, and stopped all test Gateways/providers. Private evidence was retained; no operator Gateway or live state was touched. [Exact-head CI is green](https://github.com/openclaw/openclaw/actions/runs/39046961062). The final build, proof identity, budget ledger, and cleanup receipts are recorded; merge remains gated on ClawSweeper's exact-head readiness. `pr-simplify` against merge base `0b64fd18fcdccfa5ef3a1837909e7321ebcbca50`: 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. Co-authored-by: Ayaan Zaidi <[email protected]>
|
Superseded by #175256 (landed in 6db8577), which removes the eager host byte compaction for Codex instead of reordering it. Thanks @scotthuang for the diagnosis. |
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-`/compact` work in #158044; this implements the maintainer's [lazy-seed direction](openclaw/openclaw#158044 (comment)), 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 explicit `null` to 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.md` and `results.json`; private transcript contents and credentials are not published here. BEFORE executed `7bfde4923e84f67e2961ea24d6a6fb6108680a03`; AFTER executed `df4c0017e1a8c4971afd8b0819e29923242ba970`. Final head `7083100abbdcc77bb9a28ac1afc41e647e299ead` is **production-identical to df4c**: `git diff df4c0017 7083100a --stat` contains only `host-seed.test.ts | 12` (11 additions, one deletion) for its test-table type. The [67 incoming main commits](openclaw/openclaw@7bfde49...0b64fd1) 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. | Scenario | Repeats | BEFORE host ops / calls | AFTER host ops / calls | Result | |---|---:|---:|---:|---| | Oversized ordinary turn | 5 | 1 / 1 | 0 / 0 | All three historical facts retained | | Below-budget control | 5 | 0 / 0 | 0 / 0 | All three facts retained | | Fresh rotation at final history allowance | 2 | 0 / 0 | 1 / 2 | 73,678-byte seed; all three facts retained | | Subsequent rotation with covering summary | 2 | 0 / 0 | 0 / 0 | No repeat host summary; all three facts retained | | 8 KiB refresh, compaction disabled | 2 | 0 / 0 | 0 / 0 | 20,459 / 20,463-byte seeds retain the active 17,862-byte exchange and task once; older facts omitted with the native-seed notice | | Same refresh, compaction enabled | 1 paired, plus 2 repair-proof repeats | 1 / 1 | 1 / 1 | 22,222-byte seed; active exchange and all three facts retained | | Forced-cold upgrade, first next turn | 2 | 1 / 2 | 1 / 1 | 1,744-byte seed contains persisted summary; settings/auth/history and all facts retained | | Same upgrade, second next turn | 2 | 1 / 2 | 0 / 0 | Warm native reuse, no repeat host maintenance | | High-byte-cap but token-bounded upgrade | 1 | 0 / 0 | 1 / 2, then 0 / 0 | Deliberately not a below-all-budgets control; all facts retained | Supporting recorded-head campaigns also exercised real native `/compact` followed 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. | Cell | BEFORE median [min–max], ms | AFTER median [min–max], ms | |---|---:|---:| | Oversized ordinary turn, n=5 each | 1,714.492 [1,683.089–1,792.939] | 1,484.624 [1,462.629–1,495.408] | | Control, n=5 each | 1,492.385 [1,463.280–1,495.413] | 1,523.846 [1,478.522–1,551.325] | ### 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/start` requests. | Model | Summary calls BEFORE → AFTER | Input tokens BEFORE → AFTER | Wall ms BEFORE → AFTER | AFTER seed bytes | |---|---:|---:|---:|---:| | A | 2 → 1 | 41,896 → 41,700 | 10,284.090 → 9,766.600 | 67,614 | | B | 2 → 1 | 41,855 → 41,602 | 12,733.944 → 11,388.505 | 67,174 | | C | 2 → 1 | 41,873 → 41,639 | 12,074.490 → 11,443.134 | 67,368 | 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 - The task-owned observer exercised the real host compactor, atomic persistence, and stock native injection: one host operation, two summary calls, nine injected items / 73,678 bytes, and **zero native compaction RPCs**. The report's legacy `nativeSyncAfterHost` flag also counts expected injection; it does not mean `thread/compact/start`. - Retained callbacks after completed-source retirement and after public reset rejected with zero additional summary/native effects; transcript-plus-entry hashes stayed identical. Reset during prepared seeding produced zero stale injections; the next turn was healthy with neither old-thread reuse nor stale seed markers. Public reset retires both source and writer; isolated writer-only reassignment is additionally covered by the owner regression. - E2E exposed and repaired two real defects: an oversized tail crowded out a fitting persisted summary, and the compactor's default kept tail exceeded the final seed allowance. The seed now reserves a fitting summary and gives the existing compactor the matching retention budget. Negative owner tests fail before these repairs. - The upgrade is explicitly **forced-cold**: native 0.160.0→0.162.0 changes runtime/policy identity. This is not presented as a warm-binding migration. Saved operator settings, authentication, logical history, and real pre-existing latch state were checked. - The existing [160,000-CJK-weighted-character summary input cap](https://github.com/openclaw/openclaw/blob/0b64fd18fcdccfa5ef3a1837909e7321ebcbca50/packages/agent-core/src/harness/compaction/utils.ts#L393) samples oversized histories and marks gaps. This PR does not promise lossless summaries or hide that pre-existing limitation. - With compaction disabled, the configured cap still omits older historical facts with a notice; no-cap defaults and the full saved record are unchanged. In the disabled 8 KiB case, BEFORE recalled three old facts and AFTER recalled none, while preserving the active task/exchange. That is the explicit configured-bound behavior, not an inherited-loss claim. - Cleanup removed 98 receipt-owned temporary roots, deferred none, and stopped all test Gateways/providers. Private evidence was retained; no operator Gateway or live state was touched. [Exact-head CI is green](https://github.com/openclaw/openclaw/actions/runs/39046961062). The final build, proof identity, budget ledger, and cleanup receipts are recorded; merge remains gated on ClawSweeper's exact-head readiness. `pr-simplify` against merge base `0b64fd18fcdccfa5ef3a1837909e7321ebcbca50`: 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. Co-authored-by: Ayaan Zaidi <[email protected]>
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-`/compact` work in #158044; this implements the maintainer's [lazy-seed direction](openclaw/openclaw#158044 (comment)), 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 explicit `null` to 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.md` and `results.json`; private transcript contents and credentials are not published here. BEFORE executed `7bfde4923e84f67e2961ea24d6a6fb6108680a03`; AFTER executed `df4c0017e1a8c4971afd8b0819e29923242ba970`. Final head `7083100abbdcc77bb9a28ac1afc41e647e299ead` is **production-identical to df4c**: `git diff df4c0017 7083100a --stat` contains only `host-seed.test.ts | 12` (11 additions, one deletion) for its test-table type. The [67 incoming main commits](openclaw/openclaw@7bfde49...0b64fd1) 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. | Scenario | Repeats | BEFORE host ops / calls | AFTER host ops / calls | Result | |---|---:|---:|---:|---| | Oversized ordinary turn | 5 | 1 / 1 | 0 / 0 | All three historical facts retained | | Below-budget control | 5 | 0 / 0 | 0 / 0 | All three facts retained | | Fresh rotation at final history allowance | 2 | 0 / 0 | 1 / 2 | 73,678-byte seed; all three facts retained | | Subsequent rotation with covering summary | 2 | 0 / 0 | 0 / 0 | No repeat host summary; all three facts retained | | 8 KiB refresh, compaction disabled | 2 | 0 / 0 | 0 / 0 | 20,459 / 20,463-byte seeds retain the active 17,862-byte exchange and task once; older facts omitted with the native-seed notice | | Same refresh, compaction enabled | 1 paired, plus 2 repair-proof repeats | 1 / 1 | 1 / 1 | 22,222-byte seed; active exchange and all three facts retained | | Forced-cold upgrade, first next turn | 2 | 1 / 2 | 1 / 1 | 1,744-byte seed contains persisted summary; settings/auth/history and all facts retained | | Same upgrade, second next turn | 2 | 1 / 2 | 0 / 0 | Warm native reuse, no repeat host maintenance | | High-byte-cap but token-bounded upgrade | 1 | 0 / 0 | 1 / 2, then 0 / 0 | Deliberately not a below-all-budgets control; all facts retained | Supporting recorded-head campaigns also exercised real native `/compact` followed 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. | Cell | BEFORE median [min–max], ms | AFTER median [min–max], ms | |---|---:|---:| | Oversized ordinary turn, n=5 each | 1,714.492 [1,683.089–1,792.939] | 1,484.624 [1,462.629–1,495.408] | | Control, n=5 each | 1,492.385 [1,463.280–1,495.413] | 1,523.846 [1,478.522–1,551.325] | ### 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/start` requests. | Model | Summary calls BEFORE → AFTER | Input tokens BEFORE → AFTER | Wall ms BEFORE → AFTER | AFTER seed bytes | |---|---:|---:|---:|---:| | A | 2 → 1 | 41,896 → 41,700 | 10,284.090 → 9,766.600 | 67,614 | | B | 2 → 1 | 41,855 → 41,602 | 12,733.944 → 11,388.505 | 67,174 | | C | 2 → 1 | 41,873 → 41,639 | 12,074.490 → 11,443.134 | 67,368 | 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 - The task-owned observer exercised the real host compactor, atomic persistence, and stock native injection: one host operation, two summary calls, nine injected items / 73,678 bytes, and **zero native compaction RPCs**. The report's legacy `nativeSyncAfterHost` flag also counts expected injection; it does not mean `thread/compact/start`. - Retained callbacks after completed-source retirement and after public reset rejected with zero additional summary/native effects; transcript-plus-entry hashes stayed identical. Reset during prepared seeding produced zero stale injections; the next turn was healthy with neither old-thread reuse nor stale seed markers. Public reset retires both source and writer; isolated writer-only reassignment is additionally covered by the owner regression. - E2E exposed and repaired two real defects: an oversized tail crowded out a fitting persisted summary, and the compactor's default kept tail exceeded the final seed allowance. The seed now reserves a fitting summary and gives the existing compactor the matching retention budget. Negative owner tests fail before these repairs. - The upgrade is explicitly **forced-cold**: native 0.160.0→0.162.0 changes runtime/policy identity. This is not presented as a warm-binding migration. Saved operator settings, authentication, logical history, and real pre-existing latch state were checked. - The existing [160,000-CJK-weighted-character summary input cap](https://github.com/openclaw/openclaw/blob/0b64fd18fcdccfa5ef3a1837909e7321ebcbca50/packages/agent-core/src/harness/compaction/utils.ts#L393) samples oversized histories and marks gaps. This PR does not promise lossless summaries or hide that pre-existing limitation. - With compaction disabled, the configured cap still omits older historical facts with a notice; no-cap defaults and the full saved record are unchanged. In the disabled 8 KiB case, BEFORE recalled three old facts and AFTER recalled none, while preserving the active task/exchange. That is the explicit configured-bound behavior, not an inherited-loss claim. - Cleanup removed 98 receipt-owned temporary roots, deferred none, and stopped all test Gateways/providers. Private evidence was retained; no operator Gateway or live state was touched. [Exact-head CI is green](https://github.com/openclaw/openclaw/actions/runs/39046961062). The final build, proof identity, budget ledger, and cleanup receipts are recorded; merge remains gated on ClawSweeper's exact-head readiness. `pr-simplify` against merge base `0b64fd18fcdccfa5ef3a1837909e7321ebcbca50`: 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. Co-authored-by: Ayaan Zaidi <[email protected]>
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-`/compact` work in #158044; this implements the maintainer's [lazy-seed direction](openclaw/openclaw#158044 (comment)), 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 explicit `null` to 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.md` and `results.json`; private transcript contents and credentials are not published here. BEFORE executed `7bfde4923e84f67e2961ea24d6a6fb6108680a03`; AFTER executed `df4c0017e1a8c4971afd8b0819e29923242ba970`. Final head `7083100abbdcc77bb9a28ac1afc41e647e299ead` is **production-identical to df4c**: `git diff df4c0017 7083100a --stat` contains only `host-seed.test.ts | 12` (11 additions, one deletion) for its test-table type. The [67 incoming main commits](openclaw/openclaw@7bfde49...0b64fd1) 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. | Scenario | Repeats | BEFORE host ops / calls | AFTER host ops / calls | Result | |---|---:|---:|---:|---| | Oversized ordinary turn | 5 | 1 / 1 | 0 / 0 | All three historical facts retained | | Below-budget control | 5 | 0 / 0 | 0 / 0 | All three facts retained | | Fresh rotation at final history allowance | 2 | 0 / 0 | 1 / 2 | 73,678-byte seed; all three facts retained | | Subsequent rotation with covering summary | 2 | 0 / 0 | 0 / 0 | No repeat host summary; all three facts retained | | 8 KiB refresh, compaction disabled | 2 | 0 / 0 | 0 / 0 | 20,459 / 20,463-byte seeds retain the active 17,862-byte exchange and task once; older facts omitted with the native-seed notice | | Same refresh, compaction enabled | 1 paired, plus 2 repair-proof repeats | 1 / 1 | 1 / 1 | 22,222-byte seed; active exchange and all three facts retained | | Forced-cold upgrade, first next turn | 2 | 1 / 2 | 1 / 1 | 1,744-byte seed contains persisted summary; settings/auth/history and all facts retained | | Same upgrade, second next turn | 2 | 1 / 2 | 0 / 0 | Warm native reuse, no repeat host maintenance | | High-byte-cap but token-bounded upgrade | 1 | 0 / 0 | 1 / 2, then 0 / 0 | Deliberately not a below-all-budgets control; all facts retained | Supporting recorded-head campaigns also exercised real native `/compact` followed 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. | Cell | BEFORE median [min–max], ms | AFTER median [min–max], ms | |---|---:|---:| | Oversized ordinary turn, n=5 each | 1,714.492 [1,683.089–1,792.939] | 1,484.624 [1,462.629–1,495.408] | | Control, n=5 each | 1,492.385 [1,463.280–1,495.413] | 1,523.846 [1,478.522–1,551.325] | ### 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/start` requests. | Model | Summary calls BEFORE → AFTER | Input tokens BEFORE → AFTER | Wall ms BEFORE → AFTER | AFTER seed bytes | |---|---:|---:|---:|---:| | A | 2 → 1 | 41,896 → 41,700 | 10,284.090 → 9,766.600 | 67,614 | | B | 2 → 1 | 41,855 → 41,602 | 12,733.944 → 11,388.505 | 67,174 | | C | 2 → 1 | 41,873 → 41,639 | 12,074.490 → 11,443.134 | 67,368 | 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 - The task-owned observer exercised the real host compactor, atomic persistence, and stock native injection: one host operation, two summary calls, nine injected items / 73,678 bytes, and **zero native compaction RPCs**. The report's legacy `nativeSyncAfterHost` flag also counts expected injection; it does not mean `thread/compact/start`. - Retained callbacks after completed-source retirement and after public reset rejected with zero additional summary/native effects; transcript-plus-entry hashes stayed identical. Reset during prepared seeding produced zero stale injections; the next turn was healthy with neither old-thread reuse nor stale seed markers. Public reset retires both source and writer; isolated writer-only reassignment is additionally covered by the owner regression. - E2E exposed and repaired two real defects: an oversized tail crowded out a fitting persisted summary, and the compactor's default kept tail exceeded the final seed allowance. The seed now reserves a fitting summary and gives the existing compactor the matching retention budget. Negative owner tests fail before these repairs. - The upgrade is explicitly **forced-cold**: native 0.160.0→0.162.0 changes runtime/policy identity. This is not presented as a warm-binding migration. Saved operator settings, authentication, logical history, and real pre-existing latch state were checked. - The existing [160,000-CJK-weighted-character summary input cap](https://github.com/openclaw/openclaw/blob/0b64fd18fcdccfa5ef3a1837909e7321ebcbca50/packages/agent-core/src/harness/compaction/utils.ts#L393) samples oversized histories and marks gaps. This PR does not promise lossless summaries or hide that pre-existing limitation. - With compaction disabled, the configured cap still omits older historical facts with a notice; no-cap defaults and the full saved record are unchanged. In the disabled 8 KiB case, BEFORE recalled three old facts and AFTER recalled none, while preserving the active task/exchange. That is the explicit configured-bound behavior, not an inherited-loss claim. - Cleanup removed 98 receipt-owned temporary roots, deferred none, and stopped all test Gateways/providers. Private evidence was retained; no operator Gateway or live state was touched. [Exact-head CI is green](https://github.com/openclaw/openclaw/actions/runs/39046961062). The final build, proof identity, budget ledger, and cleanup receipts are recorded; merge remains gated on ClawSweeper's exact-head readiness. `pr-simplify` against merge base `0b64fd18fcdccfa5ef3a1837909e7321ebcbca50`: 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. Co-authored-by: Ayaan Zaidi <[email protected]>
…175256) Related: openclaw#158044, openclaw#126171, openclaw#115514, openclaw#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` (openclaw#126171). ## Why This Change Was Made The guard introduced in openclaw#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-`/compact` work in openclaw#158044; this implements the maintainer's [lazy-seed direction](openclaw#158044 (comment)), 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; openclaw#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 explicit `null` to 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.md` and `results.json`; private transcript contents and credentials are not published here. BEFORE executed `81dde48ac1141487da66e6b9106aa6f7412e6e3b`; AFTER executed `df4c0017e1a8c4971afd8b0819e29923242ba970`. Final head `7083100abbdcc77bb9a28ac1afc41e647e299ead` is **production-identical to df4c**: `git diff df4c001 7083100 --stat` contains only `host-seed.test.ts | 12` (11 additions, one deletion) for its test-table type. The [67 incoming main commits](openclaw/openclaw@81dde48...140f7d9) 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. | Scenario | Repeats | BEFORE host ops / calls | AFTER host ops / calls | Result | |---|---:|---:|---:|---| | Oversized ordinary turn | 5 | 1 / 1 | 0 / 0 | All three historical facts retained | | Below-budget control | 5 | 0 / 0 | 0 / 0 | All three facts retained | | Fresh rotation at final history allowance | 2 | 0 / 0 | 1 / 2 | 73,678-byte seed; all three facts retained | | Subsequent rotation with covering summary | 2 | 0 / 0 | 0 / 0 | No repeat host summary; all three facts retained | | 8 KiB refresh, compaction disabled | 2 | 0 / 0 | 0 / 0 | 20,459 / 20,463-byte seeds retain the active 17,862-byte exchange and task once; older facts omitted with the native-seed notice | | Same refresh, compaction enabled | 1 paired, plus 2 repair-proof repeats | 1 / 1 | 1 / 1 | 22,222-byte seed; active exchange and all three facts retained | | Forced-cold upgrade, first next turn | 2 | 1 / 2 | 1 / 1 | 1,744-byte seed contains persisted summary; settings/auth/history and all facts retained | | Same upgrade, second next turn | 2 | 1 / 2 | 0 / 0 | Warm native reuse, no repeat host maintenance | | High-byte-cap but token-bounded upgrade | 1 | 0 / 0 | 1 / 2, then 0 / 0 | Deliberately not a below-all-budgets control; all facts retained | Supporting recorded-head campaigns also exercised real native `/compact` followed 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. | Cell | BEFORE median [min–max], ms | AFTER median [min–max], ms | |---|---:|---:| | Oversized ordinary turn, n=5 each | 1,714.492 [1,683.089–1,792.939] | 1,484.624 [1,462.629–1,495.408] | | Control, n=5 each | 1,492.385 [1,463.280–1,495.413] | 1,523.846 [1,478.522–1,551.325] | ### 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/start` requests. | Model | Summary calls BEFORE → AFTER | Input tokens BEFORE → AFTER | Wall ms BEFORE → AFTER | AFTER seed bytes | |---|---:|---:|---:|---:| | A | 2 → 1 | 41,896 → 41,700 | 10,284.090 → 9,766.600 | 67,614 | | B | 2 → 1 | 41,855 → 41,602 | 12,733.944 → 11,388.505 | 67,174 | | C | 2 → 1 | 41,873 → 41,639 | 12,074.490 → 11,443.134 | 67,368 | 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 - The task-owned observer exercised the real host compactor, atomic persistence, and stock native injection: one host operation, two summary calls, nine injected items / 73,678 bytes, and **zero native compaction RPCs**. The report's legacy `nativeSyncAfterHost` flag also counts expected injection; it does not mean `thread/compact/start`. - Retained callbacks after completed-source retirement and after public reset rejected with zero additional summary/native effects; transcript-plus-entry hashes stayed identical. Reset during prepared seeding produced zero stale injections; the next turn was healthy with neither old-thread reuse nor stale seed markers. Public reset retires both source and writer; isolated writer-only reassignment is additionally covered by the owner regression. - E2E exposed and repaired two real defects: an oversized tail crowded out a fitting persisted summary, and the compactor's default kept tail exceeded the final seed allowance. The seed now reserves a fitting summary and gives the existing compactor the matching retention budget. Negative owner tests fail before these repairs. - The upgrade is explicitly **forced-cold**: native 0.160.0→0.162.0 changes runtime/policy identity. This is not presented as a warm-binding migration. Saved operator settings, authentication, logical history, and real pre-existing latch state were checked. - The existing [160,000-CJK-weighted-character summary input cap](https://github.com/openclaw/openclaw/blob/140f7d9e325f6f38f94bf8a9041050ecc3fd1e55/packages/agent-core/src/harness/compaction/utils.ts#L393) samples oversized histories and marks gaps. This PR does not promise lossless summaries or hide that pre-existing limitation. - With compaction disabled, the configured cap still omits older historical facts with a notice; no-cap defaults and the full saved record are unchanged. In the disabled 8 KiB case, BEFORE recalled three old facts and AFTER recalled none, while preserving the active task/exchange. That is the explicit configured-bound behavior, not an inherited-loss claim. - Cleanup removed 98 receipt-owned temporary roots, deferred none, and stopped all test Gateways/providers. Private evidence was retained; no operator Gateway or live state was touched. [Exact-head CI is green](https://github.com/openclaw/openclaw/actions/runs/39046961062). The final build, proof identity, budget ledger, and cleanup receipts are recorded; merge remains gated on ClawSweeper's exact-head readiness. `pr-simplify` against merge base `140f7d9e325f6f38f94bf8a9041050ecc3fd1e55`: 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. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #126171
What Problem This Solves
Fixes repeated host compaction on the next chat turn after successful manual Codex compaction when OpenClaw's transcript mirror remains above its byte budget.
User Impact
Explicit compaction applies the existing host byte guard before native Codex compaction. Below-budget sessions and sessions with valid byte-progress accounting remain native-only. A committed host summary stays committed if native compaction fails; the manual failure remains visible and clients receive the host update once.
Maintainer decision remains open: accept host-first manual compaction latency. Historical operator testing measured about 15m26s for the first host summary plus 30s native time; this PR does not claim to make that first summary faster. There are no configuration, schema, retention, or migration changes. The released synchronous SessionManager SDK and process-local incognito contracts remain supported.
Why This Change Was Made
Codex owns its native history; native compaction does not rewrite OpenClaw's SQLite transcript mirror. Manual and ordinary-turn paths share one host accounting owner, with atomic boundary/count/latch persistence and current writer authority. Native-only accounting retains the host byte latch; a host rewrite below budget explicitly clears it.
The October 13 refresh resolves 12 text conflicts by merging main
f6c9a769e0f24780696a5aaf0e90dabf748adbccinto the existing PR history. It retains upstream #168051 latch semantics, #169622 worker-backed source/currentness checks, #170199 actor ownership, and committed compaction details. It removes the superseded PR-only write-view helper because main's native persistence owner now carries that rollback protection.The latest review's P2 navigation finding is fixed: compaction captures the existing navigation assertion, checks it at worker admission and before receipt adoption, and preserves a genuinely newer published view. The dedicated accounting transaction retains the same exception while still checking binding, writer, ownership, lifecycle, and caller authority. No new state owner or public SDK export is introduced.
Evidence
Product head:
a33bc638124dd72f88e6289e79dbff76417dc68c. Previous head7eb59d0bf6f3c442c628a41cd68b44fbaa4f4efbremains first parent; history is not rewritten.Code anchors for this revision: manual byte/accounting owner, navigation capture and receipt adoption, dedicated-owner newer-view exception, and real-worker navigation regression.
At publication GitHub reports MERGEABLE / BLOCKED, with 35 later main commits behind the branch but no merge conflict. New-head CI is still running; the block is not being treated as a code conflict or a passing review. Maintainers can edit the branch. The security-review publisher workflow completed successfully, but deliberately marks
openclaw/security-sensitive-reviewandopenclaw/ci-gatered:Security review is awaiting maintainer approval.This is an approval gate, not a failing product test.All current runs used temporary synthetic state and private frozen dependencies, Node 24.18.0 / pnpm 12.9.0 on macOS. No running installation, Gateway, real database/configuration, or external channel was used.
The current tests exercise the queued manual entry, real host compaction owner and SQLite workers, slash-command handling, Gateway RPC, admission/cancellation, canonical path aliases, incognito storage, committed-host/native-failure publication, and latch refresh/rearming. Model and native-harness outputs are synthetic; these are runtime/storage boundary tests, not a new live Codex or Weixin end-to-end run.
Initial failures were identified and corrected: old delegate/hydration fixtures lacked the newly required runtime-config snapshot (the delegate also resets its module graph, so preparation must use the post-reset instance); an actor callback signature and a raw-JSON test type needed adaptation. The line-cap check required moving existing entry/routing fixture factories into their existing test-support module, without deleting coverage. These integration/fixture failures are not claimed as upstream product regressions.
The 12 conflicted files and resolution
docs/reference/database-schemas/worker-access.md: retain the current worker/actor owner documentation and the manual boundary/accounting contract.src/agents/sessions/agent-session-compaction.tsand.test.ts: publish committed details once, preserve provider/server-endpoint compaction and cancellation fencing.src/agents/sessions/session-manager-entries.ts,session-manager-metadata.ts, andsession-manager-persistence.ts: retain main's actor/worker split, currentness and navigation assertions, and acknowledged-commit handling.src/auto-reply/reply/agent-runner-memory.ts: share accounting with manual compaction while preserving native-only latch retention.src/auto-reply/reply/commands-compact.ts: use current prepared session reads and skip accounting already committed by the host owner.src/config/sessions/session-entry-projection.ts: retain main unchanged (undefinedretains,nullclears the latch).src/config/sessions/session-accessor.compaction-boundary.test.ts: preserve both upstream writer/transaction coverage and manual accounting regressions.src/gateway/server-methods/sessions-compact.tsandsrc/gateway/server.sessions.compaction.test.ts: preserve native/server semantics, stale-owner checks, negative-estimate coverage, and one committed-host notification even after native failure.Reproducible commands, negative controls, and observed failure signatures
The second command initially passed 27 Gateway cases and 103 infra cases but failed the ten unprepared-snapshot fixture cases; it is not claimed as an entirely passing invocation. The next command passed 128 cases after those fixtures were corrected. Unaffected passing results are retained rather than rerun for appearances.
Each control below changed only the named production condition in the isolated worktree, ran the specified existing test filter, then restored the exact source bytes. These are deliberate defect controls, not a claim that the whole historical head was rerun.
-tfilterpersistWorkerRecordsession-manager-async-message.test.ts/fences local navigationReceived: undefined); exit 1, 27.95skeeps a newer published view when an awaited compaction receiptundefinedinstead of explicit host latch clearingcompact.delegate.test.ts/clears (the byte latch|stale byte suppression)undefined; exit 1, 36.92sagent-runner-memory.test.ts/preserves host byte suppression when native token-pressure compaction succeedsFinal restored-source command (8 pass):
node scripts/run-vitest.mjs src/agents/sessions/session-manager-async-message.test.ts src/agents/embedded-agent-runner/compact.delegate.test.ts src/auto-reply/reply/agent-runner-memory.test.ts -t 'fences local navigation|keeps a newer published view when an awaited compaction|clears (the byte latch|stale byte)|preserves host byte suppression' --maxWorkers=1The new host-summary-under-budget case cost 2.354s in the full delegate run; native latch preservation was under one second in the full owner run. No new sleeps, polling, longer timeouts, production test seams, or serial test configuration were added. Hosted CI timing for this revision is not yet available.
Preserved historical live/hosted evidence and limits
On macOS over official v2026.9.6, earlier operator testing reduced host bytes from 21,224,992 to 311,754, persisted the checkpoint, completed native compaction, kept a second manual request native-only, and allowed ordinary chat afterward. Initial host compaction took about 15m26s + 30s native. This is historical evidence, not a current-head provider run or a latency fix.
Historical product head
2bc49c17c57dd739f460fb7e7af702195f315bbapassed secretless fork validation through evidence commitc202912da226699ab07c11fd3a38618b42d8739f: 77 tests, production/test types, scoped static checks, and runtime build. Earlier broader 226-test/build and four type-lane results remain pinned to their historical revisions. They do not certify this refresh.The native contract was personally rechecked in sibling Codex source at
be9060ff9620e170a05a6353ab293efb7c704248:ThreadCompactStartParamsidentifies a native thread;thread_processor.rs::thread_compact_startsubmitsOp::Compact;core/compact.rsrewrites native history, not the OpenClaw transcript database.Current-head CI/review and maintainer acceptance of host-first latency remain separate. No CI rerun/dispatch, production restart, real model/channel request, or PR merge was performed.