[Bug] Python SDK: Session.run() hangs forever when the runtime stalls — request_timeout_seconds doesn't bound the turn #3588
wangjianyuweg
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
Session.run()'s event-collection loop (python/sdk/src/deepseek_harness/api.py) blocks onsubscription.next(), which isqueue.get()with no deadline.request_timeout_secondsonly bounds thesession/promptrequest-response exchange (client.py,_request_raw); nothing bounds the turn itself.When the runtime accepts the prompt, emits the
agent/inbox/splicedreceipt, and then stalls — a hung model HTTP call, a runtime deadlock, or any state where the process stays alive butsession.status: idlenever arrives —harness.run()blocks forever: no exception, no recovery short of killing the host process, and the runtime subprocess stays alive too.The same permanent hang occurs when the receipt's
inserted[].iddoesn't match the prompt response'smessageId: thereceivedgate then discards every notification, includingidle.Repro
A fake runtime that answers
initialize+session/prompt, emits the receipt, then goes silent — withrequest_timeout_seconds=1.0configured:{ "runtime_pid": 18552, "thread_alive_past_request_timeout": true, "proc_alive_past_request_timeout": true, "thread_alive_after_6s": true, "proc_alive_after_6s": true }harness.run()was still blocked 6.8 s later (and stays blocked indefinitely), runtime subprocess alive. Happy to provide the full repro script.Repro output screenshot:
Proposed fix
DeepSeekHarnessConfig.turn_timeout_seconds(defaultNonekeeps current behavior).Session.run()computes a wall-clock deadline, passes the remaining time toNotificationSubscription.next(timeout=...), and on expiry returns withfinish_reason="timeout"(realturn/endkinds still win when present), preserving the events collected so far.I've pushed a working fix with regression tests to my fork (PRs appear disabled on this repo, so linking the branch directly):
With the fix, the repro above returns in 3.05 s with
finish_reason='timeout'at the configured bound. Tests:python/sdk/tests/test_turn_timeout.py— stalled runtime returnstimeoutinstead of hanging; slow-but-alive runtime without the option still completes normally.All reactions