Skip to content

fix(sessions): apply archive retention without cron - #182053

Merged
steipete merged 14 commits into
openclaw:mainfrom
Yuaneen:fix/session-archive-retention-cron-181976
Oct 24, 2026
Merged

steipete merged 14 commits into
openclaw:mainfrom
Yuaneen:fix/session-archive-retention-cron-181976

Conversation

@Yuaneen

@Yuaneen Yuaneen commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #181976

What Problem This Solves

Configured reset/deletion archive expiry is silently skipped when cron is disabled or has no sessions to remove.

User Impact

The existing Gateway transcript-maintenance pass expires eligible archive files and canonical rows at startup and once a minute, independently of cron and cold storage. Age-based deletion honors warn mode, disabled retention, live references, and pending publication; disk-budget retention remains independent. Legacy file-only archives remain supported; no configuration or data migration is required.

Why This Change Was Made

Archive expiry belonged to a side effect of cron-run deletion, while the periodic transcript owner only admitted cold-storage work. The maintainer rewrite puts expiry in that existing owner and removes the internal cron cleanup option and forwarding path. The canonical archive worker checks references and the complete prepared row identity before unlinking; the existing writer admission checks current runtime policy immediately before the synchronous deletion batch. Legacy files use the same owner's guarded removal operation.

This addresses ClawSweeper's warn-mode and protected-file findings and removes the accessor-barrel import that caused the original PR's import-cycle/build failures. Pagination and bounded writer batches remain intact. If unlink or commit fails, the canonical recovery blob remains; a later pass can reconcile a missing derived file without introducing another transaction protocol.

The follow-up CI/ClawSweeper findings are also repaired: the generated boundary inventory now records the same two cleanup references under their new owner, and the cleanup-service regression verifies file/row expiry in one pass plus a harmless repeat. No guard allowance was increased.

Thanks @Yuaneen for the original fix and regression intent. Both contributor commits remain in the PR history.

Evidence

  • Main-source confirmation (unchanged through merged main 18105dbed6b762c9a64573836fd52989992bb248): cold-storage-only return, scheduler gate, and cron-only expiry invocation.
  • The production maintenance regression disables cron, cold storage, and disk-budget eviction. It checks enforced reset/deletion/legacy expiry while retaining fresh, referenced, and pending archives, plus warn/disabled controls. On the base, the cold-storage gate leaves expired archives and the removal assertions fail; local base/fix execution was not performed under the contributor source-trust policy. Existing coverage retains bounded pagination, row identity, policy revocation, and rollback/retry contracts.
  • Final head: 50946220ad81561620f677ca3bb16de5c479b87e. Exact-head CI completed with 86 passed, 3 failed, and 27 skipped jobs. All three PostgreSQL conformance jobs passed. The two leaf failures below also leave the aggregate CI gate red. The two initial PR-caused validation failures are repaired and green: source contracts and cleanup-service consumer shard.
  • Static checks passed: oxlint for 19 changed TypeScript files, oxfmt for 20 non-generated files, and main-relative whitespace checks. The generated inventory was regenerated and checked using trusted-main static tooling, with no increase in its total allowance.
  • Simplification pass completed. Fresh independent Codex autoreview is scoped-clean through P2; the final main merge preserves the reviewed patch byte for byte. ClawSweeper's final-head review reports no actionable code findings and confirms all four prior findings resolved.
  • Main-relative numstat: production +108/-97 (net +11), tests +170/-94, docs +5/-0, generated inventory +1/-1. The remaining production growth preserves guarded file removal, current policy checks, and legacy-file expiry after deleting cron cleanup ownership.
  • Contributor-branch live Gateway/channel and latest-stable upgrade E2E were skipped per explicit maintainer policy. Contributor code was not executed locally. The trusted-main diagnostic below was explicitly authorized for CI attribution and uses the existing synthetic model fixture. ClawSweeper's remaining live/upgrade requests are proof-only and excluded by that policy; PR CI is the broad execution gate.

Current-head CI failures:

Failure Evidence and attribution
Completion-tools denial text PR job 120834069743 exactly matches latest completed scheduled-main job 120827461306, including both owner cases at prepare.completion-tools.test.ts:933. Verified inherited.
Restored-wake concurrency Inherited, main reproduces. PR job 120834069552 expects two requests and observes three at gateway-restored-requester-settle.e2e.test.ts:178. Three trusted-main Bun runs reproduced the same failing case and expected-2/got-3 signature; Bun run 2 reports the exact :178:73 frame. See the pinned-main reproduction below.

Trusted-main restored-wake reproduction

Classification: inherited, main reproduces. A detached checkout was created from fresh ls-remote main SHA 51403439b21a5736e61665e9bbd6278953a28631, and HEAD plus clean tracked source were verified before each invocation. pnpm install --frozen-lockfile --prefer-offline and the repository-owned JavaScript runtime preparation succeeded. Only test/gateway-restored-requester-settle.e2e.test.ts was selected, preserving all four cases and their order. No PR-tree code was executed.

The following command ran three times with the pinned Bun 1.4.4-canary.1+ef37c31de, then once with OPENCLAW_VITEST_RUNTIME=node on Node 26.12.1:

OPENCLAW_E2E_USE_PREBUILT_DIST=1 OPENCLAW_VITEST_RUNTIME=bun \
  node scripts/run-vitest.mjs run \
  --config test/vitest/vitest.e2e.config.ts \
  test/gateway-restored-requester-settle.e2e.test.ts \
  --maxWorkers=1 --reporter=verbose
Trial Exit Command wall time, including setup/cleanup Result
Bun 1 1 496.317 s 3 passed; concurrency case failed: expected 2, got 3
Bun 2 1 347.417 s 3 passed; concurrency case failed: expected 2, got 3
Bun 3 1 441.399 s 3 passed; concurrency case failed: expected 2, got 3
Node 1 143 753.344 s Setup stalled; wrapper terminated after 300,000 ms without output; no test-case result

Bun reproduced consistently in 3/3 trials. The Node invocation is an infrastructure/setup gap, not a passing run or an assertion reproduction; it was not retried. The initial canceled declaration-build setup preceded these four invocations and is not counted as a test run.

Root-cause hypothesis: main #182285, commit 5d47168b9170d92c45aeb82cd7680719f211b89a (also an ancestor of this PR head), intentionally releases the shared two-slot preparation budget when a restored delivery is admitted. The owner retains settlement ownership separately; the documented contract explicitly permits this release. The fixture sets maxConcurrent: 8 but assumes a two-model-execution cap. That stale expectation can explain admission of a third wake while prior model responses are held. The earlier peak-two sample precedes the CLI probe and is not simultaneous with the later count-three assertion; request identities were not instrumented, so distinct admission versus retry is not claimed as runtime-proven. Repair belongs to the main requester-wake/test owner, outside this retention PR. No source change or push was made for this classification.

The earlier missing-bootstrap-file failures did not recur on the final head; PostgreSQL 3/3 passed. They were traced to main commit 7a9a6a98, with a matching failure subsequently observed in scheduled-main PostgreSQL job 120827460249. No rerun-only fix is claimed.

@Yuaneen
Yuaneen marked this pull request as ready for review October 24, 2026 00:41
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 24, 2026
@indra622

Copy link
Copy Markdown
Contributor

I was independently working on #181976 and found this PR during pre-publication checks. I am holding my alternative PR to avoid duplicating this work. Your periodic-owner approach covers an important case my entry-write-only approach did not: after an actual isolated Gateway startup, expired archives remained for 65 seconds without a session write, but were removed after a normal entry-write RPC.

Could we consolidate around the periodic owner and include these preservation regressions?

I applied this PR's five-file patch at a89e56505294900a9366eb14273cf0f9c59194f3 to a disposable integration tree based on main 904ab2e8da31826c6dd0bdbdb4b1e126b8c0acdf, with my canonical-pruning changes and a reconciled #181746 pagination patch. Through the real SQLite periodic-maintenance function, using synthetic archives, I observed:

  • enforce, retention 1h: expired reset/deleted files and rows removed; fresh archive retained.
  • Retention false: files and rows retained.
  • warn, retention 1h: expired files and rows were removed, rather than preserved by the test's warn-mode expectation.
  • An expired reset archive protected by a live previous-session reference: its canonical row remained, but its derived file was removed.

These are integration observations, not confirmed failures on your raw PR head. I have not run this PR alone through a full Gateway. It would be useful to replay the last two cases on your head and agree on the intended policy before drawing conclusions. Source-wise, the directory cleanup happens before canonical pruning checks references, so checking eligibility before unlinking may be worth considering.

My local alternative reuses canonical writer custody and full row-identity checks for physical removal, and preserves the recovery blob on unlink/commit failure. I can contribute the focused synthetic fixtures and this safety approach without adding another scheduler or duplicating the CLI cleanup work in #97103. The reconciled pagination combination passed 22 focused tests; #97103 itself did not apply cleanly, so I am not claiming compatibility with that PR.

Would consolidating these checks into this PR be helpful? No production data, credentials, model calls, or real channel messages were used in these experiments.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR applies configured archive expiry through periodic Gateway maintenance independently of cron and cold storage.

Example: Cron and cold storage are disabled, archive retention is 1h, and an unreferenced deleted archive is two hours old.

  • Before: The archive file and canonical database row remain indefinitely.
  • After: The next Gateway maintenance pass removes both while preserving fresh, referenced, and unpublished archives.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The source repair is focused and prior defects are resolved, but supplied evidence does not exercise the repaired behavior or establish existing-state upgrade compatibility.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Configured reset/deletion archive expiry silently stops when cron is disabled or removes no sessions.
Reason: The existing documented retention contract should work independently of cron, and the feature-history owner has approved this repair direction.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR: it fixes a current retention bug, addresses all four prior findings, and has no additional concrete code defect identified.

Priority: P2
Reviewed head: 50946220ad81561620f677ca3bb16de5c479b87e

Before merge

  • Add real behavior proof - The repaired Gateway-to-worker expiry path has no current-head execution evidence: the inspected screenshots show historical settings UI, indra622's observations used a combined earlier tree, and the maintainer explicitly records skipped live and upgrade runs; that skip does not satisfy this review's external-PR proof or mandatory stored-data compatibility requirements. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide current-head startup or periodic expiry without session writes, preservation controls, and a populated upgrade from v2026.10.6; base-red/head-green execution is also not shown.
Agent review details

How this fits together

The Gateway maintenance scheduler discovers existing session stores and passes configured expiry rules to the archive worker, which checks references and row identity before removing files and canonical rows.

flowchart TD
  A[Runtime configuration] --> B[Gateway maintenance scheduler]
  B --> C[Session store discovery]
  C --> D[Archive retention owner]
  D --> E[Worker writer admission]
  E --> F[Reference and identity checks]
  F --> G[Archive files and database rows]
Loading

Technical review

Best possible solution:

Use the existing periodic maintenance and archive-worker owners to enforce configured expiry while preserving references, unpublished recovery copies, and bounded writer batches.

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

Current-main source confirms both cold-storage gates and cron-dependent expiry; the linked report identifies official releases, but this read-only review ran no target code.

Is this the best way to solve the issue?

The repair uses existing scheduling, discovery, writer admission, and archive ownership, removes the replaced cron path, and preserves the merged pagination fix.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Periodic transcript maintenance changes intended behavior with a stated reason (aa0ad4c: Cold storage introduced an opt-in startup and periodic maintenance owner; the repair explains why configured archive expiry also belongs there.)
  • Canonical archive deletion and recovery keeps the original intent (fc4d5d7: Canonical recovery blobs prevent transcript loss and protect unpublished archives; the new worker-owned unlink preserves those safeguards and strengthens exact-row matching.)
  • Worker execution and bounded deletion keeps the original intent (2350af4: Archive retention moved off the Gateway thread while retaining physical ownership, writer ordering, references, and current admission.)
  • Retention pagination keeps the original intent (4db08cf: Bounded pages prevent retained prefixes from starving later eligible archives; the repair keeps paging and adjusts the retained-prefix fixture to the new owner-driven expiry semantics.)
  • Filesystem retention errors keeps the original intent (fad7edd: Real filesystem failures must remain visible while missing-file races remain benign; guarded removal retains error propagation through the maintenance owner.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Avant: Raw commit fc4d5d7 adds src/config/sessions/session-accessor.sqlite-archive-store.ts:237 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fc4d5d744fad; files: src/config/sessions/session-accessor.sqlite-archive-store.ts)
  • xiaopan-xydt: Raw commit 4db08cf adds src/config/sessions/session-accessor.sqlite-archive-store.ts:190 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4db08cf94959; files: src/config/sessions/session-accessor.sqlite-archive-store.ts)

PR surface

Source +11, Tests +76, Docs +5, Other 0. Total +92 across 21 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 13 108 97 +11
Tests 6 170 94 +76
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 21 284 192 +92

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +108/-97; tests +170/-94 The small production increase retains guarded removal and policy checks while deleting cron-only plumbing; tests cover distinct preservation, failure, and consumer boundaries.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #181976
Summary: This PR owns the cron-independent expiry repair; pagination and independent deleted-retention settings address different remaining behavior.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Configured archive expiry silently fails without cron activity, with no demonstrated outage or immediate data loss.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Attach redacted current-head automatic-expiry and populated-upgrade results, preserving settings and noneligible history.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-24T01:30:39.891Z sha 53fd697 :: needs real behavior proof before merge. :: [P1] Honor warn mode before applying archive retention | [P2] Check canonical preservation before unlinking archive files
  • reviewed 2026-10-24T08:37:43.067Z sha 2880e54 :: needs real behavior proof before merge. :: [P2] Update the cleanup consumer regression for owner-driven expiry | [P2] Update the accessor debt baseline for the moved cleanup call

Reviewed October 24, 2026, 5:16 AM ET / 09:16 UTC (Revision 3).

steipete and others added 4 commits October 24, 2026 00:49
Preserve exact content from main ab8293d after an interrupted local merge. The following merge completes the same pinned main integration; no new implementation is introduced here.
Run configured archive expiry through the existing transcript maintenance owner.
Retire cron-only retention plumbing, honor warn mode, and let the archive worker
check current references and row identity before removing files and rows.
Preserve legacy-file cleanup and carry runtime policy into writer admission.

Fixes openclaw#181976

Co-authored-by: Yuaneen <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 24, 2026
@steipete

steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

Updated this existing request for final repaired head 50946220ad81561620f677ca3bb16de5c479b87e.

The original P1 warn-mode and P2 protected-file findings are addressed through the existing transcript-maintenance owner and guarded archive removal. Both follow-up P2 findings are now repaired too: the generated boundary inventory relocates the same two references without increasing its allowance, and the cleanup-service regression verifies file/row expiry in one pass plus a harmless subsequent pass.

Static lint/format and a fresh independent Codex review through P2 passed. The final main merge preserves the reviewed patch byte for byte. Exact-head CI is running; the PR body records the prior run's repaired failures and separate main/unclassified failures.

Live Gateway/channel and upgrade E2E remain skipped under the explicit maintainer proof policy. Contributor code was not executed locally; PR CI runs the regressions. Those proof-only requests do not add a hold for this takeover.

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper clawsweeper Bot removed the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Oct 24, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
steipete added a commit that referenced this pull request Oct 24, 2026
…82780)

Initialize the title provider fixture's session store before publishing its
runtime config. Eager snapshot capture otherwise leaves Gateway create/send
using the default store while the test reads an empty custom store.

Preserve the existing task, attachment, control-only, and manual-name proof.
Related: #182053
@steipete
steipete merged commit a677064 into openclaw:main Oct 24, 2026
265 of 275 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…enclaw#182780)

Initialize the title provider fixture's session store before publishing its
runtime config. Eager snapshot capture otherwise leaves Gateway create/send
using the default store while the test reads an empty custom store.

Preserve the existing task, attachment, control-only, and manual-name proof.
Related: openclaw#182053
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
* fix(sessions): apply archive retention without cron

* fix(sessions): keep archive retention on the accessor seam

* chore: preserve verified main integration

Preserve exact content from main 26472ac after an interrupted local merge. The following merge completes the same pinned main integration; no new implementation is introduced here.

* test(sessions): seed archive references without arming maintenance

* chore(sessions): align archive cleanup boundary baseline

* test(sessions): cover owner-driven archive expiry

---------

Co-authored-by: Yuaneen <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
@Yuaneen
Yuaneen deleted the fix/session-archive-retention-cron-181976 branch October 26, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: session.maintenance.resetArchiveRetention is silently not applied when cron is disabled

3 participants