Skip to content

opencode run exits as if complete when a step finishes reason "length" with zero output #42900

Closed

Description

@njhillson

Description

When a step finishes with reason: "length", output: 0, no tool call and no assistant text, opencode run treats the run as complete: the process exits and the transcript simply stops. In-flight work is lost, and to a process-liveness supervisor it is indistinguishable from a normal finish (ours logged "FINISHED clean" for two such deaths).

This happens when a thinking-capable model spends its entire limit.output budget on reasoning tokens. The turn is exhausted, not finished — there is no answer, no tool call, no stop reason from the model.

Cost in practice: one death lost 59 uncommitted edits across 22 files, ~50 minutes in, four tests from green. Frequency here is roughly 1 in 10 long headless runs.

Raising limit.output does not fix it. After raising the cap 8192 → 16384 → 32768, runs died at 8,191 / 16,383 / 31,999 reasoning tokens respectively, each with zero output — a runaway turn consumes essentially the whole budget whatever it is, so raising the cap only buys more wasted generation per death. Healthy steps in the same runs use 30–730 reasoning tokens, two orders of magnitude below the ceiling, so there is no gradual signal to alert on.

The recovery path already exists and works. After one such death, opencode run --session <id> "<continue instruction>" resumed with the full prior context and completed the task with no re-verification. run just never takes that path itself.

Suggested fix

On a step finishing reason == "length" with zero output tokens and no tool call, continue the session (optionally a bounded retry with a log line) instead of exiting as complete. Failing that, a distinct non-zero exit status would at least let supervising scripts react — today they cannot tell it from success.

Steps to reproduce

  1. Point opencode at a thinking-capable model via LM Studio (OpenAI-compatible provider) with limit.output set.
  2. Run headless: opencode run --format json --dir <workdir> "<task that asks for a long composed document>".
  3. Intermittently a step finishes reason: "length" with output: 0 and no tool call; the process exits and the run is over.

Asking for a large document in a single turn makes it substantially more likely — that is when the model is most apt to think past the ceiling.

OpenCode version

1.18.18

Operating System

macOS (darwin 25.6.0)


Investigated and drafted with Claude Code.

Activity

  1. github-actions commented on Aug 16, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. njhillson commented on Aug 16, 2026

    @njhillson
    Author

    Duplicate of #17471 (same root cause and fix) and #18108 (same code path, prompt.ts:698-699). I've moved the distinct evidence — the zero-output reasoning-burn variant, the headless silent-exit behaviour, and the measurement showing cap-raising does not help — into a comment on #17471 rather than leaving a third issue open. Apologies for the noise.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions