You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bd46e3d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(runtime,hono): a returned error answer carrying a userMessage says it varies by Accept-Language (#38274)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao2nxJ1WFfhVcttSAtWX2GTp)_Fixes#38123
repo:objectstack#3 · os-tesla · session_01L9qibxRYWXrA8r7F5oJ2mH
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户看不到变化:调度器各模块自己接住错误后返回的提示本来就按请求语言给出,现在响应头也写明它随请求语言变化,和上一张卡修好的那几条出口一致。
- 属于界面多语言这条线,替用多种语言访问同一部署的用户解决:缓存可能把一种语言的错误提示交给说另一种语言的人。
- 只多一个响应头,状态码、错误码和正文都不变;不带提示文字的错误应答不加;有问题可以直接撤回。
- 无
## What changes
- `packages/runtime/src/dispatcher-plugin.ts`, `sendResultBase`'s
`response` arm: when `answerVariesByLanguage(result.response.body)`
(`@objectstack/types`, landed with #38114) is true, it writes
`res.header('Vary', ['Accept-Language'])`. That is the contract's
multi-value form, which the hosts append. It is written after the
route's own headers, so nothing after it can replace it.
- `packages/adapters/hono/src/index.ts`, `createHonoApp`'s `toResponse`,
`response` arm: the same question of the body, answered with
`c.header('Vary', 'Accept-Language', { append: true })`, after the
dispatcher's own headers.
- `packages/types/src/localized-answer-vary.ts`: docblock only. Its "Who
asks" list now names the two returning exits beside the three throwing
ones. No new export.
- Changeset: `@objectstack/runtime`, `@objectstack/hono`,
`@objectstack/types` patch.
## Why
A shared cache in front of the server must never hand a user an error
message in someone else's language, so every localized error answer says
it varies by `Accept-Language`. The rule sits on the exits rather than
in `errorFromThrown`: #38114 put the rule on the three exits that answer
a THROW. An answer a dispatcher domain catches and composes itself is
RETURNED as `{ handled: true, response }` and leaves only through these
two exits, which until now wrote nothing but `response.headers`. Per the
claim (route A, bounded in-place widening of the same defect class), the
one exit rule covers every producer of a returned `userMessage`, each
named here:
- `HttpDispatcher.errorFromThrown`, the card's own case (for example
`POST /automation/_record-starts`, whose catch hands over the `/data`
read's localized `recordNotFoundError`);
- `deps.error` carrying a `userMessage` (ruling B′ on #24914): the
automation resume door's and trigger door's `400 FLOW_FAILED`;
- the `/actions` door's `apiErrorResponse` (`action-dispatch.ts`,
`actionsDoorAnswerOf`);
- the dispatch foot's marked `PERMISSION_DENIED` 403
(`http-dispatcher.ts`, `declaredUserMessage`).
## Tests
Each pin goes into the existing harness file for its exit, as a
top-level `describe`:
-
`packages/runtime/src/dispatcher-plugin.declared-user-message.test.ts`,
`[#38123] the dispatcher RETURNED exit`. Every case drives a REAL route
mounted by `createDispatcherPlugin` and reads the fake response's header
writes:
- `errorFromThrown`: `POST /api/v1/automation/_record-starts`, with the
`/data` read throwing the real `recordNotFoundError(object, id,
context)`. For `en`, `zh-CN` and `ja-JP` callers: 404
`RECORD_NOT_FOUND`, the `userMessage` in that language, exactly one
`Vary` write of `['Accept-Language']`, and it is the last header
written. Control: the same route's unmarked `400 VALIDATION_FAILED`
writes no `Vary`.
- the resume door (`deps.error` with a `userMessage`), the trigger door
and the `/actions` door: `400 FLOW_FAILED` from a scripted engine whose
result carries an app hook's mark. Marked: the mark on the wire and one
`Vary` write, last. Control: the unmarked result writes no `Vary`.
- the dispatch foot: a marked `PERMISSION_DENIED` 403 gets the `Vary`
write; the unmarked one does not.
- `packages/adapters/hono/src/hono-response-header-array.test.ts` (the
`toResponse` header harness), `[#38123] the returned answer`. One row
per producer above, with the nested ADR-0112 body that producer
composes, written out because this package's `@objectstack/runtime` is a
stub: marked ⇒ `Vary: Accept-Language`, unmarked ⇒ no `Vary`. Appended,
not set: a route's own `Vary: Accept-Encoding` keeps its token beside
`Accept-Language`, and with CORS on, `Origin` keeps its place.
<details><summary>Readings (base origin/main bd5407e, head
e6eed88)</summary>
- Before the change, through the real mounted `POST
/api/v1/automation/_record-starts` (probe in the card's pre-claim
report): `404 RECORD_NOT_FOUND`, `userMessage` in en / zh-CN / ja-JP,
and the only header written was `X-Request-Id`. No `Vary`.
- Ablation through `scripts/ablation-replace.mjs` on the committed fix,
deleting one exit's line, then restoring it; each restore was checked as
`blob == HEAD` with an empty `git diff HEAD`. Both suites import their
exit from source.
- runtime: `Tests 7 failed | 28 passed (35)`. The seven marked rows of
the new describe failed (three languages, three flow doors, the foot
403), and every control passed.
- hono: `Tests 6 failed | 7 passed (13)`. The four marked producer rows
and the two "appended" rows failed, and every control passed.
- Package suites, each `pnpm --filter PKG test` under the verify lock,
exit 0:
- types: 42 files, 963 tests.
- hono: 14 files, 272 tests.
- runtime: 655 files, 12455 passed and 25 skipped.
- `typecheck` exit 0 on types, hono and runtime.
- `eslint --no-inline-config` exit 0 on the five touched `.ts` files.
- Derived local gate set at `e6eed882`: `dispatch-gates --ran`
reconciles 71 derived, 70 run with `exit 0`, 1 NOT MEASURED, 0 unrun.
The NOT MEASURED one is `check:dual-build-cjs-loads`, which exited 3
(PREREQUISITE NOT MET): it reads every package's `dist/`, and this tree
built only the runtime and hono closures. CI's `Lint & Repo Gates` runs
it. `check-plugin-teardown-shape --self-test` needed its fixture commit
fetched into the shallow clone, then exited 0.
- `overlap-check` before the first push was not run; it was run right
after it on e6eed88: clean against origin/main and against #38185, the
one open PR sharing `dispatcher-plugin.ts`.
</details>
## Acceptance notes
- Correction to the pre-claim report: `mcp.ts` is not one of these
producers. Its `deps.error` with a `userMessage` (`resumeDoorError`)
answers `dispatchActionResume`, the kernel's in-process host API
(`action-dispatch.ts`), not an HTTP route, so no response header
applies.
- No dedupe of the token. No producer today returns both a `userMessage`
body and its own `Vary: Accept-Language` header:
`localizedNotImplemented` localizes `message`, not `userMessage`, and
the `/meta` reads that set the header answer success bodies. `Vary` is a
list, so a repeated token is harmless.
- The hono pins live in `hono-response-header-array.test.ts`, the
`toResponse` header harness, rather than
`hono-thrown-message-disclosure.test.ts`, which the claim named: that
file pins `thrownJson`, the throw arm, and this change is the returned
arm.
## Verification
Read first, by risk:
1. `packages/runtime/src/dispatcher-plugin.ts`: the end of
`sendResultBase`'s `response` arm (the exit `os dev` serves for every
dispatcher-mounted route).
2. `packages/adapters/hono/src/index.ts`: `toResponse`'s `response` arm.
Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run
src/dispatcher-plugin.declared-user-message.test.ts` shows 35 passing.
Delete the `res.header('Vary', …)` line in `sendResultBase` and the same
command shows 7 failing.
## 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; lint passes on the touched files.
- [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` 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 with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L9qibxRYWXrA8r7F5oJ2mH
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibxRYWXrA8r7F5oJ2mH)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(runtime,hono): an error answer a dispatcher domain returns with a `userMessage` says it varies by `Accept-Language`
8
+
9
+
Clause-②: no
10
+
Metadata-protocol: none
11
+
12
+
An error answer whose body carries a `userMessage` is in the caller's language, so it now carries `Vary: Accept-Language`, as the thrown refusals already do. This covers the answers a dispatcher domain catches and composes itself: `HttpDispatcher.errorFromThrown`, a `deps.error` call carrying a `userMessage` (the automation resume and trigger doors' `FLOW_FAILED`), the `/actions` door, and the dispatch foot's marked `PERMISSION_DENIED`. Both exits that send such an answer ask the body: `@objectstack/runtime`'s dispatcher plugin and `@objectstack/hono`'s `createHonoApp`. The token is appended, so a `Vary` that CORS, compression or the route writes keeps its own tokens. Status codes, error codes and bodies are unchanged, and an answer with no `userMessage` gets no new header.
0 commit comments