Parallel Reconcile-Merge
Overview
Parallelism itself is not the enemy — uncoordinated parallelism is. The
chapter's safe pattern embeds a parallel window inside a sequential control
flow: planning verifies the branches are truly independent, the branches run
simultaneously reading different data sources and writing to separate channels,
and only the merge node combines them.
This skill implements the execution + reconciliation half:
- Per-branch error isolation (tree-pipeline error aggregation): each branch
runs in isolation; an exception is caught and recorded in that branch's own
result. "One branch's failure shouldn't cascade to others or corrupt shared
state." Branches receive a copy of context and never write shared state —
only the merge node combines them.
- Reducer-style deterministic merge (Example 5-8): merge successful branch
values with a reducer (
add, extend, union, max, min) so the result
is "deterministic merging regardless of execution order."
- Completion policy:
all_or_nothing (every branch must succeed) vs
partial_coverage (a quorum suffices — "sometimes three successful branches
out of four provide sufficient coverage").
- Flag union: any red flag from any branch is surfaced; a failed sibling
never silently drops another branch's flag.
In the DevOps latency investigation (account 123456789012), the planner spawns
parallel hypothesis tests — database connection-pool metrics and payment-service
memory profiles — reading different data sources. The pool branch raises a
pool_exhausted flag; the memory branch comes back normal. Reconcile surfaces
the flag, merges both findings, and (under all-or-nothing for a confirmation
phase) reports completion only if both branches succeeded. The analogous claims
case runs fraud / provider-credentials / medical-necessity branches the same
way: any flag from any branch affects the final decision.
When to Use
- A planning node has verified branch independence (different data sources, no
shared decision, no shared mutable state)
- Parallel hypothesis tests, multi-aspect verification (fraud / pricing /
credentials), parallel research tracks
- You need deterministic merge + a quorum/all-or-nothing completion policy +
flag aggregation
Phrases: "merge parallel branches", "reconcile branch results", "controlled
parallelism", "error isolation across branches", "all-or-nothing vs partial
coverage", "state reducer merge".
When NOT to Use
- Branches share mutable state or make a joint decision (uncoordinated
parallelism — the documented failure mode; serialize or re-decompose first)
- Strictly sequential dependent steps (use a sequential pipeline)
- You actually need concurrency tuning — this is the isolation+merge contract;
swap in threads/asyncio/Send API for the dispatch mechanism in production
Process
| Step |
Input |
Action |
Output |
Verification |
| 1 |
branch_fns (name -> fn), context |
lib.execute_branches(...) |
list of BranchResult |
a raising branch yields ok=False and does NOT abort siblings |
| 2 |
branch values + reducer name |
lib.reduce_field(values, REDUCERS[name]) |
merged value |
merge is order-independent for commutative reducers |
| 3 |
results + mode + min_success + reducer |
lib.reconcile(...) |
MergeOutcome |
all_or_nothing fails if any branch failed; partial_coverage completes at quorum; flags are unioned |
| 4 |
branch_fns + context (+policy) |
lib.run_parallel_window(...) |
end-to-end MergeOutcome |
succeeded/failed partition matches branch outcomes |
Rationalizations
| Agent rationalization |
Documented rebuttal |
| "Just let the branches share state — it's simpler." |
Shared mutable state across parallel branches is exactly the uncoordinated-parallelism failure Cognition documents. The chapter's branches "read from different knowledge graph regions and write their findings to separate channels that only the orchestrator combines." |
| "If one branch fails, fail the whole thing." |
Only under all-or-nothing. The chapter notes "three successful branches out of four provide sufficient coverage" for many tasks — partial-coverage is a first-class mode. Pick the mode per task; do not hard-fail by default. |
| "A crashed branch — just drop it and its flags." |
Error isolation records the failure; flag union still surfaces every flag from every branch. A dropped flag (e.g. a fraud signal) is a silent correctness hole. Failure isolation is not the same as discarding signal. |
| "Combine the branch scores any way — order won't matter." |
Only commutative reducers are order-safe. The reducer pattern (Example 5-8) exists precisely so merge is "deterministic regardless of execution order"; ad-hoc combination reintroduces race-order dependence. |
Red Flags
- Branches mutate
context and expect siblings to see it. They get copies
by design; a branch relying on another branch's write is not independent and
should not be in this window.
all_or_nothing chosen for an exploratory fan-out. One flaky branch
fails the whole window when partial coverage would have sufficed — wrong mode
for the task.
- Flags empty but a branch reported a problem in its value. The branch is
not surfacing red flags through the flags channel; the merge cannot union
what it cannot see.
Non-Negotiable Verification
- Run the benchmark battery.
python cli.py benchmark must report:
- a raising branch is isolated (ok=False) and siblings still run
- all_or_nothing completes only when every branch succeeds
- partial_coverage completes at the quorum and fails below it
- flags are unioned across branches (including from non-failing siblings)
- reducer merge is order-independent for a commutative reducer
- succeeded/failed partition matches branch outcomes
- Verify CLI help. Exits 0 and prints the SKILL.md description.
Security Posture
- Prompt injection. Branch results are untrusted - branches typically run
LLM reasoning over untrusted sources. The merge treats values and flags as
data (reducers, unions), never executing them; one compromised branch can
bias the merged value but cannot rewrite siblings' channels, because
branches get context copies and only the merge node combines.
- Data exfiltration. No network calls, no file writes in the window
itself. The merge concentrates findings from every branch into one outcome -
apply per-branch data-access policy upstream, since the merged report sees
everything any branch saw.
- Privilege escalation. No shell invocation, no eval. The guarded property
is signal integrity: flag union guarantees a failed or malicious sibling
cannot suppress another branch's fraud/red flag, and completion policy - not
any single branch - decides whether the window counts as done.
Source Attribution
Distilled from Agentic GraphRAG (O'Reilly, by Anthony Alcaraz and Sam Julien) Ch5 — Reasoning &
Planning: "Tree Pipeline: Parallel Exploration" (Example 5-7), "State
management across pipelines" reducer pattern (Example 5-8), and "The
Multi-Agent Debate" / "The architecture of controlled parallelism" (Example
5-16) — independence verification, per-branch error isolation, and the
ontologically-validated merge.
1---2name: parallel-reconcile-merge3description: Controlled-parallelism window for a tree pipeline (Ch5 Tree Pipeline + "The architecture of controlled parallelism" + state reducers, Examples 5-7/5-8/5-16). Dispatches independent branches that read different data and write to separate channels, isolates errors per-branch so one branch's failure neither cascades nor corrupts shared state, then reconciles the survivors with a reducer-style deterministic merge and decides completion as all-or-nothing or partial-coverage. Surfaces the union of every branch's red flags — a failed branch never silently drops a flag. Use when a planning node has verified true independence between branches (fraud / provider / pricing verification; parallel hypothesis tests). NOT for branches that share mutable state or make joint decisions (that is uncoordinated parallelism, the failure mode), NOT for strictly sequential dependent steps, NOT as a thread pool (this is the isolation+merge contract; the concurrency mechanism is a production swap).4---56# Parallel Reconcile-Merge78## Overview910Parallelism itself is not the enemy — uncoordinated parallelism is. The11chapter's safe pattern embeds a parallel window inside a sequential control12flow: planning verifies the branches are truly independent, the branches run13simultaneously reading different data sources and writing to separate channels,14and only the merge node combines them.1516This skill implements the execution + reconciliation half:1718- **Per-branch error isolation** (tree-pipeline error aggregation): each branch19 runs in isolation; an exception is caught and recorded in that branch's own20 result. "One branch's failure shouldn't cascade to others or corrupt shared21 state." Branches receive a copy of context and never write shared state —22 only the merge node combines them.23- **Reducer-style deterministic merge** (Example 5-8): merge successful branch24 values with a reducer (`add`, `extend`, `union`, `max`, `min`) so the result25 is "deterministic merging regardless of execution order."26- **Completion policy**: `all_or_nothing` (every branch must succeed) vs27 `partial_coverage` (a quorum suffices — "sometimes three successful branches28 out of four provide sufficient coverage").29- **Flag union**: any red flag from any branch is surfaced; a failed sibling30 never silently drops another branch's flag.3132In the DevOps latency investigation (account `123456789012`), the planner spawns33parallel hypothesis tests — database connection-pool metrics and payment-service34memory profiles — reading different data sources. The pool branch raises a35`pool_exhausted` flag; the memory branch comes back normal. Reconcile surfaces36the flag, merges both findings, and (under all-or-nothing for a confirmation37phase) reports completion only if both branches succeeded. The analogous claims38case runs fraud / provider-credentials / medical-necessity branches the same39way: any flag from any branch affects the final decision.4041## When to Use4243- A planning node has verified branch independence (different data sources, no44 shared decision, no shared mutable state)45- Parallel hypothesis tests, multi-aspect verification (fraud / pricing /46 credentials), parallel research tracks47- You need deterministic merge + a quorum/all-or-nothing completion policy +48 flag aggregation4950Phrases: "merge parallel branches", "reconcile branch results", "controlled51parallelism", "error isolation across branches", "all-or-nothing vs partial52coverage", "state reducer merge".5354## When NOT to Use5556- Branches share mutable state or make a joint decision (uncoordinated57 parallelism — the documented failure mode; serialize or re-decompose first)58- Strictly sequential dependent steps (use a sequential pipeline)59- You actually need concurrency tuning — this is the isolation+merge contract;60 swap in threads/asyncio/Send API for the dispatch mechanism in production6162## Process6364| Step | Input | Action | Output | Verification |65|------|-------|--------|--------|--------------|66| 1 | branch_fns (name -> fn), context | `lib.execute_branches(...)` | list of `BranchResult` | a raising branch yields ok=False and does NOT abort siblings |67| 2 | branch values + reducer name | `lib.reduce_field(values, REDUCERS[name])` | merged value | merge is order-independent for commutative reducers |68| 3 | results + mode + min_success + reducer | `lib.reconcile(...)` | `MergeOutcome` | all_or_nothing fails if any branch failed; partial_coverage completes at quorum; flags are unioned |69| 4 | branch_fns + context (+policy) | `lib.run_parallel_window(...)` | end-to-end `MergeOutcome` | succeeded/failed partition matches branch outcomes |7071## Rationalizations7273| Agent rationalization | Documented rebuttal |74|------------------------|--------------------|75| "Just let the branches share state — it's simpler." | Shared mutable state across parallel branches is exactly the uncoordinated-parallelism failure Cognition documents. The chapter's branches "read from different knowledge graph regions and write their findings to separate channels that only the orchestrator combines." |76| "If one branch fails, fail the whole thing." | Only under all-or-nothing. The chapter notes "three successful branches out of four provide sufficient coverage" for many tasks — partial-coverage is a first-class mode. Pick the mode per task; do not hard-fail by default. |77| "A crashed branch — just drop it and its flags." | Error isolation records the failure; flag union still surfaces every flag from every branch. A dropped flag (e.g. a fraud signal) is a silent correctness hole. Failure isolation is not the same as discarding signal. |78| "Combine the branch scores any way — order won't matter." | Only commutative reducers are order-safe. The reducer pattern (Example 5-8) exists precisely so merge is "deterministic regardless of execution order"; ad-hoc combination reintroduces race-order dependence. |7980## Red Flags8182- **Branches mutate `context` and expect siblings to see it.** They get copies83 by design; a branch relying on another branch's write is not independent and84 should not be in this window.85- **`all_or_nothing` chosen for an exploratory fan-out.** One flaky branch86 fails the whole window when partial coverage would have sufficed — wrong mode87 for the task.88- **Flags empty but a branch reported a problem in its value.** The branch is89 not surfacing red flags through the flags channel; the merge cannot union90 what it cannot see.9192## Non-Negotiable Verification93941. **Run the benchmark battery.** `python cli.py benchmark` must report:95 - a raising branch is isolated (ok=False) and siblings still run96 - all_or_nothing completes only when every branch succeeds97 - partial_coverage completes at the quorum and fails below it98 - flags are unioned across branches (including from non-failing siblings)99 - reducer merge is order-independent for a commutative reducer100 - succeeded/failed partition matches branch outcomes1012. **Verify CLI help.** Exits 0 and prints the SKILL.md description.102103## Security Posture104105- **Prompt injection.** Branch results are untrusted - branches typically run106 LLM reasoning over untrusted sources. The merge treats values and flags as107 data (reducers, unions), never executing them; one compromised branch can108 bias the merged value but cannot rewrite siblings' channels, because109 branches get context copies and only the merge node combines.110- **Data exfiltration.** No network calls, no file writes in the window111 itself. The merge concentrates findings from every branch into one outcome -112 apply per-branch data-access policy upstream, since the merged report sees113 everything any branch saw.114- **Privilege escalation.** No shell invocation, no eval. The guarded property115 is signal integrity: flag union guarantees a failed or malicious sibling116 cannot suppress another branch's fraud/red flag, and completion policy - not117 any single branch - decides whether the window counts as done.118119## Source Attribution120121Distilled from *Agentic GraphRAG* (O'Reilly, by Anthony Alcaraz and Sam Julien) Ch5 — Reasoning &122Planning: "Tree Pipeline: Parallel Exploration" (Example 5-7), "State123management across pipelines" reducer pattern (Example 5-8), and "The124Multi-Agent Debate" / "The architecture of controlled parallelism" (Example1255-16) — independence verification, per-branch error isolation, and the126ontologically-validated merge.