Skip to content

fix(sqlite): retain healthy handles after automatic rollback - #157241

Merged
roboclaw-bot merged 1 commit into
mainfrom
fix/release-quota-io-recovery-20260924
Sep 24, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
fix/release-quota-io-recovery-20260924

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes otherwise usable SQLite connections being closed after SQLite automatically rolls back a failed outer transaction, which can invalidate retained read admission during fallback recovery.

User Impact

A failed write is still reported without replay, but subsequent operations can reuse the same healthy database connection. Nested rollback failures and errors after commit starts still fence the handle. No schema, persistence contract, corruption policy, or configuration changes.

Why This Change Was Made

Before commit begins, an open handle with no active transaction means cleanup has no transaction left to roll back. Discard its staged state/publications rather than treating the redundant ROLLBACK error as a broken connection. Track entry into commit processing separately so a durable commit followed by an owner failure cannot take that recovery path.

Requested by Peter Steinberger during release-regression verification.

Worked on by

Work sessions

Evidence

  • Native SQLite disk-full regression fails before the fix and passes afterward: the transaction rolls back, pending publications are discarded, the operation executes once, integrity remains valid, and a later transaction succeeds on the retained handle.
  • Two native commit-owner regressions prove that throwing or returning a Promise after COMMIT still closes/fences the connection and suppresses publication without replay. Both failed against the initial repair and pass after the commit-phase distinction.
  • 68 tests passed across four files in 35.66 s wall, covering transactions, schema facts, corruption recovery, and model-fallback quota recovery. Transaction suite alone: 29 passed / 3.25 s wall; added postcommit cases approximately 7 ms each. Hosted timings pending.
  • Production and the affected core-test graph typechecks, scoped lint/format, storage guards, and diff checks passed. Fresh independent review through P3 is scoped-clean.

Limit: the original packaged Gateway quota E2E replay did not reach test execution because its private-QA build was blocked by a separately diagnosed declaration-root problem. The native transaction boundary is proven; this is not a claim that the complete Gateway fallback flow or full release validation passed.


View the OpenClaw team session

@clawsweeper

clawsweeper Bot commented Sep 24, 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.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 24, 2026 11:27
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 24, 2026, 7:34 AM ET / 11:34 UTC.

ClawSweeper review

What this changes

The branch lets SQLite transaction cleanup retain an open handle after a pre-commit automatic rollback and adds native disk-full and post-commit failure regressions.

Merge readiness

✅ Ready for maintainer review

Current main still closes the SQLite handle after an automatic outer rollback. The focused patch addresses that behavior, and the source review found no blocking defect.

Priority: P2
Reviewed head: d9575c92749ed78a6bb2b58ce78e3f5aa2d7377a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level change has direct native SQLite regression evidence and a clearly stated Gateway proof limit.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR reports before-and-after execution of the production transaction helper against native SQLite with an injected disk-full failure: the write rolls back, publication is suppressed, integrity remains valid and a later write succeeds on the retained handle. Its separate post-commit cases check fencing. The packaged Gateway quota replay did not run; no stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR reports before-and-after execution of the production transaction helper against native SQLite with an injected disk-full failure: the write rolls back, publication is suppressed, integrity remains valid and a later write succeeds on the retained handle. Its separate post-commit cases check fencing. The packaged Gateway quota replay did not run; no stored-data contract changes.
Evidence reviewed 7 items Introduced recovery guard: The introduced branch retains an open connection only when no transaction remains before commit processing; otherwise rollback or fencing remains in place.
Native boundary regressions: The added cases force native SQLite disk-full rollback, check that staged publication is discarded and the same handle can write again, and check that failures after COMMIT still fence the handle.
Current main remains affected: The main-branch helper unconditionally attempts ROLLBACK after an operation error and fences the connection when that rollback fails; it lacks the proposed pre-commit distinction.
Findings None None.
Security None None.

How this fits together

SQLite transaction helpers wrap reads and writes to OpenClaw’s local databases. They settle native transactions and coordinate staged state before callers reuse a connection.

flowchart LR
 A[Store operation] --> B[Transaction helper]
 B --> C[Native SQLite transaction]
 C --> D{Failure phase}
 D -->|Transaction ended before commit| E[Discard staged state]
 E --> F[Reuse open handle]
 D -->|Commit started or state uncertain| G[Fence handle]
 C -->|Success| H[Publish committed state]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +13, Tests +77. Total +90 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 15 2 +13
