Skip to content

fix(sqlite): let nested page reclamation finish - #201557

Merged
vincentkoc merged 1 commit into
mainfrom
fix-sqlite-reclamation-reentrant-drain-20261119
Nov 19, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix-sqlite-reclamation-reentrant-drain-20261119

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Nested SQLite page reclamation can wait for the foreground writer that is awaiting that same reclamation, leaving the operation and cleanup stuck. The existing WAL regression timed out on main.

User Impact

Background reclamation requested by an active foreground writer can proceed through the existing reentrant admission path. Normal background work still waits for queued foreground work. No schema, retention, or authority policy changes.

Why This Change Was Made

Skip the preliminary background drain only when the current async context already owns the same physical database queue and its holder is a foreground writer. The existing reservation still checks reentrancy, identity, cancellation, and permitted keys; worker callbacks cannot borrow a worker holder.

Evidence

  • Original regression: main CI failure, reclaims pages off-thread and applies current checkpoint receipts (reclaim), with a 120-second test timeout and 180-second cleanup timeout.
  • The four causal source/test files and dependency manifests are unchanged between the failed revision and this fix's base. Configuration inventory changes only add unrelated test files.
  • Formatting and normal signed-commit hooks passed. Local ClawSweeper review of c027899907abc325f11a7ce5b47e316a166b4899..4b4afe3c735befdac35efcdb185bf9a9c2c42dfd found no correctness or security findings (confidence 0.90).
  • The unchanged WAL file passed all 4 cases: reclaim (635 ms), resource close (470 ms), shared-state close (470 ms), and periodic vacuum (857 ms). The full admission file passed all 34 cases, including foreground ordering, background cancellation, and worker-lock exclusion.
  • Targeted formatting, type-aware lint, core types, and the state/logging and agent/session test-type leaves passed.
  • Local proof used the checksum-pinned OpenClaw Bun 1.4.4 fork with Node 24.22.1 on macOS arm64 and a private frozen dependency install. The original failure was Linux CI; no production incident is claimed.
Exact local proof commands
OPENCLAW_VITEST_RUNTIME=bun node --import ./scripts/tsx.mjs scripts/test-projects.mts src/config/sessions/session-accessor.sqlite-reclamation-wal.test.ts -- --maxWorkers=1
OPENCLAW_VITEST_RUNTIME=bun node --import ./scripts/tsx.mjs scripts/test-projects.mts src/state/openclaw-agent-write-admission.test.ts -- --maxWorkers=1
node scripts/run-format.mts --check src/state/openclaw-agent-write-admission.ts
node scripts/run-oxlint.mjs --tsconfig tsconfig.core.json src/state/openclaw-agent-write-admission.ts
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.state-logging.json --incremental
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.agents-sessions.json --incremental

The tests retain their original assertions and deadlines. The existing failing regression was reused; no duplicate test or test-only production seam was added.

@vincentkoc vincentkoc self-assigned this Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 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.

@vincentkoc
vincentkoc marked this pull request as ready for review November 19, 2026 01:42
@vincentkoc
vincentkoc enabled auto-merge (squash) November 19, 2026 01:43
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets background SQLite reclamation reuse its active foreground writer admission instead of waiting for that writer to drain.

Example: Archive pruning holds the database writer and awaits reclaiming up to 7 free pages while another writer is queued.

  • Before: Reclamation waits for the foreground queue to drain, while its foreground owner waits for reclamation.
  • After: Reclamation enters the existing reentrant reservation, completes, and lets the queued writer proceed afterward.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with meaningful existing integration coverage; supplied execution evidence is harness-based.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal admission repair is outside the contributor proof gate; supplied validation exercises real SQLite and worker code through the existing WAL harness, with no shipped CLI or Gateway demonstration claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Session archive cleanup can remain stuck when it awaits page reclamation from inside its foreground writer.
Reason: The maintainer-authored change restores completion without new configuration, storage formats, scheduling machinery or weakened worker exclusion.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a source-verifiable self-deadlock that remains on fetched main; no introduced correctness or security defect was found.

Priority: P2
Reviewed head: 4b4afe3c735befdac35efcdb185bf9a9c2c42dfd

Before merge

None.

Findings

None.

Agent review details

How this fits together

The agent database admission owner orders foreground writes and background SQLite worker operations; reclamation enters through the session storage layer and returns checkpoint and vacuum results.

flowchart TD
  A[Session archive pruning] --> B[Foreground writer admission]
  B --> C[Nested page reclamation]
  C --> D[Background admission]
  D --> E[Existing reentrant reservation]
  E --> F[SQLite worker]
  F --> G[Checkpoint and vacuum receipt]
Loading

Technical review

Best possible solution:

Keep the narrow exception in the existing admission owner so nested reclamation can finish without changing ordinary background precedence.

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

The existing WAL fixture and current-main control flow establish the circular wait; no target code was executed during this read-only review, and the historical timeout log could not be inspected.

Is this the best way to solve the issue?

The defect is waiting for a drain that includes the awaiting caller. The invariant is that nested work may reuse its active foreground admission while unrelated background work yields. This patch is the smallest complete repair using the existing queue, context and reservation owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9bd2fe9 adds src/state/openclaw-agent-write-admission.ts:145 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9bd2fe918222; files: src/state/openclaw-agent-write-admission.ts)
  • Vincent Koc: Raw commit 1c8be7f adds src/state/openclaw-agent-write-admission.ts:46 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1c8be7fb6e9a; files: src/state/openclaw-agent-write-admission.ts)

PR surface

Source +8. Total +8 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 8 0 +8
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 8 0 +8

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: The source establishes a reclamation deadlock with focused regression evidence, but the report claims no production incident or currently broken user deployment.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The source establishes a reclamation deadlock with focused regression evidence, but the report claims no production incident or currently broken user deployment.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

Reviewed November 18, 2026, 8:57 PM ET / November 19, 2026, 01:57 UTC.

@vincentkoc
vincentkoc merged commit 60ab512 into main Nov 19, 2026
229 checks passed
@vincentkoc
vincentkoc deleted the fix-sqlite-reclamation-reentrant-drain-20261119 branch November 19, 2026 02:05
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
RomneyDa added a commit that referenced this pull request Nov 19, 2026
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
openclaw#201557)

(cherry picked from commit 60ab512)

Release adaptation: Preserve source guard; add real nested queue regression with abort cleanup. Baseline hangs;26/26green.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
#201557)

Baseline adaptation: Keep the production reservation change as upstream and add a baseline regression using the foreground writer owner and a bounded abort.

(cherry picked from commit 60ab512)

Co-authored-by: RomneyDa <[email protected]>
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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