Skip to content

feat(s3): route UploadPartCopy and ListParts (#532, #551) - #552

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/s3-multipart-router
Aug 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/s3-multipart-router

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #532
Closes #551

Two S3 multipart operations were unroutable, and both for the same reason, so they ship as one review of parseS3Operation's precedence order rather than two separate reorderings.

The shared cause

The object-level verb arms had drifted apart on when they test uploadId. PUT, DELETE and POST all tested it; GET alone did not, and PUT tested X-Amz-Copy-Source before it. Since every multipart operation addresses the same key with the same verb as its general-object counterpart, nothing but the ordering distinguishes them.

The invariant is now stated once in the router where all four arms are visible — a multipart request is identified by its uploadId, and the general object-verb operation is a fall-through the router must reach only after every multipart test has failed. A comment on one arm would not have prevented the other.

#532 — UploadPartCopy was worse than filed

Measured against v0.89.0 on a live server, not inferred: the request answered 200 with a correctly-shaped CopyPartResult, so nothing looked wrong — while CopyObject wrote the destination object. A head-object on the destination mid-upload returned ContentLength 6291456, which real S3 never exposes, and the complete-multipart-upload that followed failed InvalidPart because no part had been stored.

Now: stores a part, leaves the destination key absent until Complete, honors x-amz-copy-source-range and the x-amz-copy-source-if-* preconditions, returns ETag/LastModified in a CopyPartResult. Copied and uploaded parts mix in one upload and a copied part's checksum is computed under the upload's algorithm, so Complete still assembles a COMPOSITE object checksum over the mixture.

#551 — ListParts had no handler at all

Found while reproducing #532. GET /<bucket>/<key>?uploadId=… reached GetObject → 404 NoSuchKey, for an upload whose parts substrate had stored and could list. A caller polling its own upload could not tell an upload with parts from a key that does not exist.

Now: ListPartsResult with max-parts/part-number-marker paging, the upload's storage class and checksum configuration, and each part's number, ETag, size, LastModified and checksum. Zero parts is 200 with an empty list, not a 404. An unknown uploadId, or one addressed through the wrong key, is 404 NoSuchUpload rather than the NoSuchKey GetObject answered.

Provenance

Two refusals are substrate's own choice, not the API model's:

  • A malformed or out-of-bounds x-amz-copy-source-range is 400 InvalidArgument. The reference documents only InvalidRequest, and for an unsupported byte-range source. Unlike a GET's advisory Range header — malformed is ignored, past-EOF is clamped — a copy-source range is part of the request's meaning, so a range substrate cannot honor is refused rather than silently turned into a different copy.
  • bytes=0- is refused where a GET would accept it: an open-ended range does not describe the extent of a part.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... → 0 issues, make test (race), make docs-reference docs-reference-check docs-versions, npm --prefix docs run build, go vet -C test/e2e ./..., go test -C test/e2e ./... — all clean.

Each gate fails before the fix. Reverting only the router ordering (leaving both handlers in place) turns every new test red, and #532's and #551's gates go red independently.

End to end against a live server, matching the plan's checks:

$ aws s3api list-parts --bucket mpu-dst --key j --upload-id "$UP"      # 200, empty list (was 404 NoSuchKey)
$ aws s3api upload-part-copy --bucket mpu-dst --key j --part-number 1 --upload-id "$UP" --copy-source mpu-src/big
{"CopyPartResult": {"ETag": "\"ba0f00...\"", "LastModified": "2026-08-04T00:27:11+00:00"}}
$ aws s3api head-object --bucket mpu-dst --key j                       # 404 (was ContentLength 6291456)
$ aws s3api list-parts --bucket mpu-dst --key j --upload-id "$UP"      # 1 part, Size 6291456
$ aws s3api complete-multipart-upload ...                              # 200 (was InvalidPart)
$ aws s3api head-object --bucket mpu-dst --key j --query ContentLength # 6291456 — now the key exists
$ aws s3api list-parts --bucket mpu-dst --key j --upload-id nope       # NoSuchUpload
$ aws s3api upload-part-copy ... --copy-source-range bytes=0-9         # Size 10
$ aws s3api upload-part-copy ... --copy-source-range bytes=0-9999999   # InvalidArgument

Mutation testing

Seven mutants, all CAUGHT, none survived — anchor-count asserted before applying, gofmt -w && go vet gated, run under -race:

Mutant Caught by
the part copy writes the destination object as well as the part DestinationKeyStaysAbsent
ListParts drops the ascending part-number sort ReportsUploadedParts, Pagination
loadUploadFor stops confirming bucket/key ListParts_Errors/wrong_key, and an existing Complete test
an upload with no parts answers 404 ListParts_EmptyUpload
x-amz-copy-source-range is ignored all three SourceRange subtests
IsTruncated never reported Pagination
part-number-marker ignored Pagination

Plus the two router reversions above, which each go red independently.

Compatibility

A test that asserts a part copy writes the destination object, or that GET ?uploadId answers 404 NoSuchKey, will go red. That is the fix. CopyObject and GetObject without multipart parameters are unchanged, and two tests pin that explicitly.

Refactors carried along

parseS3CopySource is extracted so CopyObject and UploadPartCopy cannot drift on what a copy source means. loadUploadFor and writePart are extracted so all four multipart operations resolve an upload and store a part the same way — the mutation run confirms the shared loadUploadFor is covered by both the new tests and the existing Complete tests.

Both operations were unroutable, and both for the same reason:
parseS3Operation's object-level verb arms had drifted apart on when they
test uploadId. PUT/DELETE/POST all tested it; GET alone did not, and PUT
tested X-Amz-Copy-Source before it.

A part copy was therefore claimed by CopyObject, which answered 200 with
a correctly-shaped CopyPartResult while writing the destination object
instead of storing a part — so HeadObject mid-upload reported a
ContentLength real S3 never exposes, and Complete then failed with
InvalidPart. ListParts reached GetObject and answered 404 NoSuchKey for
an upload whose parts substrate had stored.

UploadPartCopy now stores a part and leaves the destination key absent
until Complete, honors x-amz-copy-source-range and the
x-amz-copy-source-if-* preconditions. ListParts returns a
ListPartsResult with max-parts/part-number-marker paging; zero parts is
200 with an empty list, and an unknown or wrongly-keyed uploadId is
404 NoSuchUpload.

The router invariant is now stated once where all four verb arms are
visible, since the arms drifting apart is what produced both bugs.
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.85590% with 53 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/s3_plugin.go 76.85% 29 Missing and 24 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e77fef3 into main Aug 4, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/s3-multipart-router branch August 9, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant