Repository navigation
refactor(sessions): run archive retention pruning in workers - #163218
Conversation
Move periodic published-archive candidate selection and conditional deletion through the existing archive reader and agent worker registry. Recheck references and file absence inside the admitted transaction while preserving retention policy and native Incognito ownership.
Declare retained archive-reader results as batches and keep the request-kind alias private to the worker type catalog. This type-only correction emits identical JavaScript.
Rename nested retention callback parameters without changing the worker payload. Focused retention tests, core typechecking, and targeted lint pass.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 11:46 PM ET / October 2, 2026, 03:46 UTC (Revision 2). ClawSweeper reviewWhat this changesMoves expired session-archive selection and deletion into existing database workers while preserving retention rules and checking deletion eligibility again. Merge readiness✅ Ready for maintainer review This PR remains useful because fetched main and the latest release still perform retention SQL on the calling thread. No actionable introduced defect was found, and the prior review contains no outstanding findings. Priority: P2 Review scores
Verification
How this fits togetherSession archives preserve deleted or reset conversation history in each agent’s SQLite database. Periodic maintenance applies retention rules after derived archive files disappear, then removes eligible canonical archive rows. flowchart TD
A[Periodic maintenance] --> B[Archive retention facade]
B --> C[Read worker selects bounded candidates]
C --> D[Age and file checks]
D --> E[Existing writer admission]
E --> F[Worker rechecks references and row identity]
F --> G[Delete eligible rows and report count]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +64, Tests +213. Total +277 across 8 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep retention policy in the existing facade and let the established database workers own candidate reads and conditional deletion. Do we have a high-confidence way to reproduce the issue? Not applicable to this internal refactor; current-main source directly establishes the calling-thread SQL being migrated, and the captured validation reports a failing original-facade negative control. Is this the best way to solve the issue? Yes. Reusing existing archive readers, writer admission, and worker registration provides one owner for database execution while preserving the async facade and retention policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2dc1071d2081. 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)
|
|
Merged via squash.
|
…w#163218) * refactor(sessions): prune retained archives through workers Move periodic published-archive candidate selection and conditional deletion through the existing archive reader and agent worker registry. Recheck references and file absence inside the admitted transaction while preserving retention policy and native Incognito ownership. * fix(sessions): align archive batch reader contract Declare retained archive-reader results as batches and keep the request-kind alias private to the worker type catalog. This type-only correction emits identical JavaScript. * style(sessions): avoid retention input shadowing Rename nested retention callback parameters without changing the worker payload. Focused retention tests, core typechecking, and targeted lint pass.
What Problem This Solves
Periodic published-archive retention still selected and deleted canonical archive rows on the Gateway thread, despite the existing archive reader and agent write worker.
Why This Change Was Made
Reuse the archive-pruning adapter for bounded candidate reads and register
session.archivePruning.pruneRetentionin the existing typed agent operation registry. Its synchronous worker transaction rechecks current session references, file absence, and the prepared row identity before deleting. Stale candidates are skipped; only actual deletions count.Cron and cleanup already await this facade. The age/reason rules, 256-row selection cap, stable ordering, path containment, and retention policy remain unchanged. The obsolete host SQL body is removed.
User Impact
Archive retention selection and deletion leave the Gateway thread. Physical database ownership, writer ordering, live authority, and settlement stay with the existing adapter. No operator action is required.
session-accessor.sqlite-archive-store.tssession-history-archive-pruning.worker.tssrc/cron/session-reaper.tsMeasured with
node scripts/database-worker-inventory.mjs --jsonat pinned base786a6b56e8c8b7f2b9b0bf154db179c3e833efd2and the final head. No inventory reclassification. Production delta: +169 / -105 / net +64; tests add 213 lines. Main was merged atb2b61883450864f3a168373a9b2336e7e05aa26ewithout conflicts.Evidence
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test src/config/sessions/session-history-archive-retention.test.ts --maxWorkers=1: 10 passed after the final callback cleanup; 111.02 s wall, 4.30 s summed test cases on the loaded local host. Testbox's equivalent run took 17.20 s wall, 1.03 s summed test cases. Covers calling-thread SQL, bounded ordering, retention rules, stale rows, new references, reappearing files, authority revocation, and rejection without replay.OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 node scripts/run-vitest.mjs src/config/sessions/cleanup-service.fix-missing.test.ts src/config/sessions/session-history-archive-pruning.admission.test.ts src/config/sessions/session-accessor.sqlite-page-reclamation.binding.test.ts --maxWorkers=1: 31 passed, 46.67 s wall on Testbox (392.62 s locally).pnpm test src/config/sessions/session-history-archive-retention.test.ts --maxWorkers=1 -t 'prunes through the worker'fail at the calling-thread SQL assertion. Restoring the candidate passed. Blacksmith Testboxtbx_01m3x37xm33yqzt88x7txcd2vdverified the physical checkout and changed-file hashes; Testbox workflow.pnpm check:database-worker-ratchet --base 786a6b56e8c8b7f2b9b0bf154db179c3e833efd2: passed.node scripts/check-changed.mjs --base origin/main: passed the first 14 checks, then stopped at the unchanged plugin compatibility deadline check described below. The remaining commands were executed through its nativecreateChangedCheckPlanandcreateChangedCoreTestCheckhelpers: core production types, all 27 affected test type graphs, unused-export scans, and remaining guards passed. Initial single-row reader typing and input-shadowing findings were fixed and rechecked.node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfopassed.pnpm check:import-cyclesandpnpm check:madge-import-cycles: 0 cycles.pnpm build: exit 0; runtime load checks verified 53 built modules. It reported a UI startup-JS budget warning: 364.1 KiB gzip versus 363.6 KiB. This PR changes no UI files.Final targeted lint passed with:
Inherited check failure:
plugin-boundary-reportreports 11 compatibility records due for removal.git diff b2b61883450864f3a168373a9b2336e7e05aa26e HEAD -- scripts/plugin-boundary-report.ts src/plugins/compatis empty. The owner'slistPluginCompatRecords()andisPluginCompatEligibleForRemoval()return the same 11 overdue records at the recorded failure time. The full changed gate is therefore not claimed green; its unrelated deadline failure remains visible.The initial setup build was invalidated by source edits during preparation; the final full build above completed on stable source. A follow-up Testbox lease expired and another remained queued without executing, so the remaining checks ran locally. Task-owned Testboxes are stopped/finished.
Compatibility retained
No public SDK contract changes. The already-async retention facade keeps its name; its host SQL implementation is gone. Removed the unused internal
SessionArchivePruningWorkerInputtype export; the request-kind alias remains local to the catalog.readSessionArchivePruningInDatabaseandpruneSessionArchivesByRetentionInDatabaseare synchronous kernels executed by workers. Their native adapter remains only for process-held Incognito databases and explicit Doctor/cleanup maintenance scopes, which cannot use the ordinary durable worker path. Existing single-archive deletion, legacy-file removal, and page-reclamation contracts are unchanged.Update behavior
No schema, stored format, durability, configuration, permission, or retention-policy change. No migration or updater/Doctor behavior change.
Overlapping open PRs
#140793 independently splits deleted/reset retention policy and adds caller-currentness checks to
prunePublishedSessionArchivesByRetention. This PR remains policy-neutral and preserves the existing adapter's authority checks. Its reaper changes do not overlap this PR's files.