Repository navigation
Commit ea41c49
fix(rest): relay a declared service outage from the external-datasource routes as 503 (#30952)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DUZr21b5Uwo4sS3QxyC1M1x)_
Fixes #30609
Clause-②: no
Metadata-protocol: none
domain:server#5 card thread · session `session_016WV4cwJiP1ALmQ1rTttNGc`
· branch `claude/project-thread-ticta6` (named in the seat's re-posted
claim on the card). Branched from `main` at 33043bd.
## 维护者速读
- 改了什么:外部数据源导入接口(`POST
/api/v1/datasources/:name/external/tables/:remote/import`)遇到租户服务暂时不可用时,现在回
`503 SERVICE_UNAVAILABLE`(请稍后重试),不再回 `400
EXTERNAL_IMPORT_ERROR`(请求写错了)。同一组外部数据源接口共用这一处,所以它们遇到同类服务停摆也一样回 503。
-
为什么改:导入要先读租户形态来决定对象落到哪个包;租户服务读不出时抛的是「服务不可用」,但这里把它当成调用方的错误,调用方会去改请求而不是重试。数据源管理接口和
MCP `import_object` 工具早就回 503,REST 这一处没跟上。
- 风险与回滚:很低。只改了一个错误分支的状态码,只认同时带 `status 503` 和 `code SERVICE_UNAVAILABLE`
的错误;其它拒绝照旧 400,此前此后都不会保存任何东西。回滚即 revert 本 PR。
- 先看:`packages/rest/src/external-datasource-routes.ts` 的
`answerThrown`(新增的 503 分支,在 404
分支之前);`packages/rest/src/external-datasource-unknown-name.test.ts`
末尾新增的两个用例。
- 两分钟验证:`pnpm --filter @objectstack/rest exec vitest run
src/external-datasource-unknown-name.test.ts`,预期 17 个用例全过,其中「answers 503
SERVICE_UNAVAILABLE and saves nothing」一条。
- 需要你做的:无,席位落地。
## What changes
`answerThrown`, the one catch every `/datasources/:name/external/*`
route answers through, relayed only sandbox faults and the `404
RESOURCE_NOT_FOUND` envelope; every other throw became this family's
`400`. Since PR #30602 the import's landing reads the effective tenancy
posture (`classifyAdmissionTenancyPosture`), which throws
`AuthzStoreUnavailableError` (`status 503`, `code SERVICE_UNAVAILABLE`)
when a registered `tenancy` service cannot answer. The import therefore
told the caller its request was malformed when the truth was "retry".
It now relays an error carrying `status 503` and `code
SERVICE_UNAVAILABLE` as that envelope, ahead of the `404` relay, exactly
as `service-datasource`'s `badRequest` does.
- **Choice of read: the envelope (`status` + `code`), not
`isAuthzStoreUnavailableError`.** It is the read both twins make
(`badRequest` in `admin-routes.ts`, and the MCP `import_object` tool's
`thrownRefusalEnvelope`), so the three doors cannot drift on what counts
as an outage. The brand predicate would relay only the
authorization-store outage and keep answering `400` for any other
service that declares the same envelope. Both fields are required, so an
error carrying a stray `status` cannot re-route itself.
- **The `EXTERNAL_DATASOURCE_ERROR` routes get the same relay.** They
share the catch, and a declared dependency outage is the same truth on a
read or a draft as on the import: `400` would tell the caller to change
a request that was never wrong. This matches `badRequest`, which serves
every admin route the same way. No refusal that is not a declared outage
changes: a sandboxed refusal declaring a 4xx and the metadata door's
`409 DESTRUCTIVE_CHANGE` keep this family's `400` and code.
File surface as claimed: `answerThrown` only, its test beside it, one
changeset. `refuseFederationRequest` and the route registrations are
untouched (open draft PR #30702 edits those; hunks disjoint, re-checked
before push).
## Tests
New top-level `describe` in
`packages/rest/src/external-datasource-unknown-name.test.ts`, the file
that already pins `answerThrown`'s `404` relay over the real
`ExternalDatasourceService` and the real `HonoHttpServer`. Its `mount()`
takes config overrides now; the existing pins are unchanged. The landing
hook runs the real `classifyAdmissionTenancyPosture` over a `tenancy`
factory that rejects, which is the read `service-datasource`'s plugin
makes.
- the import on that outage answers `503 SERVICE_UNAVAILABLE`, its
message names the failed `tenancy` read, carries no `data`, and
`persistObject` is never called;
- a plain landing refusal from the same seam still answers `400
EXTERNAL_IMPORT_ERROR` with its own sentence, nothing saved.
Reproduction and ablation, one run (`node scripts/ablation-replace.mjs`,
anchor `envelope?.status === 503 && envelope?.code ===
'SERVICE_UNAVAILABLE'` replaced by `false`, anchor x1 -> x0, blob
b99785d -> 6d0515af): the outage pin goes red with `expected { status:
400, … } to deeply equal { status: 503, … }` (1 failed, 16 passed),
which is the defect as `main` answers it; restored, blob == HEAD, `git
diff HEAD` empty. The test imports the routes from `src/` by relative
path, so no build sits between the mutation and the run.
## Acceptance notes
- None.
## Verification
All local readings on head `3bccb0f74e` (the final head), worktree off
`main` 33043bd; `origin/main` has since moved 6 commits, none touching
`packages/rest`, `service-datasource` or `packages/core/src/security`,
so not merged.
<details><summary>Derived gate families: 60 derived, 59 run green, 1 NOT
MEASURED</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 60 commands; each run with its exit
code captured before any pipe (record: `gates-ran-3bccb0f74e.txt`).
- `dispatch-gates.mjs --ran`: `60 derived famil(ies) accounted for — 59
run, 1 NOT-MEASURED`.
- NOT MEASURED: `pnpm check:dual-build-cjs-loads`, reason: exit 3
`PREREQUISITE NOT MET` (reads the whole tree's `dist/`, which this
worktree has not built; CI's run is the reading).
</details>
<details><summary>Package and repo checks</summary>
- `pnpm --filter @objectstack/rest test` (under the verify lock): exit
0, `Test Files 393 passed (393)`, `Tests 7458 passed | 332 skipped
(7790)`.
- `pnpm --filter @objectstack/rest typecheck`: exit 0.
- `pnpm lint`: exit 0.
- `pnpm check:cli-command-ids`: exit 0. `pnpm check:adr-symbol-anchors`:
exit 0.
- `test:repo` (the `repo` vitest project) not run locally: the diff
touches no file in it and the derivation does not name it; CI's `Test
Core` runs it.
- Full dogfood not run: no `!` in the title and no `(narrowing)` arm.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cwJiP1ALmQ1rTttNGc)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cwJiP1ALmQ1rTttNGc
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6910797 commit ea41c49
3 files changed
Lines changed: 90 additions & 4 deletions
File tree
- .changeset
- packages/rest/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
630 | 643 | | |
631 | 644 | | |
632 | 645 | | |
| |||
640 | 653 | | |
641 | 654 | | |
642 | 655 | | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
643 | 659 | | |
644 | 660 | | |
645 | 661 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | | - | |
| 41 | + | |
37 | 42 | | |
38 | 43 | | |
39 | 44 | | |
| |||
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| 52 | + | |
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
| |||
161 | 167 | | |
162 | 168 | | |
163 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
0 commit comments