qwen-code/docs/superpowers
jinye 76a57154b2
fix(core): add streaming inactivity timeout to the OpenAI pipeline (#5827)
* fix(core): add streaming inactivity timeout to the OpenAI pipeline

The OpenAI client `timeout` only bounds connect + first response. Once a
streaming request returns 200, inter-chunk inactivity is unbounded, so a
provider that accepts the request then streams nothing (observed with a
DashScope/Bailian endpoint returning 200 with no finish_reason) hangs
indefinitely — the only existing idle timer is telemetry-only and never aborts.

executeStream now wraps the raw chunk stream in an inactivity watchdog: if no
chunk arrives for streamIdleTimeoutMs (default 120s, configurable via
contentGenerator.streamIdleTimeoutMs; <= 0 disables), it aborts the per-request
controller (freeing the socket) and throws. A user AbortError is propagated when
the parent signal was cancelled; otherwise a synthetic ETIMEDOUT, which
classifyRetryError treats as a retryable transport error — identical to a real
socket read timeout — so the existing stream-transport retry recovers a
zero-chunk (first-byte) stall and surfaces a clear error after exhaustion. The
timer resets on every chunk (including thinking deltas), so active streams are
never interrupted.

Out of scope: surfacing a terminal turn_error to the UI on retry exhaustion
(separate change); the non-streaming path is already bounded by the SDK timeout.

🤖 Generated with [Qwen Code](https://github.com/QwenLM/qwen-code)

* fix(core): keep ETIMEDOUT code on stream inactivity timeout (bypass error handler)

Audit found the inactivity timeout could not auto-retry: the OpenAI error
handler detects code 'ETIMEDOUT' as a timeout and re-throws a generic Error
WITHOUT the code, so classifyRetryError no longer saw a retryable transport
error. (The original tests missed this because the mock error handler is a
pass-through, not the real EnhancedErrorHandler.)

Make the inactivity timeout a dedicated StreamInactivityTimeoutError that
processStreamWithLogging rethrows directly — the same bypass StreamContentError
already uses — so the ETIMEDOUT code survives to classifyRetryError and the
stream-transport retry recovers a stalled first-byte stream.

Adds a regression test with an error handler that faithfully replicates the
code-stripping, asserting the code survives and the handler is bypassed.

🤖 Generated with [Qwen Code](https://github.com/QwenLM/qwen-code)

* test(core): fix fake-timer deadlock in inactivity timeout tests

Two tests awaited expect(consume).rejects before advancing the fake timers, so
the rejection could never arrive and the tests hung to timeout. Assign the
assertion promise, advance the timers, then await it.

🤖 Generated with [Qwen Code](https://github.com/QwenLM/qwen-code)

* codex: address PR review feedback (#5827)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* codex: fix PR 5827 CI lint failure

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* codex: address PR review feedback (#5827)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* codex: address PR review feedback (#5827)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* codex: address PR review feedback (#5827)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

---------

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-06-24 23:33:55 +00:00
..
plans feat(serve): add daemon idle detection to GET /health?deep=true (#4934) 2026-06-18 06:55:03 +00:00
specs fix(core): add streaming inactivity timeout to the OpenAI pipeline (#5827) 2026-06-24 23:33:55 +00:00