Skip to content

feat(parallel): support nested parallel tasks with automatic flattening#150

Merged
rileyhilliard merged 1 commit intomainfrom
feat/nested-parallel-tasks
Jan 27, 2026
Merged

feat(parallel): support nested parallel tasks with automatic flattening#150
rileyhilliard merged 1 commit intomainfrom
feat/nested-parallel-tasks

Conversation

@rileyhilliard
Copy link
Copy Markdown
Owner

@rileyhilliard rileyhilliard commented Jan 26, 2026

Summary

  • Allow parallel tasks to reference other parallel tasks
  • Automatically flatten nested parallel references at execution time
  • Detect and prevent circular references (A -> B -> A)
  • Deduplicate diamond dependencies (shared task runs once)

Example

tasks:
  test-opendata:
    parallel: [opendata-1, opendata-2, opendata-3]
  test-backend:
    parallel: [backend-1, backend-2, backend-3]
  # References parallel tasks - expands to 7 tasks
  test:
    parallel: [test-opendata, test-backend, frontend]

Running rr test expands to: opendata-1, opendata-2, opendata-3, backend-1, backend-2, backend-3, frontend

Benefits

  • Run rr test-opendata for just opendata splits
  • Run rr test for everything
  • Add a 4th split to test-opendata and test automatically includes it
  • No manual flattening or repetition required
  • --dry-run shows the expanded task list

Test plan

  • Unit tests for FlattenParallelTasks function
  • Unit tests for cycle detection
  • Unit tests for diamond dependency deduplication
  • Validation tests for nested parallel refs
  • Linter passes
  • All existing tests pass

Fixes #145

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Parallel tasks can now reference other parallel tasks, with automatic flattening and deduplication.
    • Enhanced dry-run output displays expanded task hierarchies with total execution count.
    • Added validation to detect circular references in parallel task configurations.
  • Documentation

    • Added comprehensive sections on nested parallel task configuration, usage patterns, and CLI flags for parallel execution.

✏️ Tip: You can customize this high-level summary in your review settings.

Allow parallel tasks to reference other parallel tasks. When rr encounters
a nested parallel reference, it flattens the task tree before execution.

Example:
  test-opendata: {parallel: [opendata-1, opendata-2, opendata-3]}
  test-backend: {parallel: [backend-1, backend-2, backend-3]}
  test: {parallel: [test-opendata, test-backend, frontend]}

Running `rr test` expands to 7 tasks: opendata-1, opendata-2, opendata-3,
backend-1, backend-2, backend-3, frontend.

Features:
- Cycle detection prevents infinite recursion (A -> B -> A)
- Diamond dependencies are deduplicated (shared task runs once)
- --dry-run shows expanded task list
- No depth limit on nesting

This makes maintaining large parallel task groups much easier - add splits
to a subtask and parent tasks automatically include them.

Fixes #145

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 26, 2026

Caution

Review failed

An error occurred during the review process. Please try again later.

Walkthrough

This PR introduces support for nested parallel tasks—allowing parallel tasks to reference other parallel tasks with automatic flattening. It includes cycle detection to prevent circular references, modifies the CLI to use flattened task lists, enhances dry-run visualization to show task expansion, and adds comprehensive documentation and tests.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md, README.md, docs/configuration.md
Added "Nested parallel tasks" documentation describing automatic flattening behavior, YAML examples, CLI flags for parallel execution, and circular-reference detection. Includes example task hierarchies showing how nested references expand to executable subtasks.
Validation Logic
internal/config/validate.go
Removed prohibition on nested parallel references. Introduced FlattenParallelTasks() public API that recursively expands parallel tasks to flat, deduplicated lists. Added detectParallelCycle() DFS-based cycle detection integrated into validation flow. Enhanced error messages for non-existent references, self-references, and circular references.
CLI Execution
internal/cli/parallel.go
Updated to use flattened subtasks from config.FlattenParallelTasks() instead of direct task references. Enhanced dry-run rendering to detect and display task expansion, showing original references and nested subtasks. Added total task count to dry-run output. Updated renderDryRunPlan signature with additional parameters.
Tests
internal/config/validate_test.go
Expanded validation tests: changed "nested parallel task" from error to allowed; added "deeply nested" and circular reference scenarios. Introduced comprehensive FlattenParallelTasks test suite covering simple nesting, mixed references, complex nesting with deduplication, deep chains, error cases (non-parallel, missing tasks), and deduplication verification.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI
    participant Validator
    participant Executor
    
    User->>CLI: Execute parallel task (nested refs)
    CLI->>Validator: ValidateParallelTasks() + detectParallelCycle()
    Validator->>Validator: DFS cycle detection
    alt Cycle detected
        Validator-->>CLI: Error (circular reference)
        CLI-->>User: Fail with guidance
    else Valid config
        Validator-->>CLI: ✓ Validation passed
        CLI->>Validator: FlattenParallelTasks(task)
        Validator->>Validator: Recursively expand nested refs
        Validator->>Validator: Deduplicate expanded list
        Validator-->>CLI: Flattened task list
        CLI->>CLI: Build TaskInfo from flattened tasks
        alt Dry-run mode
            CLI->>CLI: Render expansion details<br/>(original refs + nested subtasks)
            CLI-->>User: Display expansion preview
        else Execute
            CLI->>Executor: Execute flattened tasks in parallel
            Executor->>Executor: Run all expanded tasks
            Executor-->>User: Results
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

The changes introduce substantial new logic in the validation layer (cycle detection via DFS, recursive flattening with deduplication), modify CLI execution flow to integrate flattened results, and affect both happy-path and error-handling routes. While well-tested, the cycle detection algorithm and flattening correctness require careful verification, especially around edge cases like diamond dependencies and circular references.

Possibly related PRs


Comment @coderabbitai help to get the list of available commands and usage tips.

@rileyhilliard rileyhilliard merged commit 8f715df into main Jan 27, 2026
9 checks passed
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.

Support nested parallel tasks (parallel task referencing another parallel task)

1 participant