Skip to content

agent: turn interrupted before large write executes; retries restart from scratch and file is never created #59811

Closed as not planned

Description

@Seeken-dai

Summary

In a long coding session, the agent tried to create a new ~1,200-line single-file HTML prototype with one large write tool call. The turn ended mid-response before the tool call executed, so nothing was persisted. On every retry the agent re-read source files and re-stated its full plan instead of resuming, and again never reached the write. The same zero-progress cycle repeated 5+ times; the target file was never created.

Environment

  • opencode version: 2.2.0
  • OS: Windows_NT 10.0.26300 (win32 x64)
  • Terminal: Unavailable (terminal environment variables not set)
  • Shell: cmd.exe (PowerShell for tool commands)
  • Install/channel: latest
  • Active plugins: hermes-notify.js (user-level config)

Reproduction

  1. Ask the agent to produce a large single-file artifact (~1,000+ lines / ~120 KB) in one write call, preceded by a detailed plan.
  2. The turn is cut off mid-response, before the write executes. No error is shown; the turn just stops.
  3. User says "continue". The agent re-plans from scratch (re-reads files, restates the spec) and the turn again ends before the write runs.
  4. Repeat. No partial output ever lands on disk, so each restart starts from zero.

Expected Behavior

  • If a response is truncated, tool calls already issued in that turn should either execute or the harness should surface an explicit interruption error, instead of a silent stop.
  • After an interrupted turn, the session should make it cheap to resume (e.g. a checkpoint of the last completed action) rather than nudging the model into a full re-plan.
  • For large files, agent guidance should prefer chunked writes (small skeleton first, then incremental edits) so progress is preserved across interruptions.

Actual Behavior

Five-plus consecutive turns each ended before the write executed. No error was surfaced to the user; from their side the agent appeared to "hang" every time. No relevant log was captured.

Additional Context

  • Frequency: consistently reproducible with one large write call in that session. Small writes and edits (a few dozen lines, config/PRD edits) completed fine throughout the same session, so the failure correlates with very large tool-call payloads and/or very long single turns.
  • The session used a long summarized conversation checkpoint, which may contribute to per-turn output length pressure; no truncation error was reported anywhere.
  • Workaround that worked: abandon the single large write; write a <100-line skeleton, then append the rest in several small edits. A handoff spec was also prepared so another agent could execute in small chunks.

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr

    Thanks for the report, @Seeken-dai.

    On 2.2.0, a reply that runs out of output tokens isn't meant to stop silently. A cut-off tool call should fail with a visible error telling the model to split large payloads into smaller calls. OpenCode should then continue on its own, and after three truncated replies in a row it should show "Response still truncated after two output token limit continuations". You saw none of that, so these turns may have ended some other way, for example a dropped or timed-out connection to the provider. To narrow it down, could you share:

    1. Provider and model you were using (e.g. anthropic/claude-..., openrouter/..., a custom endpoint), and any limit.output / output-token settings you have configured.
    2. Which client: TUI, the desktop app, or opencode run.
    3. What was on screen when a turn stopped, in your own words: did the assistant's message end mid-sentence or mid-tool-call, was the session still shown as busy, and was there any error at all? A screenshot would help.
    4. Logs from a session where it happened, if you can reproduce it again. Logs are under %USERPROFILE%\.local\share\opencode\log\; please include the lines around the time the turn stopped.

    You can reply here with the details or edit the issue. If you edit it, please also leave a comment saying you've updated it so we know you're done.

    These issues look related, though I'm not sure any of them is the same problem. They're ordered from most to least likely:

  2. houleiyx commented on Oct 29, 2026

    @houleiyx

    The key detail might be how the provider stream ended: did it report an output limit, drop the connection, or finish sending the write tool call without
    OpenCode executing it? Those would point to different causes.

    If your provider uses a configurable API base URL, a local capture of the last few stream events could help. I’m involved with ccglass, which can record OpenCode’s requests and responses. A redacted capture alongside the provider/model and OpenCode logs would give
    maintainers something concrete to trace. Splitting the file into smaller writes sounds like the right workaround for now.

  3. Seeken-dai commented on Oct 29, 2026

    @Seeken-dai
    Author

    Thanks for the triage. Answers to your four questions below. Log timestamps are UTC; local time is UTC+8. Redactions: provider id/name, internal LAN address, API keys, session IDs and project paths are omitted.

    1. Provider and model

    • Custom OpenAI-compatible provider (npm: @ai-sdk/openai-compatible), baseURL pointing at an internal LAN gateway (redacted: http://<internal-host>:8080/v1).
    • Session model: glm-5.3-flash (a GLM-5.3-Flash-class model). The failing model's entry has no limit block in user config — no limit.output set on our side. Other model entries in the same config set explicit limits (context 1000000 / output 128000–131072), but those were not the session model.

    2. Client

    • Windows desktop app (background service + UI). One user-level local plugin is configured; it fails to load on every boot with "Plugin must export a default definition…", noted for completeness, likely unrelated.

    3. What was on screen

    • The reply just stops: visible text ends mid-plan, the pending large write tool call (~120 KB payload) never executes, no tool result, no error toast. From the user's side the turn looks hung; typing "continue" starts a fresh turn in which the model re-plans from scratch. No screenshot available retroactively; we can capture one on the next occurrence.

    4. Log findings (opencode.log)

    For 2026-10-27 (the failing day):

    • The background service restarted at 06:55:39Z (14:55 local), 2–3 minutes after the last successful tool calls (spawning process at 06:52–06:53Z). The first failed turn follows that restart. The service restarted 7 times that day (boots at 01:27Z, 03:15Z, 05:55Z, 06:55Z, 09:07Z, 09:34Z, 09:36Z) — possibly related to desktop(win): background service SIGKILLed mid-turn when snapshot capture blocks /api/info for >6s -> ~60s restart loop, aborted turns #51216.
    • Crucially, no stream errors, no output-token/truncation errors, and no provider errors are logged anywhere near the failing turns — they just end silently.
    • session websocket failed repeatedly; using http at 09:32:29Z (17:32 local); session websocket connect failed; using http also present.
    • Failed to fetch models.dev … TimeoutError after 10s at 07:00:53Z — external network is flaky on this machine (same error recurs on several other days); separate from the LAN provider.
    • 2026-10-28T01:46:43Z Failed to drain Session … ECONNRESET: socket connection closed unexpectedly at service start; a similar drain failure with a different cause appeared on 2026-10-22.

    One lead worth flagging

    HTTP_PROXY / HTTPS_PROXY are set system-wide to a local proxy (127.0.0.1:7890), and NO_PROXY does not exempt the LAN provider host — so provider traffic routes through that proxy. An older log line (2026-07-22) proves the path: stream error … AI_APICallError: Cannot connect to API: connect ECONNREFUSED 127.0.0.1:7890. On the failing day there were no such errors, which is consistent with the proxy closing long-lived SSE streams cleanly — i.e. the turn ends with no fetch error and no output-token signal, matching #40146 ("truncated turns recorded as normal completions"). We own the gateway, so on the next occurrence we can capture the provider-side stream (or bypass the proxy for that host) to confirm.

  4. opencodejr commented on Oct 31, 2026

    @opencodejr

    Closing this as not planned, since we haven't heard back with the details we asked for. Thanks again for the report, @Seeken-dai.

    We needed the provider and model, the client you used (TUI, desktop or opencode run), what was on screen when a turn stopped, and logs from around that time. On 2.2.0, running out of output tokens should show a visible error and continue on its own, so a turn ending with no message at all points to another cause. Without those details we can't tell which.

    If it happens again, please reply here with those details or open a new issue, and we'll take another look. Your workaround, a small skeleton first and then several smaller edits, is a reasonable way to avoid it in the meantime. #56344 and #51216 may also be worth watching if your setup matches either.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions