Repository navigation
fix(objectql): the loser of a concurrent update answers 409 again on an object with a metadata beforeUpdate hook - #35165
Conversation
…-0142 D4) Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt Co-authored-by: Claude <noreply@anthropic.com>
…ody, not the door The unit enclosed the middleware chain, so on a single-connection store the loser of a concurrent claim ran its authorization gate after the winner's commit and was refused as not found or forbidden instead of 409 CONCURRENT_UPDATE (ADR-0142 D4). Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt Co-authored-by: Claude <noreply@anthropic.com>
…ncurrent-update-409
📓 Docs Drift CheckThis PR changes 1 package(s): 13 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 21 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 07d48d46b8b905e1e3f39df660bbfcda8f5fd336 && git checkout 07d48d46b8b905e1e3f39df660bbfcda8f5fd336
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 4b1eb0eab7ac41708a6775d1e6116ac4c038a5a3 d9fe9175e7d7e9e702ffc21fe0dd6b7fd13bfdeb && git checkout -B drift-repro 4b1eb0eab7ac41708a6775d1e6116ac4c038a5a3 && git merge --no-ff d9fe9175e7d7e9e702ffc21fe0dd6b7fd13bfdeb
node scripts/docs-audit/affected-docs.mjs --json 4b1eb0eab7ac41708a6775d1e6116ac4c038a5a3
|
|
repo:objectstack#1 · os-warren · session_01JQwxbXKtHccbeakAgquNs9 L1 review (#35142) · 2026-11-18T09:27ZL1: REWORK (one must-fix in the changeset; the code is accepted) This is the first L1 on this PR. I read the full diff against the merge base The fix (route A).
The two questions you asked.
Shape and scope.
Tests and evidence.
CI at this head, from check-runs: 37 success, 16 skipped, none failed or in progress. Must-fix
Should-fix
Notes
|
…adata hook is a blocking afterUpdate The after-abort unit opens for either term of opensAfterAbortUnit: a metadata beforeUpdate hook (side-writing) or a blocking / conditioned metadata afterUpdate hook (aborting). The fifth cell holds the aborting arm to 409 CONCURRENT_UPDATE too: private OWD, 25 rounds. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt
…m-race note The unit opens for a metadata beforeUpdate hook (since 18.6.0) or a blocking / conditioned metadata afterUpdate hook (since before 18.5.0); the note now gives the loser's answer history for each and the post-next() timing for both. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt
…e since 18.0.0, not since forever The door-level unit for a blocking or conditioned metadata afterUpdate hook first shipped in objectql 18.0.0 (17.7.0 has no opensAfterAbortUnit), so the note says 18.0.0 through 18.6.0 rather than every earlier release. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt
|
repo:objectstack#1 · os-warren · session_01JQwxbXKtHccbeakAgquNs9 L1 review, delta for REWORK 6974452034 (#35142) · 2026-11-18T11:17ZL1: ACCEPT M1, closed.
S1, taken.
N1 is carried by #35167 (whether insert and delete should get the same change). Gates. 70 of 70 exit 0, with CI at this head, from check-runs: 39 success, 18 skipped, none failed or in progress. Must-fixNone. Should-fixNone. Notes
|
|
repo:objectstack#1 · os-warren · session_01JQwxbXGvw43spR79ztEvWt Landing · 2026-11-18T11:18Z · head
This card started before Warren's 08:54Z intake rule, so it finishes. hotcrm#2634 (the 18.6.0 upgrade) waits on this landing. |
🤖 Generated with Claude Code
https://claude.ai/code/session_01JQwxbXGvw43spR79ztEvWt
Fixes #35142
Clause-②: no
Metadata-protocol: none
维护者速读
beforeUpdate钩子,或带阻断式 / 带条件的元数据afterUpdate钩子),「after-abort 事务单元」原先包住整个写入(含授权中间件),现在只包住引擎本体(钩子、写行、after 链);中间件在事务开启之前运行,与无钩子对象一致。409 CONCURRENT_UPDATE。beforeUpdate钩子一支自 18.6.0 起出错(18.5.0 为 409);阻断式afterUpdate钩子一支在 18.5.0 已是 404/403。HotCRM 的 18.6.0 升级被它挡住。next()之后的代码对这类 update 改为在提交之后运行,与无钩子对象一致;beforeUpdate一支等于回到 18.5.0,阻断式afterUpdate一支则是新变化(18.0.0 至 18.6.0 都在事务内运行)。钩子侧写回滚(fix(objectql)!: a write refused after its before* hook wrote through ctx.api rolls that hook's write back #34503 的目的)不变。回滚 = revert 本 PR 的engine-update.ts一处改动。packages/objectql/src/engine-update.ts(门入口ownUnit/inOwnUnit与executeWithMiddleware(opCtx, inOwnUnit(...))两处);packages/plugins/plugin-security/src/ownership-claim-race-sqlite.test.ts。cd packages/plugins/plugin-security && pnpm exec vitest run src/ownership-claim-race-sqlite.test.ts,预期 7/7 通过;五格各 25 轮,输家全部为CONCURRENT_UPDATE/409。What changes
UpdateFacet.updateno longer re-enters itself insideinAfterAbortUnitat the door. It decides at the door whether the write needs its own unit (opensAfterAbortUnit, unchanged), and wraps only the executor it hands toexecuteWithMiddlewarein that unit. So the middleware chain (the authorization gate's caller-scoped pre-image read among it) runs beforeBEGIN, the way it does for an update that opens no unit, and everything the unit exists for (thebefore*hooks and theirctx.apiside writes, the row write, theafter*chain) still runs inside it and rolls back together.The change applies to any update that opens its own unit, which is
opensAfterAbortUnit's whole answer, and that predicate has two arms:sideWriting: a metadatabeforeUpdatehook.a8e09bbc31(fix(objectql)!: a write refused after its before* hook wrote through ctx.api rolls that hook's write back #34503) added this term (traced in the card's trace comment), new in 18.6.0. Race answer:409in 18.5.0,404/403in 18.6.0,409again here.aborting: a blocking (onErrorabort, the default) or conditioned metadataafterUpdatehook (objectql: anafterInserthook withonError: 'abort'(the default) that throws rejects the write, but the row stays stored —HookSchema.onErrorsays abort rolls the transaction back, and a plain write opens none #22782). Its door-level unit already shipped in@objectstack/objectql@18.5.0:engine-update.ts:151-153at tag@objectstack/objectql@18.5.0(b914e7247f) readsif (this.opensAfterAbortUnit('afterUpdate', object, options?.context)) { return this.inAfterAbortUnit(() => this.update(object, data, options)); }, and that tag'sopensAfterAbortUnithas theabortingterm and nosideWritingterm. Race answer:404/403already in 18.5.0 and in 18.6.0 (the new fifth cell readsRECORD_NOT_FOUND/404x25 on main'sengine-update.ts),409here for the first time.With the unit around the whole door, the SQLite driver's single connection made the loser's whole write, gate included, wait for the winner's commit. The gate then read a row owned by the winner and refused: 404 under
private, 403 underpublic_read. The conditional write whose 0-row answer isConcurrentUpdateErrorwas never reached.Insert and delete keep their door-level unit. Measured with the same rig, 20 rounds per cell,
privateandpublic_read, with and without a metadatabefore*hook on the verb:DUPLICATE_RECORD/409in all four cells. No race-shaped defect, so no change.deleteresolvesfalse; with a hook it answersRECORD_NOT_FOUND/404. Both say the row is gone, which it is. D4 governs updates, and the 404 is not a lie about a readable row. So it stays out of this PR's scope (see Acceptance notes).What a middleware does after
next()on an update that opens its own unit now runs after the commit, as it does on every update that opens no unit. For thebeforeUpdatearm that is how 18.5.0 behaved. For theafterUpdatearm it is a change, not a return: in every release from 18.0.0 (the first@objectstack/objectqltag whose source callsopensAfterAbortUnit; 17.7.0 has 0 hits) through 18.6.0, that code ran inside the row's unit on an object with a blocking or conditioned metadataafterUpdatehook. The post-next()code that runs on an update in this tree:postHookWriteImageCheckhonoured-flag assertion (it fails closed if the engine never ran the seam; the engine always runs it inside the executor), then field-level masking of the result (no write).shouldReplayBootstrapFor) and thesys_memberorg-admin grant reconcile (writes,sys_memberonly).next()branches that act on insert/create only.On a
sys_memberupdate that opens its own unit, the org-admin grant reconcile is no longer in the same unit as the row. With a metadatabeforeUpdatehook that matches 18.5.0; with a blocking or conditioned metadataafterUpdatehook it is new. Either way it matches every unhooked object.Tests
New pin
packages/plugins/plugin-security/src/ownership-claim-race-sqlite.test.ts: the realObjectQL,SqlDriveron better-sqlite3:memory:,SecurityPluginandSharingService. It has five cells, 25 rounds each:private/public_read, each with and without a metadatabeforeUpdatehook, plusprivateon an object whose only metadata hook is a blockingafterUpdate(onError: 'abort'), which holds the predicate's other arm. Every round asserts that exactly one claim fulfils, that the loser's{code}/{status}isCONCURRENT_UPDATE/409, and that the stored owner is the winner. Two non-regression cases run on the hookedprivateobject: a deleted row answersRECORD_NOT_FOUND/404, and a row owned by someone else answers as not found, never as forbidden (no existence leak).Red on main: test commit with origin/main's engine-update.ts (blob dc1d73922a)
Fifth cell (blocking
afterUpdateonly), commit415eefd791with origin/main7d8dcf693a'sengine-update.ts(blob71476062da, door re-entry line present x1), swapped in a script with an EXIT/INT/TERM trap:(A third red in that run came from the not-found case's own setup, which deleted without a principal. Commit
06f9b81ab8fixed the setup; the case is green on main and on the fix.)Green on the fix: 4 runs x 25 rounds per cell (four cells), then 2 runs with the fifth cell
Ablation: the door-level re-entry restored through scripts/ablation-replace.mjs
@objectstack/objectqlresolves tosrc/in this suite (the plugin-security vitest alias), so the mutation reaches the run with nodist/leg.After-abort unit pins (#34412 / #34503) and the objectql suite
Acceptance notes
falsewith no metadatabeforeDeletehook,RECORD_NOT_FOUND/404with one. No declared contract picks between them, and neither misreports a readable row. Noted, not filed.next()work stays inside it while update's does not. Whether they should move the same way is carried by objectql: insert and delete keep the after-abort unit at the door while update moves it inside the middleware #35167.d9fe9175e7: origin/main and fix(objectql)!: a required field hidden by its own visibleWhen is required only when shown #34978 (sharesengine-update.ts) both merge cleanly.Verification
On head
d9fe9175e7(merge base99a0e4fbf; overlap-check against origin/main and #34978: merges cleanly, so main is not merged in again),node scripts/pm/dispatch-gates.mjs --commandsderived 70 families, and all 70 exit 0 (check:dual-build-cjs-loadsandcheck:i18nfound their dists this time and measured).check:query-options-erasureandcheck:type-check-debteach outran a 240 s per-gate runner timeout and exited 0 when rerun alone.--ranreconciliation with exit codes: 70 derived, 70 run, 0 NOT-MEASURED, 0 UNRUN. Between99c200dbb1andd9fe9175e7only the changeset text moved, so the race-test runs above (7/7 at99c200dbb1) read the same test and engine bytes.test:repoand the plugin-security suite outside the new file are left to CI (Test Core). The objectql public surface is byte-unchanged.Generated by Claude Code