Repository navigation
fix(objectql)!: a write refused after its before* hook wrote through ctx.api rolls that hook's write back - #34503
Conversation
…e* hook made A metadata-bound before* hook now opens the write door's unit on a transactional default driver, so a refusal later in the same write (a declared validation, a later before* hook) rolls the hook's side write back. A caller's open unit still decides; drivers without transactions keep the side write. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac
…ctx.api write Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac
…fore-hook-side-write-unit
… unit; changeset The hooks page and the data-flow table gain the before* row beside the after* one: the write, its before* hooks and their ctx.api writes share one unit, with the same exits. The changeset names what narrows: a before* write meant to survive a refusal rolls back, a write to another datasource is refused, MongoDB needs a replica set. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5m1wi6BQceRHYYxHFy
… hook now opens The case pinned the old path: no unit for a before* hook, so the hook's own write stayed. A metadata-bound before* hook now opens the door's unit, so the refusal rolls the hook's row back. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5m1wi6BQceRHYYxHFy
…t of its own The fixture needs a hook whose ctx.api.transaction opens and owns its unit. It used a beforeInsert hook because the write door opened no unit for one; a before* hook declared in metadata now opens the door's unit, and the hook's transaction only joined it, so a swallowed inner rollback kept its row. A blocking afterInsert with onError 'log' and no condition opens none. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5m1wi6BQceRHYYxHFy
📓 Docs Drift CheckThis PR changes 1 package(s): 30 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 7 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. 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 d07d796291e91f03360bdf899c87d2a0b1ee4981 && git checkout d07d796291e91f03360bdf899c87d2a0b1ee4981
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin ffa6db19f87617d2489b658f604af7604ba84bcd 27b46852a68bb6042fd810050b766e00c6668185 && git checkout -B drift-repro ffa6db19f87617d2489b658f604af7604ba84bcd && git merge --no-ff 27b46852a68bb6042fd810050b766e00c6668185
node scripts/docs-audit/affected-docs.mjs --json ffa6db19f87617d2489b658f604af7604ba84bcd
|
…oor's unit in the title one-hop pin The H2 case pinned that a before-hook body's transaction was the only unit, so every read on it was the title's hop. A before* hook bound from metadata now opens the write door's unit and the body's transaction joins it, so the door's own reads ride the same handle. The pin now asserts one unit for the whole write, every read on it, and exactly the title's two hop reads added over the same body that never asks. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5m1wi6BQceRHYYxHFy
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5m1wi6BQceRHYYxHFy Final head · #34503 · 2026-11-17T00:37Z Head-sha: This is the final head for review. CI on it: 57 check runs, all success or expected skip, none red;
Generated by Claude Code |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract-review-claim: session_01FEkQ5mjfxPu5HKjUtuveBR · head d4062a6 · 2026-11-17T00:38Z |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5mww9UksbwbjvM4aYn 席位核对 · PR #34503 · L1-b · 首读 · 2026-11-17T00:40ZHead-sha: d4062a6(merge base 152cd1f,7 个提交,12 个文件,+245 / −38;终版声明 6933943529) 结论:ACCEPT(L1 层面;还欠契约层 L2,见末尾) PR 形态
改动本身
测试
claim 之外改动的三个测试文件,我逐个读过,都不是削弱
读数
CI N1(不阻塞) N2(不阻塞,交席位处理) 交给契约评审(L2)留意
仍欠 |
|
review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR Contract reviewServed-tier: First review of this head. Card #34412, ruling 6929103019 (letter A), final-head record 6933943529, precedent PR #22906 (#22856) and #22782. No earlier record on the PR. ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentS1 (should-fix) — N1 (nit) — N2 (nit) — N3 (nit) — MongoDB standalone. By reading, the write is refused loudly, not left without rollback: N4 (nit) — the changeset's cost line names SQLite only; the in-memory driver snapshots its whole store per unit and restores it on rollback.
Implemented-by: VERDICT: PASS |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5m1wi6BQceRHYYxHFy State · #34503 · 2026-11-17T00:45Z Head-sha:
Generated by Claude Code |
…efore* unit Inside the unit a before* hook's ctx.api statement that fails at the database aborts the whole PostgreSQL transaction (25P02), so catching the error, onError: 'log' or a retryPolicy no longer lets the outer write land. The changeset and the hooks page say so; the live measurement is carried on the follow-up card. Claude-Session: https://claude.ai/code/session_01ADHkmSLi1reMd27fT62jJ3 Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#2 · os-steve · session_01ADHkmSLi1reMd27fT62jJ3 Final head · PR #34503 · 2026-11-17T01:33Z Taken over by area o2-E of seat |
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract-review-claim: session_01ADHkmP44onN8RMzsPMqjRq · head ea22416 · 2026-11-17T01:35Z |
|
repo:objectstack#2 · os-steve · session_01ADHkmPZf3MhxKeGaxV4P3W 席位核对L1 delta · ACCEPT · head Delta read (
|
|
l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq Contract reviewServed-tier: Delta review. Previous at-tier record: 6934090371, PASS on head What moved between the heads: one commit, ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentShort, because no design moved: the predicate, the exits and the tests are the ones the previous record judged. S1: closed. The previous record required three things. (1) The consequence named in the changeset list: done, as the fourth item under "Inside the new unit, the rules of any unit apply". (2) The same in Deferring the measurement: acceptable, as a judgment. The statement is a contract statement, but it is published with its evidence grade in both places ("Read in the driver's code, not measured on PostgreSQL" and "not yet measured on PostgreSQL"), it points at the card that owes the measurement, the mechanism it rests on is the driver's own measured note for the same database, and the direction of any error is safe: if the measurement differs, a write the text says is refused is stored, which is the behaviour before this PR. The previous record asked for exactly this split. #34563 carries exactly S1's measurement and N3, nothing else. N1 (nit): carried, open. No "same verb only" pin; no change on this head. N2 (nit): carried, open. The N3 (nit): carried to #34563, whose second item is the MongoDB standalone run. The accepted deviation stands; the changeset still says it is unmeasured. N4 (nit): carried, open. The cost line still names SQLite only. N5 (nit, new): the new rule is written for PostgreSQL alone, and MongoDB is neither named nor ruled out. On a replica set the unit is a session transaction ( N6 (nit, new): the changeset still says, two items above, that No must-fix, no should-fix. Implemented-by: VERDICT: PASS |
…fore-hook-side-write-unit
|
repo:objectstack#2 · os-steve · session_01ADHkmSLi1reMd27fT62jJ3 Landing · PR #34503 · 2026-11-17T04:06Z ACCEPT → PR #34503 comment 6935125418 (L1-b delta, head ea22416). L2 → comment 6935186906 (PASS at ea22416, CONTRACT_REVIEW_TIER).
|
Requested by Leehom · project thread
Fixes #34412
Ruling-ref: 6929103019
Clause-②: no (narrowing)
Metadata-protocol: semantic
Skills-docs: follow-up #34504
MongoDB standalone: NOT MEASURED in this PR (see Acceptance notes); no driver card filed, because the seat's order files one only on a measured refusal, and the ruling was given with this consequence named as read in code, not measured.
维护者速读
beforeInsert/beforeUpdate/beforeDelete)的保存,现在整笔放进一个事务;这次保存被拒时,钩子通过ctx.api顺手写的记录一起撤回。packages/objectql/src/engine-hooks-and-functions.ts(opensAfterAbortUnit中新增的sideWriting一项)、.changeset/34412-before-hook-side-write-unit.md、packages/objectql/src/engine-after-hook-abort-unit.test.ts(末尾 objectql: a write refused after its before* hook made a ctx.api write keeps that side write, because a single write opens no unit unless an aborting after* hook exists #34412 一组)。pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/engine-after-hook-abort-unit.test.ts,预期 21 个全过;其中"note is absent"三条在去掉修复后会变红。What changes
ObjectQL's write door decides per write whether it opens its own unit of work (opensAfterAbortUnit). Until now it did so only when a metadata-boundafter*hook on the object could abort (#22782, #22856). This PR adds one term: a metadata-boundbefore*hook on the same verb also opens the unit. The three exits stay as they are: a caller's open unit decides, an object off the default datasource opens none, and a default driver with no transactions opens none. Code-registered hooks (registerHook, nometa) still open no unit; the platform's ownsys_stamp_audit_insert/sys_stamp_audit_updateare code-registered, and no platform package declares metadata hooks, so the platform's own objects do not change.packages/objectql/src/engine-hooks-and-functions.ts— the predicate and its docblock.engine-insert.ts,engine-update.ts,engine-delete-and-aggregate.ts— call-site comments only.content/docs/automation/hooks.mdx— thebefore*row in the unit-of-work table, beside theafter*one, and what it means for abefore*hook'sctx.apiwrites (no per-hook opt-out, the cross-datasource refusal and its ledger carve-out, MongoDB replica set).content/docs/api/data-flow.mdx— thebefore*row of the hook table..changeset/34412-before-hook-side-write-unit.md—minoron@objectstack/objectql, BREAKING, ADR-0087not-required (no-migration-prescription), the precedent shape of the objectql: anafter*hook withonError: 'log'whoseconditioncannot be evaluated refuses the write (HookConditionError) while the row stays stored #22856 changeset.Why
A
before*hook that creates a record throughctx.api(the card: a time entry'sbeforeInsertcreates the week's timesheet) committed that record at once, because a single write ran in no unit. A refusal later in the same write (a declared validation, a laterbefore*hook, a driver constraint) refused the caller and left the hook's record stored. The maintainer ruled route A (6929103019): the whole write rolls back together.What narrows, named in the changeset:
before*write meant to survive a refusal now rolls back; no per-hook opt-out. The carve-out is the one any unit has: an append-only ledger on another datasource (lifecycle.classaudit/telemetry/event) is written outside the unit (enforceTransactionOrigin);before*hook'sctx.apibusiness write to another datasource is refused withCrossDatasourceTransactionWriteError; remedy: one datasource;Tests
packages/objectql/src/engine-after-hook-abort-unit.test.ts— 8 pins: the card's three verbs (insert / update / delete: the hook's note is absent after the refusal), the flipped throwing-before*control (one unit, rolled back), and the controls (success commits both rows; a caller's unit decides; a driver with no transactions keeps the side write and warns nothing; a code-registered hook opens no unit).packages/rest/src/rest-hook-condition-unevaluable-refusal.test.ts— the REST data door over a realSqlDriver(better-sqlite3):400 VALIDATION_FAILED, the outer row and the hook's row both absent; CONTROL an accepted create keeps both rows.packages/runtime/src/sandbox/hook-ctx-title-one-hop.integration.test.ts— one stale pin flipped (fix round 1, d4062a6). Its H2 case pinned that abeforeUpdatebody'sctx.api.transactionopened the only unit, so every read on it was the title's hop. Measured on 320f1f8: onebeginTransaction(the door's unit; the body's transaction joined it, no second unit), and all five reads of the write on that handle — the prior-row read oflib_loan, the title's two hops, and the result row's formula reads oflib_book/lib_reader. The pin now asserts one unit for the whole write, every read on it, and exactly the title's two hop reads (onelib_book, onelib_reader) added over the same body that opens the same transaction and never asks. File:Tests 11 passed (11);pnpm --filter @objectstack/runtime testat d4062a6:Test Files 609 passed (609),Tests 11271 passed | 19 skipped (11290).packages/objectql/src/engine-hook-stale-summary-refusal.test.ts— one stale pin updated (fixture triage: replaced). ItsbeforeInsertcase pinned the old path ("no unit opens for a before* hook, so the hook's own write stays"); it now pins the unit the hook opens (one begun, one rolled back, the hook's row absent).Ablation (one mutation, both suites):
node scripts/ablation-replace.mjsreplacedif (!aborting && !sideWriting) return false;withif (!aborting) return false;(anchor x1 to x0, blob6671f8495a2fto2f36f7d8de8e, trap restore armed), rebuilt@objectstack/objectql,ablation-dist-preflight.mjsfound the mutation indist/{core,index}.{js,mjs}(the REST suite resolves@objectstack/objectqlthrough itsexports, i.e.dist/).Tests 5 failed | 16 passed (21)— red: the three card pins, the throwing-before*control, the success control'sbeguncount; green as expected: caller-unit, no-transactions and code-registered controls.Tests 1 failed | 6 passed (7)—expected 1 to be +0on the hook's row; status/code and outer-row assertions held.6671f8495a2f== HEAD blob,git diff HEADempty;objectqlrebuilt, preflight--absentclean over 14 built files, REST pin7 passed (7).Acceptance notes
mongodis available in the build container (the driver's suites are opt-in throughOS_TEST_MONGODB_MEMORY_SERVER_ENABLEDand download the server fromfastdl.mongodb.org, which the container's egress policy refuses with 403). Code reading only:MongoDBDriver.beginTransactionalways callssession.startTransaction()and the driver declares nosupports.transactionsUnsupported, so on a standalone server the first write in the unit should be refused by the server (transactions need a replica set member or mongos). The driver is out of this PR's surface; no card is filed on a code reading alone (see the line at the top); the measurement is carried on review follow-ups of PR #34503 #34563.git merge-tree --write-treeof this head against its head54bc155b88is clean (no conflicted path). Behavioural interaction: inside its deferral scope a write that now opens this unit records its roll-up recompute instead of running it; the door's unit is ambient (txStore,inAfterAbortUnit→transaction()), so the recorded context carries no unit handle, and a recorded row whose unit rolled back is only re-read by the deferred recompute. Same shape as theafter*unit since 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; nothing to change here.supports.transactionsUnsupported, so there abefore*hook's writes stay stored after a refusal, and thehookStoppedRefusalsentence ("otherwise what was written before that point stays written") stays true;summary-errors.tsis unchanged.skills/objectstack-data/references/data-hooks.md(Before vs After table) says abefore*hook is "Within transaction" and "throw → rollback". That now holds on a transactional default driver, but the page is silent on the exits (another datasource, a driver with no transactions, code-registered hooks), on the cross-datasource refusal of abefore*hook'sctx.apiwrite, and on MongoDB needing a replica set.skills/**is outside this PR; follow-up skills/objectstack-data data-hooks.md: teach when a before* hook's ctx.api write rolls back with a refused save, and its exits #34504.before*hooks that write throughctx.apistay outside any unit (the 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 line) — a boundary, recorded, not filed.packages/runtime/src/sandbox/hook-ctx-title-one-hop.integration.test.tsis outside the claim's file surface too: its H2 pin was made red by this change on CI (Test Core 3/8 on 320f1f8) and flipped here in fix round 1.packages/qa/dogfood/test/scoped-transaction-late-write.dogfood.test.tsis outside the claim's file surface: its fixture was made red by this change (see the dogfood block) and fixed here, as the battery rule requires.25P02consequence, now named in the changeset andhooks.mdxatea224164), N3 (MongoDB standalone) and N5 (MongoDB replica set: the outcome of abefore*hook that swallows its own failedctx.apiwrite).ea224164: L1 ACCEPT 6935125418, L2 PASS 6935186906 (S1 closed).Verification
Commands, exits and verdict lines are in the folded blocks below; head named in each.
Full dogfood battery (final head 320f1f8)
bash scripts/pm/os-verify-lock.sh -c "pnpm --filter @objectstack/dogfood test"(no shard, no path) after the closure build:Test Files 476 passed | 3 skipped (479),Tests 4022 passed | 44 skipped (4066),VERDICT command-exit 0.test/scoped-transaction-late-write.dogfood.test.ts› "ctx.api.transaction(fn) that rolls back: the hook never runs" (Tests 1 failed | 4021 passed). Its fixture used abeforeInserthook precisely because the door opened no unit for one, so the hook'sctx.api.transactionowned its unit; now it joined the door's unit and the swallowed inner rollback kept its row. Fixture replaced (320f1f8): the writer hook is a blockingafterInsertwithonError: 'log'and nocondition, which opens no door unit, so the transaction it opens is its own again. File re-run:Tests 15 passed (15).Local runs (head 320f1f8, branch merged with origin/main 152cd1f)
pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' buildunderos-verify-lock.sh:VERDICT command-exit 0.pnpm --filter @objectstack/objectql testat 320f1f8:Test Files 604 passed (604),Tests 13511 passed (13511),VERDICT command-exit 0. (At fd51377 the same run had1 failed | 13510 passed: the staleengine-hook-stale-summary-refusal.test.tsbeforeInsert pin, updated in abe9374.)pnpm --filter @objectstack/rest test:Test Files 414 passed (414),Tests 8566 passed | 350 skipped (8916)(at abe9374; no rest or objectql source changed after it).pnpm --filter @objectstack/objectql --filter @objectstack/rest typecheck: exit 0 (at abe9374, same remark).Tests 21 passed (21); REST pin file:Tests 7 passed (7).node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackat 320f1f8: 99 families, run one by one with exit codes recorded;--ran:99 derived famil(ies) accounted for — 99 run, 0 NOT-MEASURED (a DERIVED zero — all 99 recorded an exit code and none of them is 3). All 99 exit 0.check:dual-build-cjs-loadsexited 1 once (@objectstack/restmissingdist/index.d.cts) whilecheck:type-check-debt's turbo build was rewritingdist/on the same box; re-run after that build: exit 0,124 published require entry point(s) across 72 package(s) load.check:type-check-debtrun under the lock:128/131 workspace packages type-checked, exit 0.pnpm lintand the rest of the farm: CI.Human Minimum
packages/specholds no runtime logic.pnpm lintis CI's run (not run locally).main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (not touched)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01FEkQ5m1wi6BQceRHYYxHFy