Repository navigation
fix(sessions): keep reset history closed after compaction - #132606
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 10:38 AM ET / 14:38 UTC. ClawSweeper reviewWhat this changesThe PR makes SQLite session-history readers retain the latest reset window after a later compaction while preserving compaction-based model-context behavior. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessNo blocking defect found in the introduced repair. Keep this maintainer-authored, maintainer-labelled PR open for normal landing review; it fixes the canonical issue rather than being eligible for automated cleanup. Priority: P1 Review scores
Verification
How this fits togetherGateway resets and compactions are stored as transcript events in each agent’s SQLite database. The history projection feeds Control UI, CLI, and memory consumers, while a separate context projection feeds the next model turn. flowchart LR
A[Gateway conversation] --> B[SQLite transcript events]
B --> C[Reset and compaction boundaries]
C --> D[History window projection]
D --> E[Control UI, CLI, and memory]
C --> F[Model context projection]
F --> G[Next model turn]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -6, Tests +151, Docs +3. Total +148 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the canonical owner-boundary repair after the normal maintainer review, preserving the documented distinction between reset-bounded history and compaction-bounded model context. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: the added boundary tests implement the reported reset → fresh message → compaction sequence for cold and warm projection caches. This reviewer did not execute the tests because the review checkout is read-only. Is this the best way to solve the issue? Yes. The change repairs the shared reset-window and history-projection owners, rather than adding downstream filtering in the Gateway, CLI, or memory consumers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f5eea3197c55. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Land-ready verificationVerified candidate: Observed behaviorThe original real SessionManager/SQLite repro returned one visible message after reset, then three after compaction, including two pre-reset messages. With this repair it remains one, with zero pre-reset messages; model context excludes those messages before and after the repair. Four message-window cases failed before the first owner repair, and four marker cases failed before the second owner repair. The attached recording uses a real built Gateway, its bundled Control UI, real session lifecycle/compaction and real SQLite. Only the model HTTP endpoint is the repository's existing synthetic OpenAI-compatible fixture. All writes were performed through the normal composer: three old exchanges, All 117 target-flow assertions passed: the same session identity survived reset; old message IDs and the old compaction marker stayed absent after subsequent compaction, reload, pagination and old-ID lookup; all six fresh dialogue rows remained; the new reset/compaction markers were correctly placed. The post-reset provider requests also contained no old conversation sentinels. Screenshots and sampled video frames were inspected. The media contains only synthetic conversation data and generic UI, and its upload was explicitly approved. The video is after-fix live evidence. Before-fix evidence is the failing real-SQLite regression/API reproduction, not the pre-reset stage of this recording. ProvenanceThe boundary-selection behavior originated in the cursor-preserving reset change, authored and merged by @steipete on July 23, 2026; the marker projection carried it into the database-backed boundary-divider change, also authored and merged by @steipete on August 11. The original reset change intentionally retained broad latest-boundary shadowing. This explicitly requested repair applies the current reset-only history contract while preserving latest-reset-or-compaction model context; it is not an unexamined deletion of that earlier policy. The current repair is authored by @steipete. Ownership and compatibilityBest-fix verdict: the canonical owner repair, not a downstream mitigation. History selects the latest reset in both cold lookup and cache refresh; model-context accounting still selects the latest reset or compaction. The shared event-history projection drops earlier boundaries and rebases marker placement through the same logical message window. Consumer guards and treating compaction as a history reset were rejected because they either duplicate policy or discard valid current-window history. The review's serialized-state detector is not a schema/migration change here: the production diff changes read-only selection/projection logic, with no table, column, index, schema version, persisted representation, writer, retention, concurrency or raw transcript mutation. The read-only-query checkpoint exception applies. Upstream context-eligibility and display-position changes are preserved, not added by this PR. Production +20/-26 (net -6); tests +369/-218 (net +151); docs +5/-2. The test delta includes relocating existing pairing coverage, not deleting its protection. Validation89 focused tests passed across nine files, including cold/warm caches, repeated reset/compaction order, retained tool pairing, empty and adjacent boundaries, every history reader, the 100k-message bound, upstream context eligibility, companion history, CLI context/reseed and automatic session-memory hooks. Both isolated production probes passed. The complete changed gate and full build passed. Fresh isolated Codex autoreview found no actionable findings at its P0 reporting threshold; the direct owner/caller review and executable proof are recorded separately above. node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-history-events.test.ts src/config/sessions/session-accessor.sqlite-bounded-context.test.ts src/config/sessions/session-accessor.sqlite-active-events.test.ts src/gateway/session-transcript-readers.markers.test.ts src/agents/cli-runner/session-history.test.ts src/gateway/session-companion-context.test.ts src/hooks/bundled/session-memory/handler-auto-reset.test.ts src/config/sessions/session-accessor.sqlite-context-accounting.test.ts src/agents/sessions/session-manager-bounded.test.tsnode scripts/check-changed.mjs -- docs/reference/session-management-compaction.md src/config/sessions/session-accessor.sqlite-active-events.test.ts src/config/sessions/session-accessor.sqlite-bounded-context.test.ts src/config/sessions/session-accessor.sqlite-history-events.ts src/config/sessions/session-accessor.sqlite-reset-window.ts src/gateway/session-transcript-readers.markers.test.tspnpm buildThe first integrated attempt stalled in module loading; a subsequent probe identified a missing installed dependency. A frozen-lockfile install repaired the environment without manifest/lockfile changes, and the unchanged tests passed. The first recorder attempt rejected an intentionally trailing space that the composer normally trims; its input fixture was normalized, without weakening the equality assertion or changing product code, and a completely fresh isolated state was used for the successful recording. A separate UI-rendering follow-up was recorded for a transient duplicate fresh-message bubble in an intermediate frame despite unique canonical history IDs; compaction/reload corrected it. That is not concealed by this query repair, and is not a claim that every intermediate paint was audited by the 117 target-flow checks. The reset-discarded messages and old summary marker remained hidden as required. The latest ClawSweeper rank-up move (live UI evidence plus exact-head CI) is addressed. No source changes or re-review request are needed for this evidence update. No operator state, real provider credentials, or protected CLI-propagation checkout was used. history-window-after.mp4 |
|
Merged via squash.
|

