Skip to content

fix(storage): dispose SQLite connections after rollback observer failures - #162139

Merged
steipete merged 1 commit into
mainfrom
codex/sqlite-execution-settlement-canonical-20260930
Oct 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sqlite-execution-settlement-canonical-20260930

Conversation

@steipete

@steipete steipete commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Related: #144592

What Problem This Solves

A throwing rollback observer could leave an unsafe SQLite connection open after native rollback failed, skip remaining observers, and hide the original transaction failure.

User Impact

Rollback observers drain in reverse order even when one throws. Failed native rollback still clears the cached database facade and disposes the connection, and later reuse reports the retained transaction/observer failure. When SQLite has already rolled back automatically, observer failure does not incorrectly trigger unsafe-connection disposal.

Schemas, stored data, retention, permissions, successful commit publication, and installed update behavior are unchanged.

Why This Change Was Made

The rollback owner collects observer failures while draining every observer. Connection disposal runs in finally, and the transaction fence retains the aggregate error for enclosing and later callers. Automatic rollback handling sits outside the native ROLLBACK failure handler so an observer error is not mistaken for failed native cleanup.

This PR is narrowed to two production files and their owning transaction tests: production +45/-20, net +25 lines. The larger broker/native-lifecycle work and callback/provisional machinery are deferred until they have a production consumer.

Evidence

  • Baseline 5381128b68b26dd988514958b6e445a55f782d67: node scripts/run-vitest.mjs src/infra/sqlite-transaction.test.ts -t 'automatic rollback|disposes failed' --maxWorkers=1 produced four expected failures and four passing controls (13.01s runner wall). Three failures leave the connection open; one loses the observer aggregate.
  • Candidate: node scripts/run-vitest.mjs src/infra/sqlite-transaction.test.ts --maxWorkers=1 passed all 33 cases; 8.47s process wall, 7.02s runner wall. The tests cover native automatic rollback, failed rollback/savepoint cleanup, reverse observer order, cache clearing before close, and retained failure on reuse.
  • Core production types passed in 39.30s, infra test types in 13.91s, and scoped typed lint in 15.85s. Formatting and git diff --check passed.
  • Independent Codex branch review against the pinned merge base completed with no actionable P0-P2 findings. Line-cap, max-lines, and assertion-safety ratchets and the core type boundary passed.

The existing test/scripts/pr-worktree-provision.test.ts case native PR source provisioning > materializes full cold/warm PR siblings, then preserves native sparse transitions has a separate Darwin no-output fixture issue: consecutive synchronous wrapper calls prevent timely reporter output. The changed-test planner selects this file on Ubuntu, where that case is skipped; this diff enables neither macOS CI lane. Focused SQLite qualification does not invoke it. Broad local test:changed on macOS would. Its deadlines and assertions are unchanged.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: XL labels Sep 30, 2026
@steipete
steipete marked this pull request as ready for review September 30, 2026 21:32
@clawsweeper

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

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: 042bd837806a353c956b3222ce6c4a6b12190b78

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 1:01 AM ET / 05:01 UTC (Revision 3).

ClawSweeper review

What this changes

The PR drains all SQLite rollback observers, preserves their failures, and ensures failed native rollback still clears connection caches and attempts disposal.

Merge readiness

✅ Ready for maintainer review

The narrowed fix remains necessary and has no actionable correctness findings. Earlier authority and worker-finalizer concerns do not apply to the current introduced patch.

Priority: P2
Reviewed head: 042bd837806a353c956b3222ce6c4a6b12190b78

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with meaningful baseline-failing native SQLite regressions and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The trusted-author exemption applies under the supplied MEMBER repository state. Native SQLite regressions exercise the changed cleanup owner but remain supplemental test evidence; the removed authority and updater changes no longer require their earlier proof. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The trusted-author exemption applies under the supplied MEMBER repository state. Native SQLite regressions exercise the changed cleanup owner but remain supplemental test evidence; the removed authority and updater changes no longer require their earlier proof. No stored-data contract changes.
Evidence reviewed 8 items Introduced production repair: The pinned introduction delta adds complete reverse-order observer draining and aggregate errors, moves cache clearing and connection closure into finally, and separates automatic rollback from native ROLLBACK failure handling.
Current main still needs the repair: Current main invokes rollback observers before cache clearing and close, allowing an observer exception to skip disposal. Its automatic-rollback observer call also remains inside the native rollback failure handler.
Latest release retains the vulnerable sequence: The transaction helper published in v2026.9.7 still calls discardSqliteTransactionState before cache clearing and connection closure, without the new finally protection.
Findings None None.
Security None None.

How this fits together

OpenClaw’s SQLite transaction helpers coordinate database writes with staged in-memory state and notifications. When a transaction fails, they restore staged state and prevent unsafe connections from serving later writes.

flowchart TD
  A[Store operation] --> B[SQLite transaction]
  B --> C{Rollback outcome}
  C -->|Automatic rollback| D[Drain staged state]
  C -->|Native cleanup fails| E[Fence unsafe connection]
  E --> D
  D --> F[Preserve transaction and observer errors]
  E --> G[Clear caches and attempt close]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +25, Tests +92. Total +117 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 45 20 +25
Tests 1 165 73 +92
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 210 93 +117

Review metrics

Metric Value Why it matters
Production versus regression growth production net +25 LOC; tests net +92 LOC Production growth implements complete observer draining and guaranteed disposal attempts; the tests consolidate older cleanup checks into native SQLite failure cases.

Technical review

Best possible solution:

Keep rollback recovery in the existing transaction owner, preserving healthy handles after automatic rollback and fencing unsafe handles while retaining all cleanup failures.

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

Yes, from source: a throwing staged rollback callback interrupts unsafe-connection cleanup on current main. The captured baseline test results support that mechanism; no tests were executed during this read-only review.

Is this the best way to solve the issue?

Yes. Draining observers and protecting disposal in the existing cleanup owner is a focused repair that preserves automatic-rollback recovery and successful transaction behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0783e3f28d4e.

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: The trusted-author exemption applies under the supplied MEMBER repository state. Native SQLite regressions exercise the changed cleanup owner but remain supplemental test evidence; the removed authority and updater changes no longer require their earlier proof. No stored-data contract changes.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 security-boundary: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded SQLite failure path without evidence of an active widespread outage.
  • 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: The trusted-author exemption applies under the supplied MEMBER repository state. Native SQLite regressions exercise the changed cleanup owner but remain supplemental test evidence; the removed authority and updater changes no longer require their earlier proof. No stored-data contract changes.

Evidence

What I checked:

  • Introduced production repair: The pinned introduction delta adds complete reverse-order observer draining and aggregate errors, moves cache clearing and connection closure into finally, and separates automatic rollback from native ROLLBACK failure handling. (src/infra/sqlite-transaction.ts:344, 042bd837806a)
  • Current main still needs the repair: Current main invokes rollback observers before cache clearing and close, allowing an observer exception to skip disposal. Its automatic-rollback observer call also remains inside the native rollback failure handler. (src/infra/sqlite-transaction.ts:344, 0783e3f28d4e)
  • Latest release retains the vulnerable sequence: The transaction helper published in v2026.9.7 still calls discardSqliteTransactionState before cache clearing and connection closure, without the new finally protection. (src/infra/sqlite-transaction.ts, c074824a27c9)
  • Owning regression coverage: Inspected tests use real DatabaseSync handles for SQLITE_FULL automatic rollback and injected native cleanup failures. Assertions cover reverse observer order, suppressed publication, cache clearing before close, preserved error identity, integrity, and refused reuse. The captured PR body reports four baseline failures and all 33 candidate cases passing in 8.47 seconds process wall; this reviewer did not execute tests. (src/infra/sqlite-transaction.test.ts:263, 042bd837806a)
  • Verified merge result: The test merge records the pinned base parent followed by the exact PR head. Its production delta contains the same focused cleanup repair, with no removal of base-only behavior. (src/infra/sqlite-transaction.ts:344, 469c7bd3a07d)
  • Re-review scope and compatibility: The complete introduction delta contains only transaction cleanup and its tests. The earlier provisional authority, broker settlement, Plugin SDK, and updater changes are absent, so their historical proof requests no longer apply. No schema, serialized state, configuration, permission, successful-commit, or installed-update contract changes were found. (src/infra/sqlite-post-commit.ts:57, 042bd837806a)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-30T21:38:42.938Z sha 5f5d0bb :: blocked before merge. :: [P1] Bound native finalizers after an owner fails
  • reviewed 2026-09-30T22:28:58.012Z sha adea9fb :: needs real behavior proof before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

The failed-generation cleanup finding describes an intentional failure-path tradeoff. After a raw owner settlement fails, this change joins the other owners’ recorded native cleanup before throwing the original failures and retaining the runtime. It does not release that runtime. If a cleanup never settles, this failure path keeps waiting; we accept that availability cost rather than reporting completion while an owner’s cleanup remains outstanding. The existing ten-second policy is preserved for successful settlement followed by native termination. Applying it to failed settlement would change the selected contract. The actual regressions cover Error/undefined identity, successful sibling native joins, and a separately registered failing generation owner; they do not claim a deadline for stalled cleanup.

The persisted-table warning does not correspond to a data-model change. The two named files change worker execution and settlement plumbing; they introduce no table, column, schema version, migration, stored-byte, or retention change.

Commit 5f5d0bbe completed the normal package build, strict prepared-tar check, and the published 2026.9.4 custom-plugin-siblings upgrade with manual restart. The updater, sibling runtime checks, activation, health/readiness, and shutdown all passed; the package and all scenario evidence files were retrieved and hash-verified. The subsequent CI-only unused-export cleanup is now adea9fbf, with 144 selected owning tests, full deadcode checks, types/lint, and an independent review passing. Its exact artifact/upgrade proof is running separately, and merge remains unarmed. The original review report and failed CI attempt remain preserved.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 30, 2026
@steipete
steipete force-pushed the codex/sqlite-execution-settlement-canonical-20260930 branch from adea9fb to 042bd83 Compare October 1, 2026 04:48
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: XL labels Oct 1, 2026
@steipete steipete changed the title refactor(storage): retain SQLite execution through cleanup fix(storage): dispose SQLite connections after rollback observer failures Oct 1, 2026
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 1, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 1, 2026
@steipete
steipete merged commit 64ba9a7 into main Oct 1, 2026
266 of 270 checks passed
@steipete
steipete deleted the codex/sqlite-execution-settlement-canonical-20260930 branch October 1, 2026 05:04
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Oct 2, 2026
Consolidate admitted transcript query and transaction owners, preserve the first rollback failure during poisoned connection cleanup, and split oversized owner modules without dropping tests. Restore real worker lifetime observations and move timeout waits to test-owned cancellation with joined cleanup.

Preserve the rollback-error ownership from #162139 while retaining unconditional cache and native cleanup. No schema, protocol, or Code Mode capability expansion.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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