Skip to content

fix(rest): the email send door refuses an array or null body with its own 400 INVALID_REQUEST - #31541

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-7t0m2i
Nov 8, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-7t0m2i

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread
Fixes #31496

Clause-②: no
Metadata-protocol: none

维护者速读

  1. 改了什么:POST /api/v1/email/send 收到 JSON 数组或 JSON null 作为请求体时,现在在路由自己这一层直接回 400 INVALID_REQUEST("JSON body required"),邮件服务不再被调用。
  2. 为什么改:数组的 typeof 也是 object,能穿过路由原来的检查;null 原来被默认成 {}。两者都被送进邮件服务,再由服务以 400 VALIDATION_FAILED("subject is required")拒绝,错误码与路由自己的约定不一致(QA QA run · owed:weekly (73/73) · 0647dabb · 2026-11-08 · 61 PASS / 7 PARTIAL / 4 FAIL / 1 BLOCKED / 0 NOT-RUN #31486 C3a)。
  3. 风险与回滚:改前改后都是 400,只是错误码从服务的 VALIDATION_FAILED 变为路由的 INVALID_REQUEST;对象请求体和不带请求体的请求行为不变。回滚即 revert 本 PR。
  4. 先看:packages/rest/src/email-routes.ts(请求体检查那 7 行),再看 packages/rest/src/email-send-door-bounds.test.ts 末尾新增的 describe。
  5. 两分钟验证:pnpm --filter @objectstack/rest exec vitest run src/email-send-door-bounds.test.ts,预期 50 个用例全绿;把检查改回 typeof body !== 'object' 后数组三个用例转红。
  6. 需要你做的:无,席位落地。

What changes

The send door's body check, in registerEmailEndpoints (packages/rest/src/email-routes.ts), was the only route body check in that file:

  • Before: const body = req.body ?? {}; if (!body || typeof body !== 'object'). An array passes typeof body !== 'object', and a JSON null was defaulted to {}. Both reached emailService.send, which refused them as malformed messages (400 VALIDATION_FAILED, "subject is required" from plugin-email's normalizeMessage).
  • After: const body = req.body === undefined ? {} : req.body; if (!isPlainObject(body)). isPlainObject is the helper the same file already uses for headers (it excludes arrays with Array.isArray). An array or null now takes the route's own 400 INVALID_REQUEST "JSON body required", before the service is reached.
  • Unchanged: an absent body is still the empty message for the service to judge. (The Hono adapter already gives {} for an empty body; the undefined arm covers an embedder whose adapter leaves it unset.) Every object body is forwarded exactly as before, and a string or number body keeps the same answer.

Sweep of the same file. email-routes.ts registers one route, so this is the only route body check in it. The other object-shape check in the file, headersRefusal, already goes through isPlainObject.

Clause-② read from the diff: no. The shipped service refuses every array and null body with a 400, because none of them carries a subject. After this change they are still refused with a 400, now with the route's own code. Nothing that answered 200 before is refused now.

Tests

packages/rest/src/email-send-door-bounds.test.ts gets a new top-level describe in the existing harness. It runs through the real HonoHttpServer transport, with a contract-typed email double:

  • Six cases, each answering 400 with code: 'INVALID_REQUEST' while send is never called: an array of numbers, an empty array, an array holding a well-formed message, a JSON null, a JSON string and a JSON number.
  • CONTROL: an object body still reaches send, as sent.
  • CONTROL: an empty object {} still reaches send, stamped only with sentBy. It is a message for the service to judge, not a missing body.

The file also gains a module-top import '@objectstack/objectql';. check:test-source-alias asks for it on any edited test whose server reach loads objectql dynamically inside a handler.

Red on main first (4 of the 6 refusal cases; the string and number cases were already green)
     × an array of numbers is refused 400 INVALID_REQUEST, and nothing is sent 12ms
     × an empty array is refused 400 INVALID_REQUEST, and nothing is sent 2ms
     × an array holding a well-formed message is refused 400 INVALID_REQUEST, and nothing is sent 2ms
     × a JSON null is refused 400 INVALID_REQUEST, and nothing is sent 2ms
AssertionError: expected 200 to be 400 // Object.is equality
      Tests  4 failed | 46 passed (50)
Ablation (scripts/ablation-replace.mjs, src is what the suite imports, so no build leg)

Leg 1 puts back if (!body || typeof body !== 'object') {. Mutation landed (anchor 1 → 0, blob 626f40efea2e → 895cf1968604):

     × an array of numbers is refused 400 INVALID_REQUEST, and nothing is sent 8ms
     × an empty array is refused 400 INVALID_REQUEST, and nothing is sent 2ms
     × an array holding a well-formed message is refused 400 INVALID_REQUEST, and nothing is sent 2ms
      Tests  3 failed | 47 passed (50)
ablation-replace: ok restored: blob == HEAD (626f40efea2e) and `git diff HEAD` is empty

Leg 2 puts back const body = req.body ?? {};. Mutation landed (blob 626f40efea2e → 47919d207c32):

     × a JSON null is refused 400 INVALID_REQUEST, and nothing is sent 12ms
      Tests  1 failed | 49 passed (50)
ablation-replace: ok restored: blob == HEAD (626f40efea2e) and `git diff HEAD` is empty

Acceptance notes

  • Same-shape checks elsewhere in packages/rest (not in this diff). I searched packages/rest/src, excluding tests, for every typeof …body… !== 'object' check. There are four. Three already exclude arrays: analytics-dataset-body-door.ts, meta-record-currency-backfill-route.ts and user-work-routes.ts. The fourth is this one. Nothing is left to list.
  • The door's INVALID_REQUEST and VALIDATION_FAILED answers are still the flat { code, error } body, while its bounds answer the nested ADR-0112 envelope. That predates this card, and this PR does not change it.

Verification

HEAD 0319dc5 (after merging origin/main once):

  • pnpm --filter @objectstack/rest test: 394 files and 7546 tests passed, 332 skipped (run on 1dfcd3e, before the merge and the test-only import commit).
  • pnpm --filter @objectstack/rest exec vitest run src/email-send-door-bounds.test.ts src/email-send-display-name.test.ts on 0319dc5: 2 files, 69 tests passed.
  • pnpm --filter @objectstack/rest typecheck: exit 0.
  • pnpm exec eslint --no-inline-config on the two touched source files: exit 0.
  • dispatch-gates --commands: 64 commands. Their exit codes are in the seat report on the card.

Generated by Claude Code

The send route admitted a JSON array (typeof object) and defaulted a
JSON null to {}, so both reached the email service and were refused
there as VALIDATION_FAILED. A present body must now be a plain object;
anything else takes the route's own 400 INVALID_REQUEST.

Claude-Session: https://claude.ai/code/session_01FEkQ5mNZhe975x6zR3ULqS
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot added the domain:server Domain lane — seat card indexed by label:pm:seat label Nov 8, 2026
@github-actions github-actions Bot added size/s documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

1 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • the SDK route bridge reached 64 of 227 client-bound route-ledger rows — the other 163 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 163: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 104 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 19 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 7d7af560562d7f739b32a8cd66390151a1c34946 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 46edf43e3a106b4276a5642a8d84706f13f6540c — the merge of head 0319dc519cf4ad6147279eefde2e4599be5f3953 into base 7d7af560562d7f739b32a8cd66390151a1c34946, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 46edf43e3a106b4276a5642a8d84706f13f6540c && git checkout 46edf43e3a106b4276a5642a8d84706f13f6540c
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 7d7af560562d7f739b32a8cd66390151a1c34946 0319dc519cf4ad6147279eefde2e4599be5f3953 && git checkout -B drift-repro 7d7af560562d7f739b32a8cd66390151a1c34946 && git merge --no-ff 0319dc519cf4ad6147279eefde2e4599be5f3953

node scripts/docs-audit/affected-docs.mjs --json 7d7af560562d7f739b32a8cd66390151a1c34946

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · os-project-manager · session_01FEkQ5o8PE7ZtVjcor51wBZ

席位意见:接受。POST /api/v1/email/send 收到 JSON 数组或 null 作为请求体时,现在由路由自己回 400 INVALID_REQUEST(“JSON body required”),不再交给邮件服务去回 VALIDATION_FAILED。没有请求体和任何对象请求体的处理不变。

席位核对 — ACCEPT · domain:server#5 · Head-sha 0319dc519cf4ad6147279eefde2e4599be5f3953 · 2026-11-08T14:20Z

The maintainer's standing authorisation for landing reviewed PRs, verbatim: 「按照 pm-dispatch 规则复核过的都授权」.

  • Shape: 3 files (+65 / −2), read from the diff.
  • Clause-② read from the diff. no is right. A JSON array or null body was refused 400 before this PR, by the service, and is refused 400 after it, by the route. Only the code changes, from VALIDATION_FAILED to the route's own INVALID_REQUEST. Nothing accepted before is refused now. No contract review is owed: check-owed-reviews does not list it. The seat read the whole diff.
  • The dev's census. The other three body checks in packages/rest already exclude arrays, so there is nothing to list.
  • Gates.
    • Head check-runs: 36 success and 17 skipped, with none red or pending.
    • check-expected-skips: OK (exit 0).
    • check-governed-merges: NOT governed.
    • The dev's derived gates: 64 of 64 exit 0.
    • Mergeable state: clean.
  • Landing: ungoverned, tier S. Ready and auto-merge go in one relay dispatch. Fixes #31496 closes the card on merge.

Generated by Claude Code

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 8, 2026 14:21
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 8, 2026 14:21
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit d5fa237 Nov 8, 2026
54 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-7t0m2i branch November 8, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation domain:server Domain lane — seat card indexed by label:pm:seat size/s tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /api/v1/email/send with a JSON array body answers 400 VALIDATION_FAILED instead of the INVALID_REQUEST the route gives every other non-object body

1 participant