n8n Fixes Silent Cross-Item Data Leak in Batched AI Agent Calls
A silent bug in n8n's batched AI Agent node let tool-call histories leak between items; here's the root cause and the fix.
When n8n's AI Agent node runs with Batch Processing enabled and two or more items in a batch call tools in the same round, a serious bug surfaces: one item's tool-call conversation history silently leaks into another's, or gets dropped entirely. The root cause traces to executeBatch.ts, which merges all items' requests but keeps only the first item's previousRequests metadata, and buildSteps.ts, which then splices that shared history into every item's context unconditionally, with no per-item filtering.
The fix is three small, targeted changes: tag every tool-call step with an itemIndex at creation time, concatenate (rather than discard) previousRequests during batch merging, and filter the merged history down to each item's own tagged entries before rebuilding its context for the next round. The fix was verified with two regression tests that failed before and passed after, alongside all 338 existing tests staying green. A related issue — a shared iterationCount circuit breaker across batch items — was documented as a known follow-up rather than folded into the same PR.
The author independently validated the diagnosis using Sentry's Seer root-cause tool and Gemini, both converging on the same mechanism and a near-identical fix. Notably, Seer's auto-generated patch shipped with zero tests, underscoring why a human-verified fix with regression coverage remains essential even when AI tooling gets the diagnosis right.