Skip to content

fix(sessions): honor total entry cap with protected history - #123081

Merged
RomneyDa merged 5 commits into
mainfrom
fix/session-maintenance-total-cap
Aug 15, 2026
Merged

RomneyDa merged 5 commits into
mainfrom
fix/session-maintenance-total-cap

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Related: #123014

What Problem This Solves

Fixes an issue where users with protected session history could retain more ordinary sessions than configured by session.maintenance.maxEntries, because archived, pinned, active, locked, and durable conversation rows stopped contributing to the capacity calculation.

Why This Change Was Made

maxEntries is again a total-row cap: every live session row consumes capacity, while protection determines only which rows may be evicted. Maintenance computes total overflow and removes that many oldest unprotected rows; if protected rows alone exceed the cap, it preserves them and leaves the store above the limit.

The file, SQLite write-triggered, cleanup-preview, and active-session warning paths use the same accounting model. SQLite writes use lightweight total-count and stale-candidate probes, then load the full session payload snapshot only when maintenance must run. This removes the eligible-entry counter and adds no public SDK surface. Operator docs and config help now describe the same behavior.

User Impact

Protected sessions remain immune from automatic deletion without granting unlimited extra capacity. For example, at a 500-row cap, 200 pinned plus 400 ordinary rows retain every pin and the newest 300 ordinary rows. If 499 rows are archived and three are ordinary, the two oldest ordinary rows are removed.

This corrects unreleased behavior from #123014; no release tag contains that change.

Evidence

  • Before the fix, the three targeted total-cap regressions failed on origin/main: protected-history overflow removed 0 rows instead of 2/100, and the active-session warning missed the same pressure (run).
  • The total-cap implementation passed 128/128 focused session maintenance, SQLite conformance, cleanup, and transcript tests (run).
  • Exact follow-up head 45ec66c7d7f: local-container Crabbox cbx_35394760e7ae passed targeted formatting and 117/117 owner-boundary tests covering total overflow, protected rows/transcripts, stale pruning, and SQLite write-triggered maintenance.
  • The initial branch changed-surface gate passed production/test types, formatting, lint, architecture, SDK-boundary, database-first, and docs checks. GitHub CI is rerunning those gates on the exact follow-up head.
  • Fresh pre-commit autoreview reported no accepted or actionable findings for both the complete branch and the follow-up SQLite delta.

Production source: +85/-128 (net -43). Tests: +71/-65. Documentation: +20/-16.

AI-assisted: implementation, tests, documentation, and validation were prepared with Codex; the maintainer directed the retention model and reviewed the tradeoff.

@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 13, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 10:42 AM ET / 14:42 UTC.

ClawSweeper review

What this changes

The PR changes session maintenance so protected rows consume the total entry cap while remaining ineligible for automatic eviction.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No blocking correctness finding remains: the final head fixes the prior malformed-JSON SQLite probe failure and consistently applies total-row accounting. This maintainer-labeled PR should remain open for normal exact-head CI and maintainer handling.

Priority: P1
Reviewed head: d83511bc520af0b7ec0d4a80f3a9f5cf57400db2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The owner-boundary repair and regressions are coherent with no remaining concrete finding; exact-head CI remains the final merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is outside the external-contributor proof gate; its body nevertheless supplies focused session-boundary validation evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is outside the external-contributor proof gate; its body nevertheless supplies focused session-boundary validation evidence.
Evidence reviewed 7 items Current main still has the defect: Current main derives the cap from eviction-eligible rows, excluding protected history from capacity pressure.
Canonical total-cap implementation: The PR head calculates overflow from all live rows, then limits removal to protected-aware eligible victims.
SQLite owner path: SQLite counts valid live rows before loading the full store, then reconstructs the preservation set before pruning or capping.
Findings None None.
Security None None.

How this fits together

Session maintenance runs after persisted-session writes and manual cleanup to prune stale history and bound stored sessions. The same retention rule must agree across file-backed stores, SQLite writes, previews, warnings, and transcript cleanup.

flowchart LR
A[Session write or cleanup] --> B[Maintenance trigger]
B --> C[Count live session rows]
C --> D[Preserve protected rows]
D --> E[Evict oldest eligible rows]
E --> F[Persist sessions and clean transcripts]
Loading

Before merge

  • Resolve merge risk (P1) - This intentionally changes persisted-session eviction semantics, so the exact-head SQLite conformance and session-maintenance checks must complete green before merge.
  • Resolve merge risk (P1) - The direct Kysely package source is absent from this checkout and DNS was unavailable; repository-local query compilation and the established guarded JSON pattern were inspected instead.
  • Complete next step (P2) - No mechanical repair finding remains; await normal exact-head CI and maintainer review.
Agent review details

Security

None.

PR surface

Source -27, Tests +88, Docs +4. Total +65 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 7 103 130 -27
Tests 5 209 121 +88
Docs 4 20 16 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 332 267 +65

Review metrics

