fix(agents): skip retry paths for tool timeouts

Thread tool-timeout state through timeout-triggered compaction, generic timeout payload synthesis, and the changelog.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Simon
2026-05-02 19:20:08 +05:30
committed by Ayaan Zaidi
parent 2605490dbd
commit 8996161e99
2 changed files with 16 additions and 2 deletions

View File

@@ -1244,7 +1244,10 @@ export async function runEmbeddedPiAgent(
// ── Timeout-triggered compaction ──────────────────────────────────
// When the LLM times out with high context usage, compact before
// retrying to break the death spiral of repeated timeouts.
if (timedOut && !timedOutDuringCompaction) {
// Skip when the timeout fired during tool execution: the LLM had
// already responded, the prompt wasn't the problem, and compacting
// would lose the in-flight tool context. See #52147.
if (timedOut && !timedOutDuringCompaction && !timedOutDuringToolExecution) {
// Only consider prompt-side tokens here. API totals include output
// tokens, which can make a long generation look like high context
// pressure even when the prompt itself was small.
@@ -2078,7 +2081,17 @@ export async function runEmbeddedPiAgent(
// Timeout aborts can leave the run without any assistant payloads.
// Emit an explicit timeout error instead of silently completing, so
// callers do not lose the turn as an orphaned user message.
if (timedOut && !timedOutDuringCompaction && !payloadsWithToolMedia?.length) {
// Skip when the timeout fired during tool execution: the assistant
// did produce a response (a tool call) that ran long; the generic
// "no response from model" payload would mislead the caller. The
// partial tool output already in the session is the correct artifact
// to surface. See #52147.
if (
timedOut &&
!timedOutDuringCompaction &&
!timedOutDuringToolExecution &&
!payloadsWithToolMedia?.length
) {
const timeoutText = idleTimedOut
? "The model did not produce a response before the model idle timeout. " +
"Please try again, or increase `models.providers.<id>.timeoutSeconds` for slow local or self-hosted providers."