[Bug] Subagents executing long tool-call sequences in a single turn fail prompt caching and compound token consumption
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Shell
- Sterne
- 11.2k
- Forks
- 1.9k
- Ø Merge
- 14 Std. 16 Min.
- Gemergte PRs (30 T.)
- 6
Beschreibung
Environment
- GitHub Copilot CLI v1.0.83
- OS: Windows 11 / PowerShell
- Primary Model: Gemini 3.8 Flash
Problem Description
When executing autonomous subagents (such as custom agents via the task tool), the agent harness allows a subagent to run hundreds of tool calls within a single monolithic turn (Turn 0) without yielding or compacting context.
Because each tool execution (file edits, test outputs, build diagnostics) is appended sequentially to the conversation history of the active turn:
- Prompt Caching is defeated: The dynamic append of intermediate tool results changes the prompt prefix and prevents effective provider-side KV prompt caching.
- Exponential Token Compounding: Every subsequent tool call re-submits the entire growing history (75k-100k+ tokens) to the model. In our session, a single subagent ran ~750 tool calls in Turn 0, compounding to over 120 million tokens consumed in under 40 minutes on local test/edit loops.
- No Turn-Yielding / Throttling Mechanism: The agent does not yield control or checkpoint its context, and background interrupt signals (
write_agent) are queued rather than preempting execution.
Expected Behavior
- Subagent harnesses should enforce turn boundaries or context compaction/eviction after a reasonable threshold of consecutive tool calls (e.g. 15-20 tool calls) to preserve prompt caching and avoid runaway token compounding.
- An explicit cancellation/stop API (
stop_agent) should exist to immediately interrupt runaway background subagents.
Actual Behavior
The subagent executed 750+ tool calls in Turn 0 without yielding, burning >120M tokens on repeated compilation and test iterations, and could not be preemptively stopped via standard agent messaging.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den Einstiegspunkten des Subagent-Harness hinter dem task tool und untersuche, wie write_agent-Nachrichten während langer Turn 0 tool-call-Sequenzen in die Warteschlange eingereiht werden. Reproduziere das 750-call-Verhalten unter Windows 11/PowerShell und überprüfe anschließend, dass der Harness den Kontext abgibt oder kompakt und dass eine stop_agent-artige Abbruchaktion einen laufenden Subagenten unterbrechen kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- powershell, shell
- Bereich
- ai, cli, performance
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100