Metric Value Why it matters
Production vs test LOC production -27 net, tests +88 net, docs +4 net The fix removes the eligible-quota policy while adding focused total-cap and SQLite regression coverage.

Stored data model

Persistent data-model change detected: serialized state: src/agents/command/session-store.test.ts, serialized state: src/config/sessions/cleanup-service.ts, serialized state: src/config/sessions/session-accessor.conformance.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-maintenance.ts, serialized state: src/config/sessions/store-maintenance-eligibility.ts, serialized state: src/config/sessions/store-maintenance-eligible-quota.test.ts, and 10 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head retention checks (recommended)
    Merge once the current head’s SQLite conformance and session-maintenance checks are green.

Technical review

Best possible solution:

Merge the single total-cap rule after exact-head checks pass, retaining the guarded SQLite stale probe and parity coverage for file-backed and SQLite maintenance.

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

Yes, from source: the focused tests construct protected history plus ordinary overflow and exercise file-backed and SQLite write-triggered maintenance; no local execution was performed in the read-only review.

Is this the best way to solve the issue?

Yes: total-row triggering plus one protected-aware victim selector is the narrowest shared owner-boundary repair, avoiding new settings or separate quota policies.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 493a3e46b3f2.

Labels

Label changes:

  • 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: This MEMBER-authored PR is outside the external-contributor proof gate; its body nevertheless supplies focused session-boundary validation evidence.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Incorrect automatic retention can evict ordinary persisted sessions under normal capacity pressure.
  • merge-risk: 🚨 session-state: The branch changes selection and deletion of persisted session rows in both SQLite and file-backed stores.
  • 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: This MEMBER-authored PR is outside the external-contributor proof gate; its body nevertheless supplies focused session-boundary validation evidence.

Evidence

What I checked:

Likely related people:

  • RomneyDa: Authored the merged eligible-quota implementation and all five commits on this corrective PR. (role: feature owner and recent area contributor; confidence: high; commits: 4afccbdaa435, c3edaf95722a, d83511bc520a; files: src/config/sessions/store-maintenance.ts, src/config/sessions/session-accessor.sqlite-maintenance.ts)
  • Peter Steinberger: Introduced active-route and durable-conversation preservation that shares the retention invariant this PR recalibrates. (role: earlier preservation contributor; confidence: high; commits: 1263d4278e86, de0d484236fc, d4f19bfd797d; files: src/config/sessions/store-maintenance.ts)
  • Ahmed Tarek: Added primary-session protection in the same cap-selection surface. (role: adjacent preservation contributor; confidence: high; commits: 8cb749ad235b; files: src/config/sessions/store-maintenance.ts)

Rank-up moves

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

  • Wait for the current exact-head SQLite and session-maintenance checks to finish green.

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 (6 earlier review cycles)
  • reviewed 2026-08-13T09:18:01.766Z sha 590cc1c :: found issues before merge. :: [P2] Use enforcement preservation when predicting active eviction
  • reviewed 2026-08-13T19:37:33.414Z sha 45ec66c :: found issues before merge. :: [P2] Pass preservation facts into active-session warning prediction
  • reviewed 2026-08-14T09:57:56.525Z sha 15ef8ee0245cd8acee4f357ba1a5762e86e04038 :: found issues before merge. :: [P2] Pass preservation facts into active-session warning prediction
  • reviewed 2026-08-14T10:06:06.221Z sha 527002c53506ba3c4bdea6b473259662673fb12a :: found issues before merge. :: [P2] Pass preservation facts to warning selection
  • reviewed 2026-08-14T10:32:36.389Z sha d79b47c :: found issues before merge. :: [P2] Pass preservation facts to warning selection
  • reviewed 2026-08-14T12:11:55.936Z sha 1d859f9 :: found issues before merge. :: [P1] Guard JSON1 extraction for malformed session rows

@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@RomneyDa
RomneyDa force-pushed the fix/session-maintenance-total-cap branch from 45ec66c to 15ef8ee Compare August 14, 2026 09:51
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 14, 2026
@RomneyDa
RomneyDa force-pushed the fix/session-maintenance-total-cap branch from 92c4f04 to 527002c Compare August 14, 2026 10:00
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@RomneyDa
RomneyDa force-pushed the fix/session-maintenance-total-cap branch from 527002c to 77970b5 Compare August 14, 2026 10:17
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@RomneyDa
RomneyDa force-pushed the fix/session-maintenance-total-cap branch from 62f08e7 to d83511b Compare August 14, 2026 14:35
@clawsweeper clawsweeper Bot added 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@RomneyDa
RomneyDa merged commit a01d40b into main Aug 15, 2026
227 of 310 checks passed
@RomneyDa
RomneyDa deleted the fix/session-maintenance-total-cap branch August 15, 2026 00:04
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
…#123081)

* fix(sessions): count protected rows toward entry cap

* perf(sessions): defer maintenance snapshot loading

* test(sessions): assert total maintenance cap

* fix(sessions): align warning preservation

* fix(sessions): guard malformed maintenance rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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