Tests 1 77 0 +77
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 92 2 +90

Review metrics

Metric Value Why it matters
Production and regression code production +15/−2 lines; tests +77/−0 lines The production growth is confined to distinguishing automatic rollback from failures after commit begins.
Focused test cost 29 transaction tests; 3.25 s local wall The PR reports a bounded native SQLite suite; hosted timing was still pending in the captured review.

Technical review

Best possible solution:

A failed outer write should leave its handle reusable only when SQLite ended the transaction before commit processing; staged state must be discarded, while uncertain commits remain fenced.

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

Yes. The native max-page-count case gives a concrete SQLITE_FULL path, and current main’s unconditional cleanup explains the closed handle; this read-only review did not run it.

Is this the best way to solve the issue?

Yes. The patch changes the existing transaction owner and preserves fencing once commit processing starts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The defect affects recovery after an exceptional SQLite write failure, with a limited demonstrated blast radius.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR reports before-and-after execution of the production transaction helper against native SQLite with an injected disk-full failure: the write rolls back, publication is suppressed, integrity remains valid and a later write succeeds on the retained handle. Its separate post-commit cases check fencing. The packaged Gateway quota replay did not run; no stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR reports before-and-after execution of the production transaction helper against native SQLite with an injected disk-full failure: the write rolls back, publication is suppressed, integrity remains valid and a later write succeeds on the retained handle. Its separate post-commit cases check fencing. The packaged Gateway quota replay did not run; no stored-data contract changes.

Label justifications:

  • P2: The defect affects recovery after an exceptional SQLite write failure, with a limited demonstrated blast radius.
  • 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. Sufficient (terminal): The PR reports before-and-after execution of the production transaction helper against native SQLite with an injected disk-full failure: the write rolls back, publication is suppressed, integrity remains valid and a later write succeeds on the retained handle. Its separate post-commit cases check fencing. The packaged Gateway quota replay did not run; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR reports before-and-after execution of the production transaction helper against native SQLite with an injected disk-full failure: the write rolls back, publication is suppressed, integrity remains valid and a later write succeeds on the retained handle. Its separate post-commit cases check fencing. The packaged Gateway quota replay did not run; no stored-data contract changes.

Evidence

What I checked:

  • Introduced recovery guard: The introduced branch retains an open connection only when no transaction remains before commit processing; otherwise rollback or fencing remains in place. (src/infra/sqlite-transaction.ts:414, d9575c92749e)
  • Native boundary regressions: The added cases force native SQLite disk-full rollback, check that staged publication is discarded and the same handle can write again, and check that failures after COMMIT still fence the handle. (src/infra/sqlite-transaction.test.ts:263, d9575c92749e)
  • Current main remains affected: The main-branch helper unconditionally attempts ROLLBACK after an operation error and fences the connection when that rollback fails; it lacks the proposed pre-commit distinction. (src/infra/sqlite-transaction.ts:402, a533ff8f836e)
  • Publication owner: Transaction-local state and deferred observers are discarded on rollback and published only after a successful outer transaction. (src/infra/sqlite-post-commit.ts:52, d9575c92749e)
  • Area history: Recent merged transaction-owner work is predominantly associated with Peter Steinberger, including prior nested-rollback handling. This supports review routing, not an exact-line introduction claim. (src/infra/sqlite-transaction.ts, 3d0254af02ba)
  • PR proof and limit: The captured PR body reports a failing-before, passing-after native SQLite disk-full regression, successful same-handle recovery and 29 transaction tests in 3.25 seconds. It expressly says the packaged Gateway quota replay did not execute.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@roboclaw-bot
roboclaw-bot enabled auto-merge (squash) September 24, 2026 12:39
@roboclaw-bot
roboclaw-bot merged commit 4d69dd0 into main Sep 24, 2026
280 of 281 checks passed
@roboclaw-bot
roboclaw-bot deleted the fix/release-quota-io-recovery-20260924 branch September 24, 2026 12:43
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash auto-merge.

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

Development

Successfully merging this pull request may close these issues.

1 participant