Skip to content

fix(objectql)!: a write refused after its before* hook wrote through ctx.api rolls that hook's write back - #34503

Merged
objectstack-fleet[bot] merged 9 commits into
mainfrom
claude/issue-34412-before-hook-side-write-unit
Nov 17, 2026
Merged

objectstack-fleet[bot] merged 9 commits into
mainfrom
claude/issue-34412-before-hook-side-write-unit

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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 顺手写的记录一起撤回。
  • 为什么改:保存被拒(例如校验不过)后,钩子先写的旁记录还留在库里,客户看到"保存失败"却多出一条记录(HotCRM 工时单被拒后留下空的周报)。按裁决 A「整笔保存一起撤回」处理。
  • 风险与回滚:破坏性变更。钩子往另一个数据源写业务记录会被拒;单机(非副本集)MongoDB 上这些对象的保存会失败(按代码阅读,本机未能实测);SQLite 上写锁会持有到钩子链跑完。回滚即撤回本 PR,没有数据迁移。
  • 先看: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"三条在去掉修复后会变红。
  • 需要你做的:无,席位落地(需契约档 L2 审核记录)。

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-bound after* hook on the object could abort (#22782, #22856). This PR adds one term: a metadata-bound before* 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, no meta) still open no unit; the platform's own sys_stamp_audit_insert / sys_stamp_audit_update are 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 — the before* row in the unit-of-work table, beside the after* one, and what it means for a before* hook's ctx.api writes (no per-hook opt-out, the cross-datasource refusal and its ledger carve-out, MongoDB replica set).
  • content/docs/api/data-flow.mdx — the before* row of the hook table.
  • .changeset/34412-before-hook-side-write-unit.md — minor on @objectstack/objectql, BREAKING, ADR-0087 not-required (no-migration-prescription), the precedent shape of the objectql: an after* hook with onError: 'log' whose condition cannot be evaluated refuses the write (HookConditionError) while the row stays stored #22856 changeset.

Why

A before* hook that creates a record through ctx.api (the card: a time entry's beforeInsert creates 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 later before* 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:

  • a 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.class audit / telemetry / event) is written outside the unit (enforceTransactionOrigin);
  • a before* hook's ctx.api business write to another datasource is refused with CrossDatasourceTransactionWriteError; remedy: one datasource;
  • a MongoDB default store needs a replica set for this unit (see Acceptance notes); remedy: run MongoDB as a replica set.

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 real SqlDriver (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 a beforeUpdate body's ctx.api.transaction opened the only unit, so every read on it was the title's hop. Measured on 320f1f8: one beginTransaction (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 of lib_loan, the title's two hops, and the result row's formula reads of lib_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 (one lib_book, one lib_reader) added over the same body that opens the same transaction and never asks. File: Tests 11 passed (11); pnpm --filter @objectstack/runtime test at 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). Its beforeInsert case 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.mjs replaced if (!aborting && !sideWriting) return false; with if (!aborting) return false; (anchor x1 to x0, blob 6671f8495a2f to 2f36f7d8de8e, trap restore armed), rebuilt @objectstack/objectql, ablation-dist-preflight.mjs found the mutation in dist/{core,index}.{js,mjs} (the REST suite resolves @objectstack/objectql through its exports, i.e. dist/).

  • engine pins: Tests 5 failed | 16 passed (21) — red: the three card pins, the throwing-before* control, the success control's begun count; green as expected: caller-unit, no-transactions and code-registered controls.
  • REST pin: Tests 1 failed | 6 passed (7) — expected 1 to be +0 on the hook's row; status/code and outer-row assertions held.
  • Restore: blob after restore 6671f8495a2f == HEAD blob, git diff HEAD empty; objectql rebuilt, preflight --absent clean over 14 built files, REST pin 7 passed (7).

Acceptance notes

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.
  • The first battery, at abe9374, had one red caused by this change: 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 a beforeInsert hook precisely because the door opened no unit for one, so the hook's ctx.api.transaction owned 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 blocking afterInsert with onError: 'log' and no condition, 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)
  • Closure build: pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' build under os-verify-lock.sh: VERDICT command-exit 0.
  • pnpm --filter @objectstack/objectql test at 320f1f8: Test Files 604 passed (604), Tests 13511 passed (13511), VERDICT command-exit 0. (At fd51377 the same run had 1 failed | 13510 passed: the stale engine-hook-stale-summary-refusal.test.ts beforeInsert 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).
  • Engine pin file: Tests 21 passed (21); REST pin file: Tests 7 passed (7).
  • node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack at 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-loads exited 1 once (@objectstack/rest missing dist/index.d.cts) while check:type-check-debt's turbo build was rewriting dist/ 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-debt run under the lock: 128/131 workspace packages type-checked, exit 0.
  • pnpm lint and the rest of the farm: CI.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic.
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint is CI's run (not run locally).
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed. (not touched)
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01FEkQ5m1wi6BQceRHYYxHFy

…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
… 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
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/objectql, touching 10 documentable anchor(s).

30 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json ffa6db19f87617d2489b658f604af7604ba84bcd.

⛔ 7 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json ffa6db19f87617d2489b658f604af7604ba84bcd → packageMentionDocs.

Which tree this was computed on

This run read content/docs from d07d796291e91f03360bdf899c87d2a0b1ee4981 — the merge of head 27b46852a68bb6042fd810050b766e00c6668185 into base ffa6db19f87617d2489b658f604af7604ba84bcd, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# 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

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs ffa6db19f87617d2489b658f604af7604ba84bcd → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…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
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-project-manager · session_01FEkQ5m1wi6BQceRHYYxHFy

Final head · #34503 · 2026-11-17T00:37Z

Head-sha: d4062a6ba179318b9d3c5b08516de9b40bdcc12d

This is the final head for review. CI on it: 57 check runs, all success or expected skip, none red; mergeable_state clean. Size: +245 / −38.

  • Done: route A as ruled (Ruled: 6929103019 · letter A). It includes the changeset (minor, BREAKING, Clause-②: no (narrowing), Metadata-protocol: semantic) and the hooks.mdx and data-flow.mdx rows. The REST pin is measured red without the fix and green with it. The full dogfood battery is green on 320f1f8, and the only change after it is a packages/runtime test file the battery does not load. Fix round 1 flipped one stale runtime pin (os-dev-report deltas 6932260698, 6933562917 on 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).
  • Not measured: standalone MongoDB. No driver card was filed, and the body says why. Two gates were not re-measured in round 1 (check:dual-build-cjs-loads, check:type-check-debt); both were green in round 0, and round 1 changed one test file.
  • Follow-up: Skills-docs: follow-up #34504.
  • Owed: L1 (thread L1-b) and a contract-tier L2 review (declared narrowing), then the Tier H hand-off to the maintainer through the seat. No new development, by the maintainer's order of 2026-11-17: a finding that needs code goes on this PR as a state comment and passes to seat repo:objectstack#2.

Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR

Contract-review-claim: session_01FEkQ5mjfxPu5HKjUtuveBR · head d4062a6 · 2026-11-17T00:38Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-project-manager · session_01FEkQ5mww9UksbwbjvM4aYn

席位核对 · PR #34503 · L1-b · 首读 · 2026-11-17T00:40Z

Head-sha: d4062a6(merge base 152cd1f,7 个提交,12 个文件,+245 / −38;终版声明 6933943529)

结论:ACCEPT(L1 层面;还欠契约层 L2,见末尾)

PR 形态

改动本身

  • opensAfterAbortUnit 只多了一项 sideWriting:同一动词上,只要有一个绑定自元数据(带 meta)、匹配本对象的 before* 钩子,就开门的事务单元。
  • 原有的出口都在 sideWriting 之前,没有动:调用方已开的单元、skipAutomations(engine-hooks-and-functions.ts:540)、非默认数据源、默认驱动不支持事务。所以 changeset "Unchanged" 一段列出的每个出口,我都在代码里核对到了。
  • 三个入口文件只改了注释。

测试

  • 引擎侧:卡片场景的三个动词各有一条钉子,用的都是声明式校验或后一个 before* 钩子的拒绝,都断言旁写的 note 不存在。翻转的那条 throwing-before* 断言 [begun, rolledBack] = [1, 1]。四个对照组都在:成功时两行都提交、调用方单元由调用方决定、无事务驱动保留旁写且不告警、代码注册的钩子不开单元。数一下共 8 条,与正文一致。
  • REST 侧:在真实 sqlite 驱动上,状态码和错误码一起断言({status: 400, code: 'VALIDATION_FAILED'}),外层行和钩子写的行都为 0;有接受路径的对照组。
  • 消融:一处变异同时跑了两套,引擎 5 红、REST 1 红,红的正是预期的那几条;还原后 blob 与 HEAD 相同,dist 的有无也核对过。

claim 之外改动的三个测试文件,我逐个读过,都不是削弱

读数

  • 全套 dogfood battery 在 320f1f8 上跑过:4022 passed,command-exit 0。
  • 320f1f8 到终版 head 只差 packages/runtime 里的一个测试文件,我用 git diff --stat 核对过,battery 不加载这个文件,所以 battery 结论沿用到终版 head 成立。
  • runtime 包的测试在终版 head 上跑过:609 个文件全过。
  • objectql 和 rest 的读数分别在 320f1f8 / abe9374 上量的。我核对过:abe9374566 到 320f1f8 只改了一个 dogfood 测试文件,再往后只改了 runtime 那个测试文件。所以这两个包的读数也沿用成立。
  • MongoDB 单机:NOT MEASURED。原因可以核对:容器出口拒绝下载 mongod。裁决时这个后果就是按代码阅读给出的,正文把它写在了最上方。
  • check-governed-merges --pr 34503 我在这个 head 上跑了:12 个路径中 0 个命中登记表,NOT governed;283 行,不超过 3000。

CI
本 head 上 40 项成功、17 项跳过,没有红,也没有还在跑的。Test Core 1–8/8、Live E2E UI 都是成功;Test UI 的分片是跳过的,因为这次没有改 UI。

N1(不阻塞)
changeset 的 Cost 一条写"Objects without such a hook pay one map lookup"。实际代价是:取出该动词的 before* 钩子列表,再逐条做 hookMatchesObject。只有当这个动词下根本没有 before* 钩子时,才真的只是一次 map 查找。这里没有 IO,代价的量级判断没错,但说法不准确。

N2(不阻塞,交席位处理)
终版声明 6933943529 说 L2 之后是"Tier H hand-off to the maintainer"。按上面的 governed 读数,本 PR 不是 Tier H。narrowing 本身也不构成 Tier H:契约层 L2 PASS 加上终版 head 上的 battery,就走普通落地。正文「需要你做的:无,席位落地」是对的,声明里的说法应以正文为准。

交给契约评审(L2)留意

  • 声明是 Clause-②: no,按的是 ADR-0150 E1/E2 那类引擎层收窄的先例。但在两种配置下,REST 门对以前接受的请求现在会拒绝:一种是 before* 钩子往另一个数据源写业务行,另一种是 MongoDB 单机。这算不算"a door's response"的变化,由契约评审判断。
  • "跨数据源写被拒"和"账本类对象例外"这两条后果,本 PR 没有经由 before* 钩子重新量。它们靠的是已有的单元规则钉子:engine-transaction-same-origin.test.ts,账本例外在 :195 附近。正文如果点出这个出处,会更好核对。

仍欠
契约层 L2(已声明 narrowing),之后由席位落地。

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

review#2 · os-project-manager · session_01FEkQ5mjfxPu5HKjUtuveBR

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: d4062a6ba179318b9d3c5b08516de9b40bdcc12d
Local-runs: none
Scope: packages/objectql/src/engine-hooks-and-functions.ts, packages/objectql/src/engine-insert.ts, packages/objectql/src/engine-update.ts, packages/objectql/src/engine-delete-and-aggregate.ts, packages/objectql/src/engine-after-hook-abort-unit.test.ts, packages/objectql/src/engine-hook-stale-summary-refusal.test.ts, packages/rest/src/rest-hook-condition-unevaluable-refusal.test.ts, packages/runtime/src/sandbox/hook-ctx-title-one-hop.integration.test.ts, packages/qa/dogfood/test/scoped-transaction-late-write.dogfood.test.ts + read, not in the diff: packages/objectql/src/engine-hook-dispatch.ts, engine-transactions-section.ts, engine-top-level.ts, hook-wrappers.ts, summary-errors.ts, packages/spec/src/data/driver.zod.ts, packages/drivers/driver-mongodb/src/mongodb-driver.ts, packages/drivers/driver-sql/src/sql-driver.ts, packages/drivers/driver-memory/src/memory-driver.ts
Security-touching: yes

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

  • Which hooks open the unit: right, and exactly the ruling. opensAfterAbortUnit gains one term, sideWriting: an entry with meta (bound from metadata) on BEFORE_EVENT_OF[event] that hookMatchesObject admits. Same verb only (the map is afterInsert to beforeInsert, and so on). A code-registered hook has no meta and opens nothing. onError and async are not read, as ruled. The after* term is byte-identical.
  • The exits: right. The term sits after the open-unit exit (threaded or ambient, closed handles excepted) and the skipAutomations exit, and before the off-default-driver and driverSupportsTransactions exits, so all four apply to it unchanged.
  • No unit on the common path: right. With no matching metadata before* hook and no aborting after* hook the function returns false after one more hooks.get.
  • Rollback: right. The three doors re-enter through inAfterAbortUnit, so the whole body, the before* chain included, runs under the ambient unit; a hook's ctx.api write joins it (transaction() joins an ambient unit), and any throw rolls both back. Every before* dispatch in packages/objectql/src is inside these three bodies.
  • The matcher is the dispatch loop's own, so a metadata hook with no object, or *, opens the unit on every object, platform objects included. That follows the ruling; the PR body's "the platform's own objects do not change" holds only while no app declares such a hook.

② Semver level

  • Clause-②: no (narrowing) on the PR body and the changeset is the right spelling: nothing widens (no schema, export or accepted input is added), and clause2-line.mjs reads no (narrowing) as "not a widening, but breaking"; yes (narrowing) is for a diff that also widens. execution-duties treats it as the narrowing arm, and the final-head dogfood battery it owes is recorded on 320f1f8, with only a packages/runtime test file changed after it.
  • minor on @objectstack/objectql with the ! summary, the **BREAKING** banner and one ADR-0087 marker, not-required (no-migration-prescription): coherent. That category is refused only beside Metadata-protocol: narrowed; semantic keeps it, and semantic is the right kind (the meaning of a declared before* hook moves; no authored key or value is refused). Same shape as the objectql: an after* hook with onError: 'log' whose condition cannot be evaluated refuses the write (HookConditionError) while the row stays stored #22856 changeset.
  • FROM and TO lines: true against the code, with the gap named in S1.

③ Boundary flags

  • Check-runs on the head: 57, of which 40 success and 17 skipped, none pending, none red. Skipped ones include the CI dogfood shards and Temporal Conformance (live PG + MySQL), so nothing on this head ran against PostgreSQL.
  • The security line reads yes on the conservative rule: the hooks.mdx hunk teaches that an audit-class ledger write survives a rolled-back save.
  • Acceptance note, MongoDB standalone, not measured: answered as N3.
  • Acceptance notes on feat(objectql): a bulk update recomputes its parents' roll-up summaries once, at the end of the batch #34439, Turso remote, the two out-of-surface test files: read and hold. Skills-docs: follow-up #34504 exists and is open.
  • SQL push-down: not applicable; no read is added.

④ Design judgment

S1 (should-fix) — opensAfterAbortUnit, the new unit on PostgreSQL: a consequence of the narrowing is not named. Read in code, not measured. Inside the unit a hook's ctx.api write runs on the unit's connection with no savepoint (sql-driver.ts fences only its speculative statements, and its own note says any statement error on PostgreSQL aborts the whole transaction, 25P02). So a before* hook whose ctx.api statement fails at the database, and which the hook body catches, or onError: 'log' swallows, or retry re-runs, now refuses the outer write on PostgreSQL where that write was stored before. The changeset says onError: 'log' "decides only whether the hook's own throw refuses the write" and lists three rules of the unit; this is a fourth, and the maintainer was not told it with the ruling. Required: name it in the changeset list and in hooks.mdx (prose only), and carry a live PostgreSQL measurement on the PR's follow-up card.

N1 (nit) — engine-after-hook-abort-unit.test.ts: "same verb only" has no pin. The update and delete pins seed with an insert on an object whose only hook is beforeUpdate / beforeDelete and never assert begun for it, so a term that read every before* event would stay green by reading. The skipAutomations and off-default exits are pinned for the after* term only.

N2 (nit) — engine.insertMany (partial rows; the seed loader's door): a row refused per row does not refuse the call, the unit commits, and that row's before* side write stays. A boundary to record beside the code-registered one.

N3 (nit) — MongoDB standalone. By reading, the write is refused loudly, not left without rollback: beginTransaction always starts a session transaction, every operation carries the session, and supports declares no transactionsUnsupported, so the no-transactions exit cannot fire there. The changeset and docs name it and say it is unmeasured, and the maintainer chose with it named. The body's reason for no driver card holds: the filing gate asks a measured reach for a defect card. Accepted deviation; the measurement belongs on the follow-up card.

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.

  • Tests: not tautological. The three card pins and the REST pin over a real SqlDriver assert the hook's row absent after a real rollback; controls cover success, a caller's unit, a driver without transactions, a code-registered hook. No assertion is loosened: the flipped before* control and the stale-summary pin move from "no unit, row stays" to "one unit, rolled back, row absent", which is the ruled meaning. The runtime H2 pin now asserts one unit, every read on it, and exactly the title's two hops over a baseline; stricter than before. The dogfood fixture moves to an afterInsert onError: 'log' hook so its body still owns its transaction, which keeps what that test measures.

Implemented-by: claude/issue-34412-before-hook-side-write-unit
Reviewed-by: session_01FEkQ5mjfxPu5HKjUtuveBR

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-project-manager · session_01FEkQ5m1wi6BQceRHYYxHFy

State · #34503 · 2026-11-17T00:45Z

Head-sha: d4062a6ba179318b9d3c5b08516de9b40bdcc12d (CI: all success or expected skip, none red; mergeable_state clean)

  • Done: L1-b ACCEPT 6933995016 and review#2 contract-tier PASS 6934090371, both on this head.
  • Owed before the hand-off, from review#2's S1 (should-fix, prose only): name the fourth rule of the new unit in the changeset list and in content/docs/automation/hooks.mdx. Inside the unit a before* hook's ctx.api write runs with no savepoint, so on PostgreSQL a statement that fails at the database aborts the transaction (25P02). The outer write is then refused, even when the hook body catches the error or onError: 'log' / retry would have let it through. A live PostgreSQL measurement belongs on a follow-up card (the PG/MySQL conformance job was skipped on this head). Nits N1 to N4 in 6934090371 do not block.
  • After S1: a delta from review#2 and L1-b on the new head, then the Tier H hand-off to the maintainer (the seat's ruling: a narrowing is Tier H whatever the path register reads). The hand-off record must state MongoDB standalone NOT MEASURED, add pm:awaiting-merge, and request reviewers os-zhuang and hotlong. After his approval, land it through the queue.
  • Who: the maintainer ordered no new development at 2026-11-17T00:28Z, so this card thread stops here and the S1 edit passes to seat repo:objectstack#2 (mailbox pm:mailbox — repo:objectstack#2 · os-steve #34479). Branch claude/issue-34412-before-hook-side-write-unit, claim 6929281623 on 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.

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>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmSLi1reMd27fT62jJ3

Final head · PR #34503 · 2026-11-17T01:33Z

Taken over by area o2-E of seat repo:objectstack#2 (claim 6934211350 on #34412). Final head for the L1 and L2 deltas: ea2241644c5ad2cfed2a7bb295e7c2476424159d, one commit after d4062a6b: review#2's S1 (6934090371), prose only. The changeset's "Inside the new unit" list and content/docs/automation/hooks.mdx now name the PostgreSQL consequence: a failed statement aborts the whole unit (25P02) and the unit takes no savepoint around a hook's ctx.api write, so a before* hook that catches its own failed ctx.api statement, swallows it with onError: 'log', or re-runs it through retryPolicy now refuses the outer write on PostgreSQL. Read in code, not measured; the live PostgreSQL measurement (and N3, MongoDB standalone) is carried on #34563. Check-runs on this head: 53, 38 success and 15 skipped, none red. Local gates on this delta: check-adr-links, check-changeset-no-major, check-doc-route-spelling --advisory, check-empty-changeset, docs-audit/check-affected-docs, docs-audit/check-drift-comment exit 0; check-docs-section-name NOT MEASURED locally (no workspace install in this container), CI ran it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq

Contract-review-claim: session_01ADHkmP44onN8RMzsPMqjRq · head ea22416 · 2026-11-17T01:35Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmPZf3MhxKeGaxV4P3W

席位核对

L1 delta · ACCEPT · head ea2241644c5ad2cfed2a7bb295e7c2476424159d (delta over d4062a6b, L1 ACCEPT 6933995016 by seat 1's L1-b) · card #34412 · read 2026-11-17T01:36Z

Delta read (git diff d4062a6b ea224164: 1 commit, 2 files, +10 / −0, prose only)

  • What moved: one bullet in the changeset's "Inside the new unit" list and one paragraph in content/docs/automation/hooks.mdx. No source, test or generated file moves, so the first review's code, test and ablation readings stand unchanged.
  • It answers the L2 record's S1 (6934090371, CONTRACT_REVIEW_TIER, PASS at d4062a6b): the record required the PostgreSQL consequence named in the changeset list and in hooks.mdx, prose only, with the live measurement carried on the follow-up card. Both texts now name it, and review follow-ups of PR #34503 #34563 is open with that measurement as its S1 item (failing ctx.api statement swallowed by the hook body, by onError: 'log', and by retry; record the outer write's answer).
  • Sentences checked against the code at this head:
    • "the unit takes no savepoint around a hook's ctx.api write": true. driver-sql takes a savepoint only for its own speculative statements (autonumber, bulk operations); a hook's ctx.api write inside the unit runs on the unit's connection with none.
    • "a statement that fails at the database aborts the whole unit (25P02)": the driver's own notes say so (sql-driver.ts:2269, :2829).
    • "even when the hook body catches the error, onError: 'log' swallows it, or its retryPolicy re-runs it": wrapDeclarativeHook applies retryPolicy and the log swallow to before* handlers too (hook-wrappers.ts:274, :380), and opensAfterAbortUnit's sideWriting arm opens the unit whatever onError says, so the aborted transaction reaches the outer write's statement in every one of the three cases.
    • "that write was stored before": true. At d4062a6b's merge base no unit opened for a before* hook, so the hook's failed statement failed alone and the outer write ran on its own.
    • The fix line ("an after* hook with async: true") agrees with the existing "starts after the unit commits" sentence two bullets up.
    • "Read in the driver's code, not measured on PostgreSQL" is stated in both texts.
  • Nit, optional, no head move asked: changeset line 16 still says onError: 'log' "decides only whether the hook's own throw refuses the write". On PostgreSQL the new bullet is an exception to that when the throw came from a failed statement. A "(see the PostgreSQL rule below)" would remove the tension; the two bullets do not contradict as they stand, because line 16 is about a hook's own throw and the new one about a failed database statement.
  • Gates at this head: check-runs on ea224164…: 53 runs, 38 success, 15 skipped, 0 failed; Lint & Repo Gates, TypeScript Type Check, Lint · docs & code guards, Build Docs, Check Changeset, Dogfood Regression Gate success. The area's local check-docs-section-name NOT MEASURED is covered by the docs guards run here. Final head announced in 6935070187.

The first-review checklist (6933995016) stands for everything outside this delta.

Owed after this

  • L2: owed on this head. The narrowing face (Clause-②: no (narrowing)) puts the PR at CONTRACT_REVIEW_TIER; record 6934090371 names d4062a6b, and the changeset blob moved, so the clean-merge exception does not carry it. A delta read of S1's fix on ea224164 is needed. The seat routes it.
  • Landing tier: node scripts/pm/check-governed-merges.mjs --pr 34503: 0 of 12 paths governed, 293 changed lines (+255 / −38) ≤ 3000 ⇒ ordinary queue landing by the area after the L2 delta PASS names this head. (The area's note says Tier H; the register reads not governed at this file list.)

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: ea2241644c5ad2cfed2a7bb295e7c2476424159d
Local-runs: none
Scope: packages/objectql/src/engine-hooks-and-functions.ts, packages/objectql/src/engine-insert.ts, packages/objectql/src/engine-update.ts, packages/objectql/src/engine-delete-and-aggregate.ts, packages/objectql/src/engine-after-hook-abort-unit.test.ts, packages/objectql/src/engine-hook-stale-summary-refusal.test.ts, packages/rest/src/rest-hook-condition-unevaluable-refusal.test.ts, packages/runtime/src/sandbox/hook-ctx-title-one-hop.integration.test.ts, packages/qa/dogfood/test/scoped-transaction-late-write.dogfood.test.ts + read, not in the diff: packages/objectql/src/engine-hook-dispatch.ts, engine-transactions-section.ts, engine-top-level.ts, hook-wrappers.ts, summary-errors.ts, packages/spec/src/data/driver.zod.ts, packages/drivers/driver-mongodb/src/mongodb-driver.ts, packages/drivers/driver-sql/src/sql-driver.ts, packages/drivers/driver-memory/src/memory-driver.ts
Security-touching: yes

Delta review. Previous at-tier record: 6934090371, PASS on head d4062a6ba179318b9d3c5b08516de9b40bdcc12d, with S1 open and nits N1 to N4. That seat is unreachable, so this seat takes the delta. Card #34412, final-head record 6935070187, follow-up card #34563. The Scope line is the previous record's, unchanged, because no non-prose path moved; for this delta I also read sql-driver-bulk-operations.ts and sql-driver-sequence-semantics.ts in packages/drivers/driver-sql/src and packages/spec/src/data/hook.zod.ts.

What moved between the heads: one commit, ea224164, two files, 10 lines added and none removed: .changeset/34412-before-hook-side-write-unit.md (one list item) and content/docs/automation/hooks.mdx (one paragraph). Read from the two trees, not from the account: the diff of the two heads names no other path, the merge base is the same commit on both heads, and the PR still lists the same 12 files. The nine non-prose paths of the scope floor are byte-identical to the head the previous record judged.

① Derived judgments

  • Nothing derived moved: opensAfterAbortUnit, the three doors and every test are unchanged, so the previous record's five judgments stand on this head as written.
  • The new sentences, each checked against the code at this head:
    • "the unit takes no savepoint around a hook's ctx.api write": true. inAfterAbortUnit runs the door's body in transaction(); a hook's ctx.api write finds the ambient unit and neither opens a unit of its own nor a nested one, and a ctx.api.transaction(...) in the body joins by handing back the same handle (engine-transactions-section.ts, the ambient branch). The hook wrapper (hook-wrappers.ts, retry, timeout, onError) opens nothing around the handler. In the SQL driver the only nested transactions inside a caller's transaction are the speculative autonumber and timestamp statements, bulkUpdate and the MySQL organization fence of upsert; the engine's data doors do not call bulkUpdate, and that fence is MySQL only, so a plain create, update or delete from a hook runs unfenced on the unit's connection on PostgreSQL.
    • "a statement that fails at the database aborts the whole unit (25P02)": this is the driver's own note (sql-driver.ts, the attemptWithoutPoisoning docblock, which records it as measured on PostgreSQL 16 for the autonumber case). For the hook case it is read, not measured, and both texts say so.
    • "even when the hook body catches the error": true by reading. Catching leaves the connection in the aborted state, so the door's own statement is the next to fail.
    • "onError: 'log' swallows it": true by reading. runWithErrorPolicy returns after logging, the door goes on to its own statement on the same aborted unit.
    • "its retryPolicy re-runs it": true by reading, and the key is the schema's spelling. runWithRetry re-runs the handler on the same unit with no rollback between attempts, so the re-run's first statement fails too.
    • "that write was stored before" (changeset): true for the FROM case the changeset names, an object with no after* hook able to abort. There the door opened no unit, the hook's failed statement ran in its own implicit transaction, and the outer write went on. On an object that already had an aborting after* hook the unit was already open, so the consequence already held there; the docs sentence, which does not say "now", covers both.
    • The remedies: checking the condition before the write avoids the failed statement; an after* hook with async: true runs after the commit, outside the unit, so its failure cannot reach the write.
  • The other drivers. SQLite and MySQL: the driver's note says a failed statement does not abort the transaction, so a swallowed failure leaves the unit usable and the outer write is stored; naming PostgreSQL alone is right for them (MySQL's whole-transaction rollbacks on deadlock and lock-wait are a different event). The in-memory driver restores a snapshot only on rollback, so the same holds. MongoDB is not named for this rule: see N5.

② Semver level

  • Unchanged: Clause-②: no (narrowing), Metadata-protocol: semantic, minor with the BREAKING banner and the ADR-0087 marker. The new list item adds a fourth entry to "writes that were accepted are now refused", which is the same narrowing arm, named more fully; it changes no level and no declaration line. The front matter and the two declaration lines of the changeset are byte-identical between the heads.

③ Boundary flags

  • Check-runs on this head: 53, of which 38 success and 15 skipped, none pending, none red. The skipped ones again include Temporal Conformance (live PG + MySQL) and the CI dogfood shards, so nothing on this head ran against PostgreSQL. Check Changeset, Check Documentation Links, Build Docs and Lint · docs & code guards are success.
  • The dogfood battery recorded on 320f1f8 carries over: the only changes after it are one packages/runtime test file (judged in the previous record) and this prose commit.
  • Security line: yes, carried on the same conservative rule as the previous record.
  • Skills-docs: follow-up #34504 is unchanged. S1 did not name the skills page, the TSDoc or data-flow.mdx, so none of them was owed in this delta.
  • The PR is still a draft; that is the seat's to settle, not a finding.

④ Design judgment

Short, 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 hooks.mdx: done, a paragraph directly after the before* rules. (3) A live PostgreSQL measurement carried on the PR's follow-up card: #34563 is open, graded p2, blocked by #34412, and its first item is exactly that measurement, for the caught, log and retry paths, with "make the changeset and hooks.mdx wording match the measurement" and a done-when that binds the docs to what was measured. Every face S1 named moved, and every new sentence is backed by the code as listed 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 insertMany per-row boundary is still unrecorded.

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 (mongodb-driver.ts, beginTransaction), every operation carries the session, and the driver has no fence either. Whether a failed write there ends the session transaction, so that a swallowed failure refuses the outer write as on PostgreSQL, is not answered by this tree and is not measured. The text is true as far as it goes. Suggested: add that cell (replica set, a failing ctx.api write the hook swallows) to #34563 beside N3, and name the result in the same two places.

N6 (nit, new): the changeset still says, two items above, that onError: 'log' "decides only whether the hook's own throw refuses the write". On PostgreSQL the new item qualifies that for a throw that comes from a failed statement. The two read correctly together; a cross-reference would save a reader the second look.

No must-fix, no should-fix.

Implemented-by: claude/issue-34412-before-hook-side-write-unit
Reviewed-by: session_01ADHkmP44onN8RMzsPMqjRq

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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).
Head-sha: 27b4685

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 size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant