Skip to content

fix(sessions): let idle compacted sessions enter cold storage - #157994

Merged
obviyus merged 1 commit into
openclaw:mainfrom
anyech:fix/cold-storage-checkpoint-self-reference
Sep 29, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
anyech:fix/cold-storage-checkpoint-self-reference

Conversation

@anyech

@anyech anyech commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #157993

What Problem This Solves

Fixes: idle sessions compacted before checkpoint retirement can remain in active SQLite indefinitely because their legacy checkpoint metadata references their own current ID.

User Impact

User impact: coldStorage.afterDays can archive those idle current windows as configured, while active windows and genuine cross-generation history remain protected. No migration or user action is required; cold storage remains lossless.

Why This Change Was Made

Ignore a legacy checkpoint ID only when it equals that node's current_session_id, matching the existing usageFamilySessionIds rule. Keep every distinct checkpoint ID protected. The change does not alter legacy history retention or destructive cleanup behavior.

Evidence

A focused regression covers idle self-references, distinct older-generation references, and recent activity. The contributor's seven targeted cold-storage suites passed 77 tests. A fresh run of the eligibility suite on the unchanged PR head passed 19/19 in 13.47 seconds wall time (added case: 1 ms).

The contributor's read-only v2026.9.6 shadow comparison reduced protected IDs from 880 to 737, making 143 idle sessions totaling about 532 MiB eligible without newly protecting other IDs. That measurement describes one installation, not a general performance claim.

A real Gateway archive comparison now also passes:

  • Published [email protected], using an explicit isolated profile, created two sessions and transcript events through sessions.create and chat.inject. Offline fixture preparation added legacy checkpoint self-references plus a distinct referenced session ID and aged both windows ten days, beyond coldStorage.afterDays: 1.
  • The PR was integrated locally with main 6f4c801c18f911625c971fa6cb7c3bd4de1d5e87, without pushing the merge. Both Gateway builds used that same tree; the negative control restored only this PR's two files from that main revision.
  • Current main's existing Doctor upgrade converted the published agent database from schema 23 to 24 before cloning identical inputs for the comparison. This is not a schema change introduced by this PR. Both maintenance runs preserved PRAGMA user_version = 24.
  • Built CLI/Gateway processes used explicit separate profiles and ports, with resolved config and database paths checked before startup. sessions.storage.status confirmed completed maintenance without errors.
  • Negative control: 2 hot, 0 cold, with both transcripts' two events retained in SQLite. Candidate: 1 hot, 1 cold, with the self-referencing idle transcript's two events moved into a 788-byte .jsonl.zst archive; the genuinely referenced transcript retained both events in SQLite.

Both Gateways were stopped. This proves synthetic published-state upgrade and actual archive writes, not an archive write against the contributor's production store.

Test Cost

The added regression checks the production SQLite eligibility selector at the self-reference/history boundary, which a narrower mock would not verify. On a cold local run, pnpm test src/config/sessions/session-cold-storage-eligibility.test.ts --maxWorkers=1 passed 19/19 tests in 46.63 s wall time (Vitest duration 22.02 s); the added case took 3 ms. The cold-run wall time includes harness startup and transformation, not just the added case.

On CI run 36107190601 for head 0b63d8e8182484bb811877a606a0f780a1af90a8, the added case passed in 1 ms. Its containing shard reported 532.98 s for 149 files; that shared shard duration is not the incremental cost of this regression. The CI workflow completed successfully.

Attribution and maintainer intent

Thanks to @anyech for reporting this bug and contributing the fix. No overlap with Pash/Sarah changes.

…ge protection

Legacy compaction checkpoint metadata records the session's own current id
(the built-in compactor keeps session identity). Cold-storage eligibility added
every checkpoint id to the protected set, so any session that was ever
compacted before checkpoints were retired (openclaw#154131) kept its idle current
window in SQLite forever, regardless of afterDays.

Skip checkpoint references equal to the node's current session id, matching
the existing usageFamilySessionIds handling and the function's documented rule
that only activity and explicit cross-generation references protect bytes.
Cross-generation checkpoint references remain protected; cleanup/disk-budget
retention of legacy history is unchanged. Cold storage is lossless, and the
current window is still protected by running status and recent activity.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 12:48 AM ET / 04:48 UTC (Revision 3).

ClawSweeper review

What this changes

The branch lets idle current-session transcripts enter cold storage when legacy compaction checkpoints refer to that same session, while retaining protection for older referenced generations.

Merge readiness

✅ Ready for maintainer review

Current main still has the reported cold-storage eligibility defect. This focused PR addresses it at the existing selector, and the linked issue remains open pending a fix. No actionable patch defect or additional before-merge action was identified.

Priority: P2
Reviewed head: 0b63d8e8182484bb811877a606a0f780a1af90a8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair has relevant real-store eligibility evidence, a meaningful regression, and reported targeted and CI results.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The changed SQLite eligibility selector was compared before and after the patch on a real v2026.9.6 shadow store; the reported result made 143 idle current windows eligible without newly protecting IDs. An archive write was not exercised, but the claim being repaired is eligibility. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed SQLite eligibility selector was compared before and after the patch on a real v2026.9.6 shadow store; the reported result made 143 idle current windows eligible without newly protecting IDs. An archive write was not exercised, but the claim being repaired is eligibility. No stored-data contract changes.
Evidence reviewed 8 items Introduced patch: The pinned branch filters checkpoint IDs equal to the node’s current session ID and adds a SQLite-backed regression covering self-references, an older generation, and recent activity.
Current-main defect: Fetched main still adds all three legacy checkpoint IDs to the protected set, including IDs equal to the current session ID.
Archive boundary: Candidate selection excludes protected IDs, and the write transaction rechecks protection, snapshot identity, and transcript activity before archiving.
Findings None None.
Security None None.

How this fits together

OpenClaw’s cold-storage worker reads session activity and history references from SQLite to select transcript payloads for archival. It checks eligibility again before replacing transcript rows with a recoverable archive.

flowchart LR
  A[Session activity] --> C[Cold-storage eligibility]
  B[Legacy checkpoint references] --> C
  C --> D{Current or older generation?}
  D --> E[Protect active and older windows]
  D --> F[Archive eligible idle window]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +22. Total +23 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 8 +1
Tests 1 22 0 +22
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 31 8 +23

Review metrics

Metric Value Why it matters
Regression test cost 46.63 s cold file wall; 3 ms added case; 1 ms CI case The PR body supplies the single-worker and CI measurements for the added owner-boundary regression.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #157993
Summary: The linked open issue describes the same checkpoint self-reference defect; this PR is its candidate fix.

Members:

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

Technical review

Best possible solution:

Keep cold-storage eligibility in its existing selector: let inactivity govern a current window’s checkpoint self-references, preserve distinct historical references, and retain the separate lossless archive and cleanup contracts.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main unconditionally protects a checkpoint ID even when it equals an idle node’s current ID. This read-only review did not execute target code.

Is this the best way to solve the issue?

Yes. The patch changes the existing eligibility selector at the faulty comparison while keeping distinct historical references protected.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 68834d21c435.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs a bounded opt-in cold-storage defect that can leave idle transcript payloads in SQLite indefinitely.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed SQLite eligibility selector was compared before and after the patch on a real v2026.9.6 shadow store; the reported result made 143 idle current windows eligible without newly protecting IDs. An archive write was not exercised, but the claim being repaired is eligibility. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed SQLite eligibility selector was compared before and after the patch on a real v2026.9.6 shadow store; the reported result made 143 idle current windows eligible without newly protecting IDs. An archive write was not exercised, but the claim being repaired is eligibility. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-09-25T07:27:10.837Z sha 0b63d8e :: needs changes before merge. :: none
  • reviewed 2026-09-25T08:41:26.232Z sha 0b63d8e :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 25, 2026
@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit b578706 into openclaw:main Sep 29, 2026
224 checks passed
@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Landed in b578706. Thanks @anyech for reporting this and contributing the focused fix! Idle sessions with legacy checkpoint self-references can now move to cold storage without weakening protection for distinct referenced generations. The built Gateway comparison on published-release-created fixtures showed the negative control retaining both transcripts hot and the candidate archiving only the idle self-referencing transcript; maintenance preserved the database schema version.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…aw#157994)

Closes openclaw#157993

## What Problem This Solves

Fixes: idle sessions compacted before checkpoint retirement can remain in active SQLite indefinitely because their legacy checkpoint metadata references their own current ID.

## User Impact

User impact: `coldStorage.afterDays` can archive those idle current windows as configured, while active windows and genuine cross-generation history remain protected. No migration or user action is required; cold storage remains lossless.

## Why This Change Was Made

Ignore a legacy checkpoint ID only when it equals that node's `current_session_id`, matching the existing `usageFamilySessionIds` rule. Keep every distinct checkpoint ID protected. The change does not alter legacy history retention or destructive cleanup behavior.

## Evidence

A focused regression covers idle self-references, distinct older-generation references, and recent activity. The contributor's seven targeted cold-storage suites passed 77 tests. A fresh run of the eligibility suite on the unchanged PR head passed 19/19 in 13.47 seconds wall time (added case: 1 ms).

The contributor's read-only v2026.9.6 shadow comparison reduced protected IDs from 880 to 737, making 143 idle sessions totaling about 532 MiB eligible without newly protecting other IDs. That measurement describes one installation, not a general performance claim.

A real Gateway archive comparison now also passes:

- Published `[email protected]`, using an explicit isolated profile, created two sessions and transcript events through `sessions.create` and `chat.inject`. Offline fixture preparation added legacy checkpoint self-references plus a distinct referenced session ID and aged both windows ten days, beyond `coldStorage.afterDays: 1`.
- The PR was integrated locally with main `48563f20cf22b25987fb727e52e6365c30a7d300`, without pushing the merge. Both Gateway builds used that same tree; the negative control restored only this PR's two files from that main revision.
- Current main's existing Doctor upgrade converted the published agent database from schema 23 to 24 before cloning identical inputs for the comparison. This is not a schema change introduced by this PR. Both maintenance runs preserved `PRAGMA user_version = 24`.
- Built CLI/Gateway processes used explicit separate profiles and ports, with resolved config and database paths checked before startup. `sessions.storage.status` confirmed completed maintenance without errors.
- Negative control: **2 hot, 0 cold**, with both transcripts' two events retained in SQLite. Candidate: **1 hot, 1 cold**, with the self-referencing idle transcript's two events moved into a 788-byte `.jsonl.zst` archive; the genuinely referenced transcript retained both events in SQLite.

Both Gateways were stopped. This proves synthetic published-state upgrade and actual archive writes, not an archive write against the contributor's production store.

## Test Cost

The added regression checks the production SQLite eligibility selector at the self-reference/history boundary, which a narrower mock would not verify. On a cold local run, `pnpm test src/config/sessions/session-cold-storage-eligibility.test.ts --maxWorkers=1` passed 19/19 tests in 46.63 s wall time (Vitest duration 22.02 s); the added case took 3 ms. The cold-run wall time includes harness startup and transformation, not just the added case.

On CI run [36107190601](https://github.com/openclaw/openclaw/actions/runs/36107190601) for head `0b63d8e8182484bb811877a606a0f780a1af90a8`, the added case passed in 1 ms. Its containing shard reported 532.98 s for 149 files; that shared shard duration is not the incremental cost of this regression. The CI workflow completed successfully.


## Attribution and maintainer intent

Thanks to @anyech for reporting this bug and contributing the fix. No overlap with Pash/Sarah changes.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

Cold storage never archives idle sessions with legacy compaction checkpoint self-references

2 participants