Repository navigation
Commit e411388
fix(scenarios): the run grader reads a hook's declared refusal off the door's declaredCode (#33556)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X9GF8q7Br6jm5Yk5d7UFpR1)_
domain:devx#4 · os-project-manager · session_01FEkQ5nw3MDkRymEzv6FDJs
Fixes #33497
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:场景 runner 把 MCP 门返回的 `declaredCode`(hook 自己声明的拒绝码,被门降级到 `code`
旁边)保留到 `ObservedAnswer` 上;评分器 `refusalMeets` 读它:声明码等于 `declaredCode`
时精确命中,声明 `VALIDATION_FAILED` 时 4xx 上带 `declaredCode` 即算 app 自己的拒绝。
- 为什么改:门实际返回的是 `RESOURCE_CONFLICT` 409 + `declaredCode:
ASSET_NOT_IN_STOCK`,runner 只留了 `code`,评分器看到的是平台冲突码,于是 app 正确拒绝的
`check_out_asset_in_repair` 被判失败;原测试把 hook 码直接塞进 `code`,门从来不这么返回。
- 风险与回滚:只改评分器和 runner,门、线上形状、卡片期望都没动;平台码仍然严格:没有 `declaredCode`
的目录码不命中别的声明码,5xx 或无 status 的 `declaredCode` 不命中。回滚即还原本 PR。
- 先看:`packages/qa/scenarios/src/score/scenario-operation-grade.ts` 的
`refusalMeets`(L225)和
`refusalText`(L237);`packages/qa/scenarios/src/runner/observe.ts` 的
`declaredCodeOf`(L218)、`refusedBy`(L242)。
- 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run
test/runner/mid-tier-run-readings.test.ts`,预期 49 条全绿。
- 需要你做的:无,席位落地。
## What changes
- **Runner, `packages/qa/scenarios/src/runner/observe.ts`.** `refusedBy`
(L242) now takes the tool output and returns the refused answer with
`code`, `status` and `declaredCode`, each only when served.
`declaredCodeOf` (L218) reads `declaredCode` off the same envelope
`refusalOf` reads (the same two JSON readings; the nested `error` object
when it carries a string `code`, else the flat body), and answers
`undefined` for an absent or empty one: no default is invented. The
three refused-answer paths go through it: a write call's refusal
(`refusalAnswerOf`), the last read on the object when no write was made
(`lastReadRefusalOutput`, L147, read at L270), and the runner's probe
(`observeProbe` builds a one-call turn and reads it through
`observedAnswer`).
- **Type, `scenario-operation-grade.ts` L94.** `ObservedAnswer`'s
refused member gains the optional `declaredCode?: string`.
- **Grader, `refusalMeets` (L225).** (a) A declared code equal to the
answer's `declaredCode` meets exactly, like `code === declared`. (b) For
a declared `VALIDATION_FAILED`, a present `declaredCode` at a 4xx status
meets, whatever the catalogue `code` beside it. A catalogue code with no
`declaredCode` still never meets a different declared code, and a
`declaredCode` at 5xx or with no status does not meet.
- **`refusalText` (L237)** names what met: `refused RESOURCE_CONFLICT
(409), the hook's declared refusal ASSET_NOT_IN_STOCK`.
- **Docs.** The `refusalMeets` docblock and
`packages/qa/scenarios/README.md` L70–L75 now describe the wire shape:
`code` is the status's catalogue code, `declaredCode` is the hook's own.
The wire codes the tests pin are the door's (`HttpStatusErrorCodeMap`,
`packages/spec/src/api/errors.zod.ts` L183, with 4xx otherwise
`VALIDATION_ERROR` through `standardErrorCodeForHttpStatus`): 400 and
422 → `VALIDATION_ERROR`, 403 → `PERMISSION_DENIED`, 404 →
`RESOURCE_NOT_FOUND`, 409 → `RESOURCE_CONFLICT`, 500 → `INTERNAL_ERROR`.
## Tests
All in
`packages/qa/scenarios/test/runner/mid-tier-run-readings.test.ts`.
- **Item 2, re-pinned on the wire shape (L162).** The hook's
`OVER_RECEIPT` at 400, 403, 404, 409 and 422 is served as the status's
catalogue code with `declaredCode: 'OVER_RECEIPT'`, and meets
`VALIDATION_FAILED`. Negatives: each catalogue code with no
`declaredCode` (`VALIDATION_ERROR` 400, `PERMISSION_DENIED` 403,
`RESOURCE_NOT_FOUND` 404, `RESOURCE_CONFLICT` 409, `INTERNAL_ERROR` 500)
does not meet; `declaredCode` at 500 does not meet; `declaredCode` with
no status does not meet; a hook's `NOT_REQUESTER` served at 400 does not
meet `PERMISSION_DENIED`.
- **Rule (a), new (L184).** `RESOURCE_CONFLICT` 409 + `declaredCode:
'ASSET_NOT_IN_STOCK'` meets a declared `ASSET_NOT_IN_STOCK` (and
`RESOURCE_CONFLICT`); the same conflict with no `declaredCode` does not
meet `ASSET_NOT_IN_STOCK`; a different declared code (`OVER_RECEIPT`)
does not meet.
- **"Applies to every card"** now grades each card's validation
operation on `VALIDATION_ERROR` 400 + `declaredCode`, with the detail
`refused VALIDATION_ERROR (400), the hook's declared refusal …`.
- **R1.8 (L647)** grades `check_out_asset_in_repair` on
`RESOURCE_CONFLICT` 409 + `declaredCode: 'ASSET_NOT_IN_STOCK'`, both
halves passing with the new detail; `RESOURCE_CONFLICT` 409 with no
`declaredCode` fails.
- **Item 4**'s "an app's own code is no permission refusal" probe is
served as `VALIDATION_ERROR` 400 + `declaredCode: 'NOT_APPROVER'`.
- **2b, new runner tests (L214)**, on `asset_lifecycle
check_out_asset_in_repair`:
- `declaredCode` reaches the `ObservedAnswer` through a `create_record`
call and through the probe, in the nested (`{ error: { code, message,
status, declaredCode } }`) and the flat (`{ error, code, status,
declaredCode }`) shape;
- through the last read on the object when no write was made;
- absent stays absent: a door that served none, or an empty one, leaves
no key (`toStrictEqual`);
- end to end through `gradeCardOperation`: the served shape passes both
halves; the same conflict with no `declaredCode` fails
`agent:refused:VALIDATION_FAILED-or-withheld` and
`platform:refused:VALIDATION_FAILED`.
**Ablation** (head `06330bd9`, `scripts/ablation-replace.mjs`, anchor `
...(declaredCode !== undefined ? { declaredCode } : {}),` in
`observe.ts` deleted, anchor 1 → 0, blob `d6a5337a5748` →
`d9534323aac4`; the tests import `src/`, so no dist is in the path):
<details><summary>Ablated: 3 failed | 46 passed (49); restored: 49
passed</summary>
```text
× reaches the ObservedAnswer through a write call and through the probe, nested and flat
× reaches it through the last read on the object when no write was made
× grades end to end: the served wire shape passes both halves; ⛔ the same conflict with no declaredCode fails both
+ "agent:refused:VALIDATION_FAILED-or-withheld",
+ "platform:refused:VALIDATION_FAILED",
Test Files 1 failed (1) · Tests 3 failed | 46 passed (49)
ablation-replace: ok restored: blob == HEAD (d6a5337) and `git diff HEAD` is empty
```
</details>
The "absent stays absent" case stays green under the ablation, as it
should.
## Acceptance notes
- **Legacy shape: no test kept.** No door the runner calls serves a
hook's unregistered code as `code`. The `/data` faces of the MCP record
tools answer through `refusalAsTheDoorServesIt`
(`packages/mcp/src/mcp-http-tools.ts` L990), which serves the door's
catalogue `code` with `declaredCode` whenever the door demoted
(`dataDoorRefusalEnvelope`, L954); the resource body does the same
(`packages/mcp/src/mcp-server-runtime.ts` L2179–L2187). The door's
demotion is `resolveThrownHttpError`'s code row
(`packages/types/src/thrown-http-error.ts` L253: a registered code
stays, anything else is derived from the status) with
`demotedDeclaredCode` (L526). `run_action` demotes the same way
(`packages/types/src/actions-door-answer.ts` L58, L69–L70). So the
legacy `code: 'OVER_RECEIPT'` and `code: 'ASSET_NOT_IN_STOCK'` cases are
dropped.
- **Observed, not changed: the legacy branch.** `refusalMeets` still
lets a `code` outside the `ErrorCode` catalogue at 4xx meet a declared
`VALIDATION_FAILED` (the branch before this change). It is kept so that
no reading narrows beyond the order's rulings, and it is now unpinned
because no door was found serving that shape. class: observation ·
reach: none · carrier: none. The seat may retire it on a later card.
- **Observed, not changed: a hook refusal at 403.** A hook that refuses
at 403 reaches the grader as `code: 'PERMISSION_DENIED'` with its
`declaredCode`. It meets a declared `PERMISSION_DENIED` through `code
=== declared`, as before this change, and now also a declared
`VALIDATION_FAILED` through rule (b) (ruling A: any 4xx). class:
observation · reach: none (no card declares `PERMISSION_DENIED` for a
hook's own refusal) · carrier: none.
- **`refusalOf` left as it is.** It lives in
`packages/qa/scenarios/src/score/scenario-run-grade.ts`, outside the
ordered surface, so `declaredCode` is read in `observe.ts` by a private
reader that mirrors its envelope selection, rather than by widening
`refusalOf`'s `Refusal`.
- **The new optional field** `ObservedAnswer.declaredCode` is an
additive optional member of a published package type, ordered under
`Clause-②: no`.
- **No live door probe.** The card quotes PR #33488's dev's probe of the
served shape; the tests pin that shape.
## Verification
On head `06330bd9` (branch `claude/project-thread-rl158j`, merge base
`origin/main` `e3f0cfd4`), each exit code captured before any pipe:
- `pnpm --filter @objectstack/scenarios test`: exit 0, Test Files 32
passed (32), Tests 712 passed (712).
- `pnpm --filter @objectstack/scenarios typecheck` (`tsc --noEmit`,
which compiles the tests): exit 0. `pnpm --filter @objectstack/scenarios
build`: exit 0.
- `node --stack-size=4000 node_modules/eslint/bin/eslint.js
packages/qa/scenarios --no-inline-config`: exit 0 (the package has no
`lint` script).
- Derived gates (`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`, 59 families): 58 exit 0; `pnpm
check:dual-build-cjs-loads` exit 3 PREREQUISITE NOT MET (needs every
package's `dist/`), **NOT MEASURED**, CI runs it. `--ran`: "59 derived
famil(ies) accounted for — 58 run, 1 NOT-MEASURED".
- `dispatch-gates --tier`: no path-derived mandate. 239 changed lines,
under the 3000 threshold. No governed surface.
- Changeset `.changeset/33497-scenario-grader-declared-code.md` (file
name unique to this card).
- CI families are read from this PR's check-runs, not re-run here.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5nw3MDkRymEzv6FDJs
Co-authored-by: Claude <noreply@anthropic.com>1 parent c43bffd commit e411388
5 files changed
Lines changed: 187 additions & 52 deletions
File tree
- .changeset
- packages/qa/scenarios
- src
- runner
- score
- test/runner
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
145 | | - | |
| 146 | + | |
| 147 | + | |
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
152 | | - | |
| 154 | + | |
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
| |||
205 | 207 | | |
206 | 208 | | |
207 | 209 | | |
208 | | - | |
209 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
210 | 253 | | |
211 | 254 | | |
212 | 255 | | |
213 | | - | |
214 | | - | |
| 256 | + | |
| 257 | + | |
215 | 258 | | |
216 | 259 | | |
217 | 260 | | |
| |||
224 | 267 | | |
225 | 268 | | |
226 | 269 | | |
227 | | - | |
228 | | - | |
| 270 | + | |
| 271 | + | |
229 | 272 | | |
230 | 273 | | |
231 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
88 | 95 | | |
89 | 96 | | |
90 | 97 | | |
| |||
192 | 199 | | |
193 | 200 | | |
194 | 201 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
199 | 206 | | |
200 | | - | |
201 | | - | |
202 | | - | |
| 207 | + | |
| 208 | + | |
203 | 209 | | |
204 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
205 | 216 | | |
206 | 217 | | |
207 | 218 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
212 | 224 | | |
213 | 225 | | |
214 | 226 | | |
215 | | - | |
| 227 | + | |
216 | 228 | | |
217 | 229 | | |
218 | 230 | | |
| 231 | + | |
| 232 | + | |
219 | 233 | | |
220 | | - | |
| 234 | + | |
221 | 235 | | |
222 | 236 | | |
223 | 237 | | |
224 | 238 | | |
225 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
226 | 242 | | |
227 | 243 | | |
228 | 244 | | |
| |||
0 commit comments