Preface¶
When connecting third-party or self-hosted OpenAI-compatible endpoints in DeepSeek Harness (DSH), streaming SSE occasionally fails after content has already been output, with a silent gap of several minutes in the middle, and then failing at approximately 304–305 seconds locally. The error is TypeError: terminated, with the cause being BodyTimeoutError (UND_ERR_BODY_TIMEOUT), which is classified by DSH as TRANSPORT. Platform-side logs often show the client proactively disconnecting (e.g., LiteLLM/nginx 499), while the upstream continues generating and billing—appearing to be a “network or peer issue,” but actually it’s the undici client clock that Node’s built-in fetch depends on.
Below we introduce the host-side plugin dsh-stream-timeout-fix released by maintainer SundaeYAGO: it replaces the bodyTimeout/headersTimeout of the undici global dispatcher at the process level to eliminate the misjudgment mentioned above; and we explain installation, configuration, and its relationship with DSH’s own streamIdleTimeoutMs.
What is this¶
dsh-stream-timeout-fix is a minimal DeepSeek Harness host plugin (approximately 120 lines in the repository), categorized under model inference-related capabilities. It does not include retry logic, nor does it modify providers, authentication, or routing; it does only one thing: prevent the global undici dispatcher used by DSH’s entire LLM call chain (dsh-llm-pi-ai → pi-ai → OpenAI SDK v6 → globalThis.fetch) from using the default 300-second body/headers timeout.
The primary target users are: third-party/self-hosted OpenAI-compatible endpoints (private deployments, LiteLLM-type gateways, self-hosted vLLM, etc.) that have long response times and occasionally experience long periods without bytes during streaming. The documentation states: if connecting to stable large cloud APIs, this plugin is typically not needed.
The maintainer declares the plugin is open-sourced for personal use and does not guarantee continuous maintenance; it has not yet been published to the npm registry. The plugin runs with the current DSH process permissions; you should read the source code and MIT license before installation.
Symptoms and root cause (brief)¶
Typical failure sequence:
- SSE is established, inference tokens, partial answers, or tool call increments are already flowing;
- There are no body bytes for several minutes in the middle (the upstream may still be generating);
- Locally,
TypeError: terminatedis thrown after approximately 304–305 seconds of silence, often shown as a transport-type failure on the DSH side.
Two default clocks related to undici and Node’s built-in fetch (from original documentation):
| Clock | Default value | Function | Error when triggered |
|---|---|---|---|
headersTimeout |
300_000 ms |
Wait for first response byte | HeadersTimeoutError (UND_ERR_HEADERS_TIMEOUT) |
bodyTimeout |
300_000 ms |
Idle time between adjacent body bytes (resets on each byte received) | BodyTimeoutError (UND_ERR_BODY_TIMEOUT), message often terminated |
bodyTimeout resets per byte, so “slow but continuously data-rich” long streams are generally unaffected; the problem occurs with stalls where the interval between adjacent shards exceeds 300 seconds. The DSH failure classifier matches /terminated/ and maps it to TRANSPORT, which can easily misinterpret client clock issues as peer or network problems.
Core features¶
The plugin performs a process-level replacement at load time (logically equivalent to):
setGlobalDispatcher(new Agent({ bodyTimeout: 1_800_000, headersTimeout: 600_000 }))
Default meanings (can be overridden in configuration):
bodyTimeout: 30 minutes (1_800_000ms), deliberately still a finite value to allow recycling of truly dead connections;headersTimeout: 10 minutes (600_000ms).
A single replacement covers all providers in the host process that use globalThis.fetch. Stream-layer watchdogs (such as pi-ai’s streamIdleTimeoutMs) and DSH retry plugins still work independently; this plugin only eliminates the discrepancy between undici’s default 300 seconds and the business layer’s “idle” judgment.
Important boundary: If silence is still cut off at exactly 300 seconds with pi-ai stream idle timeout after 300000ms (code: TIMEOUT), this is the default value of streamIdleTimeoutMs on the DSH routing, not undici—this needs to be adjusted separately (see “Adjusting with streamIdleTimeoutMs” below). Gateway or server-side idle disconnections cannot be modified by this plugin.
Installation and activation¶
Environment requirements: Node ≥ 22.19.0 (consistent with engines and undici dependency in package.json).
The package has not yet been published on npm; npm install dsh-stream-timeout-fix and dsh plugin … add dsh-stream-timeout-fix will currently return 404. The available method provided in the documentation is as follows.
If your DSH CLI supports the same git specifications as other plugins, you can directly use:
dsh plugin --profile <profile-name> add github:SundaeYAGO/dsh-stream-timeout-fix
The above command can replace the multi-step operation of manually modifying the profile; the plugin’s built-in cordis.patch.yml will mount the plugin line, no need to manually modify the profile patch.
Manual method (in the profile directory ~/.dsh/profiles/<profile-name>/):
- Add
"dsh-stream-timeout-fix": "^1.0.0"todependenciesinpackage.json(or point to a local link path, fill in according to your actual method of obtaining the package); - Add
"dsh-stream-timeout-fix"todsh.profile.bundles; - Run installation/linking in the profile directory (e.g.,
pnpm install), then restart DSH (or check if your version supports live bundle application).
After the first npm release, the CLI installation method provided by the official documentation is:
dsh plugin --profile <profile-name> add dsh-stream-timeout-fix
Configuration¶
| Configuration item | Default value | Setting location |
|---|---|---|
bodyTimeoutMs |
1800000 |
Patch line config, or environment variable DSH_STREAM_TIMEOUT_BODY_MS |
headersTimeoutMs |
600000 |
Patch line config, or environment variable DSH_STREAM_TIMEOUT_HEADERS_MS |
Setting to 0 means disabling the corresponding clock; the documentation does not recommend global disabling, otherwise the means of recycling dead sockets will be lost.
Verification of effectiveness¶
- The corresponding entry in the loader is enabled/active (
include:stream-timeout-fix); - The host logs show something like:
[stream-timeout-fix] global dispatcher replaced: bodyTimeout=1800000ms, headersTimeout=600000ms ...; - At runtime, you can view the installed
Agentand effective timeout throughglobalThis.__streamTimeoutFix.
You can locally run the repository tests and reproduction scripts (in the plugin source directory):
npm test
node scripts/reproduce-300s.mjs # Default fetch: reproduces being killed at ~304 seconds
node scripts/reproduce-300s.mjs --plugin # After applying plugin logic: survives 300 seconds of silence
If it still fails after long silence, you can compare intervals: 304–305 seconds often points to undici’s default clock in the stack; exactly 300 seconds with pi-ai stream idle timeout points to the DSH watchdog; other values are more likely server-side or gateway idle limits.
Adjusting with streamIdleTimeoutMs¶
Installing this plugin alone will not automatically increase DSH’s default tolerable stream idle time. When not set by routing, streamIdleTimeoutMs defaults to 300000, and will still cut off at 300 seconds. The documentation suggests explicitly increasing it for the corresponding provider in the profile patch, and it must be greater than the longest stall you want to survive:
providers:
your-provider:
streamIdleTimeoutMs: 1800000 # 30 minutes
pi-ai’s timing starts from the request dispatch, including the wait before the first token; large prompt prefilling and mid-stream stalls share the same budget.
Applicable scenarios and notes¶
More suitable for: Self-hosted or third-party OpenAI-compatible endpoints that occasionally have long periods without shards during streaming generation, and where the error signature is terminated + UND_ERR_BODY_TIMEOUT, with silence of approximately 304–305 seconds.
Not necessary: When connecting to stable cloud APIs and never encountering the above signatures.
Process-level impact: All fetch calls in the host will use the timeout you configured; this is a design goal, but the impact is on the entire process.
Cost: The plugin itself does not send network requests; before the fix, it may be cut off at ~304 seconds but still billed by the upstream; after the fix, requests may wait longer, and receiving more tokens will also be billed according to provider rules. If combined with unlimited retries, repeated stalls will amplify expenditure.
Capabilities unrelated to this plugin: Does not include retries (can be configured separately in the profile with @deepseek-ai/dsh-llm-retry, etc.); does not solve server-side SSE heartbeats or gateway idle limits; only applies to the Node client path.
Before installation, please read the “Verification status” in the repository README: the author demonstrates the mechanism with local reproduction and tests, and records observations such as the target failure class not reoccurring from 2026-10-13 to 2026-10-18; one “shard interval >300 seconds and end-to-end success” acceptance is still listed as incomplete in the documentation. You can audit session shard intervals using:
node scripts/audit-session-gaps.mjs ~/.dsh/sessions --min-gap-s=250
The DSH ecosystem emphasizes “everything is a plugin”; the community directory plugin page on skillhub.cn is an independent site, with no official affiliation with DeepSeek/Hunyuan.
Conclusion¶
dsh-stream-timeout-fix addresses Node undici’s 300-second bodyTimeout for LLM SSE long silences, replaces the default value with a configurable process-level dispatcher, and distinguishes between misreported TRANSPORT errors and real DSH TIMEOUT and gateway limits. Before use, please evaluate both streamIdleTimeoutMs and billing risks.
- Directory page: https://www.skillhub.cn/plugins/SundaeYAGO/dsh-stream-timeout-fix
- Source code and complete documentation: https://github.com/SundaeYAGO/dsh-stream-timeout-fix