Skip to content

fix(sessions): drain archive retention across bounded pages - #181746

Merged
steipete merged 2 commits into
openclaw:mainfrom
xiaopan-xydt:fix/archive-retention-pagination-181722
Oct 24, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
xiaopan-xydt:fix/archive-retention-pagination-181722

Conversation

@xiaopan-xydt

@xiaopan-xydt xiaopan-xydt commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #181722

What Problem This Solves

Fixes: doctor keeps reporting retention-deleted transcript archive copies as missing when archive retention spans more than one 256-row page.

User Impact

Operators no longer see permanent stale Missing ... canonical transcript archive file(s) warnings after ordinary retention. Later eligible rows are no longer starved by an older retained prefix.

Why This Change Was Made

Retention previously read one 256-row page and filtered it after selection. It now walks bounded pages, advances only past rows intentionally retained, and drains each page in 16-row write batches. Both worker and native SQLite paths accept the page offset. Doctor warnings for genuinely unexplained missing copies and cold-storage history are unchanged.

Evidence

Reproduction through the production retention path

The proof seeds a 300-row retained prefix with published files, then 20 later retention-eligible rows with no file. It closes the database, runs the production sweepCronRunSessions() owner with resetArchiveRetention: "1h" and cron retention 1ms, then runs openclaw doctor --fix and reads the archive table again.

sweepLogs=["[object Object] cron-reaper: pruned 1 expired cron run session(s)"]
sweep {"swept":true,"pruned":1}
after code=0
[state-migrations] Auto-migrated legacy state:
- Migrated canonical transcript archive media in .../openclaw-agent.sqlite: 300 archive(s).
rows total=301 retained=300 expired=0

Doctor scanned the remaining 300 archives and emitted no Missing ... canonical transcript archive file(s) warning. The 300 retained-prefix rows remain; the 20 later missing rows were drained. One additional row is the cron trigger archive created while exercising the reaper.

Issue dataset

The tre1d measurement from #181722: an earlier weekly archive held 822 copies, one day contributed 762, and the later archive held none of those 822. There were 605 manifest/blob rows with missing files (234 / 326 / 45 per agent); every publish recorded success. Rebuilding all 605 files produced 605 writes and 0 SHA-256 mismatches.

Regression coverage

  • Base-red (7845dd3e): new regressions fail with expected 256 to be 258 and expected 0 to be 20.
  • Head-green (7e053421): both regressions pass; the full retention file passes 8/8.
  • Acceptance set: 6 affected suites pass, 83 tests total (session-history-archive-retention, archive-pruning admission, page-reclamation binding, session reaper, cleanup missing-file handling, and transcript-directive migration).
  • pnpm check:line-cap-ratchet, oxlint, and oxfmt --check pass.
  • pnpm build:runtime: TypeScript runtime and tsdown phases completed. The final UI phase failed because this host lacks the unrelated libdeflate package.

No UI changes.

AI Assistance

AI-assisted implementation and validation under contributor direction and review.

@clawsweeper

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

@xiaopan-xydt
xiaopan-xydt marked this pull request as ready for review October 23, 2026 16:09
@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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR drains archive-retention candidates across bounded pages while preserving 16-row deletion batches.

Example: A store contains 300 older archives whose files remain and 20 later expired archives whose files are absent.

  • Before: The retained prefix fills the first 256-row selection, leaving all 20 eligible rows and recurring Doctor warnings.
  • After: Retention preserves the 300 retained archives and removes the 20 eligible rows.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair backed by production cleanup-to-Doctor output, distinct regressions, and green exact-head checks; existing storage formats and deletion predicates remain unchanged.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied isolated SQLite run closes seeded storage, invokes production cron-reaper cleanup, then runs the Doctor CLI: 20 later expired rows are removed, 300 retained-prefix rows survive, and no missing-copy warning remains; recorded base-red/head-green regressions support both pagination cases.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Ordinary archive retention leaves permanent missing-copy warnings when eligible rows lie beyond the first candidate page.
Reason: The patch restores reconciliation coverage using existing owners, with no new setting, public API, storage format, or warning suppression.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current pagination defect with a focused change, credible runtime evidence, green exact-head checks, and no actionable findings.

Priority: P2
Reviewed head: fd302e5382b7d494b0c0c425391f0c3fcbc276be

Before merge

None.

Findings

None.

Agent review details

How this fits together

Session lifecycle cleanup removes expired archive files, then reconciles their canonical database rows through the existing archive reader and admitted writer; Doctor checks the remaining archive manifests.

flowchart TD
  A[Session lifecycle cleanup] --> B[Expired archive file cleanup]
  B --> C[Retention pagination owner]
  C --> D[Bounded archive reader]
  D --> C
  C --> E[Admitted deletion batches]
  E --> F[Canonical archive table]
  F --> G[Doctor manifest verification]
Loading

Technical review

Best possible solution:

Merge the existing-owner pagination repair while preserving current retention rules, deletion rechecks, and foreground writer fairness.

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

Current-main source establishes retained-prefix starvation, and the supplied runtime trace exercises that dataset through production cleanup and Doctor; this read-only review ran no target code.

Is this the best way to solve the issue?

Pagination repairs incomplete reconciliation at its existing owner, retains safety checks and bounded writes, and avoids suppressing valid Doctor warnings.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Archive candidate selection and single-page regression expectation changes intended behavior with a stated reason (refactor(sessions): run archive retention pruning in workers #163218: Move archive retention into existing workers while preserving the previous selection cap and safety contracts; that refactor did not address draining beyond one page.)
  • Deletion batch admission and writer fairness keeps the original intent (44898a3: Keep archive selection outside writer admission and yield between small deletion batches so foreground session writes remain responsive.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +19, Tests +20. Total +39 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 49 30 +19
Tests 1 23 3 +20
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 72 33 +39

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The repair addresses persistent misleading archive diagnostics and incomplete retention reconciliation without evidence of a blocked runtime or lost transcript content.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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-23T16:26:07.114Z sha 7e05342 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-23T19:40:25.632Z sha 7e05342 :: needs maintainer review before merge. :: none

Reviewed October 24, 2026, 12:34 AM ET / 04:34 UTC (Revision 3).

@tre1d

tre1d commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Dataset for the needs proof ask - 605 orphan rows, batch well over one page

The review on #181722 listed "The reporter's exact Windows dataset and deletion trigger were not reproduced" as the open risk. Here is that dataset, measured on a long-lived Windows install running 2026.10.6.

Shape consistent with the bounded-page defect

  • One day contributed 762 published archive copies into a single expiry batch. Two weekly archives one week apart show it directly: the earlier contains 822 copies dated 2026-10-08 through 2026-10-10, the later contains none of those 822. Ten older copies (dated 2026-09-27, 2026-09-29, 2026-10-04) are present in both - older rows retained while newer ones disappeared, which is the retained-prefix starvation shape rather than an age-based policy.
  • 605 rows kept their archive_name + archive_sha256 manifest entries and a populated archive_blob with no file on disk: 234 / 326 / 45 across three agents. Every one had published_at set, publish_attempts >= 1, and last_publish_error NULL - the publish recorded success.
  • Row creation is gradual, not backfilled: created_at == published_at for every row, spread across 26 distinct hours over 14 days.
  • Earliest affected row dates from 2026-09-02, so the symptom is unbounded in time rather than tied to a single event.

Content is intact. Rebuilding all 605 files from their archive_blob values produced 605 written, 0 sha256 mismatches against archive_sha256, 0 errors. This is a stale consistency report over fully retained data, not loss.

Offer: happy to re-run the same measurement against a build carrying this change and report before/after Missing ... canonical transcript archive file(s) counts per agent, if that is useful for clearing needs proof.

@xiaopan-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@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. 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
@steipete
steipete merged commit 4db08cf into openclaw:main Oct 24, 2026
133 of 134 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@xiaopan-xydt
xiaopan-xydt deleted the fix/archive-retention-pagination-181722 branch October 24, 2026 17:04
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
RomneyDa added a commit that referenced this pull request Oct 28, 2026
Beta.5 adaptation: Apply the source behavior to the c11c9d3 baseline; preserve baseline-native producer/consumer seams and include focused regression and registration adaptations for this group. See expanded-implementation-0/receipts.json for closure and qualification.

(cherry picked from commit 4db08cf)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit f9e1fa5f6573b3fb86fea9f0e3cc513285d3124d)
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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

3 participants