Closes #132586
What Problem This Solves
Fixes an issue where users would see messages and older compaction summaries reappear in session history after resetting a session and then compacting it. Reset and compaction markers could also appear after the wrong messages. Bounded history consumers, including CLI lifecycle hooks and session-memory capture, could receive the discarded turns even though model context already excluded them.
Why This Change Was Made
The canonical history-window owner now selects the latest reset for both cold reads and cache refresh; model-context accounting still selects the latest reset or compaction. The event-history owner keeps the latest reset and subsequent boundaries, mapping their raw message positions through that same visible window so every reader agrees on order, counts and IDs.
This removes redundant selection checks and the mutable marker counter. There is no consumer guard, schema/config/protocol change, retention change, new store or durable transcript rewrite. Explicitly retained reset tails, compaction-only history and model-context behavior remain supported. The documentation now explains the history/context distinction and in-place Gateway resets.
User Impact
A later compaction no longer revives reset-discarded history or saved memory content. Current reset/compaction markers remain in the correct order, and old hidden message or boundary IDs are not returned by history lookup or anchored paging. Raw transcript rows remain stored.
Evidence
The exact real SessionManager/SQLite sequence appends a user and assistant message, resets, appends one fresh user message, warms history, then compacts using the fresh user's ID:
Focused test command:
Production LOC: +20/−26 (net −6). Tests: +369/−218 (net +151), including relocation of existing retained-pairing coverage to keep its original suite within the file-size budget. Docs: +5/−2. The rebase preserves main's active-context module split, opaque ancestry/retained cuts, event-sequence/display metadata, context-eligibility filter and older-writer tests; its sole conflict was the test import block.
The first integrated test attempt was interrupted during prolonged module collection without an assertion failure. A subsequent API probe exposed a missing installed dependency entry point. A frozen-lockfile workspace install repaired dependency readiness without changing manifests or the lockfile; the unchanged focused test command and both production probes then passed.
Live verification complete: Land-ready proof, inspected screenshot and video. The real built Gateway/Control UI flow passed 117 target-flow assertions through old dialogue, compaction, same-session
/clear, fresh dialogue, compaction, reload, pagination and old-ID lookup. Only provider HTTP responses were synthetic; Gateway WebSocket, compaction, SQLite and rendering were real. The fullpnpm buildpassed. Before-fix evidence is the failing real-SQLite/API reproduction; the recording is after-fix live evidence.Exact-head CI: run 33255432806 is green at
8f19112e90f7872f042353afbead024e085d88f4, includingopenclaw/ci-gateand SQLite session lifecycle. The latest ClawSweeper rank-up move is addressed. Its serialized-state detector does not imply a schema change: this is a read-only query/projection repair with no persisted-data or migration change, as explained in the proof comment.Separate follow-up: an intermediate live frame showed a transient duplicate fresh-message bubble despite unique canonical history IDs; a UI-rendering investigation was recorded separately. It does not change the verified reset-window result, and the recording is not presented as proof that every intermediate paint is defect-free. Native landing remains pending.
AI-assisted implementation; the owners, callers, integration and evidence were inspected directly. No agent transcript is attached.