Skip to content

fix: unify model timeouts and bounded retries - #199

Merged
devhims merged 5 commits into
mainfrom
fix/bounded-model-timeout-retries
Oct 15, 2026
Merged

devhims merged 5 commits into
mainfrom
fix/bounded-model-timeout-retries

Conversation

@devhims

@devhims devhims commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Problem / Motivation

Agent runs can fail after a provider stays silent or pauses while streaming an answer. Timeout enforcement currently depends on the selected model, and a timeout from an already selected fallback ends the run without another inference attempt.

What changed

Apply the same role timeout policy to every selected model and provider. Research, transcript analysis, visual analysis and finalization allow 10 seconds to first content and 30 seconds per attempt. Text, reasoning and tool arguments count as content. Classifier and memory limits remain unchanged. Frame and storyboard analysis allow 60 seconds for inference and fallback, bounded by the original research deadline. Retrieval reserves that window plus completion overhead. The 120-second visual research deadline remains unchanged. Storyboard batches stop five seconds before it so successful batches reach finalization even if another stalls. User cancellation still aborts the operation.

Allow one timeout retry for a directly selected model. GLM switches to DeepSeek first, then permits one retry if DeepSeek times out. Each retry reuses the prompt, collected evidence and completed tool results, while checking the original phase deadline and cost budget. Clear interrupted streamed drafts before restarting. Exhausted retries cannot restart through SDK retries or finalizer schema repair.

Remove the 5-second stream idle policy and redundant 15-second finalizer timer. Keep the overall finalization deadline.

%%{init: {"themeVariables": {"signalColor": "#64748b", "sequenceNumberColor": "#ffffff"}}}%%
sequenceDiagram
    autonumber
    participant App
    participant Model as Selected model
    App->>Model: Generate from saved evidence
    Model--xApp: Request times out
    alt Before
        Note over App: Fallback timeout ends the run
    else After
        App->>Model: Retry the same request once within budget
        Model-->>App: Complete answer or terminal failure
    end
Loading

A timed-out selected model receives one retry using the same saved evidence.

Tests

Build passed. Unit suite: 1,796 passed. Agent runtime and memory integration suites: 107 passed. Regressions cover fallback exhaustion, evidence reuse, draft replacement, cancellation, budgets and retry amplification, including HTTP 409 after a timeout retry. Visual regressions cover active responses beyond 20 seconds, fallback completion, completed storyboard evidence reaching the finalizer, providers ignoring abort, and user cancellation.

Deploy the Worker after merge to activate the policy. Production verification remains pending.

@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
video2ctx-web Ready Ready Preview Oct 15, 2026 9:11am UTC

devhims commented Oct 15, 2026

Copy link
Copy Markdown
Owner Author

Changes needed at head 7c1ef09.

P2 — Preserve timeout exhaustion when a retry returns HTTP 409. In platform/src/agents/runtime/model-failover.ts:309–331, if (!eligible(error)) throw error runs before the consumed timeout allowance is made terminal. HTTP 409 is retryable in the pinned AI SDK, so after a timeout consumes the one retry, a 409 escapes and the SDK reenters doGenerate with a fresh ModelRequestState. An independent mocked regression reproduced timeout → 409 → timeout → timeout: four provider calls instead of two with the finalizer's maxRetries: 1 and a 60-second deadline. This renews exhausted retries, adding inference attempts and latency. Enforce consumed timeout exhaustion before this early throw, or preserve the allowance across SDK retries; add the 409 regression.

Verification: platform build passed; 209 focused tests, 1,788 aggregate unit tests (56 skipped), and 161 local integration tests passed. Independent probes: one passed and one failed on the finding above. Verify CI and Vercel passed for this exact head. Reviewed cancellation, budgets, evidence reuse, and streamed draft replacement. Live provider/production behavior was not tested; no code changes, merge, or deployment performed.

devhims commented Oct 15, 2026

Copy link
Copy Markdown
Owner Author

Approve at efd0ee1. No remaining findings.

The prior P2 is fixed in platform/src/agents/runtime/model-failover.ts:314–315: timeout → HTTP 409 now terminates after two provider calls; cancellation still takes precedence. The unchanged independent reproduction passes, along with overall-timeout and nested SDK-error probes.

Verified: build, 214 focused tests, 1,795 unit tests including four independent probes (56 skipped), and 161 local integrations passed. Verify CI and Vercel passed on this exact head. Live provider/production behavior remains untested.

devhims commented Oct 15, 2026

Copy link
Copy Markdown
Owner Author

Changes needed at 1c1c925.

P2 — Preserve completed storyboard batches before the research deadline. The longer timeout at platform/src/agents/providers/youtube/visual-analyst.ts:40 interacts with storyboard-analysis-batches.ts:29–38: it waits for every batch, then throws on cancellation before returning successful findings. With 12 saved sheets and 45 seconds remaining, one batch completes immediately while the other stalls through fallback; the finalizer receives none of the completed observations. The identical independent regression fails here and passes efd0ee1. Bound stalled work below the remaining deadline or retain completed findings before cancellation, while preserving user cancellation.

Prior timeout→409 fix still passes. Build, 1,793 unit tests (56 skipped), 149 integrations and 24 independent timing/retry checks passed; the evidence-retention regression failed. All eight CI jobs and Vercel passed. Offline mocks only; live providers untested.

devhims commented Oct 15, 2026

Copy link
Copy Markdown
Owner Author

Changes needed at 8b0c3db. This only merges main; the prior P2 remains.

platform/src/agents/providers/youtube/visual-analyst.ts:40 and storyboard-analysis-batches.ts:29–38 still discard completed observations when another batch exhausts the research deadline. The identical 12-sheet/45-second regression fails again: one batch completes, another stalls, and the finalizer receives no completed findings. Preserve partial results before the research deadline while honoring cancellation.

No additional findings. Timeout→409 remains fixed. Build, 188 focused checks, 1,793 unit tests (56 skipped), 203 integrations, all eight CI jobs and Vercel passed. Offline mocks only; live providers untested.

devhims commented Oct 15, 2026

Copy link
Copy Markdown
Owner Author

Approve at 15f7cc5. No remaining findings.

The unchanged storyboard-retention regression now passes: completed observations reach finalization before research cancellation. Independent checks also confirm user cancellation, ignored aborts, late responses, multi-wave deadlines and the earlier timeout→409 fix.

Passed: build/type checking, 46 independent tests, 172 focused tests, 1,796 unit tests (56 skipped), 203 integrations, all eight CI jobs and Vercel on this head. Offline mocks only; live provider/production behavior remains untested.

@devhims
devhims merged commit d26487e into main Oct 15, 2026
10 checks passed
@devhims
devhims deleted the fix/bounded-model-timeout-retries branch October 15, 2026 09:17

This branch was successfully deployed

1 active deployment
Preview — 15f7cc55 Deployed Oct 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant