Skip to content

fix(sessions): keep reset history closed after compaction - #132606

Merged
steipete merged 1 commit into
mainfrom
steipete/jovial-elbakyan-7e18d8
Aug 29, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/jovial-elbakyan-7e18d8

Conversation

@steipete

@steipete steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

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:

Observation Before After
Visible messages immediately after reset 1 1
Visible messages after subsequent compaction 3 1
Pre-reset messages returned after compaction 2 0
Model context contains pre-reset messages false false
  • Failing-first proof: four message-window cases failed before that owner was repaired. With the message repair present and the event owner unchanged, all four new marker cases failed on leaked summaries or ordering; the two original marker cases passed.
  • Integrated proof: 89 tests passed across nine files (five serialized Vitest shards). Coverage includes cold/warm cache order, appends, repeated resets/compactions, retained pairing, empty post-reset history, adjacent boundaries, full/recent/offset/count/by-ID/anchor reads, bounded hydration, and upstream context-eligibility/display-position behavior.
  • Production APIs: the byte-identical original probe passed after integration with the 1 → 1 result above; the strengthened probe passed all nine warm/cold stages, including marker order, CLI history, context-engine/reseed behavior and actual session-memory files. No mocks, provider calls or operator state were used.
  • Changed-scope checks: the complete changed-scope gate passed, including targeted formatting, core/core-test typechecks, changed-file lint, dead-export scans, boundary/storage/schema guards and runtime import-cycle checks.
  • Fresh isolated autoreview passed before commit and after integration, with no actionable findings at the required P0 scope. This is not a claim of broader-priority review or completed CI.

Focused test command:

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.ts

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 full pnpm build passed. 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, including openclaw/ci-gate and 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.

@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Aug 29, 2026
@steipete
steipete marked this pull request as ready for review August 29, 2026 13:36
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 10:38 AM ET / 14:38 UTC.

ClawSweeper review

What this changes

The PR makes SQLite session-history readers retain the latest reset window after a later compaction while preserving compaction-based model-context behavior.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No 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
Reviewed head: 8f19112e90f7872f042353afbead024e085d88f4

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-level repair with strong regression coverage, clean exact-head CI in the supplied context, and no supported blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a MEMBER-authored PR, so the external-contributor proof gate does not apply. The supplied exact-head evidence nevertheless describes an isolated real Gateway/Control UI flow using real SQLite, reset, compaction, reload, pagination, and lookup behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a MEMBER-authored PR, so the external-contributor proof gate does not apply. The supplied exact-head evidence nevertheless describes an isolated real Gateway/Control UI flow using real SQLite, reset, compaction, reload, pagination, and lookup behavior.
Evidence reviewed 8 items History-owner repair: The introduced history projection selects the last reset and retains only that reset plus later boundaries, rebasing marker positions through the visible message window.
Separate context behavior retained: The reset-window owner uses the latest reset for history but retains reset-or-compaction selection for context accounting, so the repair does not make model context follow history semantics.
Current-main comparison: The fetched main revision still contains the former combined boundary selection, under which a newer compaction could displace the reset for history reads; the PR introduces the necessary scope distinction.
Findings None None.
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

  • Resolve merge risk (P1) - The PR has the protected maintainer label, so normal maintainer handling remains required even though no introduced correctness or security blocker was found.
Agent review details

Security

None.

PR surface

Source -6, Tests +151, Docs +3. Total +148 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 20 26 -6
Tests 3 369 218 +151
Docs 1 5 2 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 394 246 +148

Review metrics

Metric Value Why it matters
Production versus test delta production -6 net; tests +151 net; docs +3 net The owner-level behavior repair reduces production code while adding boundary coverage across cache, marker, and reader paths.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.sqlite-history-events.ts, serialized state: src/config/sessions/session-accessor.sqlite-reset-window.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-reset-window.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #132586
Summary: This PR is the candidate owner-level fix for the reset-then-compaction history leak reported by the linked issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the canonical owner-boundary repair after the normal maintainer review, preserving the documented distinction between reset-bounded history and compaction-bounded model context.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: This fixes a deterministic session-history regression that can make reset-discarded conversation state reappear in user-facing history and downstream memory consumers.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a MEMBER-authored PR, so the external-contributor proof gate does not apply. The supplied exact-head evidence nevertheless describes an isolated real Gateway/Control UI flow using real SQLite, reset, compaction, reload, pagination, and lookup behavior.

Evidence

What I checked:

Likely related people:

  • steipete: Current history shows recent merged work on canonical SQLite session history, transcript display, and Gateway reader behavior in this same ownership area. (role: recent area contributor; confidence: high; commits: 015546cb8bd8, b3add942de18, a6b8eb5b418d; files: src/gateway/session-transcript-readers.ts, src/agents/cli-runner/session-history.ts, src/config/sessions/session-accessor.sqlite-reset-window.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-29T13:46:08.961Z sha 8f19112 :: needs maintainer review before merge. :: none

@steipete

steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready verification

Verified candidate: 8f19112e90f7872f042353afbead024e085d88f4. This completes the isolated Gateway/Control UI evidence requested in the latest ClawSweeper review. Exact-head CI run 33255432806 is green, including openclaw/ci-gate and the SQLite session-lifecycle check. The PR head has not changed since this proof.

Observed behavior

The 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, /compact, /clear (same-session reset), three fresh exchanges, /compact, then reload and history traversal. Manual client compaction used the supported default mode; this is not a live external-provider or safeguard-quality-audit claim.

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.

Provenance

The 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 compatibility

Best-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.

Validation

89 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.ts
node 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.ts
pnpm build

The 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.

After compaction and reload, the reset boundary precedes only fresh conversation

history-window-after.mp4

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 29, 2026
@steipete
steipete merged commit 34a430f into main Aug 29, 2026
320 checks passed
@steipete
steipete deleted the steipete/jovial-elbakyan-7e18d8 branch August 29, 2026 15:02
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Compaction reopens reset-discarded history and misorders boundary markers

1 participant