claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Workflow pipeline(): later stages starve when the concurrency cap is reached (no stage-2 agent starts until all stage-1 agents are queued/run)

Open voidfreud opened this issue 1 month ago • 0 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report
  • [x] I am using the latest version of Claude Code

What's Wrong?

In a Workflow script, pipeline(items, stage1, stage2) with many more items than the per-workflow concurrency cap runs (almost) all stage-1 calls before any stage-2 call starts. Stage-2 work for items whose stage 1 finished early is starved.

Observed run: 900 items, two stages (stage 1 = extraction agent, stage 2 = check agent), cap = 8 (machine with 10 CPUs → min(16, CPUs-2)). After ~16 minutes the run journal (journal.jsonl) showed 62 stage-1 agents started, 54 stage-1 results, and 0 stage-2 agents started.

This contradicts the workflow-authoring reference, which says pipeline has "NO barrier between stages. Item A can be in stage 3 while item B is still in stage 1" and "Wall-clock = slowest single-item chain, not sum-of-slowest-per-stage". Under the cap that isn't true: the queue appears to be FIFO by call order, so stage-2 calls queue behind every remaining stage-1 call.

What Should Happen?

Either schedule a finished item's next stage ahead of not-yet-started stage-1 calls (depth-first / per-item priority), or document that pipeline() behaves like a barrier once the cap is saturated, and how to avoid it.

Steps to Reproduce

  1. In a session with workflows enabled, run a script like:
export const meta = { name: 'pipeline-starvation', description: 'repro', phases: [{ title: 'Run' }] }
const items = Array.from({ length: 60 }, (_, i) => i)
await pipeline(items,
  (i) => agent(`Reply with the word one. (item ${i})`, { label: `s1:${i}`, model: 'haiku', effort: 'low' }),
  (r, i) => agent(`Reply with the word two. (item ${i})`, { label: `s2:${i}`, model: 'haiku', effort: 'low' }))
  1. While it runs, inspect the run's journal.jsonl (started entries with labels s1:* / s2:*).
  2. Observe that s2:* agents do not start until (nearly) all s1:* agents have been started, once more items exist than concurrency slots.

Is this a regression?

I don't know

Claude Code Version

2.1.304

Platform

Anthropic API

Operating System

macOS (26.x)

Terminal/Shell

Other (Ghostty)

Additional Information

Related workflow issue: #74599 (pipeline/parallel + resume).

voidfreud avatar Oct 20 '26 16:10 voidfreud