Skip to content

fix(sessions): stop max-lines compaction backup leaks - #125183

Merged
steipete merged 2 commits into
mainfrom
steipete/compact-archive-bug-file-removal-78833b
Aug 17, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/compact-archive-bug-file-removal-78833b

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #111122

What Problem This Solves

Fixes an issue where users running openclaw sessions compact <key> --max-lines N would create a new .bak transcript sidecar on every compaction. Session maintenance counted those files against the disk budget but could not reclaim them, so repeated manual compaction could evict other sessions' retained history while still leaving the store over budget.

Why This Change Was Made

Manual max-lines compaction now trims the canonical SQLite transcript directly without creating or returning a backup sidecar. Existing legacy compact backups are eligible for the normal high-water archive sweep, so they are removed before searchable SQLite history under disk pressure. Historical .bak filename recognition remains intact so those artifacts are never mistaken for active transcripts. The CLI docs now state explicitly that max-lines truncation is permanent and does not create a backup archive.

Owner decision: permanent max-lines truncation is intentional. The archive behavior from #111122 reached beta tags but no stable release, and keeping an OpenClaw-owned JSONL recovery sidecar would preserve the file-era runtime state that the database-first contract removes. The ClawSweeper request to restore archive creation is therefore deliberately skipped; its narrower cleanup finding is addressed by reclaiming existing legacy .bak files before any session history.

User Impact

Repeated manual compaction no longer accumulates disk-budget-charged backup files. Operators still get the retained-line count, but no Archived transcript: path is reported because no archive is created. Existing legacy compact backups remain recognizable and are reclaimed by the disk-budget sweep before searchable session history.

Evidence

  • Pre-fix regression: the updated Gateway test failed because sessions.compact returned an archived path and wrote a .jsonl.bak.* file.
  • Focused tests: node scripts/run-vitest.mjs src/config/sessions/session-history-eviction.test.ts src/config/sessions/artifacts.test.ts src/config/sessions/disk-budget.test.ts src/config/sessions/session-accessor.test.ts src/gateway/server.sessions.compaction.test.ts src/commands/sessions-compact.test.ts (186 tests passed).
  • Legacy cleanup regression: on the pre-fix PR head, an oversized .bak archive caused one searchable history entry to be evicted; after the fix, the backup file is removed, zero session entries are removed, and searchable history remains.
  • Build: pnpm build.
  • Full changed gate: node scripts/check-changed.mjs -- <12 touched paths> passed, including formatting, production/test typechecks, lint, env/max-lines/assertion ratchets, database-first, dependency, dead-export, and import-cycle guards.
  • Docs: pnpm docs:check-mdx, pnpm docs:check-links, and pnpm docs:check-i18n-glossary.
  • Live built CLI/Gateway: seeded an isolated session with seven transcript rows, ran openclaw sessions compact agent:main:main --max-lines 3, observed Compacted session agent:main:main (kept 3 lines)., verified the Gateway returned only the retained header plus the last two messages, found no .jsonl.bak.* artifact under the isolated state directory, and confirmed a second run reported No compaction needed for session agent:main:main.
  • Autoreview: clean, no accepted/actionable findings.

AI-assisted; maintainer-reviewed and live-verified.

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 17, 2026 08:58
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: S maintainer Maintainer-authored PR labels Aug 17, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 5:36 AM ET / 09:36 UTC.

ClawSweeper review

What this changes

The PR makes max-lines session compaction permanently trim SQLite transcript rows, removes the obsolete archive response, and reclaims legacy compact backups before searchable history.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking correctness findings on the updated head. It resolves the prior archive-reclamation concern; wait for exact-head CI before merging.

Priority: P1
Reviewed head: f73c54eafed79cad7794fc4194efe9b8d458549f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The updated head is a focused owner-boundary repair with the prior blocker addressed.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR includes useful live CLI/Gateway evidence, but the external-contributor proof gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR includes useful live CLI/Gateway evidence, but the external-contributor proof gate does not apply.
Evidence reviewed 5 items Current leak source: Current main writes a .bak sidecar before replacing manual-compaction rows.
Owner-boundary repair: The PR removes sidecar creation from the SQLite trim owner and retains only the kept-line result.
Prior finding addressed: Legacy .bak artifacts now enter the retained-archive classifier used before session-history eviction.
Findings None None.
Security None None.

How this fits together

The CLI sends manual compaction to the Gateway, which updates the agent’s SQLite transcript. Disk-budget maintenance removes recognized legacy artifacts before evicting searchable session history.

flowchart LR
  A[CLI max-lines request] --> B[Gateway compaction]
  B --> C[SQLite transcript trim]
  C --> D[Retained transcript]
  E[Legacy bak artifacts] --> F[Archive-first disk sweep]
  F --> G[Searchable session history]
Loading

Before merge

  • Resolve merge risk (P1) - Existing beta users may observe that archived disappears from the RPC and CLI output and that future max-lines truncation is irreversible; exact-head CI remains in progress.
Agent review details

Security

None.

PR surface

