Repository navigation
docs(skills): data-hooks teaches when a before* hook's ctx.api writes roll back with a refused save - #34964
Conversation
… 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>
|
repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C 维护者速读(席位终稿 · Head-sha: 486b6fe · 2026-11-17T19:47Z)
席位意见:建议批准。四个例外与跨数据源拒绝都由开发对着引擎代码与现有测试逐条核过(MongoDB 一条保留「读自代码、未实测」),删掉的四处重复席位逐条复核仍在原文件。 席位核对 · L1 ACCEPT · Head-sha: 486b6feCard #34504, claim 6958243261, dev report 6959003049. The seat read the diff itself.
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 |
|
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 |
|
repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C Contract reviewServed-tier: PR #34964, card #34504, face Why ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
The DON'T: holds. Inside the unit, Evals 25 and 26: both discriminate (a model without the new text names neither 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 Nits (no effect on correctness or the contract; fix with S1 or leave as accepted deviation):
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: VERDICT: PASS |
|
repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C The contract review on 486b6fe (just above) reads |
…of-work Claude-Session: https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C Co-authored-by: Claude <noreply@anthropic.com>
…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>
|
repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C 席位核对 · L1 delta ACCEPT · Head-sha: 314d9cc · 2026-11-19T07:41ZThe dev's delta report is 7002915160 on #34504. It closes S1 of record 7002617585 and merges origin/main 35c6331 (no conflict).
|
|
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. |
|
repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C Contract reviewServed-tier: Delta round on record 7002617585 (head
① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentThe
Eval 25, 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:
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: VERDICT: PASS |
Fixes #34504
Ruling-ref: 6929103019
Clause-②: no
Metadata-protocol: none
维护者速读
skills/objectstack-data/references/data-hooks.md)写清楚了一条规则:保存前钩子通过ctx.api顺手写的记录,和这次保存在同一个事务里,保存被拒就一起撤回。页面同时列出四种不撤回的情况,并新增一条"不要在保存前钩子里往另一个数据源写业务记录"。另加两条评测用例。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。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 saidWithin transaction. It now says, verbatim:2. Best Practices, the DON'T list, one new item. Verbatim:
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:
body... read masking)."SKILL.mdline 46, which carries the same summaryafter*per-row bullet undercondition, compressed from eight lines to threeinput.id... names that row and whosepreviousis that row's pre-image". The kept sentence still saysrecordis the row's real state and that a transition condition means the same for an id write and a predicate writecondition,async,retryPolicy,timeoutMs,onError,priority) are honoured only on this path" (Registration, method 1)defineStack({ hooks })orql.bindHooks([...])".priorityis still shown in method 2'sregisterHookexampleafterFindsubscription covers bothfindandfindOne." (pattern 4 callout)beforeFind/afterFindand the "Why so few?" note ("one subscription covers every read shape")skills/objectstack-data/evals/hooks-security-seeds-datasources.jsongains two cases:beforeInserthook creates atimesheetrow, a validation refuses the entry. The answer must say the row rolls back, thatonError: 'log'does not keep it, and name the exits. Graded onroll,default datasource,registerHook.beforeInserthook. The answer must redirect. Graded onCrossDatasourceTransactionWriteError,default datasource..changeset/34504-skills-before-hook-unit-of-work.md:patchon@objectstack/skills. Theskills/**tree ships in that package (packages/skills/scripts/sync-catalog.mjscopies it intodist), so this diff publishes andskip-changesetdoes not apply.Why
PR 34503 landed the engine change under ruling 6929103019 on card 34412. The ruling comment, verbatim:
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,
fff0ad0c18onmain.ctx.apiwritespackages/objectql/src/engine-hooks-and-functions.ts,opensAfterAbortUnit: thesideWritingterm opens the unit for a metadata-boundbefore*hook on the same verbcontent/docs/automation/hooks.mdx, unit-of-work table,before*row;content/docs/api/data-flow.mdx,beforeInsert/Update/DeleterowasyncnoronErrornarrowssideWritinghooks.mdx: "a refusal anywhere in the write rolls them back, with no per-hook opt-out"falsethis.getDriver(object) === defaultDriver(objectthere is the outer write's object, the one the hook is on)hooks.mdxtable: "Not opened on an object outside the default datasource"driverSupportsTransactions(defaultDriver);packages/drivers/driver-turso/src/turso-driver.ts:transactionsUnsupported: this.transportMode === 'remote'hooks.mdxtable: "or on a driver with no transactions: there abefore*hook's writes stay stored after a refusal"registerHook) opens nonesideWritingrequiresentry.meta, which only a metadata-bound hook carrieshooks.mdxtable: "A hook registered in code withregisterHookopens no unit"CrossDatasourceTransactionWriteErrorpackages/objectql/src/engine-execute-transactions.ts,enforceTransactionOriginhooks.mdx: "a write to an object on another datasource is refused withCrossDatasourceTransactionWriteError"audit/telemetry/event)packages/objectql/src/engine.ts,SYSTEM_LEDGER_LIFECYCLE_CLASSEShooks.mdx: "The one exception is an append-only ledger on another datasource"packages/drivers/driver-mongodb/src/mongodb-driver.ts:beginTransactionalways callssession.startTransaction(), and the driver declares notransactionsUnsupportedhooks.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 serverThe stay-stored clause is attached only to the two exits
hooks.mdxattaches it to. For a code-registered hook the page says only that it opens none.Tests
486b6feb8f):pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2 src/engine-after-hook-abort-unit.test.tsgivesTest 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.packages/qa/scenarios/src/skill-evals/cases.ts,loadSkillEvalCatalogover this tree): 12 bundles, 219 cases, 0 refusals;objectstack-datahas 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.md10117 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 carriessecurity.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, allSKILL.mdfiles summed: 4728 lines before, 4728 after (12 files, none touched). Tokens, bycheck-skills-token-ratchet:data-hooks.md9996 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 namedskills/**only and told me to apply the publish rule. The rule says a diff that ships needs a changeset, andskills/**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 ownctx.apiwrite to another datasource (the refusal is pinned fortransaction()inengine-transaction-same-origin.test.ts). I copied the pin file's fake engine into a temporary test, ran three cases on486b6feb8fand deleted it (git statusclean after). Results: a metadata-boundbeforeInsertwriting a business row to the other datasource was refused withCrossDatasourceTransactionWriteError(codeERR_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 declaredlifecycle.class: 'audit', the row was written outside the unit and was still there after the refusal.NOT MEASURED: a live eval round. The
skill-evalsrunner calls a model through a local login and is not a gate. The cases were checked for shape only.Not taught here, noted.
hooks.mdxalso says that on PostgreSQL a failedctx.apistatement 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.transactioncommits 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 nestedtransaction()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.mjson486b6feb8f:VERDICT clean exit 0, clean againstorigin/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
486b6feb8ffor 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.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-expressionsanswered exit 3 on its first run (prerequisite:@objectstack/formulaand@objectstack/lintnot built). Afterturbo run buildof 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/skillsbuild issync-catalog --self-testplus 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
packages/specholds no runtime logic. (not touched)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