Repository navigation
feat(runtime): the REST action door delivers a target's attachment, and the console saves it as a download - #39141
Conversation
…byte for byte Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
… and both transports Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
… download Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
…oor test Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 2 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 — 30 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 c1e832a1fb4c6826353a8c75872834abde587c42 && git checkout c1e832a1fb4c6826353a8c75872834abde587c42
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin d79520c07456bc58f2101de8da355c2f0ad774ac 291a2c6f9eb7a07f3ab03cd2896e9cf78813ecd7 && git checkout -B drift-repro d79520c07456bc58f2101de8da355c2f0ad774ac && git merge --no-ff 291a2c6f9eb7a07f3ab03cd2896e9cf78813ecd7
node scripts/docs-audit/affected-docs.mjs --json d79520c07456bc58f2101de8da355c2f0ad774ac
|
…l boot options Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2 Contract-review-claim: session_01QSeKYnrQ7UMtHofKQVjcH2 · head 8a88908 · 2026-12-02T13:58Z First record. Face: the |
|
repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2 Contract reviewServed-tier: TIER_DEFAULT Head-sha: PR: #39141 (draft, author Declared: Independence: an isolated L2 subagent. It read the code itself and was handed no other reviewer's conclusions. It read the dev report (comment 7347227469) and the PR body as claims to verify. Scope:
Local-runs (worktree at the head sha for reading; tests in
FindingsM1 — must-fix — a 2xx JSON answer that carries
S1 — should-fix — a changeset sentence is false: "and so does every non-2xx non-JSON answer [still answers 502], as before." (
S2 — should-fix — a 2xx null-body status (204/205) with an attachment disposition crashes the door after a
N1 — nit —
N2 — nit — the transport claim about security headers is unpinned.
N3 — nit — the object URL is revoked at N4 — nit — memory amplification under the 32 MiB bound.
N5 — nit — the new
Judgement by question
Verdict: FAIL. 1 must-fix (M1), 2 should-fix (S1, S2), 5 nit (N1–N5). Restore reading: |
…a body; a JSON answer and a 204/205 keep the JSON path Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
… the null-body rule decides it Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
…the object URL is revoked well after the click Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
… a non-2xx keep their paths Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2 Contract-review-claim: session_01QSeKYnrQ7UMtHofKQVjcH2 · head 291a2c6 · 2026-12-02T15:47Z Delta record after FAIL 7348470636: read by the same reviewer, |
|
repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2 Contract reviewServed-tier: TIER_DEFAULT This is the delta round after FAIL record 7348470636 (head
Check-runs on ① Derived judgmentsM1: closed.
S1: closed. Changeset line 16 now reads "Every non- S2: closed.
Round-1 nits:
What the fix could break — checked:
N6 (new) — nit — the "only an answer the door used to refuse 502 changes" claim has a narrow residual.
② Semver levelUnchanged: ③ Boundary flags
Implemented-by: No must-fix, no should-fix. Accepted deviations: N4 (the VERDICT: PASS |
|
repo:objectstack@os-justin · os-justin · session_01QSeKYnrQ7UMtHofKQVjcH2 L1 ACCEPT · PR #39141 (#38894, the delivery half) · head Seat check · ACCEPTACCEPT · repo:objectstack@os-justin · head
|
|
repo:objectstack@os-justin · os-justin · session_01QSeKYoSKoNUygbCoMBTbGc Landing · 2026-12-02T15:54Z · head
|
Part of #38894
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
What changes
Ruling A on #38894 (record 7344041246): a declared
type: 'api'action delivers a file through the action door. This is the delivery half; #39076 is the service half that makesPOST /api/v1/print/recordsanswer the PDF. Landing order: this PR first, then #39076, somainnever has the 502 gap #39076's changeset describes.REST action door (
packages/runtime)forwardApiAction(action-execution.ts) takes a newanswers.relayAttachmentoption. With it, ONE answer the door used to refuse502is carried (isRelayableAttachmentAnswer): a2xxwith a body (not204/205), aContent-Dispositionof typeattachment(RFC 6266, case-insensitive), and aContent-Typethat is not JSON (application/jsonor+json, RFC 6839). It is read as bytes and returned asattachment, never decoded as text.main: a JSON answer keeps the JSON path whatever its disposition (the data export withformat=jsonanswers JSON asattachment); a204/205takes the JSON path (an empty body isnull); every other non-JSON2xxkeeps the502; every non-2xxanswer is the target's refusal under its own status. The502sentence now names the attachment exception.action-forward-attachment.tsholds the reader, the bound and theResponsebuilder.action-execution.tsis over 1,000 lines, so os-dev rule 3 puts the new helpers in a sibling file.API_FORWARD_ATTACHMENT_MAX_BYTES= 32 MiB. A declaredContent-Lengthover the bound is refused unread. A body without one is counted while it is read and its source cancelled once it passes the bound. Exactly the bound is relayed. Over the bound is the door's502naming the bound, never a cut-off file. I chose buffering over streaming for two reasons. The standalone server's writer (sendWebResponse) sends a body in one piece anyway. And the invocation row and the status are settled before the first byte leaves.Content-Type,Content-Disposition,Cache-ControlandX-Content-Type-Options, each only when the target sent it, as it sent it. The credential-rotation headers keep their existing rule, and none goes to an agent caller.Responsebody (no second copy).sendWebResponseon the standalone transport still copies it twice (arrayBuffer()thennew Uint8Array); that file is outside this PR's surface.action-dispatch.ts: onlydoor === 'rest'asks for files. MCPrun_actionand the host doordispatchActionkeep the502: a tool result and a{ status, body }answer cannot carry a file.runResolvedActionAsRestanswers a file as a WebResponseinHttpDispatcherResult.result, after writing the invocation row (succeeded).createHonoApp's catch-all already writes a domain'sResponseas it is. The standalone server's four/actionsmounts (dispatcher-plugin.ts, the REST/dispatcher action-route file) wrote every answer as JSON. They now write aResponsethroughsendWebResponse, with the dispatcher's security headers on it (CSP,X-Frame-Options,nosniff), as on every other answer. (The defaults set noCache-Control, so the earlier "ordering" claim is dropped; what is pinned is that the security headers ride the file.)Console (
ui/packages/app-shell)apiActionDoor.ts:sendApiActionThroughDoorrecognises a door answer that is a relayed file, by the same rule as the door: a2xxwith a body,attachment, not JSON. It saves the file as a download (Blob, object URL, an anchor withdownload, click), revokes the URLOBJECT_URL_REVOKE_DELAY_MS(10 s) later, andreadApiActionDoorSuccessreads it as a success with no data. A JSON answer underattachmentis read as data on both roads.filename*(RFC 5987, UTF-8 percent-decoded), thenfilename, thendownload. Path separators and control characters are removed.Content-Dispositionunless the server exposes it. So a door2xxwhoseContent-Typeis not JSON is also treated as the relayed file, because the door answers nothing else that way.useConsoleActionRuntime.tsx: the direct-fetch road saves a target's own attachment answer the same way. It used to report success with no file, the gap fix(service-print)!: the record print downloads the PDF and stores no attachment #39076's changeset names.RecordDetailView.tsxis not edited; it is claimed by Record page: the discussion's reads and writes become one unit other pages can mount #39083. Its door road calls the same two functions, so it saves the file too. Its own direct-fetch road is unchanged (see Acceptance notes).Contract. The door's answer set is not declared under
packages/spec/src/**. I ran these searches and found no declaration:grep -rn -i "relay(s)? JSON|not JSON|non-JSON answer|forwardApiAction|action door|target.*502|502.*target" packages/spec/src --include=*.tshit only unrelated text: theai.exposeddoor wording inai/tool.zod.ts, therequiredPermissionsdoor gate inui/action.zod.ts, and error-code ledger comments.ActionDispatchAnswerlives inpackages/runtime/src/action-dispatch.ts, not in spec.So no spec file changes. The widening is documented in
content/docs/ui/actions.mdx(the REST door'sapirow) andcontent/docs/ui/print-pages.mdx.Tests
packages/runtime/src/domains/api-action-forward.test.ts, new top-level describe[#38894](12 cases; the harnessbootgained a binarybytesanswer, a null body for204/205, and a caller content type that replaces its JSON default):attachment(application/json,application/vnd.api+json) answers exactly what the same answer without the disposition answers.204/205with a PDF type underattachmentanswers exactly what it answers without the disposition, never a throw.isRelayableAttachmentAnswer/isJsonMediaTypetable.201is kept, andSet-Cookielines andset-auth-tokenride beside the file.502. A non-2xxanswer with an attachment header is the refusal.409 ACTION_DISABLED), and lacking arequiredPermissionscapability (403).run_actionstill throws502for the same answer.502 EXTERNAL_SERVICE_ERROR.isAttachmentDispositionreads the type token only.packages/qa/http-conformance/src/action-door-attachment-38894.conformance.test.ts, new (8 cases, real kernel, real HTTP), on both transports (HonoServerPlugin+createDispatcherPluginwith its default security headers over a socket, andcreateHonoApp):X-Frame-Optionsride the file;attachmentanswers the JSON envelope, never a file;2xxanswers502 EXTERNAL_SERVICE_ERROR;requiredPermissionsgets403 PERMISSION_DENIED, and the target is never called.ui/packages/app-shell/src/hooks/__tests__/useConsoleActionRuntime.apiActionDoor-27611.test.tsx, new top-level describe (7 cases):发票 INV-1.pdf), with the Blob bytes equal, the URL not revoked on the click's tick nor 1 ms before the delay, revoked at the delay, and no anchor left in the DOM;attachmentis read as data on the door road and the direct road, nothing saved;filenameanddownloadfallbacks;502with an attachment header is not saved;Acceptance notes
main(not edited here):GenerateInvoicePdfActionjsdoc paragraph "This action does not deliver the PDF yet";print-pages.mdxparagraph saying the doors relay JSON answers only.The showcase
successMessage("The invoice was printed to PDF." / 「发票已打印为 PDF。」) stays true, so it is not touched.content/docs/ui/print-pages.mdxis also edited by fix(service-print)!: the record print downloads the PDF and stores no attachment #39076, so its merge ofmainwill meet a conflict in the "Print from the console" section.GenerateInvoicePdfActionthrough the door asserts a PDF only once fix(service-print)!: the record print downloads the PDF and stores no attachment #39076 is onmain. On this branch the print route still answers201JSON. It also needs a print engine (Chromium plus a built console), and the print dogfood render suite skips locally for want of one. The transport and door pins above use a target that answers a real binary attachment; the end-to-end print belongs on fix(service-print)!: the record print downloads the PDF and stores no attachment #39076 after it merges this.RecordDetailView.tsxlines 2198–2206 (its own direct fetch for an undeclared or off-origin api click) still read a file answer asres.json()→{}and report success. Changing it needs that file, which Record page: the discussion's reads and writes become one unit other pages can mount #39083 holds.Content-Dispositionis not in the CORS exposed headers. A cross-origin console therefore falls back to the non-JSON content-type rule and the namedownload.resultDialog,onSuccess.navigatewith${result.*}, oroutcomeMessagesreads no result from a file answer (dataisundefined).Verification
Two-minute check:
pnpm --filter @objectstack/http-conformance exec vitest run src/action-door-attachment-38894.conformance.test.ts→ 6 passed (needs the package's dependency closure built). Expect identical PDF bytes through/api/v1/actions/c38894_doc/download_pdfon both transports.Read first, by risk:
packages/runtime/src/action-dispatch.ts, the api arm andrunResolvedActionAsRest. Risk: a file reaching MCP or the host door, or the invocation row.packages/runtime/src/action-forward-attachment.ts,readForwardAttachment. Risk: the bound and cancellation.ui/packages/app-shell/src/utils/apiActionDoor.ts,isDoorFileAnswerandattachmentFilename. Risk: filename parsing and the cross-origin rule.Local readings at 291a2c6, fix round on contract review 7348470636 (exit codes captured before any pipe)
api-action-forward.test.ts: 103 passed. Runtimetypecheck(tsc +check:test-typecheck): exit 0.action-door-attachment-38894.conformance.test.ts: 8 passed; itstypecheck: exit 0.useConsoleActionRuntime.apiActionDoor-27611.test.tsx: 21 passed;type-check(source andtsconfig.test.json): exit 0.eslint --no-inline-configon the changed TS files: 0 errors, and no warning on a line this PR adds.git diff HEADempty:!isJsonMediaType(...)) removed: 2 failed / 101 passed (the JSON-under-attachment door pin and the predicate table).204/205door pin, failing onTypeError: Response constructor: Invalid response status code 204, and the predicate table). A first run had a JSON content type on that pin, so the JSON guard masked it (1 failed, only the table). The pin now answers a PDF type, and the rerun is the reading above.Responsebranch removed → the self-hosted pin red; console door-file branch off → 3 red.dispatch-gates --commandsat 291a2c6 derived 108 families;--ranreconciled 108 derived, 107 run, 1 NOT-MEASURED, 0 unrun. The one NOT-MEASURED ischeck:dual-build-cjs-loads, exit 3: PREREQUISITE NOT MET, with workspace packages unbuilt, so CI's reading stands.ui vitest scripts/was OOM-killed once while sharing the box and was rerun alone to exit 0.🤖 Generated with Claude Code
https://claude.ai/code/session_01QSeKYpEYuQLqepCv5Ubf9g
Generated by Claude Code