Repository navigation
fix(storage): S3 chunked uploads resolve their object key from the upload session row - #31705
Conversation
…on row The chunk and completion doors hand sys_upload_session.key to the backend before every call, and the swappable proxy forwards setUploadKey, so an S3 chunked upload no longer fails on chunk 0 behind the proxy and a chunk or completion served by another process finds its key. Claude-Session: https://claude.ai/code/session_01ADHkmRmL5ZWYTvnS9e3kmo Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 3 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 — 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 da7a9c081b4186b6d94aa057432133cb525321a9 && git checkout da7a9c081b4186b6d94aa057432133cb525321a9
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e81636ce7ed9161e759076556871ab73d3aac4cd 8e23f6b8aba82d00c63c0adcfaae7498fe174f1d && git checkout -B drift-repro e81636ce7ed9161e759076556871ab73d3aac4cd && git merge --no-ff 8e23f6b8aba82d00c63c0adcfaae7498fe174f1d
node scripts/docs-audit/affected-docs.mjs --json e81636ce7ed9161e759076556871ab73d3aac4cd
|
…-lhttwr Claude-Session: https://claude.ai/code/session_01ADHkmRmL5ZWYTvnS9e3kmo Co-authored-by: Claude <noreply@anthropic.com>
|
domain:server#4 · os-steve · session_01ADHkmP8JJo4zF2sjTBRwnX ACCEPT · PR #31705 · #31607 · 2026-11-08T22:52ZHead-sha:
|
Requested by Steve · project thread
Fixes #31607
Clause-②: no
Metadata-protocol: none
维护者速读
sys_upload_session.key取对象 key 交给适配器;可替换存储代理补上setUploadKey转发。setUploadKey的适配器调用不变(各一个 pin)。回滚即 revert 本 PR,无数据迁移。storage-routes.ts(handUploadKeyToBackend及分片门、完成门两处调用)、swappable-storage-service.ts(setUploadKey转发)、新测试s3-chunked-upload-session-key.test.ts。pnpm --filter @objectstack/service-storage exec vitest run src/s3-chunked-upload-session-key.test.ts,预期 4/4 通过;在 main 上同一文件两个 S3 用例 500 失败。What changes
storage-routes.ts: a new module helperhandUploadKeyToBackend(storage, uploadId, key)hands the backend the object key of a chunked upload. The chunk door and the completion door call it withsession.key(thesys_upload_sessionrow each door already reads) right beforeuploadChunk/completeChunkedUpload. The init door no longer callssetUploadKeyitself: every backend call that names the upload now gets the key from the row, on whichever process serves it.swappable-storage-service.ts: the proxy forwardssetUploadKeyto the active adapter, and is a no-op for an adapter without it (same pattern as the proxy's existingverifyTokenandgetPresignedUploadOriginpassthroughs). This is what made chunk 0 fail on a single replica: the kernel'sstorageservice is the proxy, and the init door's'setUploadKey' in storageprobe never matched it.s3-storage-adapter.ts,attachment-lifecycle.ts: comments only. They described the map as filled once by the plugin, and said the proxy does not forwardsetUploadKey. Both were made false by this change. No code change in either file..changeset/31607-s3-chunked-upload-session-key.md:@objectstack/service-storagepatch.No change to the
IStorageServicecontract (packages/spec), to the chunked-upload HTTP requests or answers, tosys_upload_session(it already storeskey, a required field), or to the local adapter (it records the key beside its parts at initiation).Why the row, not a new key-taking method on the adapter: the card prefers the durable row, and the row already holds the key, so no column is added. Handing it down through the existing
setUploadKeykeeps a single way to address an upload on the adapter; the upload-session reap guard already re-seeds the same map from the same row before an abort, so the chunk and completion doors now follow that precedent. No new public name is introduced on the package entry; the proxy gains one method that the S3 adapter already had.Tests
New file
packages/services/service-storage/src/s3-chunked-upload-session-key.test.ts(4 cases). It drives the real doors (registerStorageRoutes) throughSwappableStorageService, the wayStorageServicePlugincomposes them, against an S3-compatible stand-in. Like S3, the stand-in refuses a part, completion or abort addressed to an UploadId under a different key (NoSuchUpload).completes on a single replica: init, chunk 0, chunk 1 and completion through one proxy and one S3 adapter; the bucket holds the whole file and no multipart is left open.resumes on a fresh adapter instance: another process finds the key in the session row: three replicas (separate adapter instances behind separate proxies) share one metadata store and one bucket. Init runs on A, chunk 0 on B, chunk 1 and completion on C. The object lands under the session row's key and the file row iscommitted.local: the assembled file holds the bytes sent, across two adapter instances on one root: unchanged behaviour for the local adapter.an adapter with no setUploadKey receives exactly the contract calls, with the arguments it did before: an in-memory adapter double sees the same four calls with the same arguments as onmain.A new file, not a new
describein an existing harness: the S3 stand-in is avi.mockof@aws-sdk/client-s3, which is file-scoped, and no existing file mocks S3 and mounts the routes together. No existing test was changed.Step 0: the defect on main (5d1382a), new file against the unfixed code
sys_upload_sessionfields written by the init door:id(= the backend UploadId when the backend initiated),file_id,key(required),filename,mime_type,total_size,chunk_size,total_chunks,resume_token,backend_upload_id,scope,bucket,metadata,status,expires_at; the chunk door addsparts,uploaded_chunks,uploaded_size. The object key is present, so no column is needed.Ablations (scripts/ablation-replace.mjs, restore proven blob == HEAD and git diff HEAD empty)
The test imports
./storage-routes.jsand./swappable-storage-service.jsrelatively, so vitest runssrc; nodistleg applies.ABLATION-INIT-SEED, count 1) and the chunk and completion doors no longer hand down the row's key (ABLATION-NO-ROW-KEY, count 2, anchor 2 → 0). Only the second-process case goes red, with the original error:ABLATION-PROXY-DROPS-KEY, anchor 1 → 0). Both S3 cases go red:Acceptance notes
main. The entries are small and are not a record anything trusts, since the row is the record. Noted, not filed.createUploadSessionReapGuard) still reaches the inner adapter throughgetInner()to seed the key before an abort. That still works, and the proxy now forwards the call too. It was left as is so that its tests are not changed.Verification
All on head
14e4eea9.pnpm --filter @objectstack/service-storage build && … test && … typecheckunder the lock: VERDICT command-exit 0; Test Files 76 passed (76), Tests 1428 passed (1428);check:test-typecheckOK.eslint --no-inline-config packages/services/service-storage/src(the package has nolintscript), exit 0.node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstacklisted 73; all 73 ran afterturbo run build --filter='./packages/**' --filter='./examples/**'(VERDICT command-exit 0), every one exit 0.--ranreconciliation: 73 derived, 73 run, 0 NOT-MEASURED, 0 UNRUN.!in the title, no(narrowing)arm, so the full battery is CI's):storage-chunked-parallel-parts,storage-chunked-resume-integrity,attachments-permission-matrix,error-sentences-liveunder the lock: VERDICT command-exit 0; Test Files 4 passed (4), Tests 37 passed, 1 skipped (38). These run the local adapter, so they show the local path unchanged; the S3 path is covered by the new unit file.origin/mainmoved 12 commits past the base5d1382a5; none touchespackages/services/service-storage, so no merge was taken.Human Minimum
packages/specholds no runtime logic. (packages/specuntouched.)pnpm lintpasses (root eslint--no-inline-configoverpackages/services/service-storage/src, exit 0).main, one pull request.packages/spectouched: not touched.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Card thread session:
session_01ADHkmRmL5ZWYTvnS9e3kmo(dev,domain:server#4).🤖 Generated with Claude Code
https://claude.ai/code/session_01ADHkmRmL5ZWYTvnS9e3kmo
Generated by Claude Code