Skip to content

Commit fca72df

Browse files
docs(skills): teach the fault edge on a write after an approval decision and the RESUME_FAILED refusal members (#35002)
Fixes #34637 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:自动化技能的审批参考新增一条:审批通过或拒绝之后的「改记录」步骤,如果可能被记录钩子、校验规则或权限拒绝,就从这一步画一条 fault 边到处理节点,拒绝走这条边,审批照常返回;不画时审批接口回 500 `RESUME_FAILED`,决定照旧生效,错误体带 `innerRefusal` 和 `userMessage`。另加一条评测用例。 - 为什么改:技能不教,AI 写审批流程时不会画这条边,钩子一拒绝流程就卡住,审批人只看到 500。 - 风险与回滚:只动技能文字和评测,不动运行时。为了不抬 token 上限,同一文件删了四处重复内容,每处都另有出处。回滚就是 revert 本 PR。 - 先看:① `skills/objectstack-automation/references/state-machines-and-approvals.md` 里 Branching 一节新增的那一条,以及同文件被删的四处;② `skills/objectstack-automation/evals/approval-fault-edge.json`;③ `.changeset/34637-approval-fault-edge-skill.md`。 - 两分钟验证:跑 `node scripts/check-skills-token-ratchet.mjs`,预期这份参考文件一行读作 `5913 tokens (ceiling 5916; headroom 3)`,末行是 ✓。 - 需要你做的:审批本 PR(受管面 `skills/**`)。 > **Review round (supersedes the readings below where they differ).** Contract review 7009057594 on fcf9e05: PASS with S1 should-fix. Head c242d97 merges origin/main 819c067. S1: the eval prompt now ends "None of the project's files are in this directory: write the flow as a TypeScript `defineFlow` in your answer." N1: the reference reads "the body may carry `innerRefusal` … and `userMessage`". N3: the changeset points to the list item that names the `e1` edge. N2 left. Budget on the merged tree: `state-machines-and-approvals.md` 5933 / 5936 tokens (388 lines, 23732 bytes). The eval case is unmeasured with the new prompt (no live round, by order). Gates: 48 derived, 46 exit 0, 2 not measured locally (CI runs them); overlap clean. The page teaches that a permission refusal on a post-decision write routes down a `fault` edge, so the PR carries `security`. ## What changes `skills/objectstack-automation/references/state-machines-and-approvals.md`, section *Branching, side-effects & rejection*, gains one bullet. It teaches the two points the card orders, in the wording of the merged approvals docs callout and the `ApprovalDecisionResult.resumed` docblock: 1. When a step on the `approve` / `reject` branch writes a record that a record hook, a validation rule or a permission may refuse, draw a `fault` edge from that step to a handler. The refusal takes that edge and the decision answers normally. 2. Without the edge, `POST …/approve` (or `/reject`) answers `500 RESUME_FAILED`. The decision stands (`finalized: true`), the run is stranded, and the body carries `innerRefusal` (`{ code, message }`) and `userMessage`, the hook's declared sentence to show the approver. The bullet points to SKILL.md, section *Failure routing*, for the edge shape, so the shape is not restated. One eval case is added in a new file, `skills/objectstack-automation/evals/approval-fault-edge.json`: an approval flow whose step after the decision updates a record guarded by a refusing `beforeUpdate` hook. It is graded on the approval node, the `approve` out-edge, the `update_record` step and the `type: 'fault'` edge. A `@objectstack/skills` patch changeset is included, because `skills/**` ships in that package. ### The status code, checked against the merged code and the ruling The card says "status 500 per the standing ruling". The merged code answers the same: - `packages/rest/src/approvals-routes.ts` maps the `RESUME_FAILED` prefix to status 500 and spreads the recognised stranded-decision envelope into the body. - `packages/rest/src/rest-approvals-wire-codes.test.ts` pins status 500 and the exact body key set `code`, `decision`, `error`, `finalized`, `innerRefusal`, `repairable`, `runId`, `userMessage`. - `packages/plugins/plugin-approvals/src/hook-refusal-after-decision.test.ts` pins both halves: no fault edge gives `RESUME_FAILED` with the two members, and a fault edge on the step gives `finalized: true, resumed: true` with nothing left parked. The ruling the code cites is the maintainer ruling of 2026-09-04, decision batch #37, option 1B, recorded in comment 5541861039 on issue #13807. From that record: "`POST …/reject` (and the sibling decision doors on the same path) **keeps its status code** — the 500-class `RESUME_FAILED` — and stops discarding what the engine said". The record gives the maintainer's word as verbatim 「同意」 on the presented recommendation `1B · 2及`. The approvals docs page states the 500 and cites no ruling id of its own; the id is in the code comments (`approvals-routes.ts`, `packages/types/src/stranded-decision.ts`). ### Scope fence Only the decision doors' thrown `RESUME_FAILED` envelope is taught, as merged by PR #34619. The text names `POST …/approve` and `/reject`. It does not mention `resumeFailure`, the recall door or the subflow-parent strand, and it does not say those answers carry the pair. ### Budget The reference file was at 5916 tokens against a ceiling of 5916, headroom 0. No ceiling moves. The new bullet is paid for by deleting content. Four restatements were cut, each keeping another home: | Cut | Bytes | Where the content still lives | |:--|--:|:--| | The text diagram in *Send-back for revision* | 261 | The paragraph directly above it and the snippet below it trace the same path | | Bullet "Conditional step" | 119 | The discount-approval example: the `needs_director` decision node and the comment on edge `e1` | | Bullet "Send back for revision (ADR-0044)", a pointer | 80 | The section it pointed to, in the same file | | Bullet "Hard reject" | 64 | The examples' `reject` edges into an `end` node (`e3`, `e7`) | The cuts remove 524 bytes and the new bullet adds 515, so the file is 9 bytes smaller. None of the four is a re-wrap: each removes text. | Reading | Before (`fff0ad0c18`) | After (`fcf9e05cbe`) | |:--|--:|--:| | `state-machines-and-approvals.md`, lines | 412 | 408 (net -4; budget was at most +10) | | `state-machines-and-approvals.md`, bytes | 23661 | 23652 | | `state-machines-and-approvals.md`, tokens / ceiling | 5916 / 5916 | 5913 / 5916 | | All 12 `SKILL.md` files, lines summed | 4728 | 4728 | | All 12 `SKILL.md` files, bytes summed | 246476 | 246476 | | Ratcheted authored total, tokens / ceiling sum | 191126 / 196699 | 191123 / 196699 | | `evals/approval-fault-edge.json` (eval fixture, not ratcheted), tokens | absent | 388 | No `SKILL.md` is touched. `skills/objectstack-automation/SKILL.md` stays at 6903 / 6903. ## Tests No package source changes, so no package test suite is owed. What ran, at head `fcf9e05cbe`: - `pnpm --filter @objectstack/skills build` under the shared verify lock: `VERDICT command-exit 0`; "99 file(s) across 12 skill(s) copied from skills/** into dist/skills and read back byte-identical". - The new eval case, by hand. The `skill-evals` runner has no single-case selector, so five turns of this one case were run with the runner's own argv from `packages/qa/scenarios/src/skill-evals/arms.ts` (a fresh directory, the bundle copied without `evals/` on the with-skill arm, an empty directory on the no-skill arm) and graded by literal substring as `grade.ts` does. This is a hand replication, not a runner round, and no round record was filed. | Turn | Arm | Reference text it read | Verdict under the final tokens | |:--|:--|:--|:--| | ws1 | with-skill | first revision (`5fa36a038b`) | pass | | ws2 | with-skill | final text | pass | | ws3 | with-skill | final text | pass | | ns1 | no-skill | none | fail: `label: 'approve'` missing, `type: 'role'` present | | ns2 | no-skill | none | fail: `label: 'approve'` missing, `type: 'role'` present | All three with-skill answers drew the `type: 'fault'` edge from the `update_record` step, and all three said that without it the approve call answers `500 RESUME_FAILED`. All three launched the skill and read the reference file. Stated limits: the token lists were settled after reading these answers, so the five turns are not an independent test of the final lists. Two things changed on the way. Both no-skill answers also wrote `type: 'fault'`, so the case now also requires `label: 'approve'` and forbids `type: 'role'`. The first draft forbade `label: 'error'`, and one with-skill answer that drew the fault edge correctly quoted that label while explaining why it does not catch a failure, so that token was dropped. The prompt was the same on all five turns. ## Acceptance notes - The first eval draft appended a case to `evals/flows-triggers-approvals.json`. `node scripts/pm/overlap-check.mjs` then answered `VERDICT overlap exit 1` against PR #34793, which appends its own case with the same `id: 24` at the same position. The case moved to its own file and the shared file is byte-identical to `main` again. The re-run answers `VERDICT clean exit 0` against `origin/main` (`44c7a4a415`) and 0 PR heads. - The discount-approval example in the reference keeps its `mark_won` step without a `fault` edge. The new rule is conditional (a write that may be refused), and adding a handler node and two edges to the example did not fit the budget. Noted, not changed. - `ui/scripts/check-skill-eval-tokens.mjs` scans the bundle under `ui/skills` only (1 bundle, 11 eval files), so it does not judge this case. The four `must_contain` tokens were checked by hand as taught in the bundle: `type: 'approval'` and `label: 'approve'` in the reference, `update_record` in SKILL.md and the references, `type: 'fault'` in SKILL.md. The forbidden token `type: 'role'` occurs nowhere in the bundle. - Case 5 of `evals/flows-triggers-approvals.json` forbids `label: 'error'` and has the same exposure measured above on a different prompt. Noted, not filed. ## Verification `node scripts/pm/dispatch-gates.mjs --commands` at `fcf9e05cbe` derived 47 commands (change set: 3 paths against merge base `fff0ad0c1`). All 47 ran at that head with the exit code captured before any pipe. Reconciliation: `✓ dispatch-gates --ran: 47 derived famil(ies) accounted for — 45 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3).` <details> <summary>Gates that read the changed files</summary> ```text node scripts/check-skills-token-ratchet.mjs :: exit 0 ✓ check-skills-token-ratchet: skills/objectstack-automation/references/state-machines-and-approvals.md is 5913 tokens (ceiling 5916; headroom 3). ✓ check-skills-token-ratchet: skills/objectstack-automation/evals/approval-fault-edge.json is 388 tokens — eval fixture, measured but not ratcheted. ✓ check-skills-token-ratchet: 58 authored bundle file(s) within their ceilings; 10 generator-owned file(s) and 31 eval fixture(s) measured, not ratcheted. node scripts/check-skills-token-ratchet.mjs --self-test :: exit 0 pnpm --filter @objectstack/spec run check:skill-refs :: exit 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 pnpm check:skill-links :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:skill-compatibility :: exit 0 pnpm check:skill-frame-sync :: exit 0 pnpm check:role-word :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:published-files :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 ``` </details> <details> <summary>Not measured locally, and two partial readings</summary> ```text pnpm check:dual-build-cjs-loads :: exit 3 PREREQUISITE NOT MET — this gate reads built output, and some package has no dist/. pnpm check:lean-entry-closure :: exit 3 PREREQUISITE NOT MET — this gate loads BUILT entry points, and some target is absent pnpm check:dts-closure :: exit 0 partial: "6 built package(s) swept" pnpm check:sourcemap-no-sources-content :: exit 0 partial: "6 built package(s) swept" ``` The diff touches no package source, so no whole-workspace build is owed locally. Only `@objectstack/formula`, `@objectstack/lint` and their dependencies were built, to let the doc-formula gate run. These four are whole-build readers and are left to CI. </details> The remaining 28 derived commands are self-tests and whole-tree gates; each exited 0. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (No schema touched.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` is left to CI (no code file changed). - [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: 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 0d9d982 commit fca72df

3 files changed

Lines changed: 41 additions & 11 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): `objectstack-automation` teaches the `fault` edge on a write after an approval decision, and what `RESUME_FAILED` carries without one
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`references/state-machines-and-approvals.md` § Branching, side-effects & rejection gains one bullet. When a step on the `approve` / `reject` branch writes a record that a record hook, a validation rule or a permission may refuse, the flow draws a `fault` edge from that step to a handler: the refusal takes that edge and the decision answers normally. Without the edge `POST …/approve` (or `/reject`) answers `500 RESUME_FAILED`: the decision stands (`finalized: true`), the run is stranded, and the body may carry `innerRefusal` (`{ code, message }`) and `userMessage`, the hook's declared sentence for the approver. One eval case covers it; its prompt asks for the flow as a TypeScript `defineFlow`.
11+
12+
Paid in place, the token ceiling does not move. Four restatements were cut, each keeping another home: the send-back section's text diagram (the paragraph above it and the snippet below it trace the same path), and three bullets of § Branching: "Conditional step" (the discount-approval example's `needs_director` node and the list item above it that names the `e1` edge), the send-back pointer (the section it pointed to), and "Hard reject" (the examples' `reject` edges into an `end` node).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"skill_name": "objectstack-automation",
3+
"evals": [
4+
{
5+
"id": 1,
6+
"prompt": "Build a flow `mrp_plan_approval` on `purchase_plan`: when `status` becomes `submitted`, the planning manager approves or rejects, and on approve a step sets `status` to `adopted`. That object's `beforeUpdate` hook refuses the write when capacity is already taken. A refusal must send the plan back to its owner; the approver's click must not fail or leave the run stuck. None of the project's files are in this directory: write the flow as a TypeScript `defineFlow` in your answer.",
7+
"expected_output": "A TypeScript `defineFlow`. An `approval` node (`type: 'approval'`, the planning manager as a `position` approver, not the deprecated `role` spelling) whose `label: 'approve'` edge enters an `update_record` step, and a `fault` edge from THAT step to a handler: `{ source: 'adopt_plan', target: 'bounce_back', type: 'fault' }`, the handler returning the plan to its owner (an `update_record` or a `notify`). The hook's refusal takes that edge, the decision answers normally and the run finishes. Without the edge `POST …/approve` answers `500 RESUME_FAILED`: the decision stands, the run is stranded, and the body may carry `innerRefusal` and `userMessage`, the hook's declared sentence. Not an ordinary edge labelled as an error (it traverses on success), and not the reject branch: the approver approved.",
8+
"files": [],
9+
"assertions": {
10+
"must_contain": [
11+
"type: 'approval'",
12+
"label: 'approve'",
13+
"update_record",
14+
"type: 'fault'"
15+
],
16+
"must_not_contain": [
17+
"type: 'role'"
18+
]
19+
}
20+
}
21+
]
22+
}

‎skills/objectstack-automation/references/state-machines-and-approvals.md‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ window*) where the record unlocks and the submitter reworks it, and an explicit
130130
*resubmit* re-enters the approval node over a **declared back-edge**, opening
131131
round N+1 with a fresh approver slate.
132132

133-
```
134-
approval ──approve──▶ …
135-
──reject───▶ …
136-
──revise───▶ approval_revise (record unlocked, submitter edits)
137-
└──resubmit──[type:'back']──▶ approval (round N+1)
138-
```
139-
140133
Three pieces author it:
141134

142135
1. **`revise` out-edge** — a third branch label alongside `approve` / `reject`,
@@ -362,14 +355,17 @@ Object-hook `ctx` is a different vocabulary — see **objectstack-data**
362355

363356
These are wired on the **graph**, not in node config:
364357

365-
- **Conditional step** — put a `decision` node before the Approval node, or a
366-
`condition` on the edge entering it.
367358
- **On approve / on reject** — wire downstream nodes (`update_record`,
368359
`http`, a `notify` node, …) to the `approve` / `reject` out-edge.
360+
- **A write on that branch that may be refused** (a record hook, a validation
361+
rule, a permission) — draw a `fault` edge from that step to a handler
362+
(SKILL.md § Failure routing): the refusal takes it and the decision answers
363+
normally. Without one, `POST …/approve` (or `/reject`) answers
364+
`500 RESUME_FAILED`: the decision stands (`finalized: true`), the run is
365+
stranded, and the body may carry `innerRefusal` (`{ code, message }`) and
366+
`userMessage`, the hook's declared sentence for the approver.
369367
- **Roll back on reject** — route the `reject` edge as a **back-edge** to an
370368
earlier node so the submitter can revise.
371-
- **Send back for revision (ADR-0044)** — see *Send-back for revision* above.
372-
- **Hard reject** — route the `reject` edge to an `end` node.
373369

374370
### Approval Best Practices
375371

0 commit comments

Comments
 (0)