Skip to content

fix(sessions): protected conversations stop shrinking session capacity - #123014

Merged
RomneyDa merged 1 commit into
mainfrom
fix/session-maintenance-eligible-quota
Aug 13, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/session-maintenance-eligible-quota

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where archived, active, locked, and channel sessions consumed the ordinary-session maxEntries allowance even though maintenance could not evict them. A store near the default 500-entry cap could therefore delete recent dashboard and subagent sessions on the next write.

Why This Change Was Made

Maintenance now builds one eviction-eligible set, triggers on that set's size, and keeps the newest maxEntries eligible sessions. Protected sessions remain outside the quota. The active-session warning, file-backed path, cleanup preview, and SQLite write-triggered path all use the same accounting rule.

SQLite maintenance reads and parses session_nodes once per enforcement check. It derives the complete protected-key set, eligible count, and stale-candidate decision from that snapshot, then reuses the same snapshot if maintenance runs. There is no additional count query and no new Plugin SDK export.

Pinned-session immunity is independently provided by merged #122990. This branch is rebased over that fix and covers the combined preservation and quota behavior.

AI-assisted; the implementation and tests were reviewed against the full maintenance path.

User Impact

Large archived or otherwise protected histories no longer crowd recent ordinary sessions out of the maintenance allowance. When the eligible population itself exceeds the cap, only its oldest entries are removed.

Regression Window

The general accounting defect began in commit 1263d427 on April 23, 2026, when active-session preservation was added by subtracting preserved rows from maxEntries. The first affected tagged build is v2026.4.23-beta.1; the first affected stable release is v2026.4.23.

Commit de0d4842 expanded the protected set to durable channel/thread conversations on May 2; that expansion first shipped stably in v2026.5.2.

The archived-row saturation from this incident specifically began with #112554 on July 22, when archived sessions became maintenance-protected while retaining the old subtraction model. It is present in the v2026.7.2-beta.4 tag (not promoted) and first published in v2026.7.2-beta.5. As of August 13, 2026, no stable release tag contains that archived-row regression.

Evidence

  • Blacksmith Testboxes tbx_01kzws04xf1mcw11737zbn4bf1 and tbx_01kzwtvvazw3dyce1rf286pk0j: targeted formatting and 178/178 focused session-maintenance and caller tests passed.
  • The full core changed-surface gate and the follow-up core-test gate passed, including production/test types, lint, Plugin SDK API baseline, architecture/import-cycle, database-first, and boundary checks.
  • Regression coverage includes 499 archived entries plus recent dashboard sessions, over-cap eligible-only eviction, active-session warning parity, writer-session survival, pinned/archived preservation, transcript preservation, and real SQLite write-triggered maintenance.
  • Final production delta: +118/-109, net +9 lines. SQLite trigger evaluation uses one session snapshot query rather than separate count, stale-candidate, and load queries.
  • Autoreview: Codex gpt-5.6-sol / high reasoning reported no accepted or actionable findings for the complete branch diff.

@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 size: M maintainer Maintainer-authored PR labels Aug 13, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. 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: found issues before merge. Reviewed August 13, 2026, 2:07 AM ET / 06:07 UTC.

ClawSweeper review

What this changes

The PR changes session maintenance so maxEntries limits only eviction-eligible sessions while archived, pinned, active, locked, and durable conversation rows remain outside that allowance.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: the branch coherently repairs the protected-session quota defect across file, cleanup-preview, and SQLite maintenance, but it still lacks the documentation required for the changed maxEntries contract. Likely related people: steipete (historical session-maintenance owner) and RomneyDa (recent contributor on the same path).

Priority: P1
Reviewed head: 8042c3902baf248ac54e530dc3eeaf229c67ec6b

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The runtime repair is well-targeted, but the unresolved documentation mismatch is a merge-blocking compatibility gap.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR author is a repository member, so the external-contributor proof gate does not apply; the body nevertheless reports focused Testbox coverage.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR author is a repository member, so the external-contributor proof gate does not apply; the body nevertheless reports focused Testbox coverage.
Evidence reviewed 5 items Current-main defect: Current main subtracts preserved rows from maxEntries, so protected rows consume the ordinary-session allowance even though they cannot be evicted.
Shared owner-boundary repair: The PR makes capping select eligible keys only, and its SQLite path derives trigger and removal decisions from one preserved snapshot.
Public contract remains stale: The checked-out configuration reference calls maxEntries a maximum number of SQLite session entries, while this PR intentionally permits more total rows whenever protected rows exist; no documentation file is in the branch diff.
Findings 1 actionable finding [P2] Document the eligible-entry cap
Security None None.

How this fits together

Session maintenance runs after file-backed and SQLite session writes, using preservation rules to decide which stored conversations can be pruned or capped. Its output determines retained session rows and the associated transcript cleanup plan.

flowchart LR
  A[Session writes] --> B[Session storage]
  B --> C[Preservation rules]
  C --> D[Eligible session count]
  D --> E[Prune and cap decisions]
  E --> F[Retained rows and transcripts]
Loading

Before merge

  • Document the eligible-entry cap (P2) - The changed cap now retains maxEntries eviction-eligible rows while preserved rows remain outside the quota. Current docs still promise a maximum number of SQLite session entries, so operators cannot tell why protected history leaves more rows than the configured value. Update the configuration, concept, and reference docs with the eligible-row contract and the explicit cleanup path.
  • Resolve merge risk (P1) - Merging changes an existing retention contract: protected histories can leave more total session rows than maxEntries, while current public docs still describe that setting as a general entry cap.
  • Resolve merge risk (P1) - Production code is net +9 lines; the shared non-allocating eligibility counter is justified by three maintenance callers, but its single-predicate ownership should remain intact.

Findings

  • [P2] Document the eligible-entry cap — src/config/sessions/store-maintenance.ts:539-541
Agent review details

Security

None.

PR surface

Source +9, Tests +210. Total +219 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 118 109 +9
Tests 5 230 20 +210
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 348 129 +219

Review metrics

Metric Value Why it matters
Production vs test LOC production +118/-109 (net +9); tests +230/-20 (net +210) The production growth creates one shared eligibility count for file, cleanup-preview, and SQLite paths; the test growth covers the storage-owner regressions.
Retention-contract change 0 config keys added; 1 existing limit redefined maxEntries changes from an apparent total-row cap to an eviction-eligible-row cap, which affects upgrade expectations.

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/incognito-session-transcript.test.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, and 11 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Document the retention contract before merge (recommended)
    Update the configuration, session concept, and session-management reference pages so existing operators understand why protected rows can exceed maxEntries and how to reduce them.

Technical review

Best possible solution:

Document that maxEntries caps only eviction-eligible rows, identify protected histories that can exceed it, and direct operators to unarchive/delete history or use disk-budget policy when they need to reduce total retained storage.

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

Yes, from source: with 499 protected rows, three ordinary rows, and maxEntries: 500, current main reduces the removable allowance to one and evicts ordinary rows. This read-only review did not execute the scenario.

Is this the best way to solve the issue?

No, not yet: the shared runtime repair is the best owner-boundary fix, but the PR must update the public retention contract before it is complete.

Full review comments:

  • [P2] Document the eligible-entry cap — src/config/sessions/store-maintenance.ts:539-541
    The changed cap now retains maxEntries eviction-eligible rows while preserved rows remain outside the quota. Current docs still promise a maximum number of SQLite session entries, so operators cannot tell why protected history leaves more rows than the configured value. Update the configuration, concept, and reference docs with the eligible-row contract and the explicit cleanup path.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7c8f08a88ccc.

Labels

Label justifications:

  • P1: The repair prevents maintenance from evicting recent ordinary sessions because protected sessions consume their quota.
  • merge-risk: 🚨 compatibility: Existing session stores can retain more total rows than their configured maxEntries after upgrade.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The PR author is a repository member, so the external-contributor proof gate does not apply; the body nevertheless reports focused Testbox coverage.

Evidence

What I checked:

Likely related people:

  • steipete: Historical commits establish the protected-session maintenance behavior and archived-session preservation that this quota repair follows. (role: historical session-maintenance owner; confidence: high; commits: 1263d4278e86, d4f19bfd797d; files: src/config/sessions/store-maintenance.ts, src/config/sessions/session-accessor.sqlite-maintenance.ts)
  • RomneyDa: Previously landed pinned-session maintenance work touches the same preservation predicate and storage paths. (role: recent area contributor; confidence: high; commits: f8fcfe34b9f4; files: src/config/sessions/store-maintenance.ts, src/config/sessions/session-accessor.sqlite-maintenance.ts, src/config/sessions/store.pruning.test.ts)

Rank-up moves

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

  • Update the three session-maintenance documentation surfaces with the eligible-entry contract.
  • Refresh exact-head CI after the documentation correction.

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-08-13T05:16:44.726Z sha a3741626ae02812f6853a0aa2b58a617698ed60d :: found issues before merge. :: [P2] Document the changed maxEntries contract | [P3] Remove the obsolete SQLite count helper

@RomneyDa
RomneyDa force-pushed the fix/session-maintenance-eligible-quota branch 2 times, most recently from 29f7740 to 8042c39 Compare August 13, 2026 05:57
@RomneyDa
RomneyDa force-pushed the fix/session-maintenance-eligible-quota branch from 8042c39 to 1e3d979 Compare August 13, 2026 07:30
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling labels Aug 13, 2026
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa
RomneyDa merged commit 4afccbd into main Aug 13, 2026
124 checks passed
@RomneyDa
RomneyDa deleted the fix/session-maintenance-eligible-quota branch August 13, 2026 07:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 14, 2026
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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant