Repository navigation
fix(sqlite): release settled writes behind read cursors - #169064
Conversation
Release data-writer custody when write-capable native operations and explicit transactions settle. Independent read cursors keep their snapshots without blocking session actor receipts across the whole agent database. Cover autocommit, commit, rollback, throwing transaction callbacks, and RETURNING cursor settlement with native regressions.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR releases settled SQLite write fences even when an independent read cursor remains open. Example: A connection pauses SELECT over rows 1 and 2, then commits INSERT of row 3.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a concrete write-fence leak still present on current main, preserves unfinished-write fencing, and introduces no actionable defect found in this review. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherNative SQLite operation observation feeds the physical-database admission owner, whose shared write receipts let sibling connections and session actors validate cached state. flowchart LR
A[SQLite statements and cursors] --> B[Native operation observer]
B --> C[Schema and mutation lifetimes]
C --> D[Database admission owner]
D --> E[Shared write receipts]
E --> F[Session actor reads]
Technical reviewBest possible solution: Land the focused native-owner repair with its transaction and unfinished-cursor regressions once required checks permit landing. Do we have a high-confidence way to reproduce the issue? Source establishes the parked-SELECT write-fence leak and the session actor rejection it causes; the author reports five failing-before/passing-after native cases, but this read-only review ran no code and does not independently reproduce the original Gateway incident. Is this the best way to solve the issue? The patch fixes settlement at the existing native owner using an established mutation counter, preserving explicit transactions, unfinished write cursors, schema lifetimes, and receipt publication ordering without retries or new state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4db95aa552f7. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -1, Tests +82, Docs +3. Total +84 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 11, 2026, 6:33 AM ET / 10:33 UTC. |
|
@clawsweeper approve Maintainer decision (coordinator for Peter, 2026-10-11): bug fix in in-memory database admission - releases a leaked write fence that wedged an agent until restart; no schema, stored data, or update behavior change. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
) Release data-writer custody when write-capable native operations and explicit transactions settle. Independent read cursors keep their snapshots without blocking session actor receipts across the whole agent database. Cover autocommit, commit, rollback, throwing transaction callbacks, and RETURNING cursor settlement with native regressions.
…1475 D2) After an errored turn, every later turn on cael's room session failed in about 100 ms with "Session actor has an unsettled database writer" until a Gateway restart. On 855242b a settled write on a connection that still holds a parked read cursor never releases its data-writer custody, so the database-wide fence wedges every session actor command on that agent database. Each actor turn here is a fresh durable acquisition over the real agent worker, like production turns. Fossil: a failed, committed, or autocommit write behind a parked cursor, then two later turns must commit. Controls at the same boundary: native entry-write and COMMIT failures settle so the same actor commits next, and a lost COMMIT+ROLLBACK or worker exit leaves the next turn working without replay. Also carries upstream's native owner regressions from openclaw#169064 (069a5b8) in sqlite-schema-facts.native.test.ts. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Carry openclaw#169064 (069a5b8, "fix(sqlite): release settled writes behind read cursors") unchanged. Data-writer custody is released when the connection has no active write-capable statement and no explicit transaction (mutationDepth), not only when every native statement on the connection has finished (nativeDepth). An independent read cursor, such as one an errored or aborted turn leaves parked, no longer keeps a settled write fencing every session actor on the agent database. Active write cursors and explicit transactions still hold their fence until settlement. No schema, stored data, or update behavior changes. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
First-parent upstream f4f4868..069a5b8 (11 commits: openclaw#168607 batch input acceptance and run adoption, 7158f2b, openclaw#168815, openclaw#168882 update and service lifecycle, ec5fe47, openclaw#169036 test batch d049, 4db95aa, cedb310 web-search split, openclaw#169056, openclaw#169061, and openclaw#169064 release settled writes behind read cursors). Conflicts: - user-turn-transcript.ts: upstream moved persistUserTurnTranscript into user-turn-transcript.persistence.ts. Our earlier line-cap move (user-turn-transcript.persist.ts) was a pure move, so it is retired in favour of upstream's module. Our session-delivery ack replacement is kept and now also refuses once upstream's committedInput is set (the same state upstream's hasPersisted counts). - agent-runner-execute.context-read.test.ts: both import additions kept. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… step 54 First-parent upstream cb1b6cd..19fe879: openclaw#168859 "refactor(infra): simplify database and worker coordination". Replaces the cold-admission predecessor graph with keyed top-level ordering, drops writer-preparation revocation (prepareSqliteDatabaseWriter and friends), borrower counts, worker ancestry and snapshot-staging supervision. No conflicts. None of the 20 exports it removes is referenced by fork code (only an upstream test-support local of the same name). Worker access inventory regenerated on the merged tree. This is the absorb target for #1475: openclaw#169064 (D2) arrived at step 50; the D5 producer (writer-prep revocation) is gone here. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…omes (#1475 D1) Carry adaptation for 454e86e on the 19fe879 absorb. The framed commit admission now carries `publication: turn ?? commitPublication` inside its outcome envelope, as the inline admission does since upstream openclaw#168607 and as upstream's own openclaw#169843 (ca0a172) shapes it. The host already hands `outcome.publication` to the caller's authority, so an oversized session's turn keeps its commit-stage custody recheck. No D2 code is involved; upstream openclaw#169064 is untouched. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
During a stability run on main
90f04bfb10df, every turn of one agent began failing 60-200 ms after dispatch withSession actor has an unsettled database writer. That included brand-new sessions; the transcript showed "Your request couldn't be completed", and nothing was logged before the first failure. It persisted until the Gateway restarted. Other agents (separate databases) kept working. While it was stuck, an externalBEGIN IMMEDIATE; ROLLBACKon that agent's database succeeded instantly, so SQLite held no write lock; the stuck state was in-process.Why This Change Was Made
src/infra/sqlite-schema-facts.tsreleased a settled write's shared data fence (finishSqliteDatabaseWrite) only when the handle'snativeDepthreached zero.nativeDepthalso counts a SELECT iterator parked between yielded rows (sqlite-native-observer.ts). A write could therefore settle completely while an unrelated reader stayed open on the same connection, and its writer registration stayed in the shared cell. Siblings then read an undefined scoped write token, and the session actor (session-actor.worker.ts) refuses every session that shares that database.The data fence now follows the existing
mutationDepthcounter, which tracks data, schema, and control operations. Explicit transactions and unfinishedRETURNINGcursors keep their fence until settlement; read-snapshot and schema lifetimes keep theirnativeDepthowner. No retries, timeouts, caches, or new state. The faulty condition dates to1d76f57d4be5(#167965); the strict actor read that turns it into a hard failure arrived with #168602 and became the transcript path in #168539.The exact production reader that was parked during the incident was not identified. This change fixes the demonstrated leak at the native owner that matches every observed symptom.
User Impact
An agent can no longer get stuck failing every message until a Gateway restart because an unrelated read was open when a write settled.
Evidence
RETURNING-cursor settlement (which stays fenced).chat.send: 6/6 delivered.docs/reference/database-schemas.mddescribes the corrected fence lifetime. No schema, stored data, protocol, or update behavior change.pnpm check:max-lines-ratchetflags unchangedsrc/web-search/runtime.test.ts.