Repository navigation
refactor(transfer): one marker-aware NDX reader for every role - #7228
Merged
Merged
Conversation
Upstream funnels every NDX read on a live transfer stream through
read_ndx_and_attrs() (rsync.c:322-431), whose loop classifies the value
before any attribute byte is touched. oc had four partial copies of that
rule, each missing a different branch.
Add crates/transfer/src/receiver/ndx_stream.rs holding the rule once:
- read_ndx_step() is one iteration of upstream's read_loop, in
upstream's order: file index, NDX_DONE, NDX_DEL_STATS, the
!inc_recurse || am_sender gate, NDX_FLIST_EOF, sub-list segment.
The del-stats drain sits ahead of the gate exactly as upstream has
it, so a peer without INC_RECURSE still consumes the counters.
- read_marker_aware_ndx() runs the loop for call sites that read no
attribute tail.
- read_ndx_and_attrs() adds the tail, with the attribute read inside
the loop so the protocol-29 keep-alive re-entry (rsync.c:386-391,
which jumps back after iflags is decoded) is an insertion rather
than a restructuring. That branch stays unimplemented and is
documented as a known incompleteness for peers <= 3.0.x.
The branches mutate state the classifier does not own, so a
FlistMarkerSink trait inverts the dependency: ReceiverContext
implements it by delegating to receive_one_extra_segment, and a
NoLazyFlist value stands in for the call sites that must never grow a
file list. SenderAttrs is split into an NDX half and
read_attrs_after_ndx(), which is what lets NDX_DONE stop consuming two
phantom iflags bytes.
Collapsed onto the primitive:
- receiver/file_list/on_demand.rs read_next_frame (gains the
NDX_DEL_STATS branch it lacked; FrameKind folds into NdxStep)
- receiver/file_list/receive.rs receive_extra_file_lists batched drain
- receiver/transfer/phases.rs phase-boundary and goodbye NDX_DONE reads
- generator/transfer/goodbye.rs read_ndx_skipping_del_stats, which
keeps upstream's sender asymmetry: rsync.c:343 rejects every marker
when am_sender is set, so the sender uses the primitive with markers
rejected rather than consumed.
Tests pin the branch order rather than only the behaviour, including a
measured upstream oracle showing sub-list dir_ndx values arrive
non-monotonic (1, 9, 2, 10, 3, 11), so no validation may assume ordering
or contiguity.
oferchen
marked this pull request as draft
August 6, 2026 15:48
Owner
Author
|
Verification status — draft pending a later verification pass. Verified: Linux interop passed. All 8 decomposed sub-tasks covered (primitive 471 lines + 466 lines of tests; NOT verified: nextest (stable), Linux musl, and Windows (stable) — the last is blocked on a Risk note: this touches the receiver NDX read path that all four network cells route through. The byte-neutrality diff is the gate that matters here, and it is outstanding. |
oferchen
marked this pull request as ready for review
August 6, 2026 22:12
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Upstream funnels every NDX read on a live transfer stream through
read_ndx_and_attrs() (rsync.c:322-431), whose loop classifies the value
before any attribute byte is touched. oc had four partial copies of that
rule, each missing a different branch.
Add crates/transfer/src/receiver/ndx_stream.rs holding the rule once:
- read_ndx_step() is one iteration of upstream's read_loop, in
upstream's order: file index, NDX_DONE, NDX_DEL_STATS, the
!inc_recurse || am_sender gate, NDX_FLIST_EOF, sub-list segment.
The del-stats drain sits ahead of the gate exactly as upstream has
it, so a peer without INC_RECURSE still consumes the counters.
- read_marker_aware_ndx() runs the loop for call sites that read no
attribute tail.
- read_ndx_and_attrs() adds the tail, with the attribute read inside
the loop so the protocol-29 keep-alive re-entry (rsync.c:386-391,
which jumps back after iflags is decoded) is an insertion rather
than a restructuring. That branch stays unimplemented and is
documented as a known incompleteness for peers <= 3.0.x.
The branches mutate state the classifier does not own, so a
FlistMarkerSink trait inverts the dependency: ReceiverContext
implements it by delegating to receive_one_extra_segment, and a
NoLazyFlist value stands in for the call sites that must never grow a
file list. SenderAttrs is split into an NDX half and
read_attrs_after_ndx(), which is what lets NDX_DONE stop consuming two
phantom iflags bytes.
Collapsed onto the primitive:
- receiver/file_list/on_demand.rs read_next_frame (gains the
NDX_DEL_STATS branch it lacked; FrameKind folds into NdxStep)
- receiver/file_list/receive.rs receive_extra_file_lists batched drain
- receiver/transfer/phases.rs phase-boundary and goodbye NDX_DONE reads
- generator/transfer/goodbye.rs read_ndx_skipping_del_stats, which
keeps upstream's sender asymmetry: rsync.c:343 rejects every marker
when am_sender is set, so the sender uses the primitive with markers
rejected rather than consumed.
Tests pin the branch order rather than only the behaviour, including a
measured upstream oracle showing sub-list dir_ndx values arrive
non-monotonic (1, 9, 2, 10, 3, 11), so no validation may assume ordering
or contiguity.
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.
Why
Upstream funnels every NDX read on a live transfer stream through one function,
read_ndx_and_attrs()(rsync.c:322-431). Its loop classifies the value beforeany attribute byte is touched, and the branch order is load-bearing - most
notably
NDX_DEL_STATSis drained before the!inc_recurse || am_sendergate,so a peer that never negotiated INC_RECURSE still consumes the counters instead
of desyncing on them.
oc had four partial re-implementations of that rule, each missing a different
branch:
receiver/file_list/on_demand.rsread_next_frameNDX_DEL_STATSbranchreceiver/file_list/receive.rsreceive_extra_file_listsNDX_DONEandNDX_DEL_STATSreceiver/transfer/phases.rsphase-boundary + goodbye readsgenerator/transfer/goodbye.rsread_ndx_skipping_del_statsrsync.c:343rejectionWhat
crates/transfer/src/receiver/ndx_stream.rsholds the rule once:read_ndx_step()- one iteration of upstream'sread_loop, in upstream'sorder: file index (
:332),NDX_DONE(:334),NDX_DEL_STATS(:336), the!inc_recurse || am_sendergate (:343),NDX_FLIST_EOF(:353), sub-listsegment (
:360).read_marker_aware_ndx()- the whole loop, for call sites that read noattribute tail.
read_ndx_and_attrs()- loop plus tail. The attribute read sits insidethe loop because upstream's protocol-29 keep-alive branch (
rsync.c:386-391)jumps back into
read_loopafteriflagsis decoded; that branch staysunimplemented and is documented as a known incompleteness (it is reachable -
rsync 3.0.9 emits the raw form at exactly protocol 29,
io.c:953-968, and ocnegotiates down to 28), with the
continueseam marked so adding it is aninsertion rather than a restructuring.
Those branches mutate state the classifier does not own - the receiver's
file_list/ndx_segments/flist_eof, or the generator's deletion counters.A
FlistMarkerSinktrait inverts the dependency.ReceiverContextimplements itby delegating to the existing
receive_one_extra_segment(segment reception isreused, not reimplemented); a
NoLazyFlistvalue stands in for the call sitesthat must never grow a list, and the generator's goodbye borrows itself through
a small adapter that declares the sender role so upstream's
am_senderterm iswhat rejects a marker.
SenderAttrs::read_with_codec_xattris split into an NDX half andread_attrs_after_ndx(). That split is what letsNDX_DONEstop consuming twophantom
iflagsbytes the peer never sent (rsync.c:334-335).Scope
Deliberately not in this change: routing the pipelined per-file echo sites,
collapsing the two NDX codecs in the drivers, the protocol-29 keep-alive branch,
the non-regular-file guard (
rsync.c:420-428), and the xnamesanitize_path()pass (
rsync.c:407-417). Thedir_ndxrange check is not duplicated either -receive_one_extra_segmentalready performs it (flist.c:2622-2626).Nothing is written on the
NDX_FLIST_EOFbranch. Upstream'swrite_int(f_out, NDX_FLIST_EOF)(rsync.c:358) never reaches a socket: thesender is rejected by the
:343gate first, and the receiver child runs withsock_f_out = -1; f_out = error_pipe[1](main.c:1063-1067). Upstream'sstart_flist_forward()/stop_flist_forward()teeing (io.c:1483-1489) islikewise not ported - it exists only because upstream's generator and receiver
are separate processes each parsing their own copy; oc runs both over one
file_list.Tests
New tests pin the branch order, not just behaviour:
file NDXs surface;
NDX_FLIST_EOFmid-transfer setsflist_eofand does not surface;dir_ndxvalues are non-monotonic and non-contiguous - a measuredupstream oracle produced
1, 9, 2, 10, 3, 11(level-1 dirs interleaved withnewly discovered subdirs appended to
dir_flist), so no validation may assumeordering or contiguity;
NDX_DEL_STATSis drained by a sink whoseinc_recurseis off, which onlypasses while
rsync.c:336-342precedesrsync.c:343; the sender drains it tooand its counters reach the sink;
NDX_DONEreturns without consuming the attribute tail (asserted on the readerposition, so the regression is visible even though the returned value looks
correct);
inc_recurseis genuinely on still rejects every marker withupstream's wording,
Invalid file index: %d (%d - %d), taggedRERR_PROTOCOL.The byte-for-byte upstream 3.4.4 daemon capture
(
real_upstream_multisegment_sublist_decodes_as_segments) passes unchanged asthe no-regression gate on the classifier.