Repository navigation
feat(transfer): populate DeltaChunk.expected_strong from basis signature (BR-3i.d) - #4646
Merged
Merged
Conversation
…ure (BR-3i.d) Add a wire-token to `DeltaChunk` adapter in `delta_pipeline::chunk_builder` that looks up the basis signature's strong digest for every `BlockRef` (COPY-equivalent) token and stamps it into `DeltaChunk::expected_strong` via the builder added on the applier side by BR-3i.c (#4640). Literal tokens leave the field as `None`: the sender does not embed per-literal digests, and the applier already skips comparison when nothing is set. Without this wiring, every basis-match chunk produced for the parallel receive-delta path slips through `ParallelDeltaApplier::verify_chunk` in "compute digest, skip comparison" mode, so corrupted basis bytes commit silently to the destination. With the wiring in place, the receiver-side verify-chain end-to-end gate added in BR-3i.c finally fires: a basis whose actual bytes differ from the digest the receiver shipped surfaces as `ParallelApplyError::ChecksumMismatch` before the per-file mutex is taken, leaving the destination writer untouched. The adapter is wire-protocol-free - it never touches the network reader, the decompressor dictionary, or the disk-commit thread. The caller hands in already-resolved literal bytes or already-mapped basis bytes, and the builder produces a `DeltaChunk` with the per-file sequence number bumped exactly once per emitted chunk. Out-of-bounds block indices and basis-length disagreements surface as typed `ChunkBuilderError` variants so the receiver can abort the file without ever feeding mismatched bytes into the verify step (which would otherwise be reported as a checksum-mismatch for the wrong reason). No wire-protocol changes - `DeltaChunk` is purely a receiver-side staging structure and the expected digest is held in-memory only. Public API of `ParallelDeltaApplier` is unchanged. Tests cover the BR-3i.d acceptance criteria: - copy chunks populate `expected_strong` from the signature - literal chunks leave `expected_strong = None` - end-to-end: a corrupted basis surfaces `ChecksumMismatch` and never reaches the destination writer - out-of-bounds block index surfaces typed error without bumping the sequence counter - basis-length mismatch surfaces typed error before verify - `next_chunk` dispatches each token variant correctly - `TokenForBuild::from_block_ref` filters non-BlockRef tokens
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…ure (BR-3i.d) (#4646) Add a wire-token to `DeltaChunk` adapter in `delta_pipeline::chunk_builder` that looks up the basis signature's strong digest for every `BlockRef` (COPY-equivalent) token and stamps it into `DeltaChunk::expected_strong` via the builder added on the applier side by BR-3i.c (#4640). Literal tokens leave the field as `None`: the sender does not embed per-literal digests, and the applier already skips comparison when nothing is set. Without this wiring, every basis-match chunk produced for the parallel receive-delta path slips through `ParallelDeltaApplier::verify_chunk` in "compute digest, skip comparison" mode, so corrupted basis bytes commit silently to the destination. With the wiring in place, the receiver-side verify-chain end-to-end gate added in BR-3i.c finally fires: a basis whose actual bytes differ from the digest the receiver shipped surfaces as `ParallelApplyError::ChecksumMismatch` before the per-file mutex is taken, leaving the destination writer untouched. The adapter is wire-protocol-free - it never touches the network reader, the decompressor dictionary, or the disk-commit thread. The caller hands in already-resolved literal bytes or already-mapped basis bytes, and the builder produces a `DeltaChunk` with the per-file sequence number bumped exactly once per emitted chunk. Out-of-bounds block indices and basis-length disagreements surface as typed `ChunkBuilderError` variants so the receiver can abort the file without ever feeding mismatched bytes into the verify step (which would otherwise be reported as a checksum-mismatch for the wrong reason). No wire-protocol changes - `DeltaChunk` is purely a receiver-side staging structure and the expected digest is held in-memory only. Public API of `ParallelDeltaApplier` is unchanged. Tests cover the BR-3i.d acceptance criteria: - copy chunks populate `expected_strong` from the signature - literal chunks leave `expected_strong = None` - end-to-end: a corrupted basis surfaces `ChecksumMismatch` and never reaches the destination writer - out-of-bounds block index surfaces typed error without bumping the sequence counter - basis-length mismatch surfaces typed error before verify - `next_chunk` dispatches each token variant correctly - `TokenForBuild::from_block_ref` filters non-BlockRef tokens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DeltaChunk::expected_strong: Option<ChecksumDigest>, thewith_expected_strong()builder, and a realverify_chunkthat comparesstrategy.compute(&chunk.data)againstexpected_strong. With no receiver populating the field, every basis-match chunk slipped through verify in "compute digest, skip comparison" mode and corrupted basis bytes could commit silently. This PR wires the basis signature's stored strong digest intoDeltaChunk::expected_strongfor every COPY-equivalent token.delta_pipeline::chunk_builder(crates/transfer/src/delta_pipeline/chunk_builder.rs), a wire-token toDeltaChunkadapter. ForDeltaToken::BlockRef(the receiver-side equivalent of upstream's COPY token) it looks up the referenced block in the negotiatedFileSignature, copies its stored strong digest into aChecksumDigest, and stamps it viawith_expected_strong. ForDeltaToken::Literalit leavesexpected_strong = Nonebecause the sender does not embed per-literal digests.DeltaToken::Endproduces no chunk.parallel-receive-delta(the same gate that exposesDeltaChunk). It takes already-resolved literal bytes or already-mapped basis bytes - I/O stays in the existing receiver pipeline; the builder is a pure function from(FileSignature, token, basis-bytes)toOption<DeltaChunk>. The public API ofParallelDeltaApplieris unchanged.ChunkBuilderError::{BlockIndexOutOfBounds, BasisLenMismatch}surface malformed-stream conditions before the verify step, so the receiver does not mis-attribute basis-resolution bugs as checksum mismatches.Background
ChecksumStrategyintoParallelDeltaApplier.verify_chunkand addedexpected_strongplus the typedParallelApplyError::ChecksumMismatch. That PR also documented the production caller as the missing piece (this PR).ChunkBuilderthe receiver pipeline can drive with already-decodedDeltaTokens and the basis signature it already holds.Test plan
cargo fmt --all -- --checkcleancargo clippy --workspace --all-targets --all-features --no-deps -- -D warningscleancargo nextest run -p transfer --features "parallel-receive-delta incremental-flist" -E 'test(chunk_builder)'- 7 new tests, all greencargo nextest run -p engine --features parallel-receive-delta -E 'test(verify)'- 27 tests, all green (BR-3i.c tests still pass)cargo nextest run -p protocol --all-features -E 'test(golden)'- 407 tests, all green (wire format unchanged)cargo nextest run -p transfer --features incremental-flist- new tests merged into the suite (2 pre-existing failures unrelated to this change:relative_absolute_source_preserves_full_prefixis a macOS/varsymlink quirk andempty_file_checksum_verification_sha1was already failing on this branch's HEAD before this PR)New tests in
chunk_builder::testsreceiver_populates_expected_strong_for_copy_chunks- asserts aBlockReftoken produces aDeltaChunkwhoseexpected_strongequalssignature.blocks()[block_index].strong().receiver_leaves_expected_strong_none_for_literal_chunks- assertsLiteraltokens leaveexpected_strong = None.end_to_end_corrupted_basis_fails_verify- synthetic basis whose mapped bytes disagree with the signature's stored digest;ParallelDeltaApplier::apply_chunk_parallelsurfacesChecksumMismatchandbytes_written == 0because the writer is never touched.block_index_out_of_bounds_surfaces_typed_error- typed error path; sequence counter does not bump.basis_len_mismatch_surfaces_typed_error_before_verify- guards against the receiver feeding mismatched bytes into verify and misattributing the failure to a checksum mismatch.next_chunk_dispatches_each_variant- smoke test for the dispatch helper.from_block_ref_filters_non_blockref_tokens- convenience constructor only acceptsBlockRef.