/agent-traffic-control:flatten-workflow-parallel-arrays-before-collectingfrom agent-traffic-control
Claude Code Workflow tool gotcha: a pipeline() stage that returns parallel([...]) resolves to a BARE ARRAY, but a sibling stage that returns {dimension, verified: []} resolves to an OBJECT — so a collector written as `per.flatMap(p => Array.isArray(p?.verified) ? p.verified : [])` SILENTLY DROPS every item from the array-shaped stages. Use when: (1) a fan-out review/verify workflow reports "0 confirmed / 0 refuted" or "0 findings" but the agent count / journal shows verify agents actually ran; (2) a loop-until-dry or review workflow looks suspiciously CLEAN; (3) you wrote a pipeline whose stage-2 conditionally returns parallel(...) for some items and an object for others. The "0 findings" is a FALSE all-clear from a result-collection bug, not a real result. Fix: handle BOTH shapes in the collector.
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
In the Claude Code Workflow tool, pipeline(items, stage1, stage2, …) runs each item
through the stages. A common fan-out-then-verify shape makes stage-2 return different
shapes per item:
const per = await pipeline(DIMENSIONS,
d => agent(findPrompt, {schema: FINDINGS}), // stage 1
(findings, d) => {
if (!findings.confirmed.length)
return { dimension: d.key, verified: [] }; // OBJECT shape (no findings)
return parallel(findings.confirmed.map(f => () => // BARE ARRAY shape (has findings)
agent(verifyPrompt(f), {schema: VERDICT}).then(v => ({...f, verdict: v}))));
});
per[i] is now an object {verified: […]} for dimensions that found nothing, but a
bare array [{…verdict…}, …] for dimensions that DID find candidates (because
parallel() resolves to an array). A collector written for only the object shape:
const all = per.flatMap(p => Array.isArray(p?.verified) ? p.verified : []); // BUG
evaluates Array.isArray(undefined) → false for every array-shaped element → returns []
→ silently drops all verdicts from exactly the dimensions that found bypasses. The
workflow returns confirmed: 0, refuted: 0 — a false "all clear." The real tell:
agentCount is high and the journal shows verify/v2: agents both started AND
result-ed, yet confirmed_count + refuted_count == 0 (verify agents only spawn for
candidates, so candidates existed).
Workflow script using pipeline() where a later stage conditionally returns
parallel(...) (adversarial-verify / review / loop-until-dry patterns).agentCount (or the journal under
…/subagents/workflows/wf_*/journal.jsonl) shows verify agents ran, contradicting "0".Handle BOTH shapes in the collector (this is what the canonical multi-stage example in the Workflow docs does, and it's easy to drop when simplifying):
const all = per.flatMap(p =>
Array.isArray(p?.verified) ? p.verified
: (Array.isArray(p) ? p : [])); // <-- the array-shape branch the bug omits
Better still, make stage-2 return ONE consistent shape (always an object, or always an
array) so the collector can't diverge. If a phase()/coverage map reads p.attacks_run_count,
that's also undefined for the array-shaped items — another symptom.
Recovery without re-running the agents: edit the collector line in the persisted script
(…/workflows/scripts/<name>-<runId>.js) and resume with
Workflow({scriptPath, resumeFromRunId}) — the find + verify agents are cached and return
instantly; only the fixed synthesis re-runs. The dropped findings reappear.
confirmed_count + refuted_count matches the number of verify
agents that ran (journal result lines for v*: keys).confirmed, not nothing.parallel() also resolves a thrown thunk to null, so always .filter(Boolean) the
flattened array before using verdicts.~/.claude/projects/<proj>/<session>/subagents/workflows/wf_<id>/journal.jsonl
({type:'started'|'result', key, agentId} lines) — the fastest way to confirm agents ran.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verify