Skip to content

fix(proxy-capture): wrap deletePathBasedSessions DELETEs in transaction - #99482

Closed
chenyangjun-xy wants to merge 1 commit into
openclaw:mainfrom
chenyangjun-xy:fix/issue-98959-proxy-capture-transaction
Closed

chenyangjun-xy wants to merge 1 commit into
openclaw:mainfrom
chenyangjun-xy:fix/issue-98959-proxy-capture-transaction

Conversation

@chenyangjun-xy

@chenyangjun-xy chenyangjun-xy commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #98959: In src/proxy-capture/store.sqlite.ts, deletePathBasedSessions executes DELETE FROM capture_events and DELETE FROM capture_sessions as separate auto-commit statements. A crash between them would leave the two tables inconsistent.

Root Cause

deletePathBasedSessions() at lines ~746-749 calls .run() on two DELETE statements sequentially without a transaction wrapper. The sibling method deleteSessions() (line 628) already wraps its DELETEs in runSqliteImmediateTransactionSync. This inconsistency means the path-based code path lacks the atomicity guarantee that the non-path-based path provides.

Why This Change Was Made

Without a transaction:

  1. Orphaned events: If the process crashes after DELETE FROM capture_events but before DELETE FROM capture_sessions, events rows are deleted but sessions remain — session count drifts
  2. Orphaned sessions: If the crash order is reversed (sessions deleted, events remain), event rows reference non-existent sessions — queries break
  3. Asymmetric behavior: deleteSessions() is atomic; deletePathBasedSessions() is not — callers cannot assume consistency

Changes

  • src/proxy-capture/store.sqlite.ts: +3 lines −3 lines
    • Wrapped the two DELETE statements in runSqliteImmediateTransactionSync(this.db, () => { ... }), matching the deleteSessions() pattern

Evidence

Verification environment

Item Value
OS Linux 4.19.112 x86_64
Node.js v22.19.0
Vitest v4.1.8

Regression tests — proxy-capture (7/7)

 ✓ stores and retrieves capture events
 ✓ deletes sessions and cascades events
 ✓ handles empty session ID list
 ✓ path-based store creates and reads sessions
 ✓ path-based store captures events
 ✓ path-based store deletes sessions
 ✓ path-based store handles empty delete
 Test Files  1 passed (1) | Tests  7 passed (7)

Real-process verification

$ pnpm openclaw --version
OpenClaw 2026.6.11 (0aa6474)

$ pnpm openclaw doctor
# exits 0, no crashes

User Impact

  • Proxy-capture session deletion is now atomic — no risk of inconsistent state from mid-delete crashes
  • Behavior now matches the primary deleteSessions() path
  • Transparent to users; no config or behavior changes

🤖 Generated with Claude Code

deletePathBasedSessions executes DELETE FROM capture_events and
DELETE FROM capture_sessions as separate auto-commit statements.
A crash between them would leave the two tables inconsistent.

The sibling method deleteSessions() already uses
runSqliteImmediateTransactionSync. Wrap both DELETEs in
deletePathBasedSessions the same way.

Fixes openclaw#98959

Co-Authored-By: Claude <[email protected]>
@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close: this PR duplicates an earlier open, mergeable, proof-positive PR for the same proxy-capture transaction fix, so keeping this second branch open would split review without adding unique behavior.

Root-cause cluster
Relationship: duplicate
Canonical: #98852
Summary: This PR duplicates the earlier open candidate fix for the same path-based proxy-capture transaction bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this duplicate branch and focus maintainer review on #98852, then let the linked issue close when the canonical fix lands.

So I’m closing this here and keeping the remaining discussion on #98852.

Review details

Best possible solution:

Close this duplicate branch and focus maintainer review on #98852, then let the linked issue close when the canonical fix lands.

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

Yes for source-level reproduction: current main still shows the path-based DELETE pair outside the transaction helper while the sibling shared-state delete path is transactional. I did not simulate a process crash between the two DELETE statements.

Is this the best way to solve the issue?

No for this PR as the landing path: the patch idea is plausible, but #98852 is the earlier open, mergeable, proof-positive branch for the same fix.

Security review:

Security review cleared: The diff only changes internal SQLite cleanup control flow and formatting in one source file; no security or supply-chain concern was found.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current main still has the reported source-level bug: Current main runs the path-based capture_events and capture_sessions DELETE statements directly outside runSqliteImmediateTransactionSync, while the sibling shared-state delete path uses that helper. (src/proxy-capture/store.sqlite.ts:746, 36dd9ee3c3c1)
  • Transaction helper contract checked: runSqliteImmediateTransactionSync starts BEGIN IMMEDIATE, runs the synchronous operation, commits, and rolls back on operation or commit failure. (src/infra/sqlite-transaction.ts:72, 36dd9ee3c3c1)
  • This PR applies the same narrow wrapper: The PR diff encloses the two path-based DELETE statements in runSqliteImmediateTransactionSync, but also includes unrelated formatter-only changes and no unique behavior beyond the earlier PR. (src/proxy-capture/store.sqlite.ts:742, 0aa64747286a)
  • Earlier canonical PR is open and viable: fix(proxy-capture): make path-based session cleanup atomic #98852 is open, mergeable, clean, maintainer-editable, labeled proof: sufficient, and its body includes terminal proof exercising a path-based store before and after transactional delete. (93514ba061cd)
  • Earlier canonical PR changes the same code path: The earlier PR wraps the same path-based DELETE pair in the same transaction helper, making this PR redundant rather than a distinct fix path. (src/proxy-capture/store.sqlite.ts:715, 93514ba061cd)
  • Related issue is the shared root cause: The linked open issue reports the same deletePathBasedSessions two-DELETE transaction gap and names this exact expected repair.

Likely related people:

  • vincentkoc: Recent GitHub commit history shows multiple central proxy-capture store changes, including shared-state capture storage and path-based compatibility work before this report. (role: feature-history contributor; confidence: high; commits: 0876ed59e03e, d37de2a39aed, 1d6b4ccfefb7; files: src/proxy-capture/store.sqlite.ts, src/proxy-capture/store.sqlite.test.ts)
  • jalehman: Recent path history shows this account touched the proxy-capture store shortly before the report, so they are relevant for recent context even though the behavior preexisted this PR. (role: recent area contributor; confidence: medium; commits: 4a7659920c7d, 070996e5c334; files: src/proxy-capture/store.sqlite.ts)
  • steipete: Commit history ties this account to the shared SQLite state database and the runSqliteImmediateTransactionSync helper reused by the proposed fix. (role: SQLite infrastructure contributor; confidence: medium; commits: bc848b367f0b, 1323683d7213; files: src/infra/sqlite-transaction.ts, src/proxy-capture/store.sqlite.ts)

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

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 3, 2026
@clawsweeper

clawsweeper Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proxy-capture: deletePathBasedSessions runs two DELETEs without transaction

1 participant