Skip to content

Support strategy.matrix on the agent job for parallel AI execution #26598

Open

Description

@chepa92

Problem

Currently, the strategy / matrix support in gh-aw only applies to custom jobs defined under jobs: in the frontmatter (e.g., the BatchOps pattern). The agent job itself — the core AI execution job — does not support matrix strategy, meaning it always runs as a single instance per workflow run.

This is a limitation for use cases like randomized testing at scale, where you want to dispatch N parallel agent threads with different parameters (random seeds, test configs, shards) and have each agent instance work independently and concurrently.

Use Case

I want to run randomized test campaigns where:

  1. Multiple agent instances run in parallel as matrix jobs (e.g., 5–10 concurrent threads)
  2. Each instance receives different matrix parameters (e.g., seed, test-suite, scenario)
  3. Each agent independently generates and executes randomized test scenarios using its own AI session
  4. Results from all parallel agents are aggregated at the end

Today, achieving this requires either:

  • Running agents sequentially (slow, defeats the purpose)
  • Using workflow_dispatch fan-out with multiple workflow runs (wasteful, hard to coordinate, hits per-engine concurrency)
  • Custom jobs with matrix that call back into agent workflows (fragile, not a first-class pattern)

Proposed Solution

Allow strategy on the agent job, either at the top level or under engine:

---
on:
  workflow_dispatch:
    inputs:
      threads:
        default: "5"

strategy:
  matrix:
    thread: [0, 1, 2, 3, 4]
  fail-fast: false
  max-parallel: 5

engine:
  id: copilot
  concurrency:
    group: "gh-aw-copilot-${{ github.workflow }}-${{ matrix.thread }}"

tools:
  bash: ["pytest", "jq"]
---

# Randomized Test Runner — Thread ${{ matrix.thread }}

Run randomized test suite using seed derived from thread index ${{ matrix.thread }}.
Each thread independently selects and executes a random subset of tests.

Key requirements:

  • Matrix parameters available in markdown body via ${{ matrix.* }} expressions
  • Per-instance concurrency groups so parallel agent instances don't cancel each other
  • fail-fast: false support so one failing agent doesn't kill the others
  • max-parallel to cap concurrent AI sessions and manage token/API costs

Prior Art

Alternatives Considered

Approach Limitation
workflow_dispatch fan-out (dispatch N separate runs) No shared context, hard to aggregate, per-engine concurrency blocks
job-discriminator with dispatch-ops No matrix parameters in the agent prompt
Custom job with matrix + assign-to-agent safe output Fragile, adds a full extra job layer, not first-class

Activity

  1. locked and limited conversation to collaborators on Apr 16, 2026
  2. unlocked this conversation on Apr 16, 2026
  3. kaovilai commented on May 22, 2026

    @kaovilai

    Note

    Responses generated with Claude

    Did some research into the compiler internals — this is purely a gh-aw implementation gap, not an API limitation. The Job struct already has a Strategy field and jobs.go already renders it. Custom jobs use it today (lines 625-641 of compiler_jobs.go). The agent job just never sets it.

    Files that need changes:

    1. pkg/parser/schemas/main_workflow_schema.json — Add strategy to top-level properties (currently absent). Needs matrix, fail-fast, max-parallel sub-fields.
    2. pkg/workflow/compiler_types.go — Add Strategy string to WorkflowData struct (same pattern as Container, Services, Concurrency).
    3. Frontmatter parser — Extract strategy: from frontmatter and marshal to YAML string.
    4. pkg/workflow/compiler_main_job.go — Add Strategy: c.indentYAMLLines(data.Strategy, " ") to the agent Job construction (currently missing).
    5. pkg/workflow/concurrency.go — GenerateJobConcurrencyConfig needs to incorporate matrix.* variables into the concurrency group when strategy is present, so matrix instances don't cancel each other.

    Already working (no changes needed):

    • Job.Strategy field exists on the struct
    • jobs.go rendering handles job.Strategy output
    • Custom job strategy extraction exists as reference implementation

    Non-trivial complications:

    • ${{ matrix.* }} expressions in the markdown body need to survive template expansion into the agent prompt
    • Downstream jobs (detection, safe_outputs, conclusion) all needs: [agent] — with matrix, agent becomes N parallel jobs requiring matrix-aware aggregation
    • Interaction with max-runs, rate-limit, and per-engine ET budgets when matrix multiplies agent runs
  4. locked and limited conversation to collaborators on May 22, 2026
  5. unlocked this conversation on May 22, 2026
  6. pelikhan commented on Oct 7, 2026

    @pelikhan
    Collaborator

    Status (2026-10-07; Contributor proposal): The May 22 discussion proposes compiler changes to support strategy.matrix on the agent job; the issue also calls for matrix values in the prompt and independent concurrency for each agent instance. The next step is to review those requirements against the compiler and agree on a testable design before implementation.

  7. pelikhan commented on Oct 16, 2026

    @pelikhan
    Collaborator

    Current-state refresher (2026-10-16): still relevant. On current default-branch snapshot 0d15bd1, the agent job builder configures concurrency, outputs and dependencies but does not assign Job.Strategy. The workflow schema supports strategy for custom jobs, not as a top-level agent-job setting. Existing custom-job matrix support therefore does not satisfy this request.

    The May 22 discussion remains a useful starting point, but the remaining contract is broader than adding a field: prompt access to matrix parameters, independent per-instance concurrency, artifact/output aggregation across detection and safe-output jobs, and multiplied usage limits all need a defined design. The requested single-run parallel agent matrix has not been established by the current implementation. This assessment is static inspection, not a parallel runtime experiment.

  8. pelikhan commented on Oct 22, 2026

    @pelikhan
    Collaborator

    Relevance check — 2026-10-22: keep open; a single-run matrix of agent jobs is not supported. Checked live remote main at ffdd9c9efe6a.

    The current agent job builder still constructs the agent job without Strategy. The schema exposes jobs.<custom-job>.strategy, not a top-level agent strategy; custom-job matrices therefore do not satisfy this issue. Related compiler matrix proposals #39725 and #39737 are both closed and unmerged, despite their descriptions of matrix-aware job/aggregation work.

    Next concrete step: define and implement the agent matrix contract end to end: prompt access to matrix values, per-instance concurrency, fail-fast/max-parallel, collision-free per-instance artifacts and safe-output/detection/conclusion aggregation, plus multiplied run/rate/cost limits. Acceptance should demonstrate N independent agent sessions inside one workflow run and correct aggregation; custom-job fan-out or separate dispatch runs are workarounds, not completion. Static/API review only; no workflow dispatched.

  9. added
    backlog:compiler-workflows
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlog:compiler-workflowscommunityfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions