Skip to content

Commit adcb9f8

Browse files
docs(skills): data-hooks teaches when a before* hook's ctx.api writes roll back with a refused save (#34964)
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: #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. <details><summary>Derived gate families (47 derived, 43 run, 4 not measured)</summary> - `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. </details> <details><summary>Builds and the pin run</summary> - `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. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` is CI's run (not run locally). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C)_ <!-- signed: repo:objectstack#4 · os-lizheng · session_012MmDsS4GoHCgYwA2uv3n3C --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 438ff47 commit adcb9f8

3 files changed

Lines changed: 43 additions & 18 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): the hooks skill teaches when a `before*` hook's `ctx.api` writes roll back with a refused save
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
objectstack-data's `references/data-hooks.md`, "Before vs After Hooks" table: the `before*` Transaction cell no longer says only "Within transaction". It now says the hook runs in one transaction with the outer write, so a refusal anywhere in that write (a validation, a later hook, a driver constraint) rolls back the hook's `ctx.api` writes too, with no per-hook opt-out. It names the four 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 with `registerHook` opens none. It also says MongoDB needs a replica set, which was read in the driver's code and not measured. Best Practices gains one DON'T: a `before*` hook does not write business records to another datasource through `ctx.api`. Its transaction refuses that write with `CrossDatasourceTransactionWriteError`, and only an append-only ledger (`lifecycle.class` `audit` / `telemetry` / `event`) is written outside it. `evals/hooks-security-seeds-datasources.json` gains two cases, one for each rule. Four restatements in data-hooks.md were removed to pay for the new text.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,26 @@
290290
"must_contain": ["caller", "roll"],
291291
"must_not_contain": []
292292
}
293+
},
294+
{
295+
"id": 25,
296+
"prompt": "A `beforeInsert` hook on `time_entry`, declared in the stack's `hooks`, creates the week's `timesheet` row through `ctx.api` when there is none. A validation rule then refuses the entry (`hours > 24`). Is an empty timesheet left behind? Would `onError: 'log'` on the hook keep it? In which setups does it stay?",
297+
"expected_output": "No: the save and the hook's `ctx.api` insert run in one transaction, so the refusal rolls the `timesheet` row back with the entry. `onError: 'log'` does not keep it: there is no per-hook opt-out. It stays stored only where no transaction is opened: `time_entry`, the hooked object, is off the default datasource, or the default driver has no transactions (Turso's remote transport). A hook registered in code with `registerHook` opens no transaction either, and inside a transaction the caller opened, the caller decides. MongoDB needs a replica set for this transaction (read in code, not measured).",
298+
"files": [],
299+
"assertions": {
300+
"must_contain": ["roll", "default datasource", "registerHook"],
301+
"must_not_contain": []
302+
}
303+
},
304+
{
305+
"id": 26,
306+
"prompt": "`order` is on the default datasource; `shipment`, a business object, is on our `warehouse` datasource. Write a `beforeInsert` hook on `order` that inserts the matching `shipment` row through `ctx.api`.",
307+
"expected_output": "Redirects: a `before*` hook does not write a business record to another datasource through `ctx.api`. The hook's writes run in one transaction with the save, on the default datasource, and the `shipment` insert is refused there with `CrossDatasourceTransactionWriteError`. Keep the objects a `before*` hook writes on the default datasource: move `shipment` there. Only an append-only ledger on another datasource (`lifecycle.class` `audit` / `telemetry` / `event`) is written outside the transaction, and `shipment` is not one.",
308+
"files": [],
309+
"assertions": {
310+
"must_contain": ["CrossDatasourceTransactionWriteError", "default datasource"],
311+
"must_not_contain": []
312+
}
293313
}
294314
]
295315
}

‎skills/objectstack-data/references/data-hooks.md‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
- [Best Practices](#best-practices) · [Error Handling](#error-handling) · [References](#references)
88

99
Reference companion to `objectstack-data/SKILL.md`, and the catalog's anchor for
10-
data hooks. Covers the lifecycle events, the sandboxed `body` (and the deprecated
11-
inline `handler`), the `HookContext` API, registration, and the canonical patterns
12-
(delete guards, audit trails, cross-object writes, read masking).
10+
data hooks.
1311
`check:skill-examples` skips the unmarked blocks: fragments, shapes, and pattern 4's bare `any`.
1412

1513

@@ -61,7 +59,7 @@ ObjectStack provides lifecycle events organized by operation type:
6159
| **Purpose** | Validation, enrichment, transformation | Side effects, notifications, logging |
6260
| **Can modify** | `ctx.input` (mutable) | `ctx.result` (mutable) |
6361
| **Can abort** | Yes (throw error → rollback) | A sync after-hook's throw still rolls back the transaction (see error handling) |
64-
| **Transaction** | Within transaction | **Within the transaction**. `async: true` on `afterInsert` / `afterUpdate` / `afterDelete`: starts once the outermost transaction commits, never if it rolls back (a failed commit included); on `afterFind`: starts as the read is dispatched; outside a transaction: starts at once |
62+
| **Transaction** | 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) | **Within the transaction**. `async: true` on `afterInsert` / `afterUpdate` / `afterDelete`: starts once the outermost transaction commits, never if it rolls back (a failed commit included); on `afterFind`: starts as the read is dispatched; outside a transaction: starts at once |
6563
| **Error handling** | Aborts by default (`onError: 'abort'`) | **Also aborts by default** — `onError` defaults to `'abort'` unconditionally; set `onError: 'log'` on side-effect hooks |
6664

6765
---
@@ -184,14 +182,9 @@ in neither). So:
184182
object) — the engine refuses the batch whole, before any write, when two rows'
185183
key sets differ (`MULTI_UPDATE_HOOK_KEY_DIVERGENCE`, status 400; ADR-0058
186184
Amendment II.3).
187-
- **`after*` hooks fire PER ROW, so a bulk write needs no special
188-
condition.** A predicate (`multi: true`) update/delete dispatches its `after*`
189-
hooks **once per matched row**, each on a single-record-shaped context —
190-
`previous` is that row's pre-image, `record` is that row's real state (not the
191-
bare payload), and `input.id` (`handler`; a `body`: `ctx.previous.id`) names the row. A transition condition therefore
192-
**is** available on `afterUpdate` / `afterDelete`: write it once and it means
193-
the same thing whether the write carried an id or a predicate, with no
194-
bulk-aware branch of its own.
185+
- **`after*` hooks dispatch once per matched row too** (`record` is that row's
186+
real state, not the bare payload), so a transition condition on `afterUpdate` /
187+
`afterDelete` means the same whether the write carried an id or a predicate.
195188
- **Guard optional values with `!= null`, never with `has(...)`.** A declared
196189
field holding `null` is *present*, so `has(record.spent)` is uniformly true and
197190
`has(record.spent) && record.spent > record.budget` still faults on
@@ -671,7 +664,7 @@ A `body` cannot do this: it writes back only `ctx.input`, and its `ctx.result` i
671664
> set or position), prefer declarative **field-level metadata** (secret/masked
672665
> fields) — it applies on every read path automatically. Use an `afterFind` hook
673666
> only for masking that depends on runtime logic the field metadata can't
674-
> express. A single `afterFind` subscription covers both `find` and `findOne`.
667+
> express.
675668
676669
```typescript
677670
const maskSensitiveData = defineHook({
@@ -752,9 +745,7 @@ with no start or end is neither checked nor counted.
752745
## Registration Methods
753746

754747
**1. Declarative — `defineStack({ hooks })`, the default.** `AppPlugin` auto-binds
755-
these at startup: no `register*Hook` boilerplate, and the declarative fields
756-
(`condition`, `async`, `retryPolicy`, `timeoutMs`, `onError`, `priority`) are honoured
757-
**only** on this path. A string-named `handler` (deprecated) resolves through the stack's
748+
these at startup: no `register*Hook` boilerplate. A string-named `handler` (deprecated) resolves through the stack's
758749
`functions` map.
759750

760751
```typescript
@@ -791,8 +782,12 @@ the layout both real hook modules in the repo use.
791782
cross-object operations; refuse a business rule by a
792783
[declared code](#declared-refusals-refusals); test hooks in isolation.
793784

794-
❌ **DON'T** — do expensive work in `before*` (it blocks the transaction); let a
795-
hook re-trigger itself; use `object: '*'` unless you mean every object; throw in
785+
❌ **DON'T** — do expensive work in `before*` (it blocks the transaction); write
786+
business records to another datasource from a `before*` hook through `ctx.api`
787+
(its transaction refuses that write with `CrossDatasourceTransactionWriteError`;
788+
only an append-only ledger, `lifecycle.class` `audit` / `telemetry` / `event`, is
789+
written outside it and survives its rollback); let a hook re-trigger itself;
790+
use `object: '*'` unless you mean every object; throw in
796791
`after*` unless the failure must abort the operation; react to a refused or
797792
rolled-back write from an `async: true` hook, which never runs then — use a sync
798793
hook (its `ctx.api` writes roll back with the write) or record it in the caller,

0 commit comments

Comments
 (0)