Repository navigation
v0.4.7 - Use the core idle budget and read completed streams to the end
The plugin was ten times stricter than the core about silence
A turn through this plugin regularly sat for 30 s and then failed with
pi-ai stream idle timeout after 30000ms, after which the retry policy replayed
the same request one to four times — 30 to 150 s of waiting for one step.
The cause is a default this plugin set itself. dsh-llm-pi-ai arms its idle
watchdog around each watchdog.next(iterator) call and never calls
watchdog.pulse(): the budget measures silence since the last streamed
event, not since the last byte on the wire. The core path
(dsh-llm-deepseek) does the opposite — it passes an activity callback into
its SSE parser and re-arms the timer on every chunk and every keep-alive
comment — and it runs with DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300_000.
So whenever the gateway thought before its first token, or a proxy in front of
it only sent : keep-alive comments, the plugin counted that as a dead stream
and killed a live turn. The plugin now uses the core's 300 s default;
policy.streamIdleTimeoutMs still tightens it per connection when you want
that.
Measured through the real PiAiAdapter against a server that sends one delta,
goes silent for 35 s while emitting keep-alive comments, then finishes:
| Build | Idle budget | Result |
|---|---|---|
| 0.4.6 | 30 s | fails at 30 074 ms, pi-ai stream idle timeout after 30000ms, 2 of 5 events |
| 0.4.7 | 300 s | completes at 35 075 ms, all 5 events, finish clean |
A completed turn no longer looks aborted to a proxy in front of it
When the terminal event arrived, the transport cancelled the upstream socket
immediately. That is correct for the consumer, but a middleware in front of the
gateway (a compressing or accounting proxy such as billion-context) sees a
client that vanishes mid-response and records a cancelled turn — it aborts its
own upstream work and writes the usage figures after the abort.
The transport still ends the consumer stream on the terminal event, but now
reads the tail to its end in the background first, capped at 5 s so a proxy that
never closes cannot pin the socket. Measured against a middleware that records
close before writableEnded:
| Build | Middleware verdict |
|---|---|
| 0.4.6 | client closed mid-stream: true |
| 0.4.7 | client closed mid-stream: false, response completed normally |
Verification
npm run check: 91 tests, 91 passing (was 89). New coverage: the transport
keeps reading a completed response to its end so a middleware does not see an
aborted turn, and the adapter publishes the core's idle budget while still
honouring an explicitpolicy.streamIdleTimeoutMs.- A/B through the real
PiAiAdapter(not a stub): 35 s of upstream silence.
0.4.6 fails at 30 s, 0.4.7 completes. - A/B through the real transport with a recording middleware: 0.4.6 reports a
mid-stream client close, 0.4.7 reports a completed response. - Live evidence that this was the dominant failure: in one recorded session on
the 0.4.6 build, 17 of 27 plugin attempts ended in exactly
pi-ai stream idle timeout after 30000ms, each followed by retries.
Update
npx @deepseek-ai/dsh plugin --profile web add '@thebtf/dsh-cliproxyapi-provider@0.4.7'Restart DeepSeek Harness afterwards. No settings change is needed: the new idle
budget is the default, and an existing policy.streamIdleTimeoutMs still wins.