Skip to content

feat(services/cos): verify native write checksum receipts - #9245

Merged
Xuanwo merged 1 commit into
mainfrom
xuanwo/cos-native-checksum-candidate
Nov 27, 2026
Merged

Xuanwo merged 1 commit into
mainfrom
xuanwo/cos-native-checksum-candidate

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 27, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Part of #9182.

Rationale for this change

Tencent Cloud COS computes an unsigned decimal CRC64-ECMA (CRC-64/XZ, added to opendal-core in #9240 as ChecksumAlgo::Crc64Ecma) for uploaded objects and parts and returns it in the x-cos-hash-crc64ecma response header. Supporting WriteChecksum::Any and WriteChecksum::Fast lets callers opt into native end-to-end write checksum verification on COS under RFC-9166 without buffering whole payloads or sending Content-MD5.

Because COS returns this checksum as a response receipt after receiving a single PUT or completing a multipart upload rather than enforcing a caller-supplied pre-commit whole-object digest, COS supports only Any and Fast and rejects Algo and Expected before I/O.

What changes are included in this PR?

  • Advertise Capability::write_with_checksum: true on CosBuilder and regenerate website/data/capabilities.json.
  • Validate checksum intents synchronously before I/O in CosWriter::new and CosBackend::presign: allow WriteChecksum::Any and WriteChecksum::Fast for non-append writes, and return Unsupported for WriteChecksum::Algo, WriteChecksum::Expected, append writes with a checksum intent, and presigned writes with a checksum intent.
  • Verify single-PUT writes (write_once) by computing CRC-64/XZ over the uploaded buffer with crc-fast, checking the single ASCII-digit x-cos-hash-crc64ecma response header, and populating Metadata::checksum() with ChecksumAlgo::Crc64Ecma while retaining existing ETag, Content-MD5, and version metadata.
  • Verify multipart writes by checking each UploadPart receipt before accepting its ETag (missing/invalid receipts return temporary Unexpected; mismatched receipts return temporary ChecksumMismatch so the staged part can be retried before completion), then combining verified part CRCs and byte lengths in manifest part order (checksum_combine) to check the CompleteMultipartUpload receipt.
  • Enforce post-publication non-replay on checked terminal writes: once PutObject or CompleteMultipartUpload returns a 2xx HTTP status, CosWriter marks publication_observed before reading the response body. A response-body read failure, invalid or incomplete completion XML, or missing/invalid/mismatched receipt returns a permanent Unexpected error noting that the object may already be visible, and subsequent close() calls on the same writer fail permanently instead of replaying the final request. If CompleteMultipartUpload returns HTTP 200 with an explicit <Error><Code>...</Code></Error> XML body, publication_observed is cleared and BadDigest maps to permanent ChecksumMismatch (whereas BadDigest on PutObject or UploadPart maps to temporary ChecksumMismatch). abort_part treats 404 NotFound as Ok(()) when publication_observed is set.
  • Update core/services/cos/src/docs.md, dependencies in core/services/cos/Cargo.toml (crc-fast, dev futures), and lockfiles (core/Cargo.lock, bindings/ruby/Cargo.lock), and add unit tests for receipt parsing, CRC combination, post-200 body loss, and HTTP 200 completion error bodies.

Managed Tencent COS verification against a versioned bucket covered empty Any PUT, 9-byte Fast PUT, concurrent out-of-order multipart Fast upload completed in [1, 2] order without request Content-MD5, fault-injected part receipt mismatch followed by abort preserving the prior version, fault-injected missing PUT and mismatched completion receipts under RetryLayer confirming a single terminal request and permanent Unexpected, zero-I/O Unsupported rejections for unsupported intents, and full versioned cleanup. Receipt omission and mismatch faults were injected client-side on real HTTP 200 COS responses; local scripted-transport unit tests cover post-200 stream failure and HTTP 200 <Error><Code>BadDigest</Code></Error> completion bodies.

Are there any user-facing changes?

services::Cos advertises write_with_checksum: true and supports WriteChecksum::Any and WriteChecksum::Fast on non-append writes, returning ChecksumAlgo::Crc64Ecma in Metadata::checksum(). WriteChecksum::Algo, WriteChecksum::Expected, and explicit checksum intents on append or presigned writes return Unsupported before I/O.

For checked single-PUT and multipart completion requests, COS returns the checksum receipt after publishing the object: a missing, invalid, or mismatched receipt (or response-body failure after HTTP 2xx) returns a permanent Unexpected error, the new object may already be visible, and calling close() again on the same writer will not replay the final request. Updated core/services/cos/src/docs.md and website/data/capabilities.json.

Breaking changes

AI Usage Statement

  • Harness pi via T3 Code · Model magpie/codex/gpt-6.2-astra · Effort high · Role Scoped native COS Any/Fast write checksum verification for Tracking issue of RFC-9166: Checksum Intent and Layer #9182 and coordinated implementation, review, and publication.
  • Harness pi via T3 Code · Model magpie/codex/gpt-6.2-sol · Effort max · Role Implemented COS CRC64-ECMA receipt verification, local response-handling tests, service docs, and lockfile/catalog updates, and ran managed Tencent COS fixture verification.
  • Harness pi via T3 Code · Model magpie/agy-cli/gemini-4-neon · Effort high · Role Independently reviewed candidate 8d9ba1a24a, its integration on main, and the managed COS evidence, and drafted and published this PR.

Verify COS CRC64-ECMA receipts for Any and Fast writes. Validate each staged part, then combine the CRC-64/XZ values and lengths in manifest order.

Retain the original ETag and version metadata. A successful terminal HTTP status followed by an unconfirmed receipt cannot replay the publication request from the same writer.
@Xuanwo
Xuanwo merged commit ff33279 into main Nov 27, 2026
134 of 135 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/cos-native-checksum-candidate branch November 27, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants