fix: parallel inherit cwd bug#20
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that parallel batch commands correctly inherit the working directory set by preceding serial commands. Key changes include:
- Always calling
SetCwdwith overwrite on parallel commands - Refactoring the serial batch loop to use
slices.Values - Adding unit tests and updating examples to verify cwd inheritance
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/runbatch/progressiveSerialBatch.go | Refactored loop to update CWD using slices.Values |
| internal/runbatch/parallelBatch.go | Changed SetCwd call to use overwrite=true |
| internal/runbatch/parallelBatch_test.go | Added tests for cwd inheritance in parallel batches |
| examples/copycwd-then-parallel.yml | New example showing cwd propagation in parallel runs |
| examples/avm-test-examples.yaml | Removed outdated AVM test examples |
Comments suppressed due to low confidence (1)
internal/runbatch/parallelBatch_test.go:6
- The test uses
assertandrequirebut the imports forgithub.com/stretchr/testify/assertandgithub.com/stretchr/testify/requireare missing. Add them to avoid compile errors.
import (
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Fix Parallel CWD Inheritance Bug
🐛 Problem Statement
Fixed critical issues with current working directory (cwd) propagation in Porch YAML workflows:
copycwdtotemp, subsequent parallel commands behaved inconsistently:foreachdirectorycommands incorrectly used the original directory🔧 Root Cause Analysis
Investigation revealed two critical issues:
ParallelBatchwas setting cwd/env inside goroutine loops, creating race conditionsSetCwdmethod incorrectly joined identical relative paths, creating paths like:🛠️ Solutions Implemented
1. Fixed Race Condition (
parallelBatch.go)2. Fixed Path Duplication (
base.go)3. Enhanced Example Workflow
Added "echo item" command to demonstrate
$ITEMenvironment variable:🧪 Testing & Verification
Fixed Failing Tests
TestForEachDirectoryParallel: All test cases now passVerified Workflow Behavior
📋 Behavior Guarantees
$ITEM) work correctly inforeachdirectory🎯 Impact
This fix ensures consistent and predictable working directory behavior:
copycwdtotemp→parallel batchworkflowsforeachdirectorycommands behave consistentlyResult: Resolves core cwd propagation issues while maintaining backward compatibility and improving parallel execution robustness.