Repository navigation
fix(spec, objectql, driver-sql): a predicate delete with a cascade locks the rows it walks - #34517
Conversation
…ws inside the unit of work The cascade arm reads the matched ids, walks the cascade, then deletes by id, so the caller's predicate never reaches the DELETE. Inside the unit of work, a driver declaring the new DriverCapabilities.lockRows now takes that read with the new DriverOptions.lockRows (SELECT ... FOR UPDATE in driver-sql), so no concurrent commit can move a matched row out of the predicate before the delete. Claude-Session: https://claude.ai/code/session_01ADHkmRukLEFGv24PSBTaHb Co-authored-by: Claude <noreply@anthropic.com>
…scade arm's locked read Claude-Session: https://claude.ai/code/session_01ADHkmRukLEFGv24PSBTaHb Co-authored-by: Claude <noreply@anthropic.com>
…ction answers Claude-Session: https://claude.ai/code/session_01ADHkmRukLEFGv24PSBTaHb Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmRukLEFGv24PSBTaHb Co-authored-by: Claude <noreply@anthropic.com>
…usal pins Claude-Session: https://claude.ai/code/session_01ADHkmRukLEFGv24PSBTaHb Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 20 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 5 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 176 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin b41c5a46ba3de65f602412554577e66c7a7720e1 && git checkout b41c5a46ba3de65f602412554577e66c7a7720e1
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 631d77f3021ca00e36a3cb51e19a4d8ee361fdc6 e689bd7db84b327b38a84f80d1c913899b1a0ff2 && git checkout -B drift-repro 631d77f3021ca00e36a3cb51e19a4d8ee361fdc6 && git merge --no-ff e689bd7db84b327b38a84f80d1c913899b1a0ff2
node scripts/docs-audit/affected-docs.mjs --json 631d77f3021ca00e36a3cb51e19a4d8ee361fdc6
|
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract-review-claim: session_01ADHkmP44onN8RMzsPMqjRq · head 7148349 · 2026-11-17T00:17Z |
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract reviewServed-tier: ① Derived judgmentsInputs read: card #34373 body and all 8 comments (triage, ruling 6919195250, four claims, the needs_seat report with routes A/B/C, the done report), PR #34517 body, file list and the net diff against the merge base with main, and the check-runs on the head. Nothing was built or run. Check-runs on the head: 67 runs. Every completed run concluded success or skipped; none failed. Pending at the time of reading: Accept-set and public-surface changes the diff implies:
② Semver levelChangeset
③ Boundary flagsDev deviations, each answered:
Open questions, each answered:
SQL push-down: no new id materialisation and no new in-app join. The id read followed by Open PR #34530 (card #33697) also edits Not in the diff, recorded for the seat: on PostgreSQL a locking read needs UPDATE privilege on the table in addition to SELECT (PostgreSQL's documented rule; not measured here). A platform-owned table is unaffected. A federated object whose remote role holds DELETE without UPDATE, and which delete-family lookups reference, would have its predicate delete refused by the database where it ran before. Rare and loud; worth one line in a follow-up card, not a finding on this head. ④ Design judgmentNo must-fix, no should-fix.
Implementing files:
N1 (nit) — the option's TSDoc never says outright that a driver WITHOUT the bit ignores the key on a direct call, so a direct caller must read N2 (nit) — the bit's TSDoc states the MySQL and SQL Server behaviour as fact and the driver declares the bit on every dialect, Oracle included, while only PostgreSQL and SQLite are measured (the N3 (nit) — Implemented-by: VERDICT: PASS |
|
repo:objectstack#2 · os-steve · session_01ADHkmRukLEFGv24PSBTaHb Test UI red at 7148349 is a runner timeout, not this diff.
The run concluded Stamped 2026-11-17T00:26Z. Generated by Claude Code |
|
repo:objectstack#2 · os-steve · session_01ADHkmSLi1reMd27fT62jJ3 CI note · PR #34517 · 2026-11-17T00:26Z
|
|
repo:objectstack#2 · os-steve · session_01ADHkmSLi1reMd27fT62jJ3 Final head · PR #34517 · 2026-11-17T01:04Z Final head for L1: |
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract-review-claim: session_01ADHkmP44onN8RMzsPMqjRq · head e689bd7 · 2026-11-17T01:06Z |
|
repo:objectstack#2 · os-steve · session_01ADHkmPZf3MhxKeGaxV4P3W 席位核对L1 first review · ACCEPT · head Checklist (read on GitHub at this head, not from the report)
Before landing (no push needed unless noted)
Owed after this
|
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract reviewServed-tier: ① Derived judgmentsDelta review. The previous at-tier record is comment 6933706748 (VERDICT PASS on head Inputs read: the previous record and every comment on PR #34517, the PR body, the git objects of both heads and both merge bases, the 72 check-runs on the new head, and the state of PR #34530. Nothing was built, checked out or run. What the new head is, read from the tree:
What the merge brought in from main (nine commits,
So every judgment in ① of the previous record holds unchanged on the merged tree: the two widenings ( PR #34530 and the live-bits count: main at the new merge base does NOT contain #34530. It is still open and draft (head Check-runs on the new head: 72 runs, all completed; 60 success, 12 skipped, none failed, none pending.
② Semver levelUnchanged. The changeset ③ Boundary flagsNo new boundary crossing: the merge moved no file this PR owns, and no file in the Scope. The dev deviations and open questions Q1 to Q3 answered in the previous record stand as answered. Nothing new was raised on this head. The PR body records that nits N1 to N3 and the PostgreSQL UPDATE-privilege note are filed as #34549; that is a statement about a card, not about this tree, and it changes no judgment here. Collision with open PR #34530 (card #33697), restated for the landing order because it is the one live risk on this head:
Main beyond the new merge base (13 further commits on the fetched SQL push-down: unchanged from the previous record; no new id materialisation and no in-app join in this delta. ④ Design judgmentNo must-fix, no should-fix. This section is short because nothing in the Scope moved: all seven Scope files are byte-identical to the head the previous record judged, and main brought no change to any file they import or to any reader of the new option or bit. The design judgment of record 6933706748 therefore applies to this head word for word:
Nits N1 to N3 of the previous record carry over unchanged in substance and in grade (nit): N1, the option's TSDoc does not say outright that a driver without the bit ignores the key on a direct call; N2, the bit is declared on every SQL dialect while only PostgreSQL and SQLite are measured; N3, the Turso remote transport inherits the bit. None is new, none blocks this head. No new finding on this head. Limit of this record: it holds for Implemented-by: VERDICT: PASS |
|
repo:objectstack#2 · os-steve · session_01ADHkmSLi1reMd27fT62jJ3 Landing · PR #34517 · 2026-11-17T01:10Z ACCEPT → PR #34517 comment 6934544391 (L1-b, head e689bd7). L2 → comment 6933706748 (PASS at 7148349, CONTRACT_REVIEW_TIER; the 15 PR files are blob-identical on both heads, so it carries under the clean main-merge exception, confirmed by the seat).
|
Requested by Steve · project thread
Fixes #34373
Clause-②: yes (widening: DriverOptions.lockRows and DriverCapabilities.lockRows)
Metadata-protocol: added
Skills-docs: none — a driver capability and an engine→driver option; no skill teaches DriverOptions or DriverCapabilities
维护者速读
delete(obj, { where, multi: true }))在删除事务里先给命中的行加锁再删;SQL 驱动声明新能力位lockRows,find()在事务内发FOR UPDATE。lockRows的驱动在事务内才加锁,其它驱动和split计划行为不变;回滚即回退本 PR,spec 只多两个可选键。packages/objectql/src/engine-delete-and-aggregate.ts的级联分支(约 750–775 行)和packages/drivers/driver-sql/src/sql-driver-crud.ts的lockRowsIfAsked。OS_TEST_POSTGRES_URL后跑pnpm --filter @objectstack/driver-sql exec vitest run src/sql-driver-34373-lock-rows.test.ts,看两种并发次序都不会删掉被改出条件的行。What changes
A predicate delete on an object that delete-family lookups reference reads the matched ids, walks the cascade, then deletes those rows by
id $in, so the caller's predicate is not on the final DELETE. A concurrent commit between the read and the delete that moved a row out of the predicate ({ id, source: 'idp_pending' }→active) was deleted anyway, and counted.packages/spec/src/data/driver.zod.ts):DriverOptions.lockRows(hunk@@ -113,0 +114,23 @@, afterbypassTenantAudit): on afind()inside atransaction, lock the returned rows until the transaction ends.DriverCapabilities.lockRows(hunk@@ -340,0 +367,35 @@, afteraggregationFilter) and its header bullet (hunk@@ -162,0 +186,3 @@): the driver'sfind()honours that option; absence =false.aggregationFilter—packages/spec/src/data/driver.zod.ts:339on main, read by the engine atpackages/objectql/src/engine-delete-and-aggregate.ts:1443(drv?.supports?.aggregationFilter === true), changeset.changeset/33698-measure-filter-pushdown.md: one optional capability bit, landed together with its engine reader, absence = the engine keeps its own path.DriverCapabilitiesbit next toaggregationFilter. The hunk at+367is the one that meets it; theDriverOptionshunk and the header bullet are independent.engine-delete-and-aggregate.ts, the cascade arm ofrunPredicateDelete): when the unit has a transaction handle and the driver declaressupports.lockRows, the matched-row read carrieslockRows: true. Rows deleted are still exactly the rows walked.engine-driver-options.tsbuildDriverOptions, newlock-rows-refusal-error.ts,engine.tshost getsgetDriver):lockRowsarriving at the engine→driver hop from any option bag is refused before a driver runs —NOT_IMPLEMENTED/ 501 when the object's driver does not declare the bit,PRECONDITION_REQUIRED/ 428 when no transaction reaches that driver. A lock request is never dropped silently. The read and delete verbs already refuselockRowsfrom a caller as an unknown option (rejectUnknownEngineOptions), unchanged.sql-driver-crud.tslockRowsIfAsked,sql-driver.tssupports.lockRows: true):find()/findOne()addforUpdate()(PG/MySQL/OracleFOR UPDATE, MSSQLUPDLOCK, SQLite nothing — the database lock keeps the promise, see Verification).lockRowswithout a transaction →PRECONDITION_REQUIRED/ 428.What keeps the window: a driver without the bit (memory, MongoDB, OData), and a cascade that cannot run in one transaction (
splitplan, no transactions).Tests
packages/drivers/driver-sql/src/sql-driver-34373-lock-rows.test.ts: the 428 refusal; live PG/MySQL row-lock cells (writer after the locked read waits; locked read behind a writer waits and does not return the moved row); SQLite two-connection pins for WAL (SQLITE_BUSY_SNAPSHOTon the transaction's delete, row kept as moved) and rollback journal (writerSQLITE_BUSY, delete stands).describe('[#34373] …')inpackages/objectql/src/engine-cascade-delete-atomic.test.ts: locked read with the bit; none without the bit or without transactions; the verbs' existing refusal oflockRows; 501 and 428 with code + status; the in-transaction pass.packages/objectql/src/engine-cascade-delete-atomic.test.ts— the shared harnessmakeDrivertakes{ transactional, lockRows }and records areadsledger; existing cases unchanged.packages/spec/src/data/driver.test.ts—LIVE_BITSgainslockRows; the shape pin renamed to6 live bits + 31 tombstones; accept/refuse cases for both keys.Acceptance notes
The card's scenario (guarded predicate delete vs a concurrent move) is read end to end below against live PostgreSQL 16, at head and with the lock stripped.
Review follow-ups (contract review 6933706748 nits N1–N3 and the PostgreSQL UPDATE-privilege note): filed #34549.
Verification
All readings on a shared cloud box; heavy runs under
scripts/pm/os-verify-lock.sh. Live PostgreSQL 16 local (OS_TEST_POSTGRES_URL), server zoneAsia/Shanghai, processTZ=America/New_Yorkfor the full driver-sql suite (its timezone fixtures require both skews). MySQL, SQL Server and Oracle were not measured here;Temporal Conformance (live PG + MySQL)runs the live cells on main's full battery; it is skipped on this pull request by its ownif:, so no check-run on this PR executes the live PostgreSQL or MySQL lock cells — the PostgreSQL reading here is local.Suites
@objectstack/specvitest: 937 files, 28629 passed, 1 todo.@objectstack/objectqlvitest: 605 files, 13516 passed.@objectstack/driver-sqlvitest (live PG + SQLite): 267 files passed, 4 skipped; 5459 passed, 128 skipped (MySQL / MSSQL cells NOT RUN).sql-driver-34373-lock-rows.test.ts: 7 passed, 1 skipped (MySQL cell).tsc --noEmitfor spec, objectql, driver-sql: clean.pnpm --filter @objectstack/spec check:generated: 14/14 current after the docs regeneration.End to end: ObjectQL engine + SqlDriver on live PostgreSQL
A temporary test (not committed) booted
ObjectQLwith a realSqlDriver, aticketobject and amaster_detailnotechild (so the delete takes the cascade arm), inserted onependingticket with one note, and wrappedfindso that right after the delete's matched-row read a second driver (its own pool) runsupdate(ticket, { status: 'active' })and is given 400 ms. Thenengine.delete('ticket', { where: { status: 'pending' }, multi: true }).pending; the move then found nothing)activecommitted)activerow was deleted — the card's defectAblation readings (each restored, tree clean after)
sql-driver-crud.tsreturn builder.forUpdate();→return builder;: both live-PG row-lock pins red.engine-delete-and-aggregate.ts{ ...writeOptions, lockRows: true }→writeOptions: "reads the matched rows with lockRows …" red (1 of 27).engine-driver-options.tsrefusal guard disabled: the 501 and 428 pins red (2 of 27).sql-driver-crud.tsif (!options.transaction)→if (false): "answers PRECONDITION_REQUIRED / 428" red.SQLite, two connections on one file (measured)
connect()applies): the other connection's update commits; the transaction's owndeleteManyfailsSQLITE_BUSY_SNAPSHOT; after rollback the row isactive(not deleted).SQLITE_BUSYafter the busy timeout; the transaction's delete removes the row as matched.Overlap with in-flight work
git merge-tree --write-treeof this head against #34439 (7c80b9db, sharespackages/objectql/src/engine.ts) and against branchclaude/issue-34412-before-hook-side-write-unit(320f1f86, sharesengine-delete-and-aggregate.ts): both clean, exit 0.Human Minimum
packages/specholds no runtime logic.pnpm lintpasses.main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01ADHkmRukLEFGv24PSBTaHb