Skip to content

fix(db): return undefined for empty bun:sqlite .get() results - #14203

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.51from
Ercaner1988:fix/bun-sqlite-get-no-row-null
Sep 22, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.51from
Ercaner1988:fix/bun-sqlite-get-no-row-null

Conversation

@Ercaner1988

Copy link
Copy Markdown
Contributor

Summary

  • bun:sqlite's Statement.get() returns null when no row matches. better-sqlite3, node:sqlite and sql.js return undefined, and the rest of the code is written against that (get(...) as Row | undefined; isExclusiveConnectionActivelyLeased compares with !== undefined).
  • Under Bun the lease guard therefore reports every connection as exclusively leased. Observed on a Bun-run server (a v3.8.50 install; the same code is on release/v3.8.51): the dashboard connection test returned LEASE_ACTIVE (skipped, 0 ms) for every connection tried (antigravity and mistral), usage refresh was deferred with 409, and the model-sync scheduler logged No connections with autoSync enabled, while exclusive_connection_leases was empty and no API key had the lease:exclusive scope.
  • The Bun adapter now maps the no-row null to undefined, so all drivers share one contract. The change is confined to the best-effort Bun adapter; the Node drivers are untouched, and it does not change the runtime support policy (Node remains the supported runtime).
  • Checked on Bun 1.4.0 and 1.4.2: both return null for a .get() with no matching row.

Related Issues

Validation

Choose the change type and focused loop from the
Contribution Golden Path. The full unit suite,
Vitest, the 60% coverage gate, and the production build all run in CI on this PR (#8329):

  • Change type: DB (Bun adapter)
  • Focused tests and category gates from the golden path: check-db-rules passes; the test:bun:db file set (bunSqliteAdapter, driverFactory, cliSqlite) passes 24/24 on Bun 1.4.2. The two new tests failed before the change (actual: null, expected: undefined) and pass after it.
  • npm run lint: ESLint (repo config and suppressions) and Prettier were run on the two changed files and are clean. The full-repo lint is left to CI.
  • Reconciled with the current active release base: the branch was cut from the release/v3.8.51 tip (7a921299c, 2026-09-19).
  • Production-code changes include a new or updated automated test in this PR
  • SonarQube is temporarily opt-in while the private project has no quota; it is not a PR gate.

Tests Added Or Updated

  • tests/unit/db-adapters/bunSqliteAdapter.test.ts: two new tests. One uses a fake driver whose get() returns null, so it runs under any runtime, including the Node shards. The other runs against the real bun:sqlite and is skipped outside Bun (it is picked up by test:bun:db).

Coverage Notes

  • src/lib/db/adapters/bunSqliteAdapter.ts changes by one expression. The fake-driver test covers it on every runtime; the real-driver test covers it under Bun.
  • Not run locally: the Node unit shards, typecheck:core, the full-repo lint and the production build. CI runs them on this PR.

Reviewer Notes

  • ⚠️ base-red inherited: 🔴 Release branch not green: release/v3.8.51 #13866
  • The fix is at the adapter on purpose: the !== undefined checks and the | undefined typings elsewhere assume the shared contract, so normalizing once here covers every caller instead of patching call sites one by one.
  • No migration or feature flag.

bun:sqlite's Statement.get() returns null when no row matches, while
better-sqlite3, node:sqlite and sql.js return undefined. The call sites
are typed and written against undefined (`get(...) as Row | undefined`,
and isExclusiveConnectionActivelyLeased compares with `!== undefined`),
so when the server runs under Bun every connection looked exclusively
leased: dashboard connection tests reported LEASE_ACTIVE, usage refresh
was deferred with 409, and the model-sync scheduler found no connections
to sync.

Normalize the no-row result in the Bun adapter so all drivers share one
contract. Covered by a driver-independent unit test that runs in the
Node shards and a Bun-only test against the real bun:sqlite driver.
@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @Ercaner1988 — merging via the release merge-train. Validated in local merge-train (mt-train10c) on the devbox @ train tip 4d841aa1c740bbaa03868dc0a403c62099a99a42 with the 72 sibling PRs of this batch: typecheck:core, file-size, complexity, cognitive-complexity, changelog-integrity green; changed-area node:test 831/831 (0 failing) and vitest 480/482 — the two reds are autoCombo/provider-family-combos.test.ts timing out at 20s, which reproduces on the PURE release tip under the full vitest suite (and is already tracked by the Release-Green issue #13866), so it is inherited, not this batch's. Merged --admin per merge-gates §3/§4/§7.

@diegosouzapw
diegosouzapw merged commit 0fcac56 into diegosouzapw:release/v3.8.51 Sep 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants