Skip to content

fix(core): fail length finishes that return no content - #51741

Open
Veld101 wants to merge 1 commit into
anomalyco:devfrom
Veld101:empty-length-failure
Open

Veld101 wants to merge 1 commit into
anomalyco:devfrom
Veld101:empty-length-failure

Conversation

@Veld101

@Veld101 Veld101 commented Sep 28, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #50949

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A provider can finish a Step normally with finish_reason: "length" while streaming no text, no reasoning, and no tool call, and with zero output tokens. The publisher settled that Step as a success, so the turn ended with no message, no error, and a successful exit — indistinguishable from a valid empty answer, and impossible to diagnose from the TUI/CLI.

Mirroring the existing content-filter handling, a normalized length finish with no streamed output now fails the Step with a visible error:

The model returned no content (finish reason: length)

Partial output is unaffected: a length finish that streamed any content keeps its normal settlement and visible text, and a length finish with tool calls still continues. specs/v2/session.md is updated alongside.

The error uses a new provider.incomplete type. SessionError.Error.type is a free-form string, so no schema change or client regeneration is required; the failure surfaces through the existing Step failure path with the finish reason in its message.

How did you verify your code works?

  • bun test test/session-runner-tool-events.test.ts — 28 pass (3 new cases: empty length fails the step; length with streamed text settles normally; length with a tool call keeps continuation)
  • bun test test/session-runner.test.ts test/session-step.test.ts test/session-runner-tool-events.test.ts — 252 pass / 0 fail (1 new end-to-end scenario asserting a visible terminal failure and no session.step.ended)
  • bun typecheck in packages/core, and bun turbo typecheck --filter=@opencode/core
  • bun run lint — 0 warnings / 0 errors

Note: bun run check could not complete in my environment because packages/app/src/custom-elements.d.ts is a git symlink (mode 120000) that my Windows checkout materialized as a plain text file (core.symlinks=false), so @opencode/app#typecheck fails with TS1128. That is unrelated to this change and passes on a normal checkout; @opencode/core typecheck passes.

Screenshots / recordings

Not applicable; this is not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty response with finish_reason "length" and zero tokens is treated as success

1 participant