Bound stalled provider model streams - #960
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughChangesThe PR adds provider-stream inactivity detection with first-chunk and between-chunk timeout phases. Agent streaming tracks provider activity, pauses during tool execution, propagates timeout state, records errors, and preserves terminal outcomes through fallback retry and analytics. Provider timeout handling
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Provider
participant AgentStreamRunner
participant TimeoutGuard
participant ChatHandler
participant AgentLongRetry
Provider->>AgentStreamRunner: Start provider step and emit chunks
AgentStreamRunner->>TimeoutGuard: Start, record activity, pause, finish
TimeoutGuard->>AgentStreamRunner: Emit timeout error and abort signal
AgentStreamRunner->>ChatHandler: Record provider timeout state
ChatHandler->>AgentLongRetry: Schedule fallback with provider_timeout reason
AgentLongRetry->>ChatHandler: Reconcile terminal outcome
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Closing without merging after verifying the existing request path. All HackerAI model traffic already uses OpenRouter, which applies provider read deadlines and fallback routing. It can transparently retry before output and does not replay after partial output, so the proposed guard largely duplicates the existing stall and fallback boundary. The five-minute timer also watches parsed AI SDK chunks, while OpenRouter keepalive comments are consumed by the SSE parser without reaching If production evidence later shows the OpenRouter connection itself can remain stuck, we can revisit an outer deadline designed around raw transport activity and an explicit HackerAI SLA. |
Closed without merging
This PR was closed after verifying the current OpenRouter and AI SDK behavior more closely.
All HackerAI model traffic already goes through OpenRouter, which enforces provider read deadlines and enables provider fallback by default. HackerAI also supplies explicit fallback model lists to OpenRouter. OpenRouter can retry before any tokens are delivered and intentionally does not replay after partial output; mid-stream provider timeouts are returned as in-stream errors. This already covers the primary provider-stall and safe-fallback behavior targeted here.
The additional five-minute application timer would duplicate that responsibility and introduce a correctness risk. OpenRouter sends SSE comments such as
: OPENROUTER PROCESSINGwhile a long-running model request is still alive, but the installed AI SDK parser consumes those comments without surfacing them throughonChunk. The proposed guard could therefore classify a live request as inactive and abort it after five minutes.OpenRouter does not publish its exact read-deadline duration, so an outer HackerAI deadline could still be useful if production evidence shows the OpenRouter connection itself can remain stuck. That should be reconsidered with observed failure data and a design that accounts for transport keepalives, rather than shipping a second timer based only on parsed model chunks.
Summary
streamTextexecutionRoot cause
The existing run-level caps are evaluated around completed model steps, so a provider stream that stops making progress can prevent the Agent loop from reaching those checks. The pinned AI SDK exposes
totalMs,stepMs, andchunkMs, but its currentchunkMsimplementation is first armed only after the SDK receives a stream event and can stay armed while tool execution is in progress. Using it directly would miss a never-starting response and could abort a legitimate long tool step.The new guard follows the shared Agent provider lifecycle instead: it arms immediately before each provider request, resets on provider chunks, pauses before tool execution, and clears on step completion. Both the Next.js and Trigger Agent paths inherit the same behavior from
agent-stream-runner.Behavior and risk
ProviderStreamTimeoutErrorwithPROVIDER_STREAM_TIMEOUT,first_chunkorbetween_chunks, and the bounded duration.timeoutcategory, usage tracking, refund checks, and terminal Trigger failure handling.Validation
corepack pnpm test --runInBand— 297 suites / 2,931 tests passedcorepack pnpm typecheckcorepack pnpm lint— 0 errors; 5 existing warnings in unrelated UI filesManual Agent-mode verification
Summary by CodeRabbit
provider_timeoutreason, and abort handling preserves timeout stop state.