Repository navigation
feat(storage,mcp): an upload link for a file field of a record not yet created - #33123
Conversation
…reated An upload link can now name an object and a file field with no record. The user uploads through it; the bytes land as a committed file bound to that user, object and field for one hour, and the agent's create (or update) naming the file id takes it. Another user's or a system write, another object or field, a second record, or a write after the window is refused at the field. While no record holds it, only the uploader may download it. Minting checks the object's create verdict and the field's writability. The create_upload_link tool makes recordId optional when the bridge serves this, and answers fileIds as an array. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm
…ot yet created The binding's rule arm by arm, the tool's no-record form and its schema, the bridge member, and the acceptance flow over a real showcase boot: two agent calls and one upload create a record whose file field is required. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm
The MCP guide's file tools section teaches the two-call flow, and the system-context table names the new caller-scoped verb and the one file a system write can no longer claim. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm
📓 Docs Drift CheckThis PR changes 3 package(s): 69 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 11 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 41 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 5a41ed07ab4ad2211d114132a2f680545a1d0f26 && git checkout 5a41ed07ab4ad2211d114132a2f680545a1d0f26
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 5c005e0e42e207b073843b255248877b84442342 2aaea77af4ce68f15c26c1643eeb3330f9629d99 && git checkout -B drift-repro 5c005e0e42e207b073843b255248877b84442342 && git merge --no-ff 2aaea77af4ce68f15c26c1643eeb3330f9629d99
node scripts/docs-audit/affected-docs.mjs --json 5c005e0e42e207b073843b255248877b84442342
|
The release level follows the metadata protocol alone, and this change leaves it untouched. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm
|
domain:server#7 · os-tesla · session_01L9qibzuZJBQY4wUQFJbkfx Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
… the file go A record that releases a file it took through a link with no record keeps it as any released file: its readers read it by that record's rule, and the uploader's restore or another record takes it as before. Before the upload, the id the link answered takes no write but its uploader's. The docs, changeset and table rows say which refusals carry a reason, and that the one-record rule and the hour hold while no record holds the file. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm
|
domain:server#7 · os-tesla · session_01L9qibzuZJBQY4wUQFJbkfx Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
domain:server#7 · os-tesla · session_01L9qibzuZJBQY4wUQFJbkfx 维护者速读 · PR #33123 @
|
Requested by Tesla · project thread
Fixes #32686
Clause-②: yes (widening) — nothing narrowed:
create_upload_linkacceptsobjectName+fieldwith norecordId(where the storage service serves it) and answersfileIds; a file id from such a link is accepted in that field oncreate_record/update_recordby the user who uploaded it, in one record, within an hour of the upload, while no record has held it (once a record has held and released it, it is an ordinary released file). Every existing call answers as before; the only new refusals fall on the new class of file.Metadata-protocol: none — no metadata author key is added, removed or retyped; the binding rides
sys_file.metadata, the storage row column the upload link's own state already uses.Skills-docs: updated here — the served agent skill (
packages/mcp/src/skill-md.ts) teaches the two-call flow where the host serves it;content/docs/ai/connect-mcp.mdx§ Files gains the paragraph, andcontent/docs/permissions/system-context.mdxrows 47e/47f name the new caller-scoped verb and the one file a system write can no longer claim (claim amendment 6856718179). The Console's skill mirror renders no file tools, so it is unchanged (its parity test is green).维护者速读
create_record,把链接返回的fileIds[0]填进该字段,必填文件字段的记录就能建出来(报销明细 + 必填电子发票:两次智能体调用 + 一次浏览器上传)。required规则不变。packages/services/service-storage/src/pre-record-upload.ts(绑定与判定)、record-file-access.ts的createUploadLinkForNewRecordAs与fileForNewRecordThroughLink、file-reference-lifecycle.ts的applyCopyOnClaim新分支;验收在packages/qa/dogfood/test/showcase-mcp-record-files.dogfood.test.ts末尾的新 describe。Ruling
Maintainer ruling A on #32686, recorded by triage 6844207600: 「以上原则同意」 (decision batch #1,
32686 A):Designed together with #32747 (A); this card goes first and implements one file per link (see "How #32747 adds to this").
What changes
Minting a link that names no record (
RecordFileAccess.createUploadLinkForNewRecordAs,record-file-access.ts). The caller must be a signed-in user (the system context is refused, as for every caller-scoped record-file verb), the field must be a file or image field of the object, and three permission answers must hold for that user:security.explain({ object, operation: 'create' }, caller)— the verdictcreate_record's own door asks — else403 PERMISSION_DENIED"You cannot upload a file for a new X: you cannot create X records.";security.getWritableFields(object, caller), else403 FIELD_NOT_ACCESSIBLE;readonly, else403 FIELD_NOT_ACCESSIBLE.This is stricter than the Console form, whose upload (
presign→PUT→complete) needs only a session and whose save is judged afterwards; here the save is still judged in full (the create runs under the user's permissions and validations), and the link is refused up front when the save could not succeed on permissions alone. An attachments link still needs its record. A kernel with no security service enforces no object permission on the create either, so there is nothing to ask there.The link is the same single-use, ten-minute, one-user
sys_filerow as a record link (#30892 ruling B), with norecord_idin its state. Its row id is the file id the upload will be stored under, so the mint can answer it:fileIds: [id].The upload (
consumeUploadLink→fileForNewRecordThroughLink). The field's ownacceptandmaxSizeare judged when the file arrives and before the link is spent (no record write judges them yet); a file the field cannot take is refused400 ERR_FILE_CONSTRAINT, nothing stored, and the link still works. Then the link is spent as before, the bytes are stored, and the reserved row becomes the committed file, owned by the uploader, with a binding insys_file.metadata:{ "kind": "pre_record_upload", "object": "expense_line", "field": "invoice", "user_id": "…", "organization_id": "…", "claim_until": "<upload + 1h>" }The
PUTanswers{ fileId, size, field }; the page says the file was received and to go back to the assistant (newreceivedcopy in all eleven page locales), not that it was attached.Which write may take the file (
pre-record-upload.ts#preRecordReferenceRefusal, asked fromapplyCopyOnClaiminfile-reference-lifecycle.tsafter the read check, before anything is copied or claimed):Once the hour has passed and a record holds the file, it is that record's file like any other: no row above applies, and the read check and copy-on-claim judge it.
Every refusal is the ADR-0114 field refusal (
400 VALIDATION_FAILED,fields[]entryinvalid_valueon the field) and refuses the whole write. Another writer gets the existing words for a file they cannot open, so the answer says nothing about whose upload it is; the uploader's own refusals say why (the field it was uploaded for, already in another record, or no record took it within 60 minutes) and end "Ask for a new upload link for this field and upload the file again." A damaged binding (the kind present, a value missing) reads as bound to nobody, so it refuses rather than reading as an ordinary file.Downloads (
judgeFileRead,storage-service-plugin.ts). For this new class only — a bound file no record holds, and the pending row its link reserved — only the uploader may download it (the owner arm, unchanged, answers them); everyone else is denied. Once a record holds it, it is that record's file and the existing rules judge it. Every other file is judged exactly as before.MCP (
create_upload_link,mcp-http-tools.ts). Where the bridge carriescreateUploadLinkForNewRecord,recordIdis optional in the listed schema, the description says how, and a call withfieldand norecordIdanswers{ url, expiresAt, singleUse, objectName, field, fileIds, instructions }. With no record,attachments: trueis refused before the bridge is asked. A bridge without the member keepsrecordIdrequired. The served SKILL.md teaches the flow only where the host says the bridge serves it (newRecordUploadLinks,data:write).Runtime (
domains/mcp.ts).McpRecordFileService.createUploadLinkForNewRecordAs?(optional: a storage plugin that predates it serves record links only); the bridge member answers the link as an absolute URL on the request's origin with itsfileIds, and reads no record first (there is none; the storage service asks the create verdict). The skill route passesnewRecordUploadLinks.No new error code. Refusals reuse
PERMISSION_DENIED,FIELD_NOT_ACCESSIBLE,VALIDATION_ERROR,VALIDATION_FAILEDandERR_FILE_CONSTRAINT.How #32747 adds to this
The answer already carries
fileIdsas an array, and the skill already says "the array, for a multi-file field". #32747 adds one optional input (a file count, ormultiple: trueon a multi-file field) and nothing else: the mint reserves one row per file and answers one id per file in the samefileIds; thePUTdoor accepts up to that many files; each stored file carries the binding above, unchanged; the create names the array. No key is renamed or retyped and no existing call changes, so it is purely additive.Orphans: what reclaims a file uploaded and never referenced
pendingrow, whichsys_file's lifecycleretention(7 days,status: 'pending') already reaps.deleted_at(30 days) andpendingrows, the same as for a file uploaded through the Console form and never saved (stranded-orphan-inventory.tscalls these rows immortal). After its hour the binding makes it usable by no write, so it is inert, but its bytes stay. Reported to the seat as an out-of-scope finding for a card of its own; not fixed here (ADR-0057 §3.3: no bespoke sweeper).Tests
packages/services/service-storage/src/record-file-access.integration.test.ts, new describe "[Decision] How should an MCP agent create a record whose required file field must be filled (e.g. an expense line with a required e-invoice)? #32686 — a link that names no record" (13 cases over a real ObjectQL kernel and the storage routes): the measured case (anexpense_linewith a requiredinvoiceis refused without it; mint; the create before the upload is refused as never completed; upload; the create naming the id is taken and the file is claimed; the spent link answers 404); the page says "received"; another user refused (unreadable words, file stays unclaimed); a system write refused; another field and another object refused naming the bound field; one record (a second record refused, the first keeps it, the holder's own rewrite admitted); expiry; the update path; downloads (uploader 200, another reader 403, then 200 through the record once claimed); control: a Console-style upload (presign→ rawPUT→complete) and save is taken as before and carries no binding; minting refusals (system context, non-file field, read-only field, no field); the create verdict and field writability as a security service answers them;maxSizerefused on arrival with the link not spent.packages/services/service-storage/src/pre-record-upload.test.ts(new, 13 cases): the rule arm by arm, including the other-user arm alone (the integration pin is guarded twice, see the ablations), a damaged binding, a file with no binding, and which rows are uploader-only.packages/mcp/src/mcp-file-tools.test.ts, new describe (7 cases): the no-record call, a call withrecordIdstill asking the record link, attachments with no record refused unasked, the minting refusal relayed with its code, the listed schema (recordIdoptional only where served), a bridge without the member refusing, and the skill paragraph's placement.packages/runtime/src/mcp-record-file-bridge.test.ts(2 cases): the member's absolute URL andfileIds, no record read; no member without the service verb.packages/qa/dogfood/test/showcase-mcp-record-files.dogfood.test.ts, new describe over a real showcase boot with the security, storage and MCP plugins (3 cases):create_recordwithout the e-invoice is refused; agent call 1create_upload_link { objectName: 'dogfood_expense_line', field: 'invoice' }overPOST /api/v1/mcp; the browser opens the link page (200, "received", names nothing) and uploads throughPUT /api/v1/storage/upload-links/:token; agent call 2create_record { …, invoice: fileIds[0] }is taken, the record holds the file,sys_filenames the record, andread_filereads the PDF's text back. Then another signed-in user's create naming a member's upload is refused and cannot download it, while the member's create takes it; and a member who cannot createshowcase_taskgets no link (403 PERMISSION_DENIED) and nothing is reserved.Ablations (each committed first, mutated through
scripts/ablation-replace.mjsin WRAP mode, restored to the HEAD blob)Every mutation landed (anchor 1 → 0, blob changed) and every restore read
blob == HEAD and git diff HEAD is empty;git statusafter each set showed no file an ablation touched. The storage suites readsrc/directly; the dogfood suite aliases@objectstack/runtimetosrc/, so no dist rebuild was owed for the runtime leg.not_yoursonly forwriterUserId === null, and the uploader-only download arm deletedexpected null to match object { status: 400 … })not_yoursarm alonenot_yoursarm refusespre-record-upload.test.ts"refuses another user"expected null to deeply equal { kind: 'not_yours' })writerUserId !== null && …)if (false))return nullfor a held file)if (false))expected null to match object { code: 'PERMISSION_DENIED' … })readonlyignored… { code: 'FIELD_NOT_ACCESSIBLE' … })accept/maxSizecheck before the spend deletedexpected 200 to be 400)recordIdoptional everywhereexpected [ 'objectName' ] to include 'recordId')fileIdsdropped from the member's answerInvalid arguments for tool create_upload_link: … expected string, received undefined at recordId(also the reading atorigin/main)Acceptance notes
origin/main2c98485d(order step 1): a create without the required file is refused at the field (the integration measured case asserts it, andrequiredis untouched);create_upload_linklistsrecordIdas required, so a call without it is refused by the schema (ablation 19 reproduces that reading over the real/api/v1/mcp); a link for an existing record works (every MCP cannot read or attach files: no tool downloads an attachment (e.g. a policy PDF to analyse) and none attaches one (e.g. a photographed invoice) to a record #30892 pin in the same files is unchanged and green).ruling|Ruling-ref|maintainer|⛔) at the base over the edited files:file-reference-lifecycle.ts2 (organization threading andactingOrganizationOf, neither touched),upload-link-copy.ts2 (ruling C on Studio: an unconfigured nav item vanishes from the navigation editor after reload while still counted as a pending draft; publish dialog shows raw type names in zh #32440 for page copy, and "⛔ none of them names the record, the object or the field": the newreceivedsentence names none),storage-service-plugin.ts18 (none injudgeFileRead, where the new arm sits),mcp-http-tools.ts39 (none inregisterFileTools),skill-md.ts1,file-content.ts1,runtime/src/domains/mcp.ts17 (none in the skill route's file-tools lines orrecordFileMembers),record-file-access.ts,upload-link-page.ts,upload-link-wire.ts,file-attachment-service.ts0. No ruling sits on an edited line.pnpm --filter @objectstack/runtime run typecheckand@objectstack/dogfood's ran out of heap at Node's default here while other gates ran; both exit 0 withNODE_OPTIONS=--max-old-space-size=8192.domain:server#5card [Decision] Should an approver be able to see and decide their pending approvals over MCP? #32442 editsmcp-http-tools.tsnearcreate_record,stdio-data-bridge.tsandruntime/src/domains/mcp.ts; this seat's mcp: validate_expression still answers ok where the validation/formula gate refuses (null-guard, undeclared hop field, and the rest of the gate's private passes) #32872 edits thevalidate_expressionhandler andskill-md.ts. This PR touchesregisterFileTools'create_upload_linkblock,renderFileToolLinesand the new-record skill paragraph, the skill route's three lines, andMcpRecordFileService/recordFileMembers. Whichever lands first, the other merges main once and reruns the affected gates.Verification
Readings at head
a9a6589d(after mergingorigin/main7c36f524, which touched none of this PR's files; the fourtypecheckruns and the gates were taken at0678c15b, the same tree for these packages), every heavy command underscripts/pm/os-verify-lock.sh(VERDICT command-exit 0 on each), exit codes captured before any pipe:pnpm turbo run build --concurrency=2 --filter='@objectstack/dogfood^...'after the merge, 70/70 tasks.@objectstack/service-storagetest (whole package): Test Files 82 passed (82), Tests 1540 passed.typecheckexit 0.@objectstack/mcptest (whole package): Test Files 63 passed (63), Tests 1104 passed.typecheckexit 0.@objectstack/runtimesrc/mcp-record-file-bridge.test.ts: 7 passed.typecheckexit 0 (withNODE_OPTIONS=--max-old-space-size=8192, see the notes).@objectstack/dogfoodtest/showcase-mcp-record-files.dogfood.test.ts: Test Files 1 passed, Tests 18 passed (15 existing + 3 new).typecheckexit 0 (same heap note).eslint --no-inline-configover the 17 changed TypeScript files exit 0; the server lane's whole-treepnpm lint(eslint . --no-inline-config) exit 0 ata9a6589d.node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack→ 106 families at the final diff (83 before the docs pages joined, 27 more after, plus the four roster gates that keep a roster under one of these paths:check:changeset-fixed,check:error-code-casing,check:filter-alias-parity,check:route-ledger-census, all exit 0), each run with</dev/null. Two exited 3 on the first pass and 0 on a rerun:node scripts/check-plugin-teardown-shape.mjs --self-test(its pinned fixture621a4876was outside the shallow clone; 0 aftergit fetch origin 621a487607881c66b2899b7e3477115229a156b4 --depth=1), andpnpm check:dual-build-cjs-loads(PREREQUISITE: 11 packages had nodist/; 0 aftercheck:type-check-debt's closure build had built every package, and again 0 at the merged head: 123 require entry points across 72 packages load). Every other family exited 0. Reconciliation--ran:106 derived famil(ies) accounted for — 106 run, 0 NOT-MEASURED (a DERIVED zero — all 106 recorded an exit code and none of them is 3).2aaea77a(seat contract review 6857928485, findings F1 and F3–F6): one commit on7f41ed5f, which itself is changeset-only042bdb52and docs-only7f41ed5fona9a6589d. At2aaea77a: service-storage 82/82 files (1547 tests), dogfoodshowcase-mcp-record-files18/18, typecheck 0, eslint on changed files 0, 101 derived gates + 3 roster exit 0 (--ran101 run, 0 NOT-MEASURED), 11 ablation legs all red and restored.origin/maintouches none of this PR's files; no merge.🤖 Generated with Claude Code
https://claude.ai/code/session_01L9qibwGvonkT2ydXH6AKHm