Skip to content

fix(runtime): the stream idle watchdog aborts turns while the model streams a large tool-call argument #2119

Closed

Description

What happened

The stream idle watchdog aborts a healthy turn while the model is streaming a large tool-call argument.

translateChunk in packages/runtime/src/model-adapter.ts has no case for the AI SDK's tool-input-start / tool-input-delta / tool-input-end chunks, so they fall through to default: return []. Meanwhile watchdog.markActivity() is called exactly once per yielded ModelStreamEvent (packages/runtime/src/ai-sdk-backend.ts:1405).

The two facts combine into a blind spot: for the entire time a provider spends streaming tool-call arguments, the adapter yields nothing, so the watchdog observes total silence. Once that argument stream exceeds DEFAULT_STREAM_IDLE_TIMEOUT_MS (120s, packages/runtime/src/stream-watchdog.ts:2), the watchdog fires, aborts the turn, and the turn is committed with failureClass: 'timeout'. Desktop then shows 「对话出错 / 请求超时」.

The model did not time out. Maka killed a stream that was actively producing tokens.

This is not an exotic edge case — it is the normal shape of "write this long document/file in one tool call". Any turn whose tool argument takes longer than 120s to generate is unconditionally lost, and the longer the intended output, the more certain the failure. The user-visible symptom ("request timed out") also points at the provider rather than at us, so it is easy to misfile as a network or provider problem.

Expected: time spent streaming tool-call arguments counts as model activity and does not trip the idle watchdog.

How to reproduce

  1. Run Desktop against an OpenAI-compatible reasoning provider. Observed with DeepSeek V4 Pro at high reasoning effort, but nothing here is provider-specific — it only needs a provider that streams tool arguments incrementally.
  2. Give it a task whose final step emits one very large tool-call argument — e.g. "research X, then write the full report to a file", where the closing move is a single Write/Bash call carrying a multi-thousand-token payload.
  3. The turn dies roughly 120s after the last text/reasoning/tool-result event, with 「请求超时」.

Deterministic once the argument-generation time crosses 120s; the same task with a short final tool call always succeeds.

Environment

  • Maka commit: 62024d140
  • OS: macOS 15 (Darwin 25.6.0), Apple Silicon
  • Surface: Desktop (built from source, npm run build + npm --workspace @maka/desktop run start)
  • Node.js: v22.17.0
  • Provider/model: DeepSeek V4 Pro, reasoning effort high

Logs, screenshots, or additional context

Timeline from runtime_events for the failed turn (all tool calls in this turn were fast; the last one returned in 1ms):

seq  kind               committed_at
122  function_response  16:36:02   <- last activity the watchdog can see
123  thinking           16:38:08   <- flushed at teardown
124  text               16:38:08
125  failed             16:38:08

16:36:02 → 16:38:08 is 126s, matching the 120s idle threshold plus teardown. The failed payload carries:

{"stateDelta":{"failureClass":"timeout","stopReason":"error"}}

The raw watchdog message (Model stream idle timeout after …ms) is generalized to 「请求超时」 by packages/core/src/redaction.ts:221 before it reaches the UI, so the durable event does not retain what actually fired. That made this considerably harder to diagnose than it needed to be — worth considering whether the watchdog phase (connect vs idle) should survive into the failed event, since it is diagnostic rather than sensitive.

Notably the chunk names are already known in-tree — packages/runtime/src/provider-request-telemetry.ts:675 lists tool-input-start / tool-input-end, and the tool-call index tracker added in #1976 keys off tool-input-start / tool-input-delta. The gap is specifically the translateChunk → watchdog path.

Suggested fix. Translate the tool-input-* chunks into a liveness-only ModelStreamEvent so markActivity() is reached during argument streaming. The backend consumes events through an if / else if chain with no exhaustive switch, so a new kind that matches no branch is inert apart from feeding the watchdog. This is preferable to raising the threshold, which only moves the cliff.

Secondary gap. Desktop never supplies streamConnectTimeoutMs / streamIdleTimeoutMs. Only packages/cli (connect only, via MAKA_STREAM_CONNECT_TIMEOUT_MS) and packages/headless (both) pass them through, so Desktop is pinned to the hardcoded defaults with no escape hatch — there is no way for a user hitting this to work around it, and no way to confirm the diagnosis without a rebuild. Wiring both overrides on Desktop would be a useful backstop independent of the fix above.

Activity

  1. Astro-Han commented on Aug 4, 2026

    @Astro-Han
    Contributor

    I’m claiming this issue. I reproduced the failure through the real streamText → ModelAdapter → StreamWatchdog path: SDK tool-input chunks continue arriving, but the watchdog times out because it currently observes the lossy semantic event stream.

    I’ll restore the original liveness invariant at the adapter boundary: add a required, synchronous onStreamActivity observer to ModelAdapterStreamInput, invoke it once for every successfully pulled SDK stream part before translation, wire it to watchdog.markActivity(), and remove the semantic-loop activity mark. ModelStreamEvent, timeout configuration, and unrelated watchdog lifecycle gaps will stay unchanged.

    I’ll add an adapter contract test plus a backend regression covering a tool-argument stream whose total duration exceeds the idle timeout while each chunk interval remains below it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions