Repository navigation
fix: correct batch interop framing for upstream rsync compatibility - #3084
Merged
Merged
Conversation
- Add NDX-driven replay loop in replay.rs matching upstream receiver.c: reads NDX + iflags + sum_head + delta tokens + file checksum per file, with NDX_DONE phase transitions (proto >= 29 supports phase 2 redo) - Add missing preserve_devices and preserve_acls to BatchFlags in both batch_support.rs (remote path) and batch.rs (local path)
Upstream rsync's batch files are a tee of the protocol stream, which naturally has all flist entries before any per-file delta data. Our local copy path interleaves flist entries with file data during the directory walk, producing an incorrectly ordered batch stream. Buffer per-file delta data (NDX + iflags + sum_head + tokens + checksum) in an in-memory Cursor<Vec<u8>> during the walk, then append it to the batch file after the flist end marker. This produces the correct upstream ordering: flist entries, flist end, then NDX-framed delta data, then NDX_DONE phase markers. Changes: - Add batch_delta_buf, batch_flist_index, batch_ndx_codec to CopyContext - Add begin_batch_file_delta() for NDX + iflags + sum_head preamble - Redirect finalize_batch_file_delta() and capture_batch_whole_file() to write to delta buffer instead of batch writer - Redirect flush_literal_chunk() and copy_matched_block() token writes to delta buffer - Add flush_batch_delta_to_batch() to copy buffered data and write NDX_DONE markers after flist finalization - Track flist index for correct NDX numbering in delta stream
The test_replay_with_compression_flag test was writing raw token data without NDX framing, but replay.rs now expects the upstream NDX-driven format (NDX + iflags + sum_head + delta tokens + file checksum + NDX_DONE markers).
Upstream compat.c:332-363 parse_negotiate_str() uses asymmetric logic: both sides converge on the first entry in the client's list that also appears in the server's list. The server iterates the client's (remote) list and breaks on first match; the client iterates its own local list and picks the first item also in the server's (remote) list. Our implementation incorrectly iterated the remote list for both roles, which gave server-preference ordering when acting as client. This could select a weaker algorithm (e.g., md5) when a stronger one (e.g., xxh128) was mutually supported and preferred by the client.
…-validated When both sides support zstd (upstream 3.4.1 built with SUPPORT_ZSTD in CI), auto-negotiation picks zstd. However our per-token zstd read codec does not correctly parse upstream's compressed token stream, causing "Unknown frame descriptor" errors. Remove zstd and lz4 from the vstring advertisement list so auto-negotiation falls back to zlibx. Explicit --compress-choice=zstd|lz4 still works since it bypasses vstring exchange entirely (upstream compat.c:543). Tasks #1379 (zstd) and #1380 (lz4) track re-enabling after wire format validation.
The test was writing raw token-format delta data after the flist end marker, but replay() expects NDX-framed data (NDX + iflags + sum_head + tokens + NDX_DONE). This caused a panic on .unwrap() across all CI platforms. Write proper NDX framing matching upstream receiver.c:recv_files() format: file NDX, ITEM_TRANSFER iflags, zero sum_head (whole-file transfer), token-format literal data, and two NDX_DONE markers for the phase 1 and phase 2 transitions.
The integration tests in collect.rs expected 3 rules from -FF (the old broken behavior), but upstream rsync options.c:1589-1598 produces exactly 2 rules: dir-merge /.rsync-filter (first -F) and exclude .rsync-filter (second -F). The implementation was correct after PR #3082; only the tests were wrong.
oferchen
force-pushed
the
fix/batch-interop-framing
branch
from
April 3, 2026 18:21
a73893b to
4929584
Compare
oferchen
added a commit
that referenced
this pull request
Apr 11, 2026
Add a dedicated interop test for the multi-file batch framing fix from PR #3084. The test creates a custom source tree with 11 files of varying sizes (0 bytes to 512 KB) across nested directories and validates batch roundtrips in both directions: - oc-rsync --write-batch -> upstream --read-batch - upstream --write-batch -> oc-rsync --read-batch This exercises the NDX-driven batch framing boundary conditions that were fixed in #3084, where per-file delta data must be correctly ordered after the flist end marker with proper NDX + iflags + sum_head framing.
3 tasks
oferchen
added a commit
that referenced
this pull request
Apr 11, 2026
Add a dedicated interop test for the multi-file batch framing fix from PR #3084. The test creates a custom source tree with 11 files of varying sizes (0 bytes to 512 KB) across nested directories and validates batch roundtrips in both directions: - oc-rsync --write-batch -> upstream --read-batch - upstream --write-batch -> oc-rsync --read-batch This exercises the NDX-driven batch framing boundary conditions that were fixed in #3084, where per-file delta data must be correctly ordered after the flist end marker with proper NDX + iflags + sum_head framing.
oferchen
added a commit
that referenced
this pull request
May 1, 2026
…3084) * fix: correct batch interop framing for read-batch and batch flags - Add NDX-driven replay loop in replay.rs matching upstream receiver.c: reads NDX + iflags + sum_head + delta tokens + file checksum per file, with NDX_DONE phase transitions (proto >= 29 supports phase 2 redo) - Add missing preserve_devices and preserve_acls to BatchFlags in both batch_support.rs (remote path) and batch.rs (local path) * fix: reorder batch write path to produce upstream-compatible stream Upstream rsync's batch files are a tee of the protocol stream, which naturally has all flist entries before any per-file delta data. Our local copy path interleaves flist entries with file data during the directory walk, producing an incorrectly ordered batch stream. Buffer per-file delta data (NDX + iflags + sum_head + tokens + checksum) in an in-memory Cursor<Vec<u8>> during the walk, then append it to the batch file after the flist end marker. This produces the correct upstream ordering: flist entries, flist end, then NDX-framed delta data, then NDX_DONE phase markers. Changes: - Add batch_delta_buf, batch_flist_index, batch_ndx_codec to CopyContext - Add begin_batch_file_delta() for NDX + iflags + sum_head preamble - Redirect finalize_batch_file_delta() and capture_batch_whole_file() to write to delta buffer instead of batch writer - Redirect flush_literal_chunk() and copy_matched_block() token writes to delta buffer - Add flush_batch_delta_to_batch() to copy buffered data and write NDX_DONE markers after flist finalization - Track flist index for correct NDX numbering in delta stream * fix: update batch replay test to use NDX-framed delta format The test_replay_with_compression_flag test was writing raw token data without NDX framing, but replay.rs now expects the upstream NDX-driven format (NDX + iflags + sum_head + delta tokens + file checksum + NDX_DONE markers). * fix: mirror upstream rsync asymmetric negotiation precedence Upstream compat.c:332-363 parse_negotiate_str() uses asymmetric logic: both sides converge on the first entry in the client's list that also appears in the server's list. The server iterates the client's (remote) list and breaks on first match; the client iterates its own local list and picks the first item also in the server's (remote) list. Our implementation incorrectly iterated the remote list for both roles, which gave server-preference ordering when acting as client. This could select a weaker algorithm (e.g., md5) when a stronger one (e.g., xxh128) was mutually supported and preferred by the client. * style: fix rustfmt formatting for map_err chains * style: use contains() instead of iter().any() per clippy * fix: exclude zstd/lz4 from compression auto-negotiation until interop-validated When both sides support zstd (upstream 3.4.1 built with SUPPORT_ZSTD in CI), auto-negotiation picks zstd. However our per-token zstd read codec does not correctly parse upstream's compressed token stream, causing "Unknown frame descriptor" errors. Remove zstd and lz4 from the vstring advertisement list so auto-negotiation falls back to zlibx. Explicit --compress-choice=zstd|lz4 still works since it bypasses vstring exchange entirely (upstream compat.c:543). Tasks #1379 (zstd) and #1380 (lz4) track re-enabling after wire format validation. * fix: use NDX-framed delta format in test_replay_with_token_deltas The test was writing raw token-format delta data after the flist end marker, but replay() expects NDX-framed data (NDX + iflags + sum_head + tokens + NDX_DONE). This caused a panic on .unwrap() across all CI platforms. Write proper NDX framing matching upstream receiver.c:recv_files() format: file NDX, ITEM_TRANSFER iflags, zero sum_head (whole-file transfer), token-format literal data, and two NDX_DONE markers for the phase 1 and phase 2 transitions. * style: fix rustfmt for write_token_literal call * fix: correct -FF filter shortcut tests to match upstream behavior The integration tests in collect.rs expected 3 rules from -FF (the old broken behavior), but upstream rsync options.c:1589-1598 produces exactly 2 rules: dir-merge /.rsync-filter (first -F) and exclude .rsync-filter (second -F). The implementation was correct after PR #3082; only the tests were wrong.
oferchen
added a commit
that referenced
this pull request
May 1, 2026
Add a dedicated interop test for the multi-file batch framing fix from PR #3084. The test creates a custom source tree with 11 files of varying sizes (0 bytes to 512 KB) across nested directories and validates batch roundtrips in both directions: - oc-rsync --write-batch -> upstream --read-batch - upstream --write-batch -> oc-rsync --read-batch This exercises the NDX-driven batch framing boundary conditions that were fixed in #3084, where per-file delta data must be correctly ordered after the flist end marker with proper NDX + iflags + sum_head framing.
oferchen
added a commit
that referenced
this pull request
May 5, 2026
…3084) * fix: correct batch interop framing for read-batch and batch flags - Add NDX-driven replay loop in replay.rs matching upstream receiver.c: reads NDX + iflags + sum_head + delta tokens + file checksum per file, with NDX_DONE phase transitions (proto >= 29 supports phase 2 redo) - Add missing preserve_devices and preserve_acls to BatchFlags in both batch_support.rs (remote path) and batch.rs (local path) * fix: reorder batch write path to produce upstream-compatible stream Upstream rsync's batch files are a tee of the protocol stream, which naturally has all flist entries before any per-file delta data. Our local copy path interleaves flist entries with file data during the directory walk, producing an incorrectly ordered batch stream. Buffer per-file delta data (NDX + iflags + sum_head + tokens + checksum) in an in-memory Cursor<Vec<u8>> during the walk, then append it to the batch file after the flist end marker. This produces the correct upstream ordering: flist entries, flist end, then NDX-framed delta data, then NDX_DONE phase markers. Changes: - Add batch_delta_buf, batch_flist_index, batch_ndx_codec to CopyContext - Add begin_batch_file_delta() for NDX + iflags + sum_head preamble - Redirect finalize_batch_file_delta() and capture_batch_whole_file() to write to delta buffer instead of batch writer - Redirect flush_literal_chunk() and copy_matched_block() token writes to delta buffer - Add flush_batch_delta_to_batch() to copy buffered data and write NDX_DONE markers after flist finalization - Track flist index for correct NDX numbering in delta stream * fix: update batch replay test to use NDX-framed delta format The test_replay_with_compression_flag test was writing raw token data without NDX framing, but replay.rs now expects the upstream NDX-driven format (NDX + iflags + sum_head + delta tokens + file checksum + NDX_DONE markers). * fix: mirror upstream rsync asymmetric negotiation precedence Upstream compat.c:332-363 parse_negotiate_str() uses asymmetric logic: both sides converge on the first entry in the client's list that also appears in the server's list. The server iterates the client's (remote) list and breaks on first match; the client iterates its own local list and picks the first item also in the server's (remote) list. Our implementation incorrectly iterated the remote list for both roles, which gave server-preference ordering when acting as client. This could select a weaker algorithm (e.g., md5) when a stronger one (e.g., xxh128) was mutually supported and preferred by the client. * style: fix rustfmt formatting for map_err chains * style: use contains() instead of iter().any() per clippy * fix: exclude zstd/lz4 from compression auto-negotiation until interop-validated When both sides support zstd (upstream 3.4.1 built with SUPPORT_ZSTD in CI), auto-negotiation picks zstd. However our per-token zstd read codec does not correctly parse upstream's compressed token stream, causing "Unknown frame descriptor" errors. Remove zstd and lz4 from the vstring advertisement list so auto-negotiation falls back to zlibx. Explicit --compress-choice=zstd|lz4 still works since it bypasses vstring exchange entirely (upstream compat.c:543). Tasks #1379 (zstd) and #1380 (lz4) track re-enabling after wire format validation. * fix: use NDX-framed delta format in test_replay_with_token_deltas The test was writing raw token-format delta data after the flist end marker, but replay() expects NDX-framed data (NDX + iflags + sum_head + tokens + NDX_DONE). This caused a panic on .unwrap() across all CI platforms. Write proper NDX framing matching upstream receiver.c:recv_files() format: file NDX, ITEM_TRANSFER iflags, zero sum_head (whole-file transfer), token-format literal data, and two NDX_DONE markers for the phase 1 and phase 2 transitions. * style: fix rustfmt for write_token_literal call * fix: correct -FF filter shortcut tests to match upstream behavior The integration tests in collect.rs expected 3 rules from -FF (the old broken behavior), but upstream rsync options.c:1589-1598 produces exactly 2 rules: dir-merge /.rsync-filter (first -F) and exclude .rsync-filter (second -F). The implementation was correct after PR #3082; only the tests were wrong.
oferchen
added a commit
that referenced
this pull request
May 5, 2026
Add a dedicated interop test for the multi-file batch framing fix from PR #3084. The test creates a custom source tree with 11 files of varying sizes (0 bytes to 512 KB) across nested directories and validates batch roundtrips in both directions: - oc-rsync --write-batch -> upstream --read-batch - upstream --write-batch -> oc-rsync --read-batch This exercises the NDX-driven batch framing boundary conditions that were fixed in #3084, where per-file delta data must be correctly ordered after the flist end marker with proper NDX + iflags + sum_head framing.
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
preserve_devicesandpreserve_aclsto batch stream flags, matching upstream rsync'swrite_stream_flags()inbatch.c--read-batchreplay to correctly parse the upstream NDX-driven per-file delta format (NDX + iflags + sum_head + delta tokens + file checksum) instead of the previous incorrect sequential replay--write-batchlocal copy path to produce correctly ordered batch files: all flist entries first, then NDX-framed per-file delta data appended after the flist end marker, matching upstream's tee mechanismTest plan
rsync --read-batchoc-rsync --read-batch