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
You've got five agents sharing one file and writing without coordination, which 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. Give each agent its own file, then merge after the fact; isolation first, then combine.
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. One agent reads api-docs.json (contains endpoint 1's section) 2. Another agent reads api-docs.json concurrently (also contains only endpoint 1's section — it read before the first agent wrote) 3. The first agent writes api-docs.json with endpoints 1 and 2 4. The second agent writes api-docs.json with endpoints 1 and 3 — overwriting the first agent'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
The timeout-increase option 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. The context-window-splitting option would manifest as incomplete individual sections, not as missing entire sections from the final file. The JSON-format-standardization option 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).