Skip to content

docs(hooks): state what a hook body's ctx.api.transaction joins and where it stops; skills: the measured MongoDB and PostgreSQL rule - #38155

Merged
os-zhuang merged 3 commits into
mainfrom
claude/project-thread-ohd9ea
Nov 28, 2026
Merged

os-zhuang merged 3 commits into
mainfrom
claude/project-thread-ohd9ea

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Sales · project thread

Fixes #35324
Fixes #37992

Clause-②: no
Metadata-protocol: none

维护者速读

  • 是什么:写钩子和动作脚本的开发者(以及照技能写代码的 AI)在文档和数据技能里能读到「脚本里的事务能做到哪、到哪为止」:同一段脚本里事务不能再套事务;脚本自己开的事务里触发的钩子会并进同一个事务;写到别的数据源会被拒(审计、遥测这类只追加的日志表除外);PostgreSQL 和 MongoDB 副本集上一条语句失败整个事务作废;不支持事务的数据库上什么也不回滚且没有提示。MongoDB 那句「未实测」换成了实测结论。运行时行为不变。
  • 为什么:属于「AI 照技能写出能跑的元数据」。这些边界以前只能在报错时撞上,其中 MongoDB 单机与 PostgreSQL 的规则上一张卡已实测。
  • 出错会怎样:只是文档、技能文字和两条测试,写错了是教错,可直接撤回;技能文件已在字数上限,新增靠删掉同文件里重复的代码注释来付。
  • 要你做的:技能目录属于需你批准合并的路径,请审后批准合并。

What changes

Premise corrected (card comment 7234049171): on main 0e36120 a test already pinned the nested refusal (asserting only the throw), and a body's own unit IS joined: publishTrioHandleFor (packages/objectql/src/engine-middleware-and-context.ts) publishes the trio's handle per operation. Measured on the real engine, real QuickJS and a rollback-honest driver: a hook fired by a write inside a trio-opened transaction, beforeInsert or afterInsert, with or without its own ctx.api.transaction, ran on the one handle with one begin, and commit kept both rows while rollback kept neither (8 of 8). So the docs and the skill teach the join, not a second unit.

  • packages/runtime/src/sandbox/quickjs-runner.test.ts: "rejects a nested transaction" now asserts a SandboxError, exactly one begin, the outer unit rolled back, no commit, and nothing after the nested call run.
  • packages/runtime/src/sandbox/transaction-ambient-join.integration.test.ts: two cases on the hook-body face (the engine face is engine-ambient-transaction.test.ts): inside a transaction opened through ScopedContext's trio, as an action body's ctx.api.transaction opens it, the hook body's ctx.api.transaction joins it (one begin, both writes on its handle, one commit), and its rollback undoes the hook's write.
  • content/docs/automation/hooks.mdx: new subsection "What ctx.api.transaction joins, and where it stops": joins any open unit, including one a body opened, and hooks of writes inside it join it; one level per body (nested refused); default datasource only, ledger carve-out; a failed statement aborts the unit on PostgreSQL and a MongoDB replica set even when caught; no unit and no warning on a driver with no transactions. The async after-hook bullet's "A nested transaction() joins" is bounded and links there.
  • skills/objectstack-data/references/data-hooks.md: the before* Transaction cell replaces "MongoDB needs a replica set (read in code, not measured)" with the measured rule (standalone refuses every write of such a transaction, 501 NOT_IMPLEMENTED, a single-node replica set is enough; on PostgreSQL and a MongoDB replica set a failed ctx.api statement refuses the outer write even when caught, logged or retried, 25P02 / 251; SQLite lets it through). The api.transaction row carries the same bounds as the page. The Best Practices ledger sentence points at that row instead of repeating it.
  • skills/objectstack-data/evals/hooks-security-seeds-datasources.json: the "not measured" case now expects the measured rule; the cross-datasource case names the ledger carve-out.
  • .changeset/35324-hook-transaction-bounds.md: @objectstack/skills patch (the package ships skills/**). The runtime change is tests only and ships nothing.

Skills readings (lines / bytes, base 0e36120 → head):

before after
data-hooks.md 872 / 40480 856 / 40477
hooks-security-seeds-datasources.json (eval, unpriced) 391 / 39028 391 / 39521
all skills/**/SKILL.md, lines 4952 4952
whole skills/ tree, bytes 1224261 1224751

data-hooks.md stays at 10120 tokens, its ceiling (headroom 0). The +878 bytes added are paid by 881 bytes cut in the same file: restating code comments (// Required: Target object(s) → // Required and five like it; "Database transaction handle", "Cross-object CRUD API", "Record ID being updated / deleted", "Only fields being changed", "Mask sensitive fields", two candidate example comments), section labels ("Insert / Update / Delete / Query operations:", "Mutable data", "Execution context", "Engine access", "Available in after* hooks:"), and five clauses each stated elsewhere in the file ("await is allowed", "In an after* hook the body is for side effects", "isolated QuickJS VM", ", not a global admin bypass", "(surfaces as a hook error)", the inline-handler-deprecated note, and the ledger definition now in the api.transaction row). No fact leaves the file.

The skills/** edits were written by an isolated sub-agent at the contract-review tier; node scripts/pm/verify-review-tier.mjs on its transcript: PASS — 22 assistant turn(s), every one served at CONTRACT_REVIEW_TIER.

Tests

runs (head 592009f)
  • pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/sandbox/transaction-ambient-join.integration.test.ts: 8 passed.
  • … src/sandbox/quickjs-runner.test.ts -t "nested transaction": 1 passed.
  • Ablation of the new join pins: with publishTrioHandleFor short-circuited to return chain() in the built @objectstack/objectql dist, both new cases fail (2 failed, 6 passed); dist restored from its saved copy.
  • Gates derived by node scripts/pm/dispatch-gates.mjs --commands (81): run locally, all exit 0: check:doc-anchors, check:doc-authoring, check:skill-links, check:issue-citations, check:nul-bytes, check-skills-token-ratchet.mjs, check:docs-single-h1, check:doc-frontmatter, check:cross-package-test-inputs, check:test-source-alias, check:skill-identifier-liveness, check:corpus-claim-drift, check:docs-transcript-drift, docs-audit/check-affected-docs.mjs, check-issue-citations.mjs, check:engine-double-contract, check:pm-skill-id-lint, check:skill-compatibility, check:skill-frame-sync; and (@objectstack/spec) check:skill-docs, check:skill-refs. The rest, pnpm typecheck for @objectstack/runtime and the full Test Core run: NOT MEASURED locally (dependencies built with OS_SKIP_DTS=1), left to CI.

Acceptance notes

  • data-hooks.md has a code comment "in your plugin's onEnable()" (Plugin Integration section) while the kernel contract has no onEnable; untouched here, noted for the skills lane.
  • The PostgreSQL rule inside an action body's own (owned) transaction is stated from the measured rule for a unit ("a statement that fails at the database aborts the whole unit"); the measurement itself was taken on a before* hook's unit.

Verification

Read first: the api.transaction row of data-hooks.md; the new subsection of hooks.mdx; the two new cases at the end of transaction-ambient-join.integration.test.ts.

Two-minute check: pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/sandbox/transaction-ambient-join.integration.test.ts shows 8 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L6bhgTxpM3qHFCaQuC7eyA

…k body joining a body-opened unit; docs: state what ctx.api.transaction joins

Claude-Session: https://claude.ai/code/session_01L6bhgTxpM3qHFCaQuC7eyA
Co-authored-by: Claude <noreply@anthropic.com>
…l, and the measured MongoDB and PostgreSQL rule

Claude-Session: https://claude.ai/code/session_01L6bhgTxpM3qHFCaQuC7eyA
Co-authored-by: Claude <noreply@anthropic.com>
@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 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

Nothing in this diff resolved to a documentable surface (no symbol, route or SDK anchor derived from 0 changed package(s)), so this run has no opinion about the docs.

What this run could not see

Coarse fallback — 0 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 581ae76a23c6b3ba8e2b69e7d8a920838bc51194 → packageMentionDocs.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

Contract review

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

Recorded 2026-11-28T04:42Z. PR #38155, card #35324 with #37992 folded in. Read: both cards and every comment, the PR body and file list, the net diff against main, and the check-runs on this head. No file in the diff implements or enforces the two skill files: the rest is prose (content/docs/automation/hooks.mdx), two test files and a changeset, the lane seat's ACCEPT. hooks.mdx was read as the page the skill must agree with, not reviewed.

Security-touching: yes is meant: one changed hunk of data-hooks.md (Gotcha 2) edits the sentence that teaches which principals a cross-object write is refused for under the target's sharing model. The edit drops a restating clause and changes no rule, but the hunk teaches permission behaviour, so the low-risk arm does not apply.

① Derived judgments

  • Accept-set: unchanged, right. No schema, no validator, no runtime source changes. Metadata-protocol: none holds.
  • Public surface: @objectstack/skills ships changed text in one reference page and one eval file; nothing an author can write changes. Right.
  • hooks-security-seeds-datasources.json: cases 25 and 28 change expected_output only. Their must_contain / must_not_contain assertions are unchanged and still hold against the new text (roll, default datasource, registerHook; join, ERR_CROSS_DATASOURCE_TRANSACTION_WRITE). The file parses at the head.
  • Token ceiling: the dev's reading is 10120 before and after, headroom 0. The ratchet's verdict is the Lint · docs & code guards / Lint · repo & tooling gates check-runs, see below.
  • Check-runs on this head when read: Check Changeset, Governed Surface Queue Guard, PR-body guards, Lint · PM dispatch-gates, Lint · ESLint, Lint · scoped · tooling self-tests, Check Documentation Links, Spec property liveness, Flag docs affected by code changes, Dogfood Regression Gate are success. Still in progress: Build Core, Build Docs, Test Core 1 to 10, the four Type Check jobs, Lint · repo & tooling gates, Lint · docs & code guards, Lint · CI, release & engine gates, Lint · scoped · slot lookup & corpus, Lint · scoped · query-options erasure, Live E2E UI. This record does not answer for those: the adopting seat reads their conclusions before it acts on this PASS, and a red one there overrides it.

② Semver level

.changeset/35324-hook-transaction-bounds.md is @objectstack/skills patch. That matches what the diff publishes: skill text only. The runtime change is two test files and ships nothing, so no runtime changeset is owed; hooks.mdx is not in a package.

Clause-②: no. Right: no rule, schema or authorable key is narrowed or widened, and the PR body and the changeset both carry the line.

③ Boundary flags

  • open_questions: empty in the dev report. Nothing to answer.
  • Dev flag, out of scope: the onEnable() comment in the Plugin Integration section of data-hooks.md names a method the kernel contract does not have. Untouched by this diff and no carrier. Escalated to the seat: it needs a card on the skills lane, it is not this PR's to fix.
  • Dev flag, acceptance note: the PostgreSQL abort rule is stated for a body's own (owned) unit while review follow-ups of PR #34503 #34563 measured it on a before* hook's unit. Answered: accepted. The rule is the database's (a failed statement aborts the transaction unless a savepoint is taken) and the body's unit takes no savepoint around a ctx.api write, so the owner of the unit does not change it. The text says "aborts the whole unit" and names no error code for the owned case, which is as far as the measurement goes.
  • Premise correction (card comment 7234049171): accepted on the code, see ④.
  • SQL push-down: no query, no id materialisation, no join in app code anywhere in the diff. No finding.

④ Design judgment

skills/objectstack-data/references/data-hooks.md, read against the engine and the sandbox runner on main.

  • Nested refusal. quickjs-runner.ts, the __txBegin leaf: if (txState.open) throw new SandboxError('nested ctx.api.transaction is not supported'), before beginTransaction is called, and txState is one per body run. The row's "One level per body: a nested call is refused" with the quoted message is exact. It also holds when the outer call joined rather than opened, since open is set either way.
  • Join, the corrected item 2. publishTrioHandleFor (engine-middleware-and-context.ts) publishes an open trio handle into the ambient store for each operation made through the trio's context; ScopedContextFacet.beginTransaction (engine-scoped-context.ts) reads the ambient handle first and returns it with owned: false; the runner's commit and rollback leaves abstain for a joined handle. So a hook fired by a write inside an action body's ctx.api.transaction runs with that handle published, its ctx.api writes ride it and its own ctx.api.transaction joins it. The card's original item 2 ("not ambient") does not hold on main; the skill teaching the join is right, and "its return is no commit and its throw no rollback" matches the abstaining leaves.
  • Cross-datasource and the ledger. enforceTransactionOrigin (engine-execute-transactions.ts) refuses a business write on another driver with CrossDatasourceTransactionWriteError (ERR_CROSS_DATASOURCE_TRANSACTION_WRITE) and runs a system-ledger write outside the transaction; SYSTEM_LEDGER_LIFECYCLE_CLASSES is exactly audit, telemetry, event; beginTransaction records the trio's scope so the gate judges a body's unit too. The row's carve-out, "written outside the unit and surviving its rollback", is exact. The Best Practices sentence now points at the row instead of repeating the three classes; the definition is still in the file once.
  • No transactions. The trio's beginTransaction returns null when txDriver() finds no transaction support and calls no warnTransactionUnsupported; the runner then runs the callback with no handle. "runs the callback with none and no warning: each write is stored as made, and a throw undoes none" is right for the body's face. (The engine's own transaction() face does warn once per driver; the row is about ctx.api.transaction, so there is no conflict.)
  • MongoDB and PostgreSQL cell, against PR docs(objectql): state the measured outcome of a failed ctx.api statement in a before* hook's unit #37990's wording in hooks.mdx on main: standalone refuses every write the unit carries with NOT_IMPLEMENTED (501), a single-node replica set is enough; on PostgreSQL and a MongoDB replica set a failed ctx.api statement refuses the outer write even when caught, swallowed by onError: 'log' or re-run by retryPolicy, 25P02 and 251; SQLite lets it through. The cell says the same, shorter. "read in code, not measured" is gone, as skills: objectstack-data says a MongoDB before* unit needs a replica set "read in code, not measured"; #34563 measured it #37992 asks.
  • Deletions at the ceiling. Each cut was checked for a surviving statement at the head: await (the wrapper is async and every example awaits); after-hooks are for side effects (the Purpose row of the same table); the QuickJS VM (the body vs handler table, "Runs in"); handler deprecated (same table, "Status", and four later mentions); "Only fields being changed" (Gotcha 1 states it in full); "Available in after* hooks" (the result line of HookContext, "after* only"); the admin clause ("An admin is not automatically exempt" stays). The labels and restating comments carried no fact. Nothing a reader needs left the file.

skills/objectstack-data/evals/hooks-security-seeds-datasources.json.

  • Case 25 now expects the measured rule and agrees with the cell and with hooks.mdx word for word on the codes and the three ways a failure is not escaped. The prompt asks "in which setups does it stay", and the added sentences answer the neighbouring question an author meets next; they do not contradict the first half.
  • Case 28: the added parenthesis is right for the prompt, since bank_transfer is a business object and so not a ledger. The caught throw in that prompt is the body's own, not a database failure, so "the caught throw keeps the payment row" does not collide with the PostgreSQL abort rule.

Tried to break it: a nested call under a joined outer (refused, as taught); a hook's ctx.api.transaction under a caller's engine.transaction() (ambient, joins); a ledger write inside a body's unit (carved out through the recorded trio scope); a database failure caught inside a joined callback on PostgreSQL (the row's last-but-one sentence covers it and qualifies "a throw the body catches keeps the callback's writes").

No must-fix, no should-fix.

  • N1 (nit) — in the before* Transaction cell, "25P02 / 251" sits in a parenthesis right after "retried", so it can be read as the codes of a retry; the page and eval case 25 attach them to the refusal of the outer write. Left as an accepted deviation: the file is at its ceiling and the codes are right.
  • N2 (nit) — the api.transaction row says "Hooks of a write made inside a body's transaction run in that unit" without the async: true exception (publishTrioHandleFor does not publish for a detached run). The after-column of the Transaction row in the same file states it. Left as an accepted deviation.

Implemented-by: claude/project-thread-ohd9ea
Reviewed-by: session_01L6bhgV6i8jfWwSXjpWJrjA

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

席位核对 — ACCEPT · head 592009f · cards #35324 #37992 · area s2-ai · 2026-11-28T05:07Z

L1 checklist

  • Shape and checks. The head has 41 success, 19 expected skip, 0 failed and 0 pending; mergeable_state is clean. The PR is a draft. It changes 6 files: a changeset, hooks.mdx, two runtime/objectql tests, and two skills/objectstack-data files. data-hooks.md stays at its token ceiling; no ratchet row moved.

  • Contract review at CONTRACT_REVIEW_TIER. Record 7234212662 at this head is a PASS with No must-fix, no should-fix. Its two nits are accepted as deviations, because the file is at its ceiling and the codes are correct:

    • the 25P02 / 251 parenthesis placement;
    • the missing async: true exception in the api.transaction row, which the Transaction row of the same file states.

    The reviewer's transcript passes verify-review-tier. The seat adopts the record.

  • Tests (seat read).

    • The nested-refusal test now asserts one begin, the outer unit rolled back, no commit, and that the write after the nested call does not run.
    • Two sandbox-side pins in transaction-ambient-join.integration.test.ts show a hook's ctx.api.transaction inside a trio-opened unit joining it: both rows commit together and roll back together. The dev's ablation turned both red.
  • What changes for an author. hooks.mdx and the skill now say four things:

    • which writes join a body's unit, and that it is one level deep;
    • that the default datasource and the lifecycle ledgers are carved out;
    • that a failed statement voids the unit on PostgreSQL and on a MongoDB replica set, even when caught;
    • that a driver with no transactions degrades without a warning.

    The MongoDB cell and the eval case now carry review follow-ups of PR #34503 #34563's measurement. The card's original item 2 ("not ambient") was corrected before the build (Premise corrected on docs + skills: state the bounds of a hook transaction (nested transaction() refused in the sandbox, unit not ambient, ledger carve-out, PostgreSQL abort) #35324); the review confirmed the join against publishTrioHandleFor on main.

  • Security label. The record reads Security-touching: yes. One data-hooks.md hunk (Gotcha 2) drops a restating clause from the sentence about cross-object writes under the target's sharing model, and changes no rule. The security label was added at 2026-11-28T04:44Z. Nothing private.

  • Review items answered. The dev's out-of-scope flag, the onEnable() comment in the registration example, is filed as skills(objectstack-data): the registerHook example says "in your plugin's onEnable()", but a kernel plugin has init/start, and onEnable is the app's config export #38161.

  • Declarations. Clause-②: no, Metadata-protocol: none, Rule-change: none, @objectstack/skills patch. Fixes #35324 and Fixes #37992 are right: both cards are done.

  • Governance. skills/** is Tier H, so the maintainer's approval lands it.

Tier: H. Landing: hand-off to the maintainer follows this record.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

Tier H hand-off · 2026-11-28T05:08Z · head 592009f · approver os-zhuang

维护者速读

  • 改了什么: 两张卡合成一个 PR,把「钩子里的事务」边界写清楚,内容在文档 hooks.mdx 和数据技能里:

    • 沙箱里嵌套开事务会被拒绝。
    • 操作体自己开的事务里,写入触发的钩子会加入同一个事务,只能一层。
    • 审计、遥测、事件这几类日志写在事务外。
    • PostgreSQL 和 MongoDB 副本集上,任何一条语句失败都会让整个事务作废,即使代码里捕获了异常。
    • 驱动不支持事务时会静默降级。

    MongoDB 那格的「未实测」改成了 review follow-ups of PR #34503 #34563 的实测结论。另外加强了两组测试,把这些行为钉住。

  • 影响: 只改文档、技能文字和测试,不改产品行为。写钩子的人和 Agent 能提前知道这些边界,不会到运行时才撞上失败。技能文件没超出字数上限,新增的内容靠删掉同文件里重复的注释来抵。

  • 请你留意: 卡上原来说「钩子会另开一个事务」,实测不成立(实际是加入同一事务),施工前已在卡上更正,审核对照 main 上的代码确认过。有一处顺带改到讲共享规则的句子,只删了重复的半句,规则没变,按规则加了 security 标签,没有需要私下处理的内容。

  • 审核: 契约审核(最高档)PASS(7234212662),没有必须改或建议改的项,两处小瑕疵按已接受偏差记录。席位 L1 ACCEPT 在本评论前一条。

  • 要你做什么: 需要你批准后才能合并。撤回这一次合并即恢复原样。

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 28, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review November 28, 2026 05:13
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit bbe3ced Nov 28, 2026
66 checks passed
@os-zhuang
os-zhuang deleted the claude/project-thread-ohd9ea branch November 28, 2026 06:04
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 28, 2026
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/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

3 participants