Source -12, Tests -92, Docs -1. Total -105 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 7 11 23 -12
Tests 4 16 108 -92
Docs 1 2 3 -1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 29 134 -105

Review metrics

Metric Value Why it matters
Production versus test delta production +11/-23 (net -12), tests +14/-108 (net -94), docs +2/-3 The fix deletes the sidecar-producing flow and its obsolete assertions rather than adding persistence paths.

Stored data model

Persistent data-model change detected: serialized state: src/commands/sessions-compact.test.ts, serialized state: src/commands/sessions-compact.ts, serialized state: src/config/sessions/session-accessor.sqlite-transcript-write.ts, serialized state: src/config/sessions/session-accessor.test.ts, serialized state: src/config/sessions/session-accessor.transcript.ts, serialized state: src/config/sessions/session-accessor.types.ts, and 4 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Merge after exact-head checks (recommended)
    Retain the documented permanent-truncation contract once the current head’s required checks complete green.
  2. Preserve archives intentionally
    If recoverable manual truncation is required, retain the archive contract and explicitly accept its separate artifact lifecycle.

Technical review

Best possible solution:

Merge the canonical SQLite-only flow once exact-head checks are green: no new sidecars, explicit permanent-truncation docs, and archive-first cleanup of existing legacy backups.

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

Yes: current main writes .bak before replacing SQLite rows, and the PR body supplies an after-fix Gateway/CLI run for the no-sidecar path.

Is this the best way to solve the issue?

Yes: removing file-era backup creation at the SQLite owner and sweeping existing backups before history eviction is cleaner than retaining parallel persistence.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against fbd910d417ec.

Labels

Label justifications:

  • P1: Manual compaction could consume disk budget and evict searchable session history.
  • merge-risk: 🚨 compatibility: The existing archive result field and CLI archive-path output are removed.
  • merge-risk: 🚨 session-state: The command rewrites transcript rows and changes legacy artifact reclamation order.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR includes useful live CLI/Gateway evidence, but the external-contributor proof gate does not apply.

Evidence

What I checked:

Likely related people:

  • steipete: Current session-area history and the updated repair both touch the storage and cleanup boundary. (role: recent area contributor; confidence: high; commits: f73c54eafed7, 53cede420f; files: src/config/sessions/artifacts.ts, src/config/sessions/session-accessor.sqlite-transcript-write.ts)
  • yetval: The earlier merged compaction repair introduced the archive behavior this PR revises. (role: introduced archived-compaction behavior; confidence: high; commits: db1611747f70; files: src/config/sessions/session-accessor.sqlite-transcript-write.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for required checks on the exact current head to finish green.

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-17T09:05:29.095Z sha cb3986a :: found issues before merge. :: [P1] Preserve recoverable transcript history

@clawsweeper clawsweeper Bot added 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for head f73c54eafed79cad7794fc4194efe9b8d458549f:

  • node scripts/run-vitest.mjs src/config/sessions/session-history-eviction.test.ts src/config/sessions/artifacts.test.ts src/config/sessions/disk-budget.test.ts src/config/sessions/session-accessor.test.ts src/gateway/server.sessions.compaction.test.ts src/commands/sessions-compact.test.ts — 186 passed.
  • pnpm build — passed.
  • node scripts/check-changed.mjs -- docs/cli/sessions.md src/commands/sessions-compact.test.ts src/commands/sessions-compact.ts src/config/sessions/artifacts.ts src/config/sessions/disk-budget.ts src/config/sessions/session-accessor.sqlite-transcript-write.ts src/config/sessions/session-accessor.test.ts src/config/sessions/session-accessor.transcript.ts src/config/sessions/session-accessor.types.ts src/config/sessions/session-history-eviction.test.ts src/gateway/server-methods/sessions-compact.ts src/gateway/server.sessions.compaction.test.ts — passed all changed-path gates.
  • pnpm docs:check-mdx, pnpm docs:check-links, and pnpm docs:check-i18n-glossary — passed.
  • Exact-head CI run 32015651874 completed successfully, including openclaw/ci-gate job 95346187732.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 125183 passed in hosted_exact_or_recent_parent mode for the exact head; no product-code or head change was required.

Live built CLI/Gateway proof seeded seven transcript rows, compacted with --max-lines 3, observed the visible kept-line result, read back only the retained header plus the last two messages, found no .jsonl.bak.* artifact, and observed a visible no-op on the second run. Known gaps: none.

Owner decision: max-lines truncation remains permanently destructive. The archive behavior reached beta but no stable release, and database-first ownership removes the OpenClaw-owned JSONL sidecar. Do not restore backup creation. The accepted ClawSweeper technical finding is fixed on this head: legacy .bak files are pruned before searchable SQLite history (removedFiles=1, removedEntries=0, historical session retained).

@steipete
steipete merged commit 4ffcd97 into main Aug 17, 2026
221 of 223 checks passed
@steipete
steipete deleted the steipete/compact-archive-bug-file-removal-78833b branch August 17, 2026 09:45
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
* fix(sessions): stop max-lines compaction backup leaks

* fix(sessions): reclaim legacy compact backups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant