Repository navigation
fix: stop middleware re-wrapping, and turn a branch panic into an error - #6
Merged
Merged
Conversation
Three defects, each reproduced against the current release before the fix and each now covered by a regression test. 1. Pipeline.Run and series.Run wrote the wrapped step back into their own step slice while they ran (workflow.go:46, workflow.go:281). Every run added another layer, so one middleware fired 1, then 2, then 3 times, and a Retry(3) became 9 attempts on the second run. Two concurrent runs also raced on the slice. Middleware is now applied to a local copy through a new unexported apply helper, for the length of the call only. This also means String() prints the pipeline as it was declared. Two test expectations that showed the middleware left behind by a previous Run were updated; they had encoded the bug. 2. Merge keeps the first branch; it does not add the branches together. mergo writes into a field only while that field is still empty, and every branch of a Parallel starts from a copy of the same request, so the first branch wins and the rest are dropped without a word. This one is NOT repaired. It follows from Step[T] reading and returning the same type: every branch returns the whole struct and nothing says which field a branch owns. It is now documented on Merge, MergeTransform and Parallel, in the README and in docs/llms.md, and pinned by TestMergeDoesNotCombineValues. Callers should pass their own MergeRequest. workflow/v2 removes the problem at the type level. 3. A panic in a parallel branch was logged by CapturePanic and swallowed. The goroutine returned nil, errgroup saw success, the branch result stayed nil, and mergo then panicked on the nil pointer, stopping the program. Parallel now returns a PanicError. Merge and MergeTransform also skip a nil response rather than dereference it. CapturePanic is deprecated: it leaves the caller with a zero result and no error. No exported signature changed. Clean under -race, -shuffle=on, go vet, modernize, go fix and golangci-lint. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
veggiemonk
force-pushed
the
fix/v1-defects
branch
from
September 21, 2026 13:58
ab1ca9f to
417c384
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.
Patches v1 in place. No exported signature changed, so this is a patch release, not a breaking one.
Each defect was reproduced against the current release before the fix, and each now has a regression test.
1. Middleware collected a new layer on every run — fixed
Pipeline.Runandseries.Runwrote the wrapped step back into their own slice while they ran (workflow.go:46,workflow.go:281):A
Retry(3)became 9 attempts on the second run. Two concurrent runs also raced on the slice.Middleware is now applied to a local copy, for the length of the call only, through one small unexported helper shared by
Pipeline,series,selectorandparallel:Tests:
TestPipelineDoesNotReapplyMiddleware,TestSequentialDoesNotReapplyMiddleware,TestRunDoesNotMutateThePipeline,TestConcurrentRunsAreSafe(under-race).One visible behaviour change
String()now prints the pipeline as you declared it. It used to show the middleware wrappers that a previousRunhad left behind:Two existing expectations asserted the wrapped form. They had encoded the bug, so I updated them. The middleware itself still runs exactly as before — the log output in
Exampleis unchanged.2.
Mergedrops a branch — documented, not repairedMergekeeps the first branch; it does not add the branches together. mergo writes into a field only while that field is still empty, and every branch of aParallelstarts from a copy of the same request. So the first branch fills the field and every later branch is dropped in silence:I could not fix this, and I do not think a patch can. It follows from the shape of
Step[T]: a step reads aTand returns aT, so every branch returns the whole struct and nothing says which field a branch owns. Any "fix" would just pick a different branch to lose.What this PR does instead:
Merge,MergeTransformandParallel, with the counter example spelled out.r.State.Counter++.docs/llms.md.TestMergeDoesNotCombineValues, so nobody discovers it in production. The same test shows a correctMergeRequestof your own producing 2.Parallelalready takes a user-suppliedMergeRequest, so the escape hatch exists. The defect was that the default silently loses data and the README taught it.3. A branch panic crashed the caller — fixed
CapturePaniclogged the panic and swallowed it. The goroutine returnednil,errgroupsaw success, the branch result stayednil, and mergo then panicked on the nil pointer:One panic became two, and the second was not recovered.
Parallelnow returns aPanicError:MergeandMergeTransformalso skip a nil response rather than dereference it, which closes the second half of the crash.CapturePanicis kept for compatibility and marked deprecated: it leaves the caller with a zero result and no error, which is almost never wanted.Tests:
TestParallelPanicBecomesAnError,TestMergeSkipsANilResponse.Verification
Merge order
The new README section links to
./v2, which arrives in #5. Merge #5 first, or the link is dead until it lands.🤖 Generated with Claude Code