Repository navigation
fix(agent-runtime): exclude retry backoff from stream idle time - #1981
Conversation
The idle watchdog wrapped the retry adapter, counting deliberate waits as provider silence. Long Retry-After sequences could trigger a synthetic failure and spend a retry without sending a request, exhausting the budget before the final allowed attempt. Give each provider attempt its own watchdog and abort controller. Backoff keeps the user's cancellation signal, while a stalled attempt can be aborted without poisoning the next one. Preserve the existing idle limits. Cover full retry budgets, real stalls and Stop through real Agent loops and the production sidecar with a controlled localhost provider.
muzimu217
left a comment
There was a problem hiding this comment.
Moving the idle clock into the per-attempt factory is the right fix, and the distinction the description draws is the one that matters: a deliberate backoff is not silence, so it should not spend the recovery budget that exists to detect a provider that stopped talking. The E2E list covers the cases that would otherwise regress — one 429 consuming exactly one retry, a genuine stall aborting its own attempt before recovery starts another, Stop preventing a later retry, and exhaustion still happening after eleven genuinely stalled attempts — and that last one is what keeps the retry loop bounded once the watchdog stops counting backoff.
One case I would like stated, because it is the only way this can now hang: with the watchdog disabled (0), an attempt that never produces a token has nothing to abandon it except the user's Stop. That is presumably the same as before the change, so it is not a regression — but it is worth one line in the spec, because "0 disables the watchdog" now reads as "this attempt may wait forever" rather than "the whole turn has no timeout".
The other side of the same coin: with the clock per attempt, an attempt that keeps producing a token just under the deadline still keeps itself alive indefinitely. Also unchanged, also worth knowing when someone later reports "the turn never times out".
vastsa
left a comment
There was a problem hiding this comment.
Independently verified the root cause against current main c0a9345: temporarily using main's production runtime with the new real-Agent regression yields 10 requests instead of 11 at the default idle budget, and retry statuses [1,2] instead of [1] at 30 seconds. Restoring the candidate passes both cases.
The production change is localized: per-attempt watchdog/controller preserves the user cancellation signal for retry waits, leaves defaults and budgets unchanged, and aborts abandoned network work before recovery.
Local validation at 1c339e1: shared/runtime builds and sidecar bundle pass; full runtime suite 115 files / 1582 tests pass; final targeted suite 59/59; production-sidecar localhost HTTP E2E 3/3 (Stop during backoff: one request; rate-limit recovery: two; silent request cancellation and non-overlapping replacement: two). Diff check clean; no tracked diagnostic edits retained. Primary installed Pi 1.3.0 is incompatible with required 1.4.0, so locked dependencies were installed only in the isolated review worktree.
All six remote checks green. Latest main is an ancestor; GitHub integration candidate and tested head have identical tree 58c523c4032467e44ad02b4b4769e97aaf43002a. Local E2E uses the production sidecar and real HTTP with a controlled Host boundary; no interactive Electron or paid-provider test was run locally. Remote Electron/Windows gates passed.
The main-turn idle watchdog includes deliberate retry backoff in its silence budget. With the supported 30-second idle setting, one HTTP 429 requesting a 30-second wait produces retry statuses
[1, 2]for a single rejected request. At the default 180-second setting, a sequence of ten 30-second rate-limit waits exhausts recovery after only ten requests, so the allowed eleventh attempt never reaches the fixture's successful response.Move the watchdog into the per-attempt stream factory. Each provider request owns its idle timer and abort controller; retry waits retain the user's cancellation signal. A stalled request is cancelled before recovery starts its replacement, while Stop still interrupts backoff. Preserve the existing idle defaults, minimum, disable setting, and retry limits. Update the runtime spec and add the corresponding E2E scenario.
Validation on Windows / Node 24.14.0:
node scripts/e2e-provider-retry-idle.mjsafter building the sidecar.idle watchdog charged another retry during backoff: [1,2].One initial full-suite run hit a 30-second timeout in the existing Plan execution guard test. The unchanged isolated case, its complete 42-test file, and then the complete final suite all passed.
Tested candidate:
1c339e1f5cd8ce4e454afc652d1301a7059dcbd1. Incorporated main:c0a93457329bce72c573f9f4464b0d7addf25b45.GitHub merge candidate
be0898f0937355e7e81a5f59905bded4993d7950has the identical tree (58c523c4032467e44ad02b4b4769e97aaf43002a) as the tested candidate.