Skip to content

fix(objectql): robust multi-write transactions (ambient transaction) + cross-object batch (#1604)#1607

Merged
xuyushun441-sys merged 2 commits into
mainfrom
feat/tx-ambient-fix
Jun 6, 2026
Merged

fix(objectql): robust multi-write transactions (ambient transaction) + cross-object batch (#1604)#1607
xuyushun441-sys merged 2 commits into
mainfrom
feat/tx-ambient-fix

Conversation

@xuyushun441-sys
Copy link
Copy Markdown
Contributor

Implements ADR-0034, unblocks #1604. Root cause: engine.transaction() threaded the transaction only into the top-level write; internal queries during a write grabbed another pool connection and deadlocked on SQLite's single-connection pool. Fix: AsyncLocalStorage ambient transaction — buildDriverOptions falls back to it so every data op binds to the same connection. Plus POST /api/v1/data/batch (cross-object, $ref parent refs). Tests: engine + driver multi-write guards; objectql 521 / rest 88 / driver-sql 137 green; verified e2e (atomic create + rollback + no wedge).

🤖 Generated with Claude Code

os-zhuang and others added 2 commits June 6, 2026 15:18
…deadlock

Root cause (ADR-0034): engine.transaction() threaded the open transaction only
into the top-level write's driver options; internal queries during a write
(reference checks, hooks, expand) asked the pool for another connection and
deadlocked on SQLite's single-connection pool — wedging the connection.

Fix: an AsyncLocalStorage ambient transaction store. While a transaction()
callback runs, the active transaction lives in the store; buildDriverOptions
falls back to it, so EVERY data op (even one given no explicit context) binds
to the same connection. Explicit context still wins. Both ObjectQL.transaction
and ScopedContext.transaction set the store.

Also adds the cross-object transactional batch endpoint (POST /batch, issue
#1604) with intra-batch $ref parent references, now that multi-write is safe.

Tests: engine ambient-transaction guard + driver multi-write commit/rollback
guard. Full suites green (objectql 521, rest 88, driver-sql 137). Verified
end-to-end: master-detail atomic create + rollback + no connection wedge.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Building Building Preview, Comment Jun 6, 2026 7:21am

Request Review

@xuyushun441-sys xuyushun441-sys merged commit 345e189 into main Jun 6, 2026
7 of 8 checks passed
@xuyushun441-sys xuyushun441-sys deleted the feat/tx-ambient-fix branch June 6, 2026 07:21
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling and removed size/m labels Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants