Skip to content

docs(skills): data-hooks teaches when a before* hook's ctx.api writes roll back with a refused save - #34964

Merged
os-zhuang merged 4 commits into
mainfrom
claude/issue-34504-before-hook-unit-of-work
Nov 19, 2026
Merged

os-zhuang merged 4 commits into
mainfrom
claude/issue-34504-before-hook-unit-of-work

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Fixes #34504
Ruling-ref: 6929103019

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:数据钩子技能页(skills/objectstack-data/references/data-hooks.md)写清楚了一条规则:保存前钩子通过 ctx.api 顺手写的记录,和这次保存在同一个事务里,保存被拒就一起撤回。页面同时列出四种不撤回的情况,并新增一条"不要在保存前钩子里往另一个数据源写业务记录"。另加两条评测用例。
  • 为什么改:PR 34503 已按裁决 A「整笔保存一起撤回」改了引擎行为,技能页却还只写"Within transaction"。AI 照旧页面写钩子,会写出运行时被拒或被撤回的写入(HotCRM 约 28 个对象带这类钩子)。
  • 风险与回滚:只改技能文档和评测,不改运行时。风险在措辞:页面说的必须和引擎一致。另外该页 token 上限只剩 15,所以删了同页四处重复表述来付账,上限没有动。回滚即撤回本 PR。
  • 先看:① data-hooks.md 的 "Before vs After Hooks" 表 Transaction 行 before* 单元格(核心规则);② 同文件 condition 一节的 "after* hooks dispatch once per matched row too" 一条(八行压成三行,是四处删减里唯一改写而不是整句删除的);③ evals/hooks-security-seeds-datasources.json 第 25、26 条。
  • 两分钟验证:运行 node scripts/check-skills-token-ratchet.mjs,预期看到 data-hooks.md is 10117 tokens (ceiling 10122; headroom 5),退出码 0。
  • 需要你做的:审阅并批准本 PR(skills/** 是受管面,Tier H,你批准后席位才落地)。

What changes

skills/objectstack-data/references/data-hooks.md, three places.

1. "Before vs After Hooks" table, Transaction row, before* cell. It said Within transaction. It now says, verbatim:

One transaction with the outer write: a refusal anywhere in it (a validation, a later hook, a driver constraint) rolls back the hook's ctx.api writes; no per-hook opt-out. Exits: a caller's open transaction decides; a hooked object off the default datasource, or a default driver with no transactions (Turso's remote transport), opens none, so those writes stay stored after a refusal; a hook registered in code (registerHook) opens none. MongoDB needs a replica set (read in code, not measured)

2. Best Practices, the DON'T list, one new item. Verbatim:

write business records to another datasource from a before* hook through ctx.api (its transaction refuses that write with CrossDatasourceTransactionWriteError; only an append-only ledger, lifecycle.class audit / telemetry / event, is written outside it and survives its rollback)

3. Four restatements removed, to pay for the new text. The file sat at 9996 tokens against a ceiling of 10011 (39984 bytes). The two additions cost 778 bytes, about 195 tokens. No ceiling moved, so the text is paid for by deleting 795 bytes of restatement in the same file:

Removed Bytes Where the fact still stands
Intro sentence "Covers the lifecycle events, the sandboxed body ... read masking)." 219 The page's own contents list, three lines above it, and SKILL.md line 46, which carries the same summary
The after* per-row bullet under condition, compressed from eight lines to three 371 "Why so few?" note under Hook Lifecycle Events: "Both phases dispatch once per matched row, each on a single-record-shaped context whose input.id ... names that row and whose previous is that row's pre-image". The kept sentence still says record is the row's real state and that a transition condition means the same for an id write and a predicate write
"and the declarative fields (condition, async, retryPolicy, timeoutMs, onError, priority) are honoured only on this path" (Registration, method 1) 137 Registration, method 2, which says it more exactly: those semantics "apply only through defineStack({ hooks }) or ql.bindHooks([...])". priority is still shown in method 2's registerHook example
"A single afterFind subscription covers both find and findOne." (pattern 4 callout) 68 The event table rows for beforeFind / afterFind and the "Why so few?" note ("one subscription covers every read shape")

skills/objectstack-data/evals/hooks-security-seeds-datasources.json gains two cases:

  • 25 (positive). A declared beforeInsert hook creates a timesheet row, a validation refuses the entry. The answer must say the row rolls back, that onError: 'log' does not keep it, and name the exits. Graded on roll, default datasource, registerHook.
  • 26 (DON'T). A request to write a business object on another datasource from a beforeInsert hook. The answer must redirect. Graded on CrossDatasourceTransactionWriteError, default datasource.

.changeset/34504-skills-before-hook-unit-of-work.md: patch on @objectstack/skills. The skills/** tree ships in that package (packages/skills/scripts/sync-catalog.mjs copies it into dist), so this diff publishes and skip-changeset does not apply.

Why

PR 34503 landed the engine change under ruling 6929103019 on card 34412. The ruling comment, verbatim:

Ruling: letter A · maintainer 「A 整笔保存一起撤回」 (the option he chose on the decision card) · recorded 2026-11-16T20:56Z

Route A. A write on an object that carries a metadata-bound before* hook on the same verb opens the write door's unit, with the three exits #22782 already has (a caller's open unit decides; an object off the default driver; a driver with no transactions). A refusal anywhere in that write then rolls back the hook's ctx.api side writes with it.

The skill page is what AI authors read before they write a hook. It said "Within transaction" with no condition, and nothing on the exits or on the cross-datasource refusal.

What each taught sentence rests on

All readings are from this branch's base, fff0ad0c18 on main.

Taught Code Governing doc
One transaction with the outer write; a refusal anywhere rolls back the hook's ctx.api writes packages/objectql/src/engine-hooks-and-functions.ts, opensAfterAbortUnit: the sideWriting term opens the unit for a metadata-bound before* hook on the same verb content/docs/automation/hooks.mdx, unit-of-work table, before* row; content/docs/api/data-flow.mdx, beforeInsert/Update/Delete row
No per-hook opt-out Same function: neither async nor onError narrows sideWriting hooks.mdx: "a refusal anywhere in the write rolls them back, with no per-hook opt-out"
Exit: a caller's open transaction decides Same function, first line: an open threaded or ambient unit returns false Ruling 6929103019, first exit
Exit: a hooked object off the default datasource opens none Same function: this.getDriver(object) === defaultDriver (object there is the outer write's object, the one the hook is on) hooks.mdx table: "Not opened on an object outside the default datasource"
Exit: a default driver with no transactions (turso's remote transport) opens none Same function: driverSupportsTransactions(defaultDriver); packages/drivers/driver-turso/src/turso-driver.ts: transactionsUnsupported: this.transportMode === 'remote' hooks.mdx table: "or on a driver with no transactions: there a before* hook's writes stay stored after a refusal"
Exit: a hook registered in code (registerHook) opens none Same function: sideWriting requires entry.meta, which only a metadata-bound hook carries hooks.mdx table: "A hook registered in code with registerHook opens no unit"
The cross-datasource write is refused with CrossDatasourceTransactionWriteError packages/objectql/src/engine-execute-transactions.ts, enforceTransactionOrigin hooks.mdx: "a write to an object on another datasource is refused with CrossDatasourceTransactionWriteError"
The append-only ledger carve-out (audit / telemetry / event) packages/objectql/src/engine.ts, SYSTEM_LEDGER_LIFECYCLE_CLASSES hooks.mdx: "The one exception is an append-only ledger on another datasource"
MongoDB needs a replica set (read in code, not measured) packages/drivers/driver-mongodb/src/mongodb-driver.ts: beginTransaction always calls session.startTransaction(), and the driver declares no transactionsUnsupported hooks.mdx: "on MongoDB, run it as a replica set, which any unit needs". The hedge is the one PR 34503 carries: nobody ran it on a standalone server

The stay-stored clause is attached only to the two exits hooks.mdx attaches it to. For a code-registered hook the page says only that it opens none.

Tests

  • No runtime code changes, so there is no new unit test and no ablation.
  • The engine pins that hold the taught behaviour, run on this head (486b6feb8f): pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/engine-after-hook-abort-unit.test.ts gives Test Files 1 passed (1), Tests 21 passed (21). That file pins the three verbs, the caller-opened transaction, the driver with no transactions and the code-registered hook.
  • The two new eval cases parse under the strict reader (packages/qa/scenarios/src/skill-evals/cases.ts, loadSkillEvalCatalog over this tree): 12 bundles, 219 cases, 0 refusals; objectstack-data has 46 cases (44 before).

Acceptance notes

  • Contract review round (record 7002617585 on 486b6fe: PASS with S1 should-fix). On 314d9cc (origin/main 35c6331 merged), the before* Transaction cell and eval 25 name the hooked object in the off-default-datasource exit: "Exits: a caller's open transaction decides; a hooked object off the default datasource, or a default driver with no transactions (Turso's remote transport), opens none". The changeset matches. N4 taken; N1–N3 accepted. Budget after the merge: data-hooks.md 10117 tokens against a ceiling of 10122 (40467 bytes). Gates on 314d9cc: 47 derived, 45 run with exit 0, 2 not measured locally (check:dual-build-cjs-loads, check:lean-entry-closure; CI runs them). Overlap-check clean. The page teaches security-adjacent behaviour (read masking coverage, the audit ledger row on rollback), so the PR carries security.

  • Line budget (PM-set: at most +10 net lines on data-hooks.md). Whole file: 890 lines before, 885 after (net -5; +13 / -18). Whole package, all SKILL.md files summed: 4728 lines before, 4728 after (12 files, none touched). Tokens, by check-skills-token-ratchet: data-hooks.md 9996 before, 9992 after, ceiling 10011 unchanged; ratcheted (authored) total 191126 before, 191122 after; eval fixtures (measured, not ratcheted) 53751 before, 54274 after.

  • The changeset is outside skills/**. The dispatch's file surface named skills/** only and told me to apply the publish rule. The rule says a diff that ships needs a changeset, and skills/** ships in @objectstack/skills.

  • NOT MEASURED: MongoDB on a standalone server. The page keeps the "read in code, not measured" hedge. I read the driver's code and did not run it.

  • The cross-datasource rule was measured with a throwaway probe, not left in the tree. No existing pin drives a before* hook's own ctx.api write to another datasource (the refusal is pinned for transaction() in engine-transaction-same-origin.test.ts). I copied the pin file's fake engine into a temporary test, ran three cases on 486b6feb8f and deleted it (git status clean after). Results: a metadata-bound beforeInsert writing a business row to the other datasource was refused with CrossDatasourceTransactionWriteError (code ERR_CROSS_DATASOURCE_TRANSACTION_WRITE), one unit begun and rolled back, no row on either datasource; the same write from a code-registered hook opened no unit and was stored; with the target declared lifecycle.class: 'audit', the row was written outside the unit and was still there after the refusal.

  • NOT MEASURED: a live eval round. The skill-evals runner calls a model through a local login and is not a gate. The cases were checked for shape only.

  • Not taught here, noted. hooks.mdx also says that on PostgreSQL a failed ctx.api statement inside the unit refuses the whole write even when the hook body catches the error. The card's ask does not name it, and it is not measured on PostgreSQL. carrier: review follow-ups of PR #34503 #34563.

  • Not taught here, noted. The Capabilities table says ctx.api.transaction commits on return and rolls back on throw. Inside a unit the write door opened, that transaction joins the outer unit: its return is no commit, and a throw the body catches leaves its writes in place (hooks.mdx: "A nested transaction() joins the outer unit, so its return is no commit"). The row is outside the card's ask and the file has 19 tokens of headroom left. Reported to the seat as an out-of-scope finding.

  • Overlap. node scripts/pm/overlap-check.mjs on 486b6feb8f: VERDICT clean exit 0, clean against origin/main (fff0ad0c18), and no open PR shares a file with this branch.

  • This PR touches a governed surface (skills/**). It stays a draft, and it owes an L1 review and a contract-tier L2 review before the maintainer's approval.

Verification

Head 486b6feb8f for every run below.

Derived gate families (47 derived, 43 run, 4 not measured)
  • node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack: 47 commands, each run with its exit code recorded before any pipe.
  • node scripts/pm/dispatch-gates.mjs --ran: 47 derived famil(ies) accounted for — 43 run, 4 NOT-MEASURED (4 DERIVED from a recorded exit 3). All 43 exit 0.
  • NOT MEASURED, reason: each reads every package's built dist, which this docs-only diff cannot move, and a full build was not run locally. CI runs them: check:dts-closure, check:dual-build-cjs-loads, check:lean-entry-closure, check:sourcemap-no-sources-content.
  • check:doc-formula-expressions answered exit 3 on its first run (prerequisite: @objectstack/formula and @objectstack/lint not built). After turbo run build of those two packages it answered exit 0: 26 record-scoped formula example(s) across 578 files / 1855 TS blocks judged clean.
  • check-skills-token-ratchet: 58 authored bundle file(s) within their ceilings.
  • check:skill-links: 256 relative link(s) in 72 published skill file(s) resolve; 130 fragment(s) name a real heading.
  • check-empty-changeset --base origin/main: No changeset from the merge base modified or deleted by this diff.
  • check-adr-0087-registration --base origin/main: this PR adds no declared-breaking changeset (1 non-breaking changeset(s) seen).
  • check:doc-authoring, check:corpus-claim-drift, check:role-word, check:skill-identifier-liveness, check:nul-bytes, check:published-files, check:skill-refs: exit 0.
Builds and the pin run
  • bash scripts/pm/os-verify-lock.sh -c 'pnpm exec turbo run build --concurrency=2 --filter=@objectstack/formula --filter=@objectstack/lint --filter=@objectstack/skills': Tasks: 6 successful, 6 total, VERDICT command-exit 0. The @objectstack/skills build is sync-catalog --self-test plus the sync.
  • bash scripts/pm/os-verify-lock.sh -c "pnpm --workspace-concurrency=2 --filter '@objectstack/objectql^...' build && pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/engine-after-hook-abort-unit.test.ts": Tests 21 passed (21), VERDICT command-exit 0.
  • pnpm lint, the type-check lanes and the rest of the farm: CI.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (not touched)
  • 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

… DON'T (over ratchet, deletions follow)

Claude-Session: https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C
Co-authored-by: Claude <noreply@anthropic.com>
…exits and the cross-datasource DON'T

The before* Transaction cell states one transaction with the outer write,
the four exits and no per-hook opt-out; Best Practices gains the
cross-datasource DON'T; two eval cases exercise both. Four restatements
in the same file pay for the new text (token ratchet 9996 -> 9992).

Claude-Session: https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/s documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 17, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C

维护者速读(席位终稿 · Head-sha: 486b6fe · 2026-11-17T19:47Z)

  • 改了什么:技能文档 data-hooks.md 里「before 钩子」的事务一格,原来只写「在事务内」,现在讲清楚:钩子经 ctx.api 写的数据和外层保存同属一个事务,外层任何一处被拒,钩子的写入一起回滚,不能单独豁免;并列出四种不开事务的例外(调用方自己开了事务、对象不在默认数据源、默认驱动不支持事务如 turso 远程、代码注册的钩子)。另加一条「不要」:before 钩子不要经 ctx.api 往别的数据源写业务记录(会被拒,只有审计类账本例外)。配两条评测用例。
  • 为什么改: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 已经让引擎这样工作(PR fix(objectql)!: a write refused after its before* hook wrote through ctx.api rolls that hook's write back #34503),但给 AI 读的技能还写着旧说法,AI 会写出「以为能留下的日志写入」或「跨数据源写」的钩子,运行时才发现被回滚或被拒。
  • 风险与回滚:只改技能文本和评测,不改任何运行代码;为不超 token 上限,删了同文件里四处重复表述,席位已逐条核对这些事实在同文件别处仍在。回滚即 revert。
  • 先看:skills/objectstack-data/references/data-hooks.md 第 62 行(事务一格)与 Best Practices 的 DON'T 一条。
  • 两分钟验证:打开该文件第 62 行,读 before 一列:应写明「同一事务、无单钩豁免、四种例外」。
  • 需要你做的:批准本 PR(受管面 Tier H,席位不能自批);批准前还欠一次契约审核(L2),已请 l2-review#3。

席位意见:建议批准。四个例外与跨数据源拒绝都由开发对着引擎代码与现有测试逐条核过(MongoDB 一条保留「读自代码、未实测」),删掉的四处重复席位逐条复核仍在原文件。

席位核对 · L1 ACCEPT · Head-sha: 486b6fe

Card #34504, claim 6958243261, dev report 6959003049. The seat read the diff itself.

Item Reading
Shape Draft, base main, Fixes #34504. Clause-②: no, Metadata-protocol: none. Three files: data-hooks.md (+13 −18), the eval file (+20), and a changeset. Governed surface (skills/**): Tier H.
Premise measured Holds: line 64 on main said "Within transaction" for before* with no exits. Each exit was verified by the dev against the engine code and existing pins. The cross-datasource refusal and the ledger carve-out were also measured with a throwaway probe. MongoDB keeps the "read in code, not measured" hedge, as the governing docs do.
Removed text Four restatements were deleted to fit the token ratchet (15 tokens of headroom; no ceiling moved). The seat re-checked each fact still stands on this head: the declarative fields only on defineStack (line 781); afterFind covers findOne (lines 30–42); per-row previous and input.id (lines 48, 182); the intro sentence (the page's own section list).
Budget data-hooks.md net −5 lines (budget +10), 9992 / 10011 tokens; the whole-package SKILL.md sum unchanged (4728).
Gates 43 of 47 derived families exit 0, among them the token ratchet, skill links and published files. 4 are NOT MEASURED (they need a full build; this diff cannot move them) and are CI-owned. CI is read again before the hand-off.
Changeset @objectstack/skills patch: the skill tree ships in that package, so skip-changeset does not apply. Read against the diff: the cell, the exits, the DON'T and the two evals match.
Out of scope The api.transaction row says "commit on return, rollback on throw" with no condition, while hooks.mdx says a nested transaction() joins the outer unit: the seat files it. The PostgreSQL no-savepoint note rides #34563.
Landing Governed (Tier H): the maintainer approves; the seat lands after that. Owed first: a contract-review-tier L2 record (governed rules text) and every check green.

Contract-review-handoff: l2-review#3 — CONTRACT_REVIEW_TIER not taken in this seat; seat 4 routes contract reviews to the seated L2 seat by mailbox (2026-11-17T19:47Z) · head 486b6fe

This was referenced Nov 17, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C

Contract-review-claim: session_012MmDsS4GoHCgYwA2uv3n3C · head 486b6fe · 2026-11-19T06:30Z

A fresh isolated reviewer sub-agent at CONTRACT_REVIEW_TIER renders the record (the governed rules face). The maintainer's approval is still owed after it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 486b6feb8f17a9bec275662aa0f9a5c6c9acfb7a
Local-runs: none
Scope: skills/objectstack-data/references/data-hooks.md, skills/objectstack-data/evals/hooks-security-seeds-datasources.json + none
Security-touching: yes

PR #34964, card #34504, face rules (governed skills/**). Read: the card body and all six comments, the PR body and both PR comments, the net diff against main (three files), the 44 check-runs on this head. Code read on origin/main (8b550f8193), never reviewed: packages/objectql/src/engine-hooks-and-functions.ts (opensAfterAbortUnit, registerHook options), engine-insert.ts (unit entry, enforceTransactionOrigin call), engine-execute-transactions.ts (enforceTransactionOrigin), engine.ts (SYSTEM_LEDGER_LIFECYCLE_CLASSES), engine-secrets-and-routing.ts (isSystemLedgerObject, routing order), transaction-errors.ts, engine-after-hook-abort-unit.test.ts (pin titles), packages/drivers/driver-turso/src/turso-driver.ts, packages/drivers/driver-mongodb/src/mongodb-driver.ts, packages/qa/scenarios/src/skill-evals/grade.ts, content/docs/automation/hooks.mdx, content/docs/api/data-flow.mdx. The changeset is read for its level and declaration lines only.

Why Security-touching: yes: the path name does not show it, but two changed hunks sit on security teaching. (1) The pattern 4 hunk edits the "Data Masking on Read" callout: it removes the sentence that says one afterFind subscription covers findOne, which is the coverage of a read-masking control. (2) The new DON'T teaches that an audit-class ledger row is written outside the transaction and survives its rollback, which is audit-trail behaviour. Neither is wrong (see ④), but neither is plain wording either.

① Derived judgments

  • Premise: holds. On the merge base (fff0ad0c18) the before* Transaction cell said "Within transaction". On main today it still does; nothing else has taught the rule in that cell.
  • Every taught sentence was checked against the code on main, not against the PR body's table. Result in ④: all hold on their intended reading; one phrase has a second reading that is false (S1).
  • main has moved since the base (data-hooks.md changed by other PRs, docs(skills): data-hooks api.transaction row says when it joins an outer unit and that it is one datasource; teach hook texts + ctx.text #35309 among them, and the eval file gained ids 27 to 31). Read with git plumbing only, no checkout: the three-way merge of this head onto main is textually clean, the merged eval ids are unique (25 and 26 are free on main), and the merged data-hooks.md is 40469 bytes, 10118 tokens against main's ceiling of 10122. Headroom after the merge is 4 tokens, not the 19 the PR body reports for its own base.
  • The four removed restatements: each fact still stands at this head and on the merged tree. findOne coverage: event table rows and the "Why so few?" note. Per-row after* dispatch, previous pre-image, input.id / ctx.previous.id: the "Why so few?" note ("Both phases dispatch once per matched row"). Declarative fields only on the bound path: Registration method 2, which is the more exact statement (defineStack({ hooks }) or ql.bindHooks). Intro sentence: the page's own contents list.
  • Gates: the check-runs on this head are the verdicts. 28 success, 16 skipped (opt-in, queue-only or path-filtered), none failed or pending. Check Changeset, Governed Surface Queue Guard, PR-body guards, Lint · docs & code guards and Lint · repo & tooling gates are success. The dev's four locally unmeasured families ride those CI lanes.

② Semver level

@objectstack/skills patch, Clause-②: no, Metadata-protocol: none, the same pair in the PR body and the changeset body. Correct: the diff changes teaching text and eval fixtures, moves nothing an author can write, and skills/** ships in that package, so a changeset is owed and skip-changeset would be wrong. No Clause-② arm applies. Check Changeset is success.

③ Boundary flags

④ Design judgment

data-hooks.md, the before* Transaction cell, sentence by sentence against opensAfterAbortUnit on main:

  • "One transaction with the outer write; a refusal anywhere in it rolls back the hook's ctx.api writes too": holds. sideWriting is true for any metadata-bound before* entry on the same verb that matches the object, and insert / update / delete re-enter through inAfterAbortUnit. Pinned for a declared validation (insert, update) and a later beforeDelete hook.
  • "no per-hook opt-out": holds. sideWriting reads neither onError nor async. The only switch is the caller's skipAutomations, under which the hook does not run at all.
  • "a transaction the caller opened decides": holds (first line of the function; pinned).
  • "a default driver with no transactions (turso's remote transport) opens none, so those writes stay stored": holds (driverSupportsTransactions; transactionsUnsupported: this.transportMode === 'remote'; pinned).
  • "a hook registered in code (registerHook) opens none": holds for registerHook without meta, which is what the page's own method 2 shows. The page rightly does not attach "stay stored" here: a unit another hook on the object opened would still cover it.
  • "MongoDB needs a replica set (read in code, not measured)": the driver's beginTransaction always calls session.startTransaction() and declares no transactionsUnsupported. The hedge is honest and is the one the card asks for.
  • "an object off the default datasource ... opens none, so those writes stay stored": true of the object the HOOK is on (this.getDriver(object) === defaultDriver, where object is the outer write's). See S1.

The DON'T: holds. Inside the unit, enforceTransactionOrigin throws CrossDatasourceTransactionWriteError for a non-ledger object on another driver, at the top of the side write; a ledger class object on another datasource runs outside the unit and survives. In the three no-unit exits the write is not refused but stored, so the advice "don't" is right on every path.

Evals 25 and 26: both discriminate (a model without the new text names neither registerHook nor the error class), and the scenario order in 25 is the pinned one (hook write, then the declared validation refuses). Eval 26's remedy matches hooks.mdx ("Keep the objects a before* hook writes on the default datasource").

S1 (should-fix) — "an object off the default datasource" does not say WHICH object, and one reading is false. In the cell, the only objects in view are the ones the hook writes through ctx.api, so the natural reading is "a write to an object off the default datasource opens no transaction and stays stored after a refusal". The runtime does the opposite: with the hooked object on the default datasource, that write is refused with CrossDatasourceTransactionWriteError and nothing is stored. This is the exact mistake the card exists to prevent ("rely on a log-the-attempt write surviving a refusal"), and the DON'T 740 lines later then reads as a contradiction instead of a rule. Eval 25's expected_output repeats it with two objects in play ("the object is off the default datasource": time_entry or timesheet?), so the reference answer has a false reading too. Fix: name the hooked object in both places, for example "the hook's object off the default datasource" in the cell and "time_entry is off the default datasource" in eval 25. Mind the budget: after a rebase on main the file has 4 tokens (16 bytes) of headroom.

Nits (no effect on correctness or the contract; fix with S1 or leave as accepted deviation):

  • N1 — the DON'T's ledger clause is true only for a ledger on another datasource; an audit-class object that stays on the default datasource rolls back with the save. The sentence's scope ("to another datasource") carries it and eval 26 says it outright.
  • N2 — after the merge with main the page names the same refusal two ways: CrossDatasourceTransactionWriteError here, 400 ERR_CROSS_DATASOURCE_TRANSACTION_WRITE in the api.transaction row (docs(skills): data-hooks api.transaction row says when it joins an outer unit and that it is one datasource; teach hook texts + ctx.text #35309). Both are real (class name and code).
  • N3 — eval assertions: 25 requires registerHook although its prompt's hook is declared in the stack, so a correct answer that lists only the two stay-stored setups fails; the grader is a case-sensitive substring match, so "Default datasource" at a sentence start fails both cases; 26 has no must_not_contain, so an answer that writes the hook and merely mentions the error passes. The runner is not a gate.
  • N4 — "turso's" is lower-case; the skill elsewhere writes driver-turso or "Turso".

No must-fix. One should-fix (S1): a delta review of the new head is owed by this reviewer before the maintainer's approval is sought. Tier H stands either way.

Implemented-by: claude/issue-34504-before-hook-unit-of-work
Reviewed-by: session_012MmDsS4GoHCgYwA2uv3n3C

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C

The contract review on 486b6fe (just above) reads Security-touching: yes: the changed hunks teach how data masking covers reads and that an audit-class ledger row survives rollback. Per the brief, the seat adopting the record adds security. S1 (should-fix) is open, and a delta review is owed on the fixed head (2026-11-19T07:23Z).

…atasource exit

The before* Transaction cell said 'an object off the default datasource',
which reads as the object the hook writes; that write is refused, not
stored. The cell and eval 25 now name the hooked object. The cell does
not grow (40469 -> 40467 bytes).

Claude-Session: https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C

席位核对 · L1 delta ACCEPT · Head-sha: 314d9cc · 2026-11-19T07:41Z

The dev's delta report is 7002915160 on #34504. It closes S1 of record 7002617585 and merges origin/main 35c6331 (no conflict).

Item Reading
S1 The before* Transaction cell and eval 25's expected_output now name the hooked object: "a hooked object off the default datasource" and "time_entry, the hooked object, is off the default datasource". The changeset matches. The eval prompt and assertions are unchanged.
Paid inside the hunk To pay for "hooked", "a transaction the caller opened decides" became "a caller's open transaction decides", and "too" was dropped. Neither changes what is taught; the delta review reads both. N4 (Turso capitalised) is taken.
Budget data-hooks.md is 10117 tokens against a ceiling of 10122 after the merge. The S1 edit shrank the file by 2 bytes.
Gates Locally: 47 derived, 45 exit 0, 2 not measured (they need packages this diff cannot move; CI runs them). Overlap-check clean. CI on the new head: read before landing.
PR body The seat added the review-round note.
Owed A delta contract-review-tier L2 record on this head, then the maintainer's approval (governed skills/**, Tier H).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C

Contract-review-claim: session_012MmDsS4GoHCgYwA2uv3n3C · head 314d9cc · 2026-11-19T07:42Z

A fresh isolated reviewer sub-agent at CONTRACT_REVIEW_TIER renders the delta record.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 314d9cc0ca914b6315d7d12c8a8e4d710c20b625
Local-runs: none
Scope: skills/objectstack-data/references/data-hooks.md, skills/objectstack-data/evals/hooks-security-seeds-datasources.json + none
Security-touching: yes

Delta round on record 7002617585 (head 486b6feb8f), which left S1 open. PR #34964, card #34504, face rules (governed skills/**). Read: the card body and its seven comments (delta report 7002915160 among them), the PR body, file list and six comments, the delta 486b6feb8f..314d9cc0ca on skills and .changeset, the net diff against origin/main (35c6331094), and the 45 check-runs on this head. Code read on origin/main, never reviewed: packages/objectql/src/engine-hooks-and-functions.ts (opensAfterAbortUnit), engine-hook-dispatch.ts (inAfterAbortUnit), engine-execute-transactions.ts (enforceTransactionOrigin), engine-after-hook-abort-unit.test.ts (pin titles), packages/drivers/driver-turso/src/turso-driver.ts, content/docs/automation/hooks.mdx. The changeset is read for its level, its declaration lines and its agreement with the page.

Security-touching: yes, restated on this head: the net diff still edits the "Data Masking on Read" callout (it removes the sentence on findOne coverage of an afterFind mask) and the new DON'T still teaches that an audit-class ledger row is written outside the transaction and survives its rollback. This round changed neither hunk.

① Derived judgments

  • The delta is two commits: a merge of origin/main 35c6331094 (cfeb6462d1) and the S1 wording (314d9cc0ca). The PR's own change this round is three one-line edits: the before* Transaction cell, eval 25's expected_output, and the changeset paragraph.
  • The merge is clean. git diff origin/main 314d9cc0ca names exactly the PR's three files (+43 −18), so the head is main plus this PR and nothing else. The merged eval ids are 1 to 31, each once; 25 and 26 are this PR's.
  • The merge leaves the taught sentences true. main now carries the api.transaction row from docs(skills): data-hooks api.transaction row says when it joins an outer unit and that it is one datasource; teach hook texts + ctx.text #35309 ("Inside a unit already open (the one the hook's write runs in, or a caller's) it joins that unit") and eval 28 ("a plain ctx.api write to it inside the save's unit is refused the same way"). Both agree with this PR's cell and its DON'T.
  • The four removed restatements still stand on the merged page: findOne coverage (event table rows and the "Why so few?" note), per-row dispatch (same note), the declarative fields on the bound path only (Registration method 2, ql.bindHooks), and the page's contents list.
  • Budget: the merged page is 888 lines, 40467 bytes, measured from the tree. The dev reports 10117 tokens against a ceiling of 10122. I did not measure tokens (read-only round); the ratchet's verdict is the Lint · docs & code guards run, which was still in progress when I read it.
  • Gates, as read at the end of this round: 45 check-runs; 21 success, 18 skipped, 6 in_progress, none failed. Check Changeset (both runs), PR-body guards (both runs), Governed Surface Queue Guard, Lint · ESLint, Lint · PM dispatch-gates, Type Check · workspace, Type Check · source gates and Build Core are success. Still running: Lint · docs & code guards, Lint · repo & tooling gates, Lint · CI, release & engine gates, Type Check · consumer gates, Test Core (1/10), Test Core (2/10). Their conclusions are the gate verdicts; this record does not stand in for them.

② Semver level

@objectstack/skills patch, Clause-②: no, Metadata-protocol: none, the same pair in the PR body and the changeset. Unchanged this round and still correct: teaching text and eval fixtures only, nothing an author can write moves, and skills/** ships in that package. No Clause-② arm applies. Check Changeset is success on this head.

③ Boundary flags

④ Design judgment

The before* Transaction cell on this head, the three changed phrases against opensAfterAbortUnit on main:

  • "a hooked object off the default datasource ... opens none, so those writes stay stored after a refusal": holds, and it now has one reading. The function's last line is this.getDriver(object) === defaultDriver, where object is the outer write's object, the one the hook matched. With that object off the default driver no unit is opened, so the hook's ctx.api writes are not covered and stay stored. The false reading S1 named (a write TO an off-default object stays stored) is no longer available: the phrase names the object the hook is on, and the object a hook writes to is not "hooked". The DON'T further down now reads as a separate rule and not as a contradiction.
  • "a caller's open transaction decides": holds. The first line of the function returns false when a threaded handle is open (a closed handle is not open, isClosedUnitHandle) or an ambient unit is in the store; the write then runs in that unit and its owner commits or rolls back. Pinned: "CONTROL inside a caller-opened transaction() — it joins (one unit), and the caller decides". "open" is the right word and loses nothing against "a transaction the caller opened".
  • "rolls back the hook's ctx.api writes" (the word "too" dropped): holds. The sentence still names the refusal's own scope ("a refusal anywhere in it"), and the row of the refused write is rolled back by the same unit; "too" carried no fact.
  • "Turso's remote transport": transactionsUnsupported: this.transportMode === 'remote' on main. Unchanged in substance.

Eval 25, expected_output: "time_entry, the hooked object, is off the default datasource" names which of the two objects in the prompt is meant, and it is the one the code tests. The prompt and the assertions are unchanged. Eval 26 is unchanged.

The changeset paragraph carries the same two phrases as the page. It keeps "writes too" in its own sentence, which is prose about the change and true.

Findings by id:

  • S1: closed. The cell and eval 25 name the hooked object; read against the code above.
  • N1: open, accepted. The ledger clause in the DON'T is unchanged; its scope ("to another datasource") still carries it and eval 26 says it outright.
  • N2: open, accepted. On the merged page the refusal is named by class (CrossDatasourceTransactionWriteError, the DON'T) and by code (400 ERR_CROSS_DATASOURCE_TRANSACTION_WRITE, the api.transaction row). Both are real.
  • N3: open, accepted. Eval 25 and 26 assertions are unchanged; the runner is not a gate.
  • N4: closed. "Turso's" is capitalised in the cell, eval 25 and the changeset.
  • N5 (nit, new): the PR body is stale against this head in two places a reader acts on. "What changes", item 1, still quotes the old cell verbatim ("a transaction the caller opened decides; an object off the default datasource ... turso's"). The two-minute verification line still expects 9992 tokens (ceiling 10011; headroom 19), where the dev's reading on this head is 10117 tokens (ceiling 10122; headroom 5). The tree is right and the Acceptance note at the top of that section does carry the new cell; the delta report lists the body edits under pr_body_changes. No effect on the contract.

No must-fix, no should-fix.

Tier H stands: the maintainer's approval is owed, and the six check-runs still in progress must conclude before landing.

Implemented-by: claude/issue-34504-before-hook-unit-of-work
Reviewed-by: session_012MmDsS4GoHCgYwA2uv3n3C

VERDICT: PASS

@os-zhuang
os-zhuang marked this pull request as ready for review November 19, 2026 08:14
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit adcb9f8 Nov 19, 2026
53 checks passed
@os-zhuang
os-zhuang deleted the claude/issue-34504-before-hook-unit-of-work branch November 19, 2026 08:33
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 security size/s tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

skills/objectstack-data data-hooks.md: teach when a before* hook's ctx.api write rolls back with a refused save, and its exits

3 participants