Skip to content

Commit 919c3df

Browse files
committed
docs(skills): the async-hook DON'T names both homes for reacting to a failed write
A sync hook's ctx.api writes roll back with the write, so the sentence also names the caller, where the write is made. Eval 24 requires the caller-side home and no longer forbids naming the flag. Paid by one more same-file restatement cut. Claude-Session: https://claude.ai/code/session_01WGufzgAt23MH7HTGSbYsVo Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6dbeb77 commit 919c3df

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎.changeset/34191-skills-async-hook-commit.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ docs(skills): an `async` after-hook on a write event starts after the commit and
77
Clause-②: no
88
Metadata-protocol: none
99

10-
`skills/objectstack-data/references/data-hooks.md`, the **Transaction** row of Before vs After Hooks: an `async: true` hook on `afterInsert` / `afterUpdate` / `afterDelete` starts once the outermost transaction commits and never runs if it rolls back, a failed commit included; on `afterFind` it starts as the read is dispatched; outside a transaction it starts at once. The row used to say "in the background, after commit" for every event and did not say the hook is dropped on rollback. Best Practices gains one DON'T: do not react to a refused or rolled-back write from an `async: true` hook, which never runs then; use a blocking hook. Two eval cases exercise it: a background `afterInsert` that must not announce an order that did not survive, and a request for a background hook that records a failed insert. The file pays by dropping two restatements (the "Update by id" paragraph, which repeated its row of the `ctx.api.object` method table, and the sentence above the `body` vs `handler` table, which repeated the table), so its token ceiling does not move. No schema or runtime change.
10+
`skills/objectstack-data/references/data-hooks.md`, the **Transaction** row of Before vs After Hooks: an `async: true` hook on `afterInsert` / `afterUpdate` / `afterDelete` starts once the outermost transaction commits and never runs if it rolls back, a failed commit included; on `afterFind` it starts as the read is dispatched; outside a transaction it starts at once. The row used to say "in the background, after commit" for every event and did not say the hook is dropped on rollback. Best Practices gains one DON'T: do not react to a refused or rolled-back write from an `async: true` hook, which never runs then; use a sync hook, whose `ctx.api` writes roll back with the write, or record it in the caller, where the write is made. Two eval cases exercise it: a background `afterInsert` that must not announce an order that did not survive, and a request for a background hook that records a failed insert. The file pays by dropping three restatements (the "Update by id" paragraph, which repeated its row of the `ctx.api.object` method table; the sentence above the `body` vs `handler` table, which repeated the table; and the closing sentence of the `findOne` note, which repeated its opening paragraph), so its token ceiling does not move. No schema or runtime change.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@
234234
{
235235
"id": 24,
236236
"prompt": "Write a background hook that adds a `payment_failure` row whenever an insert on `payment` is refused or rolled back. It must not slow the save.",
237-
"expected_output": "Redirects: a background (`async`) hook on `afterInsert` cannot do this. Inside a transaction it starts only once the outermost transaction commits and never runs when that rolls back (a failed commit included), so it never sees a refused or rolled-back insert. A reaction to a refused write belongs in a blocking hook, or where the write is made: the caller receives the error and records the `payment_failure` there, since a blocking hook's own `ctx.api` writes roll back with the write. The `async` flag stays for work that follows a committed insert.",
237+
"expected_output": "Redirects: a background (`async: true`) hook on `afterInsert` cannot do this. Inside a transaction it starts only once the outermost transaction commits and never runs when that rolls back (a failed commit included), so it never sees a refused or rolled-back insert. Record the failure in the caller, where the write is made: the caller receives the error and inserts the `payment_failure` row outside the rolled-back transaction. A sync hook is no home for this row either: its own `ctx.api` writes roll back with the write. The `async` flag stays for work that follows a committed insert.",
238238
"files": [],
239239
"assertions": {
240-
"must_contain": ["blocking", "commit"],
241-
"must_not_contain": ["async: true"]
240+
"must_contain": ["caller", "roll"],
241+
"must_not_contain": []
242242
}
243243
}
244244
]

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ await ctx.api.object('candidate').find({ limit: 1 }); // any row will
318318
```
319319

320320
An unpredicated `find` / `count` is fine — returning or counting every row is an
321-
honest answer. It is `findOne`'s implicit "just one of them" that turns a missing
322-
predicate into a confidently wrong record.
321+
honest answer.
323322

324323
### Capabilities — the complete list
325324

@@ -815,8 +814,10 @@ cross-object operations; refuse a business rule by a
815814
❌ **DON'T** — do expensive work in `before*` (it blocks the transaction); let a
816815
hook re-trigger itself; use `object: '*'` unless you mean every object; throw in
817816
`after*` unless the failure must abort the operation; react to a refused or
818-
rolled-back write from an `async: true` hook, which never runs then (use a
819-
blocking hook); assume `ctx.session` exists — system operations carry no user.
817+
rolled-back write from an `async: true` hook, which never runs then — use a sync
818+
hook (its `ctx.api` writes roll back with the write) or record it in the caller,
819+
where the write is made; assume `ctx.session` exists — system operations carry
820+
no user.
820821

821822

822823
---

0 commit comments

Comments
 (0)