Skip to content

Fix SQLite client locking defaults - #7162

Merged
tim-smart merged 3 commits into
mainfrom
agent/sqlite-client-defaults
Aug 9, 2026
Merged

Fix SQLite client locking defaults#7162
tim-smart merged 3 commits into
mainfrom
agent/sqlite-client-defaults

Conversation

@tim-smart

@tim-smart tim-smart commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a configurable SQLite busy timeout to the Node and Bun clients, defaulting to 5 seconds
  • clamp infinite and oversized durations to SQLite's maximum timeout
  • start explicit SQLite transactions with BEGIN IMMEDIATE to avoid snapshot upgrade failures
  • cover the timeout default, override and infinity, immediate transaction locking, and readonly transactions
  • document the synchronous busy-wait and transaction-serialization trade-offs and add a patch changeset

Why

Concurrent workflow runner and control-plane clients can contend for the same SQLite store. A zero busy timeout fails ordinary lock contention immediately, while deferred transactions can fail when upgrading a read snapshot to a writer. Waiting for locks and acquiring the write lock at transaction start avoids both failure modes.

Because both SQLite drivers are synchronous, busy waits block the event loop. The configurable timeout lets applications choose a shorter wait, while the 5-second default preserves safe out-of-the-box behavior. Immediate transactions on writable connections serialize behind other writers even when they only read; clients opened with readonly: true are unaffected.

Validation

  • pnpm vitest run --project @effect/sql-sqlite-node (60 tests)
  • bun node_modules/vitest/vitest.mjs run --project @effect/sql-sqlite-bun (4 tests)
  • package typechecks for @effect/sql-sqlite-node and @effect/sql-sqlite-bun
  • pnpm lint
  • pnpm changeset status

Closes EFF-577
Closes #6179

@changeset-bot

changeset-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e4eda0b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-node Patch
effect Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openai-compat Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node Patch
@effect/platform-node-shared Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Aug 9, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one rough edge worth documenting.

Reviewed changes — reviewed PR #7162, which hard-codes a 5-second SQLite busy timeout and BEGIN IMMEDIATE transaction start into the Node and Bun SQLite clients, adds client-level regression tests for both defaults, and ships a patch changeset.

  • busy timeout defaultPRAGMA busy_timeout = 5000 runs at connection setup in both clients, before WAL mode is enabled.
  • immediate transactions — both clients now pass beginTransaction: "BEGIN IMMEDIATE" to the shared SqlClient.make, so withTransaction acquires the write lock at transaction start, avoiding deferred-snapshot upgrade failures.
  • regression tests — "uses a 5 second busy timeout" and "starts transactions immediately" in each client; the latter contends two clients on one file using a 1ms busy timeout to fail fast.
  • changeset — patch bump for both packages.

Validated on this checkout: the full @effect/sql-sqlite-node suite (59 tests) passes, and the "starts transactions immediately" test fails when BEGIN IMMEDIATE is reverted, confirming it genuinely pins the new behavior. I also probed node:sqlite directly: BEGIN IMMEDIATE succeeds on read-only connections (no readonly regression) and contended lock acquisition honors busy_timeout.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/sql/sqlite-node/src/SqliteClient.ts
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.92 KB 6.92 KB 0.00 KB (0.00%)
batching.ts 9.72 KB 9.72 KB 0.00 KB (0.00%)
brand.ts 6.60 KB 6.60 KB 0.00 KB (0.00%)
cache.ts 10.59 KB 10.59 KB 0.00 KB (0.00%)
config.ts 20.91 KB 20.91 KB 0.00 KB (0.00%)
differ.ts 19.77 KB 19.77 KB 0.00 KB (0.00%)
http-client.ts 21.52 KB 21.52 KB 0.00 KB (0.00%)
logger.ts 10.81 KB 10.81 KB 0.00 KB (0.00%)
metric.ts 8.86 KB 8.86 KB 0.00 KB (0.00%)
optic.ts 6.68 KB 6.68 KB 0.00 KB (0.00%)
pubsub.ts 14.86 KB 14.86 KB 0.00 KB (0.00%)
queue.ts 11.54 KB 11.54 KB 0.00 KB (0.00%)
schedule.ts 10.71 KB 10.71 KB 0.00 KB (0.00%)
schema-class.ts 19.48 KB 19.48 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.41 KB 29.41 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.63 KB 25.63 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.55 KB 13.55 KB 0.00 KB (0.00%)
schema-string.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.38 KB 15.38 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 21.52 KB 21.52 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.00 KB 24.00 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.74 KB 18.74 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.57 KB 18.57 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.43 KB 18.43 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.59 KB 22.59 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.08 KB 19.08 KB 0.00 KB (0.00%)
schema.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
stm.ts 12.59 KB 12.59 KB 0.00 KB (0.00%)
stream.ts 9.67 KB 9.67 KB 0.00 KB (0.00%)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — re-reviewed #7162 against the delta of the prior Pullfrog review (3a59c29701d95f, "Address SQLite client review"):

  • configurable busyTimeout — both SqliteClientConfigs gain a busyTimeout?: Duration.Input option, applied at connection setup via PRAGMA busy_timeout = ${Duration.toMillis(...)}; defaults stay at 5 seconds. Duration.toMillis accepts Duration.Input, so string/number durations type-check and run correctly.
  • documented trade-offs — module and make() JSDoc in both clients now state that busy waits block the event loop (sync drivers) and that BEGIN IMMEDIATE makes read-only transactions serialize behind other writers; the prior review's request to call this out explicitly is addressed, and the concurrency consequence now has an escape hatch.
  • regression tests — the "uses a 5 second busy timeout" tests now also pin the override (busyTimeout: "1 second"[{ timeout: 1000 }], which would fail if the knob weren't wired), a new node "supports transactions on readonly clients" test guards the readonly + BEGIN IMMEDIATE interaction, and the bun readonly test gained a withTransaction read.
  • changeset — description expanded to reflect the configurable timeout and the event-loop/serialization trade-offs.

Validated on this checkout: the full @effect/sql-sqlite-node Client suite (8 tests) passes, including the new override and readonly-transaction tests. The prior feedback thread is resolved.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — re-reviewed #7162 against the delta since the prior approved Pullfrog review (701d95fe4eda0b, "Handle infinite SQLite busy timeouts"):

  • clamped busy timeout — both Node and Bun clients now clamp busyTimeout via Math.min(MAX_BUSY_TIMEOUT, Math.max(0, Math.round(Duration.toMillis(...)))), mapping Duration.infinity, negative, and oversized durations to SQLite's signed-32-bit maximum 2_147_483_647.
  • JSDoc — both SqliteClientConfig docs note that Duration.infinity is clamped to SQLite's maximum timeout.
  • regression tests — the node and bun "uses a 5 second busy timeout" tests now also assert busyTimeout: Duration.infinity[{ timeout: 2_147_483_647 }].

Validated on this checkout: the @effect/sql-sqlite-node Client suite (8 tests) passes. I also probed node:sqlite directly: without the clamp, PRAGMA busy_timeout = Infinity silently parses to 0 (no waiting at all), while 2147483647 round-trips — so the new test genuinely pins the clamp and the change fixes a real silent-misconfiguration edge case for Duration.infinity.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@tim-smart
tim-smart merged commit c30386d into main Aug 9, 2026
20 checks passed
@tim-smart
tim-smart deleted the agent/sqlite-client-defaults branch August 9, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite-backed workflow runner storage becomes unhealthy under concurrent runner/control-plane access

1 participant