Repository navigation
feat(sessions): automatically archive older transcripts - #145172
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 September 11, 2026, 7:24 PM ET / 23:24 UTC (Revision 5). ClawSweeper reviewWhat this changesAdds opt-in compressed transcript archival, automatic restoration, portable backups, and Settings controls, with follow-up updater and account-picker repairs. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 4 items remain This remains a distinct, maintainer-owned feature absent from current main. The earlier reader findings appear addressed, and no additional blocking code defect was identified. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw stores conversation history in per-agent SQLite databases. Gateway maintenance moves inactive history into verified archive files, while history readers restore it and supported backups capture its contents. flowchart TD
A[Saved archival policy] --> B[Gateway maintenance]
C[SQLite conversation history] --> B
B --> D{Inactive and unprotected?}
D -->|Yes| E[Verified compressed archives]
E --> F[History restoration]
F --> C
E --> G[Portable backups]
C --> G
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the accepted opt-in storage design, exact restoration, and portable backups with completed final-package upgrade validation. Do we have a high-confidence way to reproduce the issue? Not applicable to the feature request; the recorded isolated Gateway campaign exercises archival and restoration, and this read-only review did not execute tests. Is this the best way to solve the issue? Yes: the patch extends the existing session and maintenance owners, preserves serialized history, and documents the accepted storage tradeoffs; final-package upgrade validation remains unfinished. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2efa249c405b. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
c94e0c2 to
b10e15f
Compare
Add opt-in worker maintenance, live storage settings, and exact restoration from compressed JSONL archives. Advance the agent schema to 20 and embed verified cold payloads in supported backups.
Restore archived history before channel context, latest-text reads, reset and fork operations. Preserve legacy schema migration preflight and steering transcript order; regenerate native protocol bindings and repair the Windows cleanup fault fixture.
Related: #144232
Additional instructions
The branch is in
openclaw/openclaw, so maintainers can edit it directly. GitHub’s fork-collaboration toggle applies only to cross-repository PRs.What Problem This Solves
Older session transcripts keep agent databases large even when their sessions are rarely opened. Operators need automatic extraction, a visible account of the resulting storage, and a safe way to tune the policy without restarting the Gateway.
Why This Change Was Made
Adds opt-in cold storage owned by the existing Gateway maintenance lifecycle. At startup and once a minute, bounded workers move eligible inactive transcript windows into verified, immutable compressed JSONL files. SQLite retains their identity and archive metadata; opening history restores the exact serialized events and associated projections before use. Current and historical windows are eligible, with active work, recovery, pending inputs, and required history references protected.
The agent schema advances from 19 to 20 because older readers cannot safely interpret extracted event rows. The supported Doctor migration creates the new representation without rewriting existing transcripts; state schema remains 17. Supported full, SQLite, and Git backups embed verified compressed payloads in their snapshot databases, so restoration does not depend on the original archive directory.
The maintainer accepted this opt-in storage design and its operating boundaries: agent schema20, authoritative archive files, self-contained supported backups, pre-upgrade-backup rollback for older binaries, and the documented large-batch writer-queue latency. Database-only replicas must carry the archive files. The feature remains disabled by default.
User Impact
Settings → Agent Defaults → Session now shows hot/archived transcript counts, database and WAL sizes, archive file sizes, embedded archive bytes, per-agent details, and background maintenance status. Operators can enable archival, choose a positive day threshold, and start a background batch. Settings use the canonical config apply flow and take effect without a Gateway restart.
Cold storage defaults off and has its own opt-in policy, independent of retention
mode. Each pass is bounded to 128 transcripts and 64 MiB of restoration envelopes. Recently restored history stays hot for 24 hours in the current process. Text search reports excluded cold transcripts; bulk previews report archived history without restoring it. Chat/history access restores on demand, including when automatic extraction is disabled.Archive files are authoritative history. Missing or damaged files produce explicit errors and preserve their metadata; they never become an empty conversation. Restore the matching backup to recover lost bytes. Files remain after rehydration to protect in-progress backups, so smaller working databases do not promise smaller total storage on every pass. Worker commit/reclamation joins the existing database writer queue and can delay other writes; one large copied-database batch held that queue for 11.3 seconds in local testing. Compression runs off the Gateway thread.
The docs cover configuration, eligibility, search/preview behavior, recovery, backups, physical reclamation, and upgrade/downgrade boundaries. Generated config inventory increases by exactly the three accepted cold-storage paths; test graph roots are rebalanced within the existing ceilings.
Evidence
Real copied-database migration, extraction, and restoration: exact event, identity, window, and node preservation; archive hash/envelope verification; SQLite quick and foreign-key checks. No production Gateway or database was modified.
Concurrent-reader regression: the old split marker/payload read returned missing history when a second SQLite connection archived between queries. The test fails before the fix and passes with a single read snapshot. Synchronous writes against cold history reject without mutation.
Focused migration/persistence, reader/writer, eligibility, backup, search/usage, agent/CLI/SDK resume, Gateway lifecycle/RPC/config, and UI tests. Representative completed runs: 174 migration/persistence tests, 387 resume/API tests, 120 Gateway lifecycle tests, 49 final Gateway routing/history tests, 40 user-turn persistence tests, 6 backup tests, 16 usage tests, and 9 Settings component plus 3 browser E2E tests. These are separate suite receipts, not an aggregated unique test count.
Independent review findings were checked against source and behavior; the reader snapshot race and historical-window eligibility were fixed. Bulk preview restoration was deliberately excluded to avoid menu prewarming refilling the database, with a clear macOS archived-history message.
Production and macOS builds passed. Schema/config guards, unused-export checks, UI i18n, CSS lint, and runtime import-cycle checks passed. Documentation validation checked 13,448 links with zero broken links. Full repository TypeScript checks passed. TypeScript lint findings were fixed and the corrected files passed scoped rechecks; no suppressions or budget increases were added.
Supported Doctor CLI: agent schema 19 → 20, both version markers updated, original events/identities/windows/nodes/watermarks unchanged, and integrity/foreign-key checks passed.
Live isolated Gateway: 30-day and 7-day thresholds selected the expected histories; configuration enable/age/disable changes preserved the Gateway process and connection. Run now acknowledged in 32 ms and 1.2 ms before completion; concurrent message writes succeeded. Database size fell from 67.87 MB to 42.78 MB with three cold transcripts. Exact restoration, explicit missing-file failure with metadata retained, and recovery after replacing the file passed. The 115 health probes measured 27.9 ms p95 and 223.7 ms maximum; these are synthetic local observations, not a throughput guarantee.
Automatic startup on the committed code: with the 7-day policy enabled before launch, the Gateway archived three old transcripts and kept two recent transcripts hot. The harness called only storage status and health, never Run now. Both isolated Gateway processes shut down cleanly.
Follow-up validation and repairs
Cold history now restores before channel context, latest-assistant reads, reset, fork/rewind, branch inspection/switching, and parent-session forks. Missing-file failures preserve logical session/history state; existing-child no-ops do not read an unnecessary parent archive. Legacy schema14/17 preflight no longer requires the schema20 table before migration creates it, while current-schema validation remains strict. Steering waits for the initial projection and received notifications before committing its transcript prefix. Native protocol bindings were regenerated.
Linux Blacksmith Testbox runs passed the reader, historical-migration, process-census, config-hint, Swift-protocol and SQLite-guard groups, and all 19 final steering cases. A clean frozen dependency install passed 125 reader/lifecycle/migration/Doctor tests across 11 files. Earlier lifecycle coverage passed 86 distinct cases, including 21 cold success/missing-file/skip cases, with red proof against the original owners. These are separate suite receipts, not an aggregated unique count.
The packaged Linux campaign used the genuine published
[email protected]updater and old source writers. A forced process termination at the schema-20 WAL synchronization boundary rolled back coherently to schema 19 with all eight canonical table hashes unchanged. Immediate recovery correctly refused the still-valid maintenance lease; after observing its natural expiry, supportedupdate repairand two real artifact updates passed with schema 20 and unchanged data. The docs describe this recovery delay.The same installed candidate archived 257 old events through live policy configuration and the scheduled worker. Verified backup refused a missing archive. A schema-neutral package update legitimately preserved the missing reference; history access still failed explicitly. Replacing the archive, verified backup, another real package update, exact restoration of all eight original tables, and one appended message passed. Update receipts include canary, package swap, and Doctor steps, so repeated artifact updates were not already-current no-ops.
The campaign also repaired two validation gaps: synthetic update fixtures now update only the content-inventory entries they change, and native capability checks skip mutable startup. The latter returned exact JSON without touching pristine or unreadable state in six built-CLI probes; registered CLI/preAction tests passed. A CI account-picker failure reproduced a focused More action becoming Manage during refresh; keyed rows fix it, with 13 browser E2E and 58 sibling tests passing. Independent review found no remaining actionable P0–P2 findings in these repairs.
The final package at
a2dab0421d8passed both maintained published-release upgrade lanes: managed restart in 372 seconds and populated SQLite upgrade in 399 seconds, usingauto-authrestart mode. Blacksmith Testbox run. This exercises real Gateway processes through the maintained systemctl fixture; it is not a native systemd-daemon or power-loss certification. Exact-head CI passed. All cold-storage implementation files match the separately verified crash/cold-file candidate.Before and after
Synthetic Control UI fixtures; displayed counts are illustrative, not production data.