Repository navigation
fix(rest): handleRouteError says Vary: Accept-Language on a refusal carrying a userMessage - #38565
objectstack-fleet[bot] wants to merge 7 commits into
Conversation
…ge body (WIP) Co-Authored-By: Claude <noreply@anthropic.com>
…family Co-Authored-By: Claude <noreply@anthropic.com>
…ndle-route-error-vary
…s; name the exit in the who-asks note Co-Authored-By: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 27 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 9915d756ecb48716fd601903d41a7a97f9269f44 && git checkout 9915d756ecb48716fd601903d41a7a97f9269f44
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 1a9d1495e181a941d4a710dd916a89560d1b05f8 5dba7a1f7466c9cf906d57930d980cef16d70156 && git checkout -B drift-repro 1a9d1495e181a941d4a710dd916a89560d1b05f8 && git merge --no-ff 5dba7a1f7466c9cf906d57930d980cef16d70156
node scripts/docs-audit/affected-docs.mjs --json 1a9d1495e181a941d4a710dd916a89560d1b05f8
|
…n them in the ledger Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
|
repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS 席位核对 — REWORK · L1 · seat repo:objectstack#1, review thread R1 · Head-sha
|
|
repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS 2026-11-29T13:04Z · Superseded by #38585 and closed, on seat 1's order to this review thread. #38585 carries this pull's commits unchanged (branch |
…arrying a userMessage (objectstack-ai#38585) <!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Jianguo** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbBTdUoQ3z9PtcW1WA3ZSL9M)_ Fixes objectstack-ai#38542 Supersedes objectstack-ai#38565 (closed, 7256275666) Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:元数据、批量写入、审批、记录操作等接口出错时,如果错误里带有给最终用户看的那句话,响应会声明“内容随请求语言不同”;其余情况用户无感。 - 为什么做:属于多语言错误提示这一组修复,补上 rest 包里那个公共出错出口,让共享缓存不会把一种语言的出错句子给另一种语言的请求;这一版只改了发布说明的文字。 - 出错会怎样:最坏是批量换负责人或转交工作时某一行被拒,整个请求变成服务器错误;已用测试锁住这种情况,改动可直接撤回。 - 要你做的:无。 ## What changes This PR carries the branch of objectstack-ai#38565 forward from its head `5dba7a1f74`, adds one text commit for the review round, and merges the current `main`. The code is the code objectstack-ai#38565 was reviewed at; only the changeset text and this body changed. - `handleRouteError` (`packages/rest/src/error-response.ts`), the shared error exit of 43 catches in 14 files, adds `Vary: Accept-Language` when `answerVariesByLanguage(resolved.body)` holds, in the multi-value form the hosts append (`res.header('Vary', [LOCALIZED_ANSWER_VARY])`), the same call `crud-routes.ts`'s `sendRefusal` and the four catches fixed for objectstack-ai#38507 make. Status, code and body are unchanged. One change at the shared exit, none per caller. - Measured first (card Ask 0): every arm of `resolveErrorResponse` ends in `mapDataError` or `withDeclaredUserMessage`, and both ride a producer-declared `userMessage` onto the body whatever the status. So any caller can answer one when its throw declares one. The rule keys on the body, so a caller whose throws never declare a `userMessage` is unaffected. - Two callers use the exit as a classifier through a fake response: `change-owner-routes.ts` (`classifiedAnswer`) and `user-work-routes.ts` (`rowFailureAnswer`). Each sink now answers a no-op `header()`. Without that, a row refusal carrying a `userMessage` made the whole hand-over answer `500 INTERNAL_ERROR` (`TypeError: res.header is not a function`). `handleRouteError` stays strict to the `IHttpResponse` contract, with no guard. `batch-routes.ts`'s `namingFailedOperation` builds its wrapper with `Object.create(res)`, so it inherits the real `header`. - The who-asks note in `packages/types/src/localized-answer-vary.ts` names this exit (comment only, card Ask 2). - Changeset `.changeset/38542-handle-route-error-vary.md`, review round 1 (L1 7255857505 items 1 and 2): - it now names `'@objectstack/types': patch` with one sentence: the who-asks note beside `LOCALIZED_ANSWER_VARY` names the shared REST route error exit (`handleRouteError`). The note ships in that package's published `dist/index.d.ts`; - "ownership-change" is struck from the route list, which now reads "the approval and UI routes". The single Change Owner door answers through `sendError`, not this exit, and gets no `Vary` here; that door is objectstack-ai#38567. ### The three commits after `78a2fb1669` and their four files These landed on the objectstack-ai#38565 branch after its body was written. Each is a consequence of the fix, read and accepted in L1 7255857505, and admitted to the claim surface by amendment 7256078743. - `106f5fbf08` touched `scripts/engine-double-contract.pinned.json`: the new suite's two engine doubles check each `update` call with `assertEngineUpdateDispatch`, and the ledger pins that suite's `update` verb (pinned 2), as `check:engine-double-contract` asks of a new double. The same commit reshaped those doubles in the new test file. - `196639a153` touched `packages/rest/src/analytics-fault-user-message.test.ts`, `packages/rest/src/error-response-structured-arm-door-parity.test.ts` and `packages/rest/src/rest-user-facing-refusal-marking.test.ts`: each suite hands the shared exit a response fake, which must now answer `header()` because the exit calls it on a body carrying a `userMessage`. One added line per fake; no assertion changed. - `5dba7a1f74` touched `packages/rest/src/analytics-fault-user-message.test.ts` and `packages/rest/src/rest-user-facing-refusal-marking.test.ts` again: each adds `import '@objectstack/objectql'` so the engine's first load is paid at collection, as the first-load rule of `check:test-source-alias` asks of a suite that reaches the engine. ## Tests - `packages/rest/src/route-error-vary-38542.test.ts`, 8 cases, one route per caller family, each through the real route and the real exit: - data action `POST /data/:object/:id/clone`: the localized `404 RECORD_NOT_FOUND`; - metadata read `GET /meta/:type/:name/references`: a refusal with its own `userMessage`; - batch write `POST /data/:object/batch`: a hook refusal with its own `userMessage`; - each with a CONTROL (the same refusal with no `userMessage` gets no `Vary`); - the two sinks: a row refusal with a `userMessage` is listed as a failed row (200), not a 500. <details><summary>Readings at 9f9de2b</summary> - Head `9f9de2be4b` is `bea8167c` (the changeset edit on top of `5dba7a1f74`) merged with `origin/main` `696d02f5`. - Under the verify lock, `pnpm --filter '@objectstack/rest^...' build --concurrency=2`, then `vitest run --maxWorkers=2` on `route-error-vary-38542`, `change-owner-routes`, `user-work-routes`, `rest-refusal-vary-38507`, `analytics-fault-user-message`, `error-response-structured-arm-door-parity` and `rest-user-facing-refusal-marking` (every suite the branch touches, plus the objectstack-ai#38507 sibling), then `pnpm --filter @objectstack/rest --filter @objectstack/types typecheck`: VERDICT command-exit 0, Test Files 7 passed (7), Tests 151 passed (151). - Local gates, each exit captured before any pipe, all exit 0: check:nul-bytes, check:engine-double-contract, check-empty-changeset --base origin/main, check-changeset-no-major --base origin/main, check-closing-keyword-parity, check-adr-0087-registration --base origin/main, check:issue-citations, check:doc-authoring, check:cross-package-test-inputs, check:changeset-gate-self-tests. The other derived families are left to CI and its check-runs on this head. </details> ## Acceptance notes - Double token, read only and not run: some metadata read success paths (`meta-item-read-routes.ts`, `meta-collection-routes.ts`, `meta-app-bundle-routes.ts`) set `Vary: Accept-Language` in the single-value form before calls that can still throw into this exit. A refusal with a `userMessage` thrown there would carry the token twice. A repeated `Vary` token means the same thing (RFC 9110 12.5.5). - Same family, measured and left out of this PR: the single Change Owner door (`POST /data/:object/:id/change-owner`) re-sends the classified answer in the nested envelope through `sendError` and does not go through this exit. For a missing row it answers `404 RECORD_NOT_FOUND` with a `userMessage` and no `Vary`. Carrier: objectstack-ai#38567. - The ablations below were run on the objectstack-ai#38565 branch (heads `7d622fe7` and `78a2fb16`) and are not re-run here: this round changes no code or test line. - Ablation 1, `error-response.ts` restored to the base on disk: the three cases that assert `Vary` went red and the three CONTROLs stayed green. - Ablation 2, both sinks' `header()` removed: the two sink cases went red with the 500 described above. - The leftover probe branch `claude/issue-38542-handle-route-error-vary-wip` is for the seat to delete after this lands. ## Verification Read first: `.changeset/38542-handle-route-error-vary.md` (this round's only edit), then `packages/rest/src/error-response.ts` (`handleRouteError`, the one added line), then the two sinks in `change-owner-routes.ts` and `user-work-routes.ts`. Two-minute check: `pnpm --filter @objectstack/rest exec vitest run src/route-error-vary-38542.test.ts`. Expected: 8 passed. Account: zhuangjianguo 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jS3g8S6XJojU8e3EAp <!-- signed: repo:objectstack#1 · zhuangjianguo · session_01QsR2jSyQBDMyRnrrWKy7WS --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Fixes #38542
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
handleRouteError(packages/rest/src/error-response.ts), the shared error exit of 43 catches in 14 files, now addsVary: Accept-LanguagewhenanswerVariesByLanguage(resolved.body)holds, in the multi-value form the hosts append (res.header('Vary', [LOCALIZED_ANSWER_VARY])), the same callcrud-routes.ts'ssendRefusaland the four catches fixed for rest: five /data-adjacent catches outside crud-routes.ts answer mapDataError without Vary: Accept-Language #38507 make. Status, code and body are unchanged. One change at the shared exit, none per caller.resolveErrorResponseends inmapDataErrororwithDeclaredUserMessage, and both ride a producer-declareduserMessageonto the body whatever the status. So any caller can answer one when its throw declares one, and no caller family is excluded by construction. The rule keys on the body, so a caller whose throws never declare auserMessageis unaffected.change-owner-routes.ts(classifiedAnswer, used by the bulk row describer and the single door) anduser-work-routes.ts(rowFailureAnswer). Each sink now answers a no-opheader(). Without that, a row refusal carrying auserMessagemade the whole hand-over answer500 INTERNAL_ERROR(TypeError: res.header is not a function).handleRouteErrorstays strict to theIHttpResponsecontract, with no guard. All other call sites were checked by grepping:batch-routes.ts'snamingFailedOperationbuilds its wrapper withObject.create(res), so it inherits the realheader. No other fake or partial response reaches the exit.packages/types/src/localized-answer-vary.tsnow names this exit (comment only, card Ask 2).Tests
packages/rest/src/route-error-vary-38542.test.ts, one route per caller family, each through the real route and the real exit:POST /data/:object/:id/clone: the localized404 RECORD_NOT_FOUND;GET /meta/:type/:name/references: a refusal with its ownuserMessage;POST /data/:object/batch: a hook refusal with its ownuserMessage;userMessagegets noVary);userMessageis listed as a failed row (200), not a 500.Readings at 78a2fb1
pnpm --filter '@objectstack/rest^...' buildthenvitest runonroute-error-vary-38542,change-owner-routes,user-work-routes,rest-refusal-vary-38507: lock VERDICT command-exit 0, Test Files 5 passed (5), Tests 53 passed (53).pnpm --filter @objectstack/rest --filter @objectstack/types typecheck: VERDICT command-exit 0.error-response.tsrestored to the base on disk: the three cases that assertVarywent red and the three CONTROLs stayed green.header()removed: the two sink cases went red (Tests 2 failed, 6 passed) with the 500 described above.Acceptance notes
meta-item-read-routes.ts,meta-collection-routes.ts,meta-app-bundle-routes.ts) setVary: Accept-Languagein the single-value form before calls that can still throw into this exit. A refusal with auserMessagethrown there would now carry the token twice. A repeatedVarytoken means the same thing (RFC 9110 12.5.5).POST /data/:object/:id/change-owner) re-sends the classified answer in the nested envelope throughsendErrorand does not go through this exit. For a missing row it answers404 RECORD_NOT_FOUNDwith auserMessageand noVary. Carrier: rest: change-owner on a missing record answers a userMessage through sendError without Vary: Accept-Language #38567 (filed by the seat).Verification
Read first:
packages/rest/src/error-response.ts(handleRouteError, the one added line), then the two sinks inchange-owner-routes.tsanduser-work-routes.ts.Two-minute check:
pnpm --filter @objectstack/rest exec vitest run src/route-error-vary-38542.test.ts. Expected: 8 passed.Account: os-project-manager
🤖 Generated with Claude Code
https://claude.ai/code/session_01FEkQ5pH8MaBBP5T2dVcTHL