Skip to content

fix: correct batch interop framing for upstream rsync compatibility - #3084

Merged
oferchen merged 10 commits into
masterfrom
fix/batch-interop-framing
Apr 3, 2026
Merged

oferchen merged 10 commits into
masterfrom
fix/batch-interop-framing

Conversation

@oferchen

@oferchen oferchen commented Apr 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add missing preserve_devices and preserve_acls to batch stream flags, matching upstream rsync's write_stream_flags() in batch.c
  • Fix --read-batch replay 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
  • Fix --write-batch local 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 mechanism

Test plan

  • CI passes (fmt, clippy, nextest on all platforms)
  • Interop tests pass against upstream rsync 3.0.9, 3.1.3, 3.4.1
  • Batch files written by oc-rsync can be replayed by upstream rsync --read-batch
  • Batch files written by upstream rsync can be replayed by oc-rsync --read-batch

@github-actions github-actions Bot added the bug Something isn't working label Apr 3, 2026
oferchen added 10 commits April 3, 2026 21:21
- 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
oferchen force-pushed the fix/batch-interop-framing branch from a73893b to 4929584 Compare April 3, 2026 18:21
@oferchen
oferchen merged commit 6cabfe0 into master Apr 3, 2026
35 of 37 checks passed
@oferchen
oferchen deleted the fix/batch-interop-framing branch April 4, 2026 06:59
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 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant