Skip to content

[bugfix] agent: end a turn when the model read times out with no data (#345) - #419

Open
Birfy wants to merge 1 commit into
ThinkFlowLab:mainfrom
Birfy:fix/345-model-read-timeout
Open

Birfy wants to merge 1 commit into
ThinkFlowLab:mainfrom
Birfy:fix/345-model-read-timeout

Conversation

@Birfy

@Birfy Birfy commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #345.

When the model gateway waited longer than the fixed 120s read deadline and forwarded no bytes, it returned 502 and the bundled OpenCode runtime retried the same request (five hardcoded retries on 502, with 2s-scale backoff). The live turn never reached a terminal state: the panel stayed on "thinking", and interrupted only appeared after a reload.

This change:

  • Treats an unanswered model failure (forwardedBytes == 0) as the end of the turn: close the gateway, stop the harness process, and stream an end event with status: interrupted and a timeout error. A user stop remains stopped.
  • Keeps 120s as the default, applied to the whole read (including a mid-stream stall), not only the first byte.
  • Makes the deadline configurable with OPENDIRECTOR_MODEL_READ_TIMEOUT (seconds). Invalid, non-positive, or missing values keep the default. The inbound harness HTTP parse still has its own 180s bound; that bound no longer caps a longer configured upstream read.

OpenCode 1.19.5 still hardcodes retry-on-502 (up to five times). There is no supported OPENCODE_CONFIG_CONTENT retry policy in this version, so this PR does not invent a config key the runtime would ignore. Ending the turn after the first unanswered failure is what stops the silent re-sends.

Suggested labels: type:bug, area:agent, area:harness, area:provider.

Test plan

Reproduction used a silent local TCP listener as the model endpoint (no provider account, no paid calls). A harness stand-in retried 502 up to six times and would otherwise hang. After the fix, the assistant turn ends after one attempt.

Commands and results (Asia/Shanghai, Python 3.13.5, httpx 0.28.1, isolated checkout /tmp/od-wt-345 from main ffa16c46, PYTHONPATH=packages/core/src:apps/api/src):

python -m pytest tests/test_model_gateway.py -q
# 13 passed in 0.46s

python -m pytest tests/test_native_runtime.py::test_unanswered_model_timeout_ends_the_turn_without_silent_retries -q
# 1 passed in 1.01s
# The turn ended with an English `end` error ("did not respond in time"),
# conversation status `interrupted`, and exactly one upstream attempt.

python -m pytest tests/test_native_runtime.py tests/test_runtime_readiness.py -q -k "not real_opencode"
# 43 passed, 1 failed, 5 deselected in 79s

The one failure, test_rejects_removed_runtime_and_invalid_selection_before_acceptance, returned 503 (default 未安装,请安装 CLI 并登录。) instead of 409. This checkout does not have the bundled OpenCode install (npm ci was not run; the box was at inode capacity). That path is unchanged by this PR and was not treated as a regression.

Not run / not claimed:

  • Full Python suite, TypeScript/i18n/build, and release-check aggregate (not run in this environment).
  • OPENDIRECTOR_REAL_CLI=1 bundled OpenCode integration (binary not installed here).
  • Browser UI interaction. The live panel already applies a streamed end event (useAssistantChat); the API test asserts that event and the persisted interrupted status. A headed click-through of the assistant panel was not performed, so visual wording/layout was not independently verified.
  • Real DeepSeek / Zhipu / Moonshot calls. No paid generation was issued.

CI on this PR should run the repository release checks, including the Python and merge-marked native tests.

…ThinkFlowLab#345)

A first-byte or mid-stream stall longer than the read deadline used to
return 502 and leave the bundled OpenCode runtime retrying silently, so
the chat stayed on "thinking" until reload. End the live turn after an
unanswered failure, stream the terminal state, and keep 120s as the
default whole-read timeout, overridable with OPENDIRECTOR_MODEL_READ_TIMEOUT.
@github-actions github-actions Bot added area:agent Agent runtime, assistant chat and tools area:harness Harness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH) area:provider Model providers and generation protocols type:bug Something is broken labels Nov 21, 2026

This branch has not been deployed

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

Labels

area:agent Agent runtime, assistant chat and tools area:harness Harness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH) area:provider Model providers and generation protocols type:bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] agent: a turn hangs forever when the provider's first byte exceeds the fixed 120s read timeout

1 participant