An orchestrator runs 5 parallel documentation-writing agents, each assigned to document a different API endpoint. All 5 agents write their output to a shared JSON file (api-docs.json) by reading the current file, adding their section, and writing the file back. During testing, the team observes that the final api-docs.json sometimes contains only 2 or 3 of the 5 sections — the rest are silently overwritten. Which root cause and fix BEST addresses this?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Five agents sharing one file and writing without coordination is a race condition waiting to happen — it's like five people editing the same Google Doc without real-time sync, but offline. The last write wins and everyone else's work disappears. The fix is to give each agent its own file, then merge after the fact. Isolation first, then combine.
Full explanation below image
Full Explanation
The failure described is a classic read-modify-write race condition. When multiple agents share a single output file without write coordination, the following sequence produces data loss:
1. Agent A reads api-docs.json (contains endpoint 1's section) 2. Agent B reads api-docs.json concurrently (also contains only endpoint 1's section — it read before A wrote) 3. Agent A writes api-docs.json with endpoints 1 and 2 4. Agent B writes api-docs.json with endpoints 1 and 3 — overwriting A's addition of endpoint 2
The result is a file with only the sections written by whichever agent wrote last, plus any sections that were in the file before all agents started.
The fix is output isolation with a deterministic merge: 1. Each agent writes to its own file: api-docs-endpoint-1.json, api-docs-endpoint-2.json, etc. No shared write state. 2. After all 5 agents complete (fan-in barrier), a merge step reads all 5 files and combines them into the final api-docs.json 3. The merge step is a single-writer operation with no concurrency risk
Option A (timeout increase) addresses a different symptom class (slow agents) not the described symptom (missing sections in the final file). If all 5 agents complete successfully but sections are missing, timeouts are not the cause. Option C (context window limitation) would manifest as incomplete individual sections, not as missing entire sections from the final file. Option D (JSON format inconsistency) would manifest as parse errors or malformed JSON, not as silently missing sections. The exam distinguishes: agents writing correct output that is overwritten (race condition) vs agents writing incomplete/malformed output (logic or format errors).