remove per-write doltCommit from bun adapter#1
Open
timsehn wants to merge 2 commits into
Open
Conversation
The DoltliteClientAdapter used to fire dolt_commit('-A','-m',...) after
every autocommit write to a tracked table, and again after every wrapped
transaction. This was the suspected cause of opencode's read-after-write
failure on session creation (lines 305-308 of the captured SQL log on
0.10.0): INSERT INTO session returns changes=1, four immediately
subsequent SELECT WHERE id=? return rows=0.
In addition, the inTx flag was only set by adapter.transaction(fn) —
code that called db.exec("BEGIN") directly (json-migration.ts) would
bypass the gate, so each tracked-table insert inside that raw
transaction would call doltCommit while the SQL transaction was still
open.
Both problems go away if the adapter stops trying to mirror SQL
transactions into dolt history. dolt_commit is now strictly explicit;
callers can snapshot at meaningful boundaries (shutdown, idle ticks,
user action) instead of paying it on every write.
The adapter is now a thin polyfill that adds the two methods
drizzle-orm/bun-sqlite expects but @dolthub/doltlite doesn't expose:
client.transaction(fn).immediate() and stmt.values().
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The db query / db migrate / interactive shell paths all opened the database via bun:sqlite directly, which doesn't recognize doltlite's content-addressed file format — every invocation failed with "file is not a database". Switch: - db [query]: use @dolthub/doltlite's DatabaseSync (read-only) and print rows in either tsv or json format - db (no args): spawn the doltlite binary (same convention sqlite3 had, on $PATH) - db migrate: open via the bun adapter from db.doltlite.bun.ts so the drizzle bun-sqlite migrator gets a compatible client Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
DoltliteClientAdapterindb.doltlite.bun.tsused to firedolt_commit('-A','-m',…)after every autocommit write to a tracked table, and again after every wrapped transaction. This is the suspected cause of opencode's read-after-write failure on session creation (lines 305–308 of the captured SQL log on doltlite 0.10.0):INSERT INTO sessionreturnschanges=1, four immediately subsequentSELECT WHERE id=?returnrows=0.A secondary problem: the
inTxflag was only set insideadapter.transaction(fn). Code that calleddb.exec("BEGIN TRANSACTION")directly —json-migration.tsdoes this — bypassed the gate, so each tracked-table insert inside that raw transaction calleddoltCommitwhile the SQL transaction was still open.Both go away if the adapter stops trying to mirror SQL transactions into dolt history.
dolt_commitis now strictly explicit; callers can snapshot at meaningful boundaries (shutdown, idle ticks, user action) instead of paying it on every write.What's left in the adapter:
client.transaction(fn).immediate()— drizzle-bun-sqlite needs bun:sqlite's transaction shapestmt.values()— drizzle-bun-sqlite reads rows-as-arrays through thisThat's the entire surface drizzle-orm/bun-sqlite actually uses. 140 lines down to ~70.
Follow-up not in this PR
There is no automatic dolt snapshot anywhere now. A periodic + on-shutdown call to
Database.Client().$client.doltCommit(…)(or equivalent hook in opencode's lifecycle) would restore that, with the right cadence.Test plan
New
packages/opencode/test/storage/db-adapter.test.tspins the read-after-write contract through the same Drizzle entry points opencode uses:INSERT→SELECTsees the rowBEGIN IMMEDIATE/INSERT/COMMIT→ 4 retriedSELECTs (the exact failing pattern from the log) all returnrows=1BEGIN DEFERREDvariant — sameROLLBACKthrows and discards the insertBEGIN IMMEDIATEtransactions are all visible afterwardsExisting coverage:
db.test.ts:12, expectsopencode-local.dbvs current.ddb— is unrelated and pre-existed this branch)Database.transaction({behavior:"immediate"})→ projector → INSERT → COMMIT → SELECT path🤖 Generated with Claude Code