Repository navigation
Commit bbe3ced
docs(hooks): state what a hook body's ctx.api.transaction joins and where it stops; skills: the measured MongoDB and PostgreSQL rule (#38155)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuHK25Zwk1bxA8Zwyv3FSnHC)_
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
<details><summary>runs (head 592009f)</summary>
- `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.
</details>
## 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.com/claude-code)
https://claude.ai/code/session_01L6bhgTxpM3qHFCaQuC7eyA
<!-- signed: repo:objectstack#2 · os-sales ·
session_01L6bhgTxpM3qHFCaQuC7eyA -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d753fd9 commit bbe3ced
6 files changed
Lines changed: 141 additions & 57 deletions
File tree
- .changeset
- content/docs/automation
- packages/runtime/src/sandbox
- skills/objectstack-data
- evals
- references
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
380 | 408 | | |
381 | 409 | | |
382 | 410 | | |
| |||
385 | 413 | | |
386 | 414 | | |
387 | 415 | | |
388 | | - | |
389 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
390 | 419 | | |
391 | 420 | | |
392 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1101 | 1101 | | |
1102 | 1102 | | |
1103 | 1103 | | |
1104 | | - | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
1110 | | - | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1111 | 1116 | | |
1112 | | - | |
| 1117 | + | |
1113 | 1118 | | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
1118 | | - | |
1119 | | - | |
1120 | | - | |
1121 | | - | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
1122 | 1136 | | |
1123 | 1137 | | |
1124 | 1138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
287 | 330 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
| 237 | + | |
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| |||
0 commit comments