Skip to content
Pi · claude-opus-4-6debugCLI & tooling3 files · +65 −54

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

50msession
1interventions
GOAL

Diagnose why the coding agent kept stalling and requiring manual "continue" prompts, and fix the root cause in the request-building code.

  1. Prompt · +0
    Something's broken - the agent keeps getting interrupted after not very long, see the log at .research/log-20260211.json
  2. Agent did · +0m
    Explored 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
  3. Agent did · +5m
    Reported 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
  4. Agent did · +8m
    Walked 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
  5. Intervention · +32m
    Pushed 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 needed
    Why: 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.
  6. Agent did · +41m
    Reverted 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
  7. Agent did · +41m
    Updated docs/context-management-policy.md and docs/reinjection-payload-comparison.md to describe the new always-send-bundle behaviour
  8. Agent did · +42m
    Ran lint, typecheck and build, then committed and pushed the fix as 'fix(context): keep tool bundles on continuation calls' (3 files, +16/-27)
  9. Prompt · +50m
    The policy doc was written back when I fundamentally misunderstood how this worked. Please review it in that light.
  10. Outcome · +50m
    Reverted 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
VERDICT

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.

I tried this · 0

Discussion · 0

How Builds work