fix: preserve Ordered() set before Parallel() - #20
Merged
Merged
Conversation
tr1v3r
force-pushed
the
fix/midchain-parallel-section
branch
from
September 14, 2026 02:31
bab6392 to
ea94697
Compare
tr1v3r
force-pushed
the
fix/ordered-before-parallel
branch
from
September 14, 2026 02:31
e13be85 to
6c39adc
Compare
tr1v3r
changed the base branch from
fix/midchain-parallel-section
to
master
September 14, 2026 02:52
Parallel() unconditionally reset s.ordered=false, contradicting the
Ordered() contract ("the current parallel section ... or the next one
if called before it"): Ordered().Parallel(n) silently lost encounter
order. The new section's default-unordered comes from the zero value,
so an explicit Ordered() now carries into the section regardless of
call order. Adds TestParallelV2_OrderedBeforeParallel. Audit finding
M1 (stacked on fix/midchain-parallel-section).
tr1v3r
force-pushed
the
fix/ordered-before-parallel
branch
from
September 14, 2026 02:53
6c39adc to
cf45e4e
Compare
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.
Problem
Ordered()'s contract says it applies to "the current parallel section ... or the next one if called before it" (export.go, stream.go godoc). The implementation broke the second half:Parallel()unconditionally executeds.ordered = false, soreturned elements in completion order instead of encounter order — the explicitly requested ordering was silently dropped (audit finding M1; PoC: ordered-before-parallel output ≠ input order with a reversed-cost jitter map).
Root cause
ordered=falsewas meant to give new sections their documented default (unordered). But the zero value of the flag already provides that default on a fresh streamer, so the unconditional reset only ever destroyed an explicitOrdered()set beforeParallel().Fix
Drop the reset line —
s.orderedkeeps whatever the caller chose;Ordered()now applies to the section a laterParallel()opens, exactly as documented. The godoc wording is aligned ("Sections run unordered unless Ordered() was set on the stream (before or after the Parallel call — the flag carries into the section)").Test evidence
TestParallelV2_OrderedBeforeParallel:Ordered().Parallel(4).Map(reversed-cost jitter)reproduces encounter order (-racegreen).TestParallelV2_MidChainParallelKeepsOrderedSection(Parallel(2).Ordered().Map(j).Parallel(4).Limit(3)==[0 1 2]).go build/go vetclean,go test ./... -race -count=1all ok,golangci-lint0 issues.Stack note
Stacked on #19 (
fix/midchain-parallel-section): that PR keepss.ordered = falseplaced after the flush-adoption, this PR removes it. Merge #19 first; GitHub will retarget this PR to master automatically.