Skip to content

fix(sqlite-bun): read affected-row counts from run() result#52

Open
danfry1 wants to merge 3 commits into
mainfrom
fix/sqlite-bun-changes
Open

fix(sqlite-bun): read affected-row counts from run() result#52
danfry1 wants to merge 3 commits into
mainfrom
fix/sqlite-bun-changes

Conversation

@danfry1

@danfry1 danfry1 commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes a latent correctness bug in the reflow-ts/sqlite-bun adapter. bun:sqlite reports affected-row counts on the run() result object ({ changes, lastInsertRowid }), not on Database.changes (which is undefined on Bun). The adapter read this.db.changes, so several lease/durability guards never saw real row counts:

  • heartbeatRun always returned false → an active worker would appear to have lost its lease on every heartbeat.
  • updateRunStatus / updateClaimedRunStatus returned false even on success.
  • The claimNextRun double-claim guard (if (changes === 0) return null) never engaged → two workers could claim the same run under contention.

The fix reads the count from the statement result in all four methods. No behavioural change on the Node adapters.

Why it went unnoticed

The Node-based Vitest suite cannot load bun:sqlite, so the Bun adapter had zero automated coverage. This PR adds a Bun-native smoke test (scripts/smoke-bun-adapter.ts, bun run test:bun) that exercises the change-count paths, wired into the CI test job (which already runs under Bun). The smoke test fails on the pre-fix code and passes after.

Scope

Foundational fix on main. The in-flight feature PRs that touch the Bun adapter (#49 requeueRun, #51 sleepRun) are rebased on top of this so they inherit correct change detection rather than duplicating the fix.

Verified: typecheck, test (360), build, lint:deps, and test:bun all pass.

danfry1 added 3 commits June 21, 2026 21:37
bun:sqlite exposes change counts on the run() result object, not on
Database.changes (which is undefined). The bun adapter read the latter,
so heartbeatRun, updateRunStatus, updateClaimedRunStatus, and the
claimNextRun double-claim guard never reflected real row counts —
heartbeat always reported the lease lost, and the claim guard never
engaged (risking double-claims on Bun).

Read the count from the statement result instead. Adds a Bun-native
smoke test (bun run test:bun) wired into CI, since the Node-based Vitest
suite cannot load bun:sqlite and so never covered this adapter.
The coverage gate runs under Bun, where node:sqlite cannot load, so the
sqlite-node-builtin suite skips and the file is loaded-but-uncovered —
dragging the branch threshold down for any code added to it. It is fully
exercised by the dedicated node-sqlite CI job (on Node), so exclude it
from the Bun coverage run, exactly as sqlite-bun.ts already is (covered
by the bun smoke test).
The pull_request trigger filtered on base branches: [main], so a PR
targeting a not-yet-merged branch (a stacked PR) never ran CI. Drop the
base filter so every PR is checked.
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.

1 participant