Repository navigation
Commit 51b67f1
feat(refusals)!: one refusal names several declared reasons, each in the person's language (#37395)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg4gWSndajcnTbbpCWXcNy9Q)_
Fixes #36877
Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #37407
## 维护者速读
- 用户能看到什么变化:批量操作(如 HotCRM 的「提交报销」)一次拒绝多条记录时,每条原因都按用户的语言逐行显示,最后一行是总结句。
- 为什么做:拒绝语目录原来一次只能回一句,中文界面下只能给用户看英文清单;HotCRM 的报销提交卡在这里。
- 出错会怎样:只影响声明了拒绝语目录、并且一次抛出多条原因的钩子和动作;写错的原因会在保存或运行时被明确拒绝,不会把未翻译的英文漏给用户。
- 破坏性:这是一次收窄。旧版本里被忽略的 `reasons` 键现在会被读取,三种原来能保存、能运行的写法现在会被拒绝(见下方
Narrowing)。changeset 带 BREAKING 标注、迁移说明和 ADR-0087 登记。
- 要你做什么:无(入队前的批准由席位安排)。
## What changes
Ruling 7178348458 (option A, 「A 一次抛多条原因逐行翻译」), executed term by term:
- **(1) Throw shape.** A hook or `script` action body may throw `{ code,
reasons: [{ reason, params? }, …] }` beside the existing single
`reason`/`params` form. One reader, `refusalAddressFrom`
(`packages/runtime/src/sandbox/quickjs-runner.ts`), reads the address
for both run paths: the VM's `__errorInfo` channel now also carries
`reasons` (JSON-cloned like `params`) and whether the key was present. A
`reason` beside a `reasons` list, an empty list, or a list that is not
`{ reason, params? }` elements is a `listProblem`, which is the loud
fault.
- **(2) Every listed reason checked.** `declaredAnswer`
(`hook-refusal-catalogue.ts`) checks each listed reason against the
entry's `reasons`. One undeclared reason makes the whole throw the `500`
fault naming the hook or action, the code and the reason (the existing
`undeclared…ReasonAtRun` sentence). Under a code with no `reasons`,
every listed reason is undeclared. At save, `hookRefusalReasonsThrownIn`
already read `reason: 'x'` inside an inline list (the regex is
unanchored within the throw statement); it now marks such pairs `listed:
true` when the `reasons: [` list is a direct member of the thrown object
literal (the one key the run reads, so a `params: { reasons: [ … ] }`
stays the body's own data), and also reads the assignment form
`e.reasons = [{ reason: 'x' }]; throw e`. Both save checks
(`HookSchema`, `ActionSchema`) judge a listed pair through one
predicate, `isUndeclaredThrownReason`: a single reason is still read
only under a code that declares `reasons`, as before; a listed one under
every code.
- **(3) Rendering and wire.** Each line is that reason's sentence,
translated and filled from its own `params` through the existing
`ownerRefusalMessage`. `userMessage` is the lines joined by `\n`, then
the entry's own `message` as the last line (holes from the throw's
top-level `params`). The rendered lines ride the `SandboxError` as
`refusals`, and every door answers them as `details.refusals: [{ reason,
message }]`: one shape reader, `declaredRefusalLines`
(`packages/types/src/thrown-http-error.ts`, the `candidates` precedent),
read by `resolveThrownHttpError` (the `/actions` door, MCP `run_action`,
the dispatcher) and by `mapDataError`'s `userMessage` rider (the `/data`
door). The VM never sets `refusals`: only the catalogue does, so a body
cannot hand the wire a list it did not render.
- **(4) Parity.** The in-process hook handler reads its throw through
the same `refusalAddressFrom` and builds the same error shape (`code`,
`status`, `userMessage`, `refusals`), so the two paths answer
byte-identically (pinned below).
- **(5)** The catalogue entry schema and the translation keys are
unchanged. The ruling's two declaration lines (`yes` / `added`) rested
on "nothing accepted today is refused"; the diff falsifies that premise,
so the PR declares the narrowing instead (contract review M1; zone
order, on the seat's recommendation, with the fork on Bill's decision
card). If Bill keeps term 5's lines, only the declaration lines, the
BREAKING banner, the migration and the semantic entry come out.
## Narrowing (declared)
Three sources that save and run on `main` are refused at this head:
1. A literal `throw { code: 'X', reasons: [{ reason: 'y' }] }` where `X`
declares no `reasons`: refused at save at `body.source` (`main` skips
every reason under such a code). A literal `y` under a code that
declares `reasons` without it was already refused.
2. `e.code = 'X'; e.reasons = [{ reason: 'y' }]; throw e` with `y`
undeclared: refused at save (`main` has no reader for the assignment
form).
3. A body that throws a declared code with a `reasons` property of its
own (empty, not a list of `{ reason, params? }`, beside a `reason`, or
naming an undeclared reason): the run answers the loud `500` fault where
`main` answered the declared sentence and status.
The changeset carries the BREAKING banner, the FROM → TO migration for
each (declare the reason under the code's `reasons`, remove the key, or
rename the body's own property) and the ADR-0087 disposition `registered
refusal-reasons-list-literal-judged`, a new semantic entry
(`packages/spec/src/migrations/entries/semantic/18.refusal-reasons-list-literal-judged.ts`,
fence amendment 2, comment 7181270799). No mechanical rewrite: whether a
`reasons` key was meant as the list or as the body's own data is the
author's call.
The surface was widened by the zone before the edit (claim amendment
7179332961) to `packages/types/src/thrown-http-error.ts` and
`packages/types/src/data-error-classification.ts`: each door builds
`details` from a closed set of fields read there, so term (3) could not
reach the wire from `packages/runtime/src/sandbox/**` alone.
## Tests
- `packages/runtime/src/sandbox/hook-refusal-catalogue.test.ts`: the
body path (en and zh-CN lines, per-line params, closing line,
`details.refusals` on `/data` and through `thrownAnswerOf`, the
`e.reasons = […]` form); seven fault cases (undeclared listed reason,
listed reason under a code with no `reasons`, both forms, empty, element
without `reason`, non-list, list `params`), each a `500` with no
`userMessage` and no `details`; the parity pin (body vs in-process
handler, `JSON.stringify` equal on `mapDataError` and `thrownAnswerOf`,
en and zh-CN) plus the same faults in-process; CONTROL: a single reason
carries no `details.refusals` on either path.
- `packages/runtime/src/sandbox/action-refusal-catalogue.test.ts`:
through the real `/actions` door, translated lines plus
`error.details.refusals`, and `actionsDoorAnswerOf` (the MCP reader)
agrees; an undeclared listed reason is the fault naming the action.
- `packages/spec/src/data/hook-refusals.test.ts`,
`packages/spec/src/ui/action-refusals.test.ts`: the reader's listed
pairs (inline and assignment), what it leaves to run time, the
predicate, the save refusal for an undeclared listed reason and for one
under a code with no `reasons`, CONTROL: a single reason under such a
code still saves, CONTROL: a `reasons` list nested under `params` is not
a thrown list (the reader reads it as an unlisted pair, and it saves
under a code with no `reasons` on both the hook and the action check).
- `packages/types/src/thrown-http-error.test.ts`: `declaredRefusalLines`
shape reading (five no-list cases, copies only `reason`/`message`) and
both door compositions.
<details><summary>Package suites and typecheck (local)</summary>
- `pnpm --filter @objectstack/types test`: Test Files 41 passed, Tests
939 passed.
- `pnpm --filter @objectstack/runtime test`: Test Files 649 passed,
Tests 12051 passed, 25 skipped.
- `pnpm --filter @objectstack/spec test`: Test Files 895 passed, Tests
28435 passed, 1 todo.
- `typecheck` for `@objectstack/types`, `@objectstack/runtime`,
`@objectstack/spec`: exit 0 (lock VERDICT command-exit 0).
- Re-run after the last source commit (`e8d60127`): `src/sandbox/` of
runtime, 46 files / 529 passed, 2 skipped; runtime typecheck exit 0.
</details>
<details><summary>Ablation (one, on the behaviour this PR
adds)</summary>
`node scripts/ablation-replace.mjs` on `hook-refusal-catalogue.ts`, the
listed-reason check `if (!reasons ||
!Object.prototype.hasOwnProperty.call(reasons, line.reason)) {` replaced
by `if (/* ABLATED_36877 */ false) {` (anchor 1 → 0, blob 5f2aba5 →
ae48d69f): 3 failed / 50 passed, the three `[#36877]` undeclared-reason
cases on both paths. Restored: blob equals HEAD (5f2aba5), `git diff
HEAD` empty. The runtime tests import the module from `src/`, so no
rebuild was needed.
</details>
<details><summary>Ablation (rework: the direct-member bound)</summary>
On `hook-refusal-codes.ts`, `if (!direct) continue;` replaced by `if (/*
ABLATED */ false) continue;` (anchor 1): 3 failed / 145 passed in
`hook-refusals.test.ts` + `action-refusals.test.ts`, exactly the three
nested-`params` controls. Restored from a byte copy; `git diff HEAD`
empty.
</details>
## Acceptance notes
- `/data` keeps bounding `userMessage` at 500 characters (#5423).
`details.refusals` is not bounded, so each listed reason's line stays
whole there; the closing line (the code's own `message`) is only the
last line of `userMessage`, so on a list long enough to be cut, `/data`
loses it. A client renders the lines from `details.refusals` (the zone
passes this to #37403).
- The console still shows the first sentence with the rest behind
"More"; the list rendering is ruling term 6, follow-up #37403.
- A `reasons` key a body threw beside a declared code used to be ignored
(the card's probe table). It is now answered, or is the loud fault when
it is not a readable list. That is the declared narrowing above.
- MCP: `actionsDoorAnswerOf` carries `details.refusals`; whether the MCP
tool result renders `details` was not re-measured (analysis confidence
gap (c)).
## Verification
Derived gate list (`node scripts/pm/dispatch-gates.mjs --commands`, 97
commands) run locally:
- 94 exit 0.
- `pnpm check:dispatcher-error-vocabulary`: red on the first run (a
`refusalError(code)` helper read as an unresolved code stamp); fixed in
`e8d60127` by building the error inline at both sites as before; re-run
exit 0.
- NOT MEASURED, prerequisites of this checkout, not of the diff: `node
scripts/check-plugin-teardown-shape.mjs --self-test` (exit 3, its pinned
positive control needs an unshallowed clone; it grades the script, which
this PR does not touch); `pnpm check:dual-build-cjs-loads` (exit 3,
needs the whole workspace built; CI's Build Core runs it).
- `pnpm --filter @objectstack/spec check:generated`: `api-surface/` and
`export-origins/` were stale (new exports) and are regenerated in this
PR; re-check green.
Rework (`4031cd56`): `check-adr-0087-registration --base origin/main` ✓
(`[BREAKING+bang+clause-②-narrowing+metadata-protocol-narrowed]
registered refusal-reasons-list-literal-judged (new here)`);
`check-changeset-no-major`, `check-empty-changeset`,
`check:changeset-gate-self-tests`, `check:commit-card-trailers`,
`check:spec-changes`, `check:upgrade-guide` exit 0; `src/migrations` 201
passed; the two spec refusal suites 148 passed. CI's check-runs are the
authority for every family. The `(narrowing)` arm owes the full dogfood
battery on the final head: on `4031cd56`, `pnpm --filter
'@objectstack/dogfood^...' build` then, under the lock, `pnpm --filter
@objectstack/dogfood test` (no shard, no path): Test Files 487 passed, 3
skipped; Tests 4128 passed, 68 skipped; exit 0. CI on `4031cd56`: 73
runs, success or skipped, none failed.
Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run
--maxWorkers=2 src/sandbox/hook-refusal-catalogue.test.ts -t 36877` —
expect every `[#36877]` case green, including the parity pin.
Read first: `packages/runtime/src/sandbox/hook-refusal-catalogue.ts`
(`declaredAnswer`, the list branch),
`packages/runtime/src/sandbox/quickjs-runner.ts` (`refusalAddressFrom`
and the reject handler's new `reasons` clone),
`packages/types/src/thrown-http-error.ts` (`declaredRefusalLines`).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CXvMJTCqCs1b69pCH7)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CXvMJTCqCs1b69pCH7 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 66c854d commit 51b67f1
16 files changed
Lines changed: 965 additions & 60 deletions
File tree
- .changeset
- packages
- runtime/src/sandbox
- spec
- api-surface
- export-origins
- src
- data
- migrations/entries/semantic
- ui
- types/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 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 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
0 commit comments