Skip to content

refactor(sessions): run archive retention pruning in workers - #163218

Merged
steipete merged 4 commits into
mainfrom
dbasync/s23
Oct 2, 2026
Merged

steipete merged 4 commits into
mainfrom
dbasync/s23

Conversation

@steipete

@steipete steipete commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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.pruneRetention in 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.

Inventory owner Before After
session-accessor.sqlite-archive-store.ts 3 T1 calls 0 T1 calls
session-history-archive-pruning.worker.ts 6 W calls 8 W calls
src/cron/session-reaper.ts 0 T1 calls 0 T1 calls

Measured with node scripts/database-worker-inventory.mjs --json at pinned base 786a6b56e8c8b7f2b9b0bf154db179c3e833efd2 and the final head. No inventory reclassification. Production delta: +169 / -105 / net +64; tests add 213 lines. Main was merged at b2b61883450864f3a168373a9b2336e7e05aa26e without 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).
  • Original-facade negative control: restoring the pinned base's archive-store file made 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 Testbox tbx_01m3x37xm33yqzt88x7txcd2vd verified 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 native createChangedCheckPlan and createChangedCoreTestCheck helpers: 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.
  • Final core typecheck: node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo passed.
  • pnpm check:import-cycles and pnpm 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.
  • Fresh independent Codex autoreview: scoped-clean, no actionable P0–P2 findings. Per-PR CI timing is not yet available.

Final targeted lint passed with:

node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json \
  src/config/sessions/session-accessor.sqlite-archive-store.ts \
  src/config/sessions/session-accessor.sqlite-page-reclamation.ts \
  src/config/sessions/session-history-archive-pruning.types.ts \
  src/config/sessions/session-history-archive-pruning.worker.ts \
  src/config/sessions/session-history-archive-retention.test.ts \
  src/config/sessions/session-transcript-worker.types.ts \
  src/state/openclaw-agent-execution-operations.ts \
  src/state/openclaw-agent-execution.worker.ts

Inherited check failure: plugin-boundary-report reports 11 compatibility records due for removal. git diff b2b61883450864f3a168373a9b2336e7e05aa26e HEAD -- scripts/plugin-boundary-report.ts src/plugins/compat is empty. The owner's listPluginCompatRecords() and isPluginCompatEligibleForRemoval() 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 SessionArchivePruningWorkerInput type export; the request-kind alias remains local to the catalog.

readSessionArchivePruningInDatabase and pruneSessionArchivesByRetentionInDatabase are 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 2, 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.

@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 11:46 PM ET / October 2, 2026, 03:46 UTC (Revision 2).

ClawSweeper review

What this changes

Moves 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
Reviewed head: 9ae036939dcead3806a7e0dfdbf3a9df9b9a16be

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused worker migration with meaningful regression coverage and no actionable correctness or security findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified repository administrator qualifies for the maintainer-authored exemption. Inspected regressions exercise the changed retention facade through real database workers, including delayed deletion and revocation; their reported results remain supplemental. No stored schema or serialized-format contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository administrator qualifies for the maintainer-authored exemption. Inspected regressions exercise the changed retention facade through real database workers, including delayed deletion and revocation; their reported results remain supplemental. No stored schema or serialized-format contract changes.
Evidence reviewed 10 items Pinned introduction: Reviewed the merge-base-to-head changes using the host-pinned introduction identities; base-only changes were excluded from patch ownership.
Still necessary on main: Fetched main retains calling-thread candidate selection and synchronous archive-row deletion inside the retention facade.
Latest-release check: The supplied latest-release commit also retains synchronous retention selection and deletion; it does not contain this worker cutover. GitHub contents inspection succeeded after local release-blob retrieval failed with HTTP 403.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source +64, Tests +213. Total +277 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 7 169 105 +64
Tests 1 213 0 +213
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 382 105 +277

Review metrics

Metric Value Why it matters
Production versus test growth production net +64 lines; tests +213 lines Production growth implements the bounded worker operation and adapter cutover; tests cover threading and delayed-deletion safeguards.

Technical review

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

Labels

Label changes:

  • add P2: A bounded internal improvement removes synchronous retention database work from the Gateway thread without adding user configuration.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The verified repository administrator qualifies for the maintainer-authored exemption. Inspected regressions exercise the changed retention facade through real database workers, including delayed deletion and revocation; their reported results remain supplemental. No stored schema or serialized-format contract changes.

Label justifications:

  • P2: A bounded internal improvement removes synchronous retention database work from the Gateway thread without adding user configuration.
  • 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: The verified repository administrator qualifies for the maintainer-authored exemption. Inspected regressions exercise the changed retention facade through real database workers, including delayed deletion and revocation; their reported results remain supplemental. No stored schema or serialized-format contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (1 earlier review cycle)
  • reviewed 2026-10-02T03:40:42.655Z sha 9ae0369 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 2, 2026
@steipete
steipete merged commit 2350af4 into main Oct 2, 2026
139 of 140 checks passed
@steipete
steipete deleted the dbasync/s23 branch October 2, 2026 03:51
@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…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.
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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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