Skip to content

refactor: remove redundant SQLite lease-release transactions - #176500

Merged
steipete merged 2 commits into
mainfrom
dbasync/txnelide-release
Oct 18, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/txnelide-release

Conversation

@steipete

@steipete steipete commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Lease cleanup wraps a single exact-owner DELETE in a SQLite transaction, adding BEGIN IMMEDIATE and COMMIT to ordinary release and Gateway shutdown.

User Impact

No public API, configuration, schema, or lease ownership behavior changes. Eligible SQLite releases execute fewer statements while retaining nonblocking lock handling and cleanup retries.

Why This Change Was Made

The release owner knows the complete operation before writing: its conditional DELETE returns no payload. Native release uses the existing single-statement publication helper. Worker release obtains final admission and validates the physical database before the terminal DELETE; the deleted transaction-stage handshake and post-write identity check cannot reject an already committed release. The exact-owner predicate preserves a successor that acquires the row before cleanup.

Acquisition, renewal, existing-schema storage, compound startup work, and PostgreSQL retain their transactions. Gateway release retains its existing lifecycle custody and heartbeat shutdown checks. No generic envelope inference or new fallback is introduced. A standalone DELETE retains SQLite's statement atomicity; a nested caller retains its outer transaction owner.

Evidence

  • Owner regressions cover final-admission refusal and physical-identity mismatch before any DELETE, replacement-owner preservation, committed visibility through a peer connection, and nonblocking lock failures/cleanup retry exhaustion.
  • Source estimate: each eligible release changes from 3 to 1 SQL statements with no worker-request saving. The census contains three such releases (the first warm turn and both shutdowns), or six envelope statements. Estimated, unmeasured. Per-PR runs were blocked by the shared SSD stalls; the coordinator-approved combined SQLite census will measure the integrated changes.
  • Both Codex review rounds found no actionable P0–P2 findings, including the final test-only repair at 605d56f. Changed-file formatting, type-aware lint, and diff checks pass. Initial CI 39167728492 exposed an ineffective parent-thread observer in the delayed-cleanup fixture: cleanup executes in the worker, so that spy cannot observe its DELETE. The duplicate case and observer are removed; direct lock/refusal/successor coverage, retry-budget checks, and retained-cleanup coverage remain. Production code is unchanged by this repair.
  • Production +50/−17 lines (net +33); tests +97/−23. Growth is the owner-specific dispatch and regression coverage; the generic transaction policy stays unchanged.
  • Two local runtime attempts stalled in filesystem rename; neither supplies a test pass or measurement. The read-only SSD wait was stopped without starting another build or workload. PR CI supplies the focused owner tests and broader checks. The published-driver update cell passed on the identical production code at a8b3181. PostgreSQL/identity review approved the exact 605d56f head; the PostgreSQL transaction and admission sequence remain unchanged. Final PR CI completed with the three behavioral failures described below; all PostgreSQL and static jobs passed. The incomplete local full-tree scan timed out at its standard limit; its queued retry never started. The completed same-revision CI scan reports 58 production / 35 full-tree / 0 script export findings, all matching scheduled main (59 / 37 / 0). The other dependency and unused-file findings also match main; no new findings. The remaining supplemental run was cancelled after the required scan completed; terminal cancellation is confirmed, and the supplemental run is not claimed green.

Supplemental CI also reports an unchanged UI bundle budget failure (base and candidate both 1,494,580 bytes, +0 bytes) and the Swedish translation-memory failure seen in scheduled main 39163574553/job/117782015543. These are recorded separately from the lease owner and static proof; no UI source is changed.

The final ordinary CI run reports three failing shards: backup config capture rejects a retired snapshot staging token; session-recovery teardown finds an active native database borrower; and update-status SQLite-safety fixtures do not receive their expected refusal. Recovery teardown is independently reproduced on scheduled main 39172446197/job/117808338765, and both unsafe-SQLite fixture failures match main 39172446197/job/117808338666. Both are inherited and routed for repair. The backup-staging failure is diagnosed as cross-file shared-temp fixture interference, as detailed below; it is not claimed to have reproduced on main. The tested CI merge is 36f9eebc8df7e89cee22900c38160e6fb168264b, combining main dbe55cc with the reviewed head. A focused Linux Testbox compares those exact revisions under Node 24.19.0; this is supplemental because the failing CI shards use Bun. Both revisions passed the selected backup and recovery cases under Node, and both failed the unsafe-SQLite fixture with the same assertion. The lease was stopped and cleanup verified. A separate focused comparison of the failed backup file under checksum-pinned Bun was cancelled because the requested Testbox remained queued without an assigned host. No Bun test ran. The original failure in src/infra/backup-config-capture.test.ts overlaps src/infra/backup-create.test.ts. Both use chooseBackupTempRoot() → os.tmpdir(): createBackupArchive() runs maintainBackupScratch({ repair: true }), which can retire a sibling’s newly created scratch directory before createBackupScratchDirectory() acquires its staging token after awaited directory/identity work. The existing scratch-refusal regression preserves that refusal. The exact CI main and merge cases both pass under Node. The maintainer accepted this diagnosis as unrelated to lease release and explicitly authorized landing this head; a separate fixture-only PR will isolate backup temp roots. No backup product code or assertion is changed here, and the failed Bun CI result is not relabeled green.

@clawsweeper

clawsweeper Bot commented Oct 18, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T22:07:14.760236Z 605d56f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@clawsweeper

clawsweeper Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR removes explicit SQLite transaction envelopes around eligible exact-owner lease deletions.

Example: Release the synthetic lease release owned by original-owner.

  • Before: The exact-owner DELETE runs inside BEGIN IMMEDIATE and COMMIT.
  • After: The same DELETE commits as one atomic statement after final admission.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The production approach is focused, but the introduced regression fails exact-head CI and runtime savings remain unmeasured.
Proof confidence 🦪 silver shellfish (2/6) This maintainer-authored PR is outside the ordinary contributor-proof gate; its body explicitly reports unsuccessful runtime attempts, and predecessor verification does not prove this head.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Lease release and Gateway shutdown perform unnecessary explicit transaction statements around a single conditional deletion.
Reason: The maintainer-directed change reuses an existing autocommit contract without adding configuration, storage formats, or competing lifecycle ownership.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-directed optimization is focused, but its new delayed-cleanup assertion fails on the reviewed head and needs a fixture repair.

Priority: P3
Reviewed head: a8b3181359c86e748204b5fa914849b6575fd087

Before merge

  • Inject the delayed-cleanup failure where the DELETE actually runs (P2) - For the undefined-schema delayed-cleanup case, withOpenClawStateLease routes release through createOpenClawStateLeaseWorkerStorage, so the parent thread's StatementSync.prototype.run spy never sees the cleanup DELETE. Consequently delayedCleanupFailures remains zero and the new assertion fails; exact-head CI confirms expected 1 versus received 0. Repair the fixture to induce and observe a failed release in its actual execution context, retaining the cleanup-exhaustion coverage rather than dropping the assertion.

Findings

  • [P2] Inject the delayed-cleanup failure where the DELETE actually runs — src/state/openclaw-state-lease-contention.test.ts:117

Tests

  • Missing end-to-end proof: No successful exact-head Gateway release/shutdown trace or measured before/after run is supplied; the maintainer-authored contributor-proof exemption applies.
Agent review details

How this fits together

Lease lifecycle owners coordinate shared-state access and Gateway ownership; release requests pass through database admission and remove only the matching owner's lease row.

flowchart TD
  A[Lease lifecycle owner] --> B[Release dispatch]
  B --> C[Worker final admission]
  B --> D[Native database admission]
  C --> E[Exact owner DELETE]
  D --> E
  E --> F[Cleanup settlement]
Loading

Technical review

Best possible solution:

Keep the existing owner-qualified autocommit path and repair the delayed-cleanup fixture so it actually exercises failed release and retained cleanup.

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

Source confirms the redundant release envelopes, and exact-head hosted CI independently records the introduced assertion failure; no target code was executed during this review.

Is this the best way to solve the issue?

Using the existing single-statement publication owner is appropriate because release is one conditional DELETE; compound operations and PostgreSQL retain their existing transaction owners.

Full review comments:

  • [P2] Inject the delayed-cleanup failure where the DELETE actually runs — src/state/openclaw-state-lease-contention.test.ts:117
    For the undefined-schema delayed-cleanup case, withOpenClawStateLease routes release through createOpenClawStateLeaseWorkerStorage, so the parent thread's StatementSync.prototype.run spy never sees the cleanup DELETE. Consequently delayedCleanupFailures remains zero and the new assertion fails; exact-head CI confirms expected 1 versus received 0. Repair the fixture to induce and observe a failed release in its actual execution context, retaining the cleanup-exhaustion coverage rather than dropping the assertion.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5f63135f917a.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/state/openclaw-state-lease-contention.test.ts --maxWorkers=1
  • pnpm test src/state/openclaw-state-lease-diagnostics.test.ts --maxWorkers=1
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4c314b3 adds src/state/openclaw-state-lease-store.ts:89 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4c314b3e8305; files: src/state/openclaw-state-lease-store.ts)

PR surface

Source +33, Tests +99. Total +132 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 50 17 +33
Tests 2 121 22 +99
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 171 39 +132

Review metrics

Metric Value Why it matters
Production versus test changes Production +50/-17; tests +121/-22 Production growth propagates the existing single-statement contract through release owners; test growth covers distinct admission, identity, replacement-owner, and contention boundaries.

Labels

Label changes:

  • add P3: This is a bounded database-overhead optimization with a concrete test-fixture blocker and no established production failure.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P3: This is a bounded database-overhead optimization with a concrete test-fixture blocker and no established production failure.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 October 18, 2026, 5:39 PM ET / 21:39 UTC.

@steipete
steipete merged commit 1c07fde into main Oct 18, 2026
317 of 402 checks passed
@steipete
steipete deleted the dbasync/txnelide-release branch October 18, 2026 23:05
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…w#176500)

Obtain final admission and validate database identity before the terminal exact-owner SQLite DELETE. Preserve PostgreSQL, acquisition, renewal, compound transactions, and nonblocking cleanup behavior.

Validation: focused lease regressions, static gates, PostgreSQL conformance and review, published-driver update proof, and two Codex review rounds complete. Recovery/update CI failures match scheduled main. Maintainer accepted the separately diagnosed backup shared-temp fixture interference; fixture isolation follows in a separate change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S 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