Repository navigation
fix(metadata-protocol): cloning a record whose file fields are set answers 201 - #36063
Conversation
Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7 Co-Authored-By: Claude <noreply@anthropic.com>
… stored form
cloneData read the source through the caller's expanded read, which serves a
file-class field as the { id, name, size, mimeType, url } object, and
re-inserted that object, which the media value-shape check refuses. The source
is now read with RAW_FILE_VALUES_CONTEXT_KEY, so every file-class field (single
and multiple) carries its sys_file id(s) into the insert and follows the same
field-reference copy rule an overrides id does.
Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7 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:
⛔ 3 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 10 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 f23f327adf1f767939ab573edcf460dc5384c6bb && git checkout f23f327adf1f767939ab573edcf460dc5384c6bb
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 1647fb3d74ba56b13fa54b1502a6b82c715bbb67 7666b5f79d5178ca19a243d35c63ad3ac49333e7 && git checkout -B drift-repro 1647fb3d74ba56b13fa54b1502a6b82c715bbb67 && git merge --no-ff 7666b5f79d5178ca19a243d35c63ad3ac49333e7
node scripts/docs-audit/affected-docs.mjs --json 1647fb3d74ba56b13fa54b1502a6b82c715bbb67
|
|
repo:objectstack#7 · os-tesla · session_01L9qibyQBB3KuDoNobNq9LH L1 · PR #36063 · head
|
…AW_FILE_VALUES_CONTEXT_KEY; changeset names the shared copy-step 500 Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7 Co-Authored-By: Claude <noreply@anthropic.com>
… test tsconfig Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7 Co-Authored-By: Claude <noreply@anthropic.com>
|
repo:objectstack#7 · os-tesla · session_01L9qibyQBB3KuDoNobNq9LH Delta L1 · PR #36063 · head
|
|
repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7 Landing: PR #36063 (#35721) at
|
Fixes #35721
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
cloneData(packages/metadata-protocol/src/protocol-data-crud.ts) read the source record through the caller's normal read, which serves every file-class field expanded to{ id, name, size, mimeType, url }(or{ id, metadataRefused: true }for a reader refusedsys_file). It inserted that object back, and the engine's media value-shape check refused it:400 VALIDATION_FAILED, "Report has an invalid file value: Invalid input: expected string, received object".The source is now read with
RAW_FILE_VALUES_CONTEXT_KEYadded to the caller's context, so the read returns file fields in their stored form: the baresys_fileid, or the list of ids for amultiplefield. Nothing else about the read changes: it is still the caller's read, with the caller's security. The copied ids then take the same path anoverridesid already took (ADR-0104 D3 wave 2 exclusive ownership: an id owned by another slot is copied into a newsys_filethat the clone's field owns).overridesare still applied after the read, so an explicit override still wins. No new file-ownership rule.Route, and why it differs from the card's wording. The card asks to normalise each file and multi-file value read from the source back to its id. This PR gets the same result by asking the engine for the stored form instead of converting the expanded form afterwards:
RAW_FILE_VALUES_CONTEXT_KEYis the spec-declared opt-out for "a caller whose subject is the stored form" (packages/spec/src/data/field-value.zod.ts). The engine's resolver honours it before it selects fields (engine-file-reference-hydration.ts,resolveFileReferences), and it selects them byFILE_REFERENCE_TYPES(image,file,avatar,video,audio). So the clone covers exactly the set the expansion covers, single andmultiple, with no second list of types to keep in step.packages/objectql/src/engine-validate.tsline 427,{ ...(options?.context ?? {}), [RAW_FILE_VALUES_CONTEXT_KEY]: true }) and by storage'sreadRecordAs(record-file-access.tsline 811).Programmatic calls with no context: the read now carries
{ __rawFileValues: true }where before it carried no context.buildSession(engine-execution-plumbing.ts) gives no session for a context with no identity fields, and the security layer's checks readcontext?.isSystem, which is unset in both cases. This is the same trade-offengine-validate.tsline 427 already makes.packages/objectql/src/engine.tsis not touched; it is still 6857 lines.Tests
New pin:
packages/qa/dogfood/test/clone-file-field-reference.dogfood.test.ts, through the real REST clone route, usingbootStack+PlatformObjectsPlugin+StorageServicePluginon a local adapter, with real bytes uploaded by presign, PUT and complete. The fixture object has afile, amultiple: truefileand animagefield.overridesname the source's file ids answers 201, and every file is copied.sys_filerow for that id is owned by(cff_doc, cloneId, field)and has the source's bytes, and the source keeps its own file. This is the same assertion helper the control uses.overridestakes the override (an unowned upload is claimed as it stands, andpapers: nullclears the field). The field the overrides leave alone still follows the copy rule.Each one reads back the stored row (
RAW_FILE_VALUES_CONTEXT_KEY, system context) and thesys_fileownership columns, not only the 201 body.Reproduction on main (BASE 8145424, file restored byte-for-byte from BASE)
protocol-data-crud.tswas restored from8145424b53(blobaf1feb89cb3dequals the BASE blob), and the new pin ran against it.@objectstack/metadata-protocolresolves tosrc/in the dogfood config's alias.The CONTROL (
overridesnaming the ids) passed on BASE, which matches the card's workaround. After the run, the restore was checked: blob56a3c2a37d4cequals HEAD's, andgit diff HEADis empty.Ablation (fix committed at efe9ec3, then mutated via scripts/ablation-replace.mjs)
The anchor
context: { ...(ctx ?? {}), [RAW_FILE_VALUES_CONTEXT_KEY]: true } }was replaced with...(ctx !== undefined ? { context: ctx } : {}) }, which is BASE's read.With the fix (efe9ec3):
Package tests and typecheck (head 9fea83f)
pnpm --filter @objectstack/metadata-protocol test:Test Files 362 passed | 9 skipped (371),Tests 23305 passed | 45 skipped (23350), lock VERDICT command-exit 0.pnpm --filter @objectstack/metadata-protocol run typecheck && pnpm --filter @objectstack/dogfood run typecheck: VERDICT command-exit 0.tsc --listFileslists both changed files (1 hit each).Acceptance notes
sys_filerow exists but its stored content is missing, the clone's copy step fails with500 FileReferenceCopyError. A 4xx would describe that case better. This PR does not change it. The plain clone now reaches the copy step that theoverridespath already reached, so the same 500 can now come from a clone with no body as well as from theoverridesworkaround.Dogfood Regression Gatedoes not run onpull_request, only in the merge queue (perdispatch-gates.mjs). The readings above are local runs underos-verify-lock.sh.Verification
Read first, in order of risk:
packages/metadata-protocol/src/protocol-data-crud.ts, thecloneDatasource read (the only behaviour hunk).packages/qa/dogfood/test/clone-file-field-reference.dogfood.test.ts,expectCopiedPerReferenceRule.Two-minute check:
pnpm --filter @objectstack/dogfood exec vitest run --maxWorkers=2 test/clone-file-field-reference.dogfood.test.ts(after building the dogfood closure). ExpectTests 3 passed (3).Local gate subset (head 9fea83f)
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderived 69 commands. Each was run, and its exit code was captured before any pipe:check-adr-0087-registration --base origin/main,check-changeset-no-major,check-empty-changeset,check:nul-bytes,check:test-source-alias,check:cross-package-test-inputs,check:durability-log-level,check:engine-double-contract,check:type-check-coverage,check:type-check-debt,check-governed-queue-guard --self-test.pnpm check:dual-build-cjs-loadsexited 3 withPREREQUISITE NOT MET — this gate reads built output, and some package has no dist/(studio, client-react and others outside the dogfood closure built here). CI's build job owns it.dispatch-gates --ran:69 derived famil(ies) accounted for — 69 run, 0 NOT-MEASURED(its own count, which takes the list as written). The exit-3 reading above corrects it to 1 NOT MEASURED.scripts/pm/overlap-check.mjsbefore each push:VERDICT clean exit 0.Generated by Claude Code