Skip to content

fix: preserve Ordered() set before Parallel() - #20

Merged
tr1v3r merged 1 commit into
masterfrom
fix/ordered-before-parallel
Sep 14, 2026
Merged

tr1v3r merged 1 commit into
masterfrom
fix/ordered-before-parallel

Conversation

@tr1v3r

@tr1v3r tr1v3r commented Sep 14, 2026

Copy link
Copy Markdown
Owner

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 executed s.ordered = false, so

stream.SliceOf(src...).Ordered().Parallel(4).Map(jitter).ToSlice()

returned 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=false was 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 explicit Ordered() set before Parallel().

Fix

Drop the reset line — s.ordered keeps whatever the caller chose; Ordered() now applies to the section a later Parallel() 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

  • New TestParallelV2_OrderedBeforeParallel: Ordered().Parallel(4).Map(reversed-cost jitter) reproduces encounter order (-race green).
  • Existing interaction coverage on this stack stays green: TestParallelV2_MidChainParallelKeepsOrderedSection (Parallel(2).Ordered().Map(j).Parallel(4).Limit(3) == [0 1 2]).
  • go build / go vet clean, go test ./... -race -count=1 all ok, golangci-lint 0 issues.

Stack note

Stacked on #19 (fix/midchain-parallel-section): that PR keeps s.ordered = false placed after the flush-adoption, this PR removes it. Merge #19 first; GitHub will retarget this PR to master automatically.

@tr1v3r
tr1v3r force-pushed the fix/midchain-parallel-section branch from bab6392 to ea94697 Compare September 14, 2026 02:31
@tr1v3r
tr1v3r force-pushed the fix/ordered-before-parallel branch from e13be85 to 6c39adc Compare September 14, 2026 02:31
@tr1v3r
tr1v3r deleted the branch master September 14, 2026 02:50
@tr1v3r tr1v3r closed this Sep 14, 2026
@tr1v3r tr1v3r reopened this Sep 14, 2026
@tr1v3r
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
tr1v3r force-pushed the fix/ordered-before-parallel branch from 6c39adc to cf45e4e Compare September 14, 2026 02:53
@tr1v3r
tr1v3r merged commit 76bd10c into master Sep 14, 2026
2 checks passed
@tr1v3r
tr1v3r deleted the fix/ordered-before-parallel branch September 14, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant