Fix agent stall from stripped tool schemas on continuation calls
Session from pi-for-excel-sessions on Hugging Face by thomasmustier · MIT · condensed by Coders Talk
Diagnose why the coding agent kept stalling and requiring manual "continue" prompts, and fix the root cause in the request-building code.
- +0Prompt · +0Something's broken - the agent keeps getting interrupted after not very long, see the log at .research/log-20260211.json
- +0mAgent did · +0mExplored the session log with jq/node scripts, found stopReason breakdown (7 aborted, 1 error, 20 stop, 102 toolUse), traced 'stop' cases back to tool schemas being stripped on continuation calls in src/auth/stream-proxy.ts
- +5mAgent did · +5mReported diagnosis: the recent isToolContinuation() optimization strips tool schemas from continuation requests, causing the model to stop after one tool call instead of chaining tool use
- +8mAgent did · +8mWalked through how tool schemas, system prompt and message history relate to context window and prompt caching, in response to a long series of clarifying questions
- +32mIntervention · +32mPushed back hard on the agent's caching explanation, arguing it didn't add up with how attention/KV-cache prefill works, and proposed the exact before/after request sequence to confirm the fix neededWhy: The agent's explanations of caching kept being imprecise or contradictory, so I had to work out the actual request shape myself before agreeing on the fix.
- +41mAgent did · +41mReverted the continuation-time tool stripping in src/auth/stream-proxy.ts, making selectToolBundle() run on every call (first and continuation) instead of only the first, keeping isToolContinuation() as telemetry only
- +41mAgent did · +41mUpdated docs/context-management-policy.md and docs/reinjection-payload-comparison.md to describe the new always-send-bundle behaviour
- +42mAgent did · +42mRan lint, typecheck and build, then committed and pushed the fix as 'fix(context): keep tool bundles on continuation calls' (3 files, +16/-27)
- +50mPrompt · +50mThe policy doc was written back when I fundamentally misunderstood how this worked. Please review it in that light.
- +50mOutcome · +50mReverted the tool-schema-stripping regression, restored full agentic tool loop, pushed commit 2b72cfa, and rewrote context-management-policy.md to reflect the corrected caching/context-window mental model
Next time I'd start the prompt with the concrete symptom and my suspicion of the recent stream-proxy change, since that's exactly where the bug was. The correction that actually mattered was refusing to accept the agent's caching explanation at face value and forcing it to lay out the literal request sequence ([SYS][TOOLS][U1]...) until the wrong optimization became obvious. The fix itself was small once we agreed on the mental model, but getting the agent to reason precisely about caching vs context window took most of the session.