When using concurrency/parallel subagents, enforce synchronization and determinism:
1) Parallelize independent work
2) Join before dependent stages
3) Single-writer rule for shared state
research.md).4) Preserve deterministic ordering
Example (orchestrated parallel workers with single writer):
async function runPlan(planDims: Dimension[], runWorkers: (d: Dimension) => Promise<Digest>) {
// 1) parallel: gather all digests for a phase
const digests = await Promise.all(planDims.map(runWorkers));
// 2) single-writer: commit sequentially in required order
for (const d of planDims) {
const digest = digests[planDims.indexOf(d)];
researchMd.append(renderDimensionSection(d, digest));
}
}
Apply this especially when multiple concurrent agents could otherwise race on files, database rows, or shared in-memory structures.