Repository navigation
fix: avoid compaction from superseded history - #150623
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. Reviewed October 1, 2026, 7:04 AM ET / 11:04 UTC (Revision 15). ClawSweeper reviewWhat this changesThe PR estimates compaction pressure from the active conversation context, preserves legacy transcript reads, and keeps incognito reads with their process-local database owner. Merge readiness⛔ Blocked before merge - 1 item remains This remains a useful fix that current main and the latest release lack. The incognito correction resolves the reported reader regression, and source inspection removes the previous migration-proof blocker; no actionable patch defects remain. Priority: P1 Review scores
Verification
How this fits togetherBefore an agent replies, OpenClaw estimates conversation size to decide whether compaction is required. The estimate should include the current summary and retained messages rather than conversation history already superseded by compaction. flowchart TD
A[Incoming agent turn] --> B[Preflight budget check]
C[Stored transcript and usage] --> B
B --> D[Active conversation context]
D --> E[Token estimate]
E --> F{Over budget}
F -->|Yes| G[Compact conversation]
F -->|No| H[Continue reply]
G --> H
Before merge
Agent review detailsSecurityNone. PR surfaceSource +59, Tests +335, Other 0. Total +394 across 7 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Use the canonical active-context reader for budget estimates while preserving legacy reads and process-local incognito ownership. Do we have a high-confidence way to reproduce the issue? Yes: current source exposes the full-history estimate after compaction when usage is stale, and the captured baseline Gateway run records an extra persisted compaction. This read-only review did not execute tests. Is this the best way to solve the issue? Yes: reusing the existing active-context owner fixes the estimate without duplicating compaction selection or changing stored data. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e34e76640d45. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (14 earlier review cycles; latest 8 shown)
|
…en-estimate # Conflicts: # src/auto-reply/reply/agent-runner-memory.preflight-stale-tokens.test.ts
|
@clawsweeper re-review — exact head 0fe2675. The PR body now includes current-main versus candidate real-Gateway evidence and a large-active-context control. The Gateway regression now catches the actual extra persisted compaction, not merely provider request count. No stored-data contract changes. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review — exact head 3c8c8d0. Corrected the first CI run’s incognito read-fence regression at the model-context reader owner. The added native-store case fails before and passes after; 38 reader tests and 222 reply-agent tests pass. Rebuilt and repeated both healthy/oversized Gateway scenarios; both pass. Two supported incognito Gateway turns also pass without creating a database file. No stored-data contract changes. |
|
🦞👀 Re-review progress:
|
|
Maintainer override on head Red CI (run 36852448961) is unrelated to this diff:
Proof: a real isolated Gateway, in the PR thread.
|
|
Landed as 5129c0a. Thanks @goutamadwant! |
* fix: estimate compaction pressure from active context * fix: satisfy memory helper line cap * test: prove active-context preflight end to end * fix: document transcript projection assertion * test: use isolated workspace for preflight proof * fix: move preflight context reads off gateway thread * test: use typed excluded activity fixture * test: detect redundant compaction after a real turn * fix: retain native incognito ownership during context reads --------- Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #150579
What Problem This Solves
Fixes: stale-usage preflight triggers unnecessary compaction after a session has already compacted but retains a large display history.
User Impact
User impact: healthy compacted sessions proceed without another budget compaction. Genuinely oversized active contexts still trigger compaction.
Why This Change Was Made
Use the existing asynchronous canonical model-context reader for the no-usage estimate, preserving the summary, retained tail, tool pairs, and newer messages while excluding superseded history. Headerless legacy projections retain their existing fallback.
The contributor's implementation and commits are preserved. Removed an unused re-export left by an earlier revision. Strengthened the real-Gateway regression to assert that no second compaction entry is persisted: one model request alone was not sufficient, because the baseline performed an unnecessary compaction without an extra provider request.
The new reader also recognizes an explicitly selected incognito database, not only an incognito-shaped session key. Such databases stay with their existing process-local owner instead of being reopened as empty worker-local databases.
No overlap with Pash/Sarah changes. Thanks to @goutamadwant for the fix and @BillBOT33 for the report.
Evidence
Secretless Docker, built runtimes, synthetic persisted sessions, explicit isolated profiles, loopback mock Anthropic transport, and real authenticated Gateway
agentturns. Baseline: current main3f263ba918c56e5c227261cb67be910e64bef74d.Each healthy fixture retained 650,000 characters of superseded history behind a compaction boundary, with a short summary/tail and stale usage. The model window was 100,000 tokens; the blocking threshold was 80,000.
The healthy candidate's single provider request included the summary, active tail, and new prompt, but not the superseded marker. Memory flushing was disabled in this proof; it exercises the compaction path, not the reporter's complete hook/draining sequence.
git diff --checkpassed.Compatibility
Read-only selection change: no SQLite schema, serialized row, writer, migration, or retention changes. The persisted-session fixtures use the existing format. This does not require a data-model migration. The legacy read fallback remains intact.
Disclosure: AI assisted with implementation review and validation.