GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(opencode): make long-lived provider streams robust to silent SSE terminations by hubert-marek · Pull Request #39970 · anomalyco/opencode

Conversation

@hubert-marek

@hubert-marek hubert-marek commented Jul 31, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #39968

Type of change

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

What does this PR do?

Fixes the three defects described in #39968, observed when a gateway terminates or stalls long-lived SSE completion responses (23 bare-EOF terminations across 13,312 requests in one ~12h run, plus one 9.5h half-open stall):

  1. EOF without a finish frame is no longer a completed turn. When a provider stream ends without a finish frame, the AI SDK synthesizes a fallback finish-step whose signature is unambiguous: unified reason "other", rawFinishReason: undefined, and null usage (a real finish frame always carries the provider's raw reason, and unusual-but-real reasons carry usage). LLMAISDK.streamFailure converts exactly that signature into a new retryable ProviderError.StreamIncompleteError before adaptation, so the session-level retry policy retries the request within the turn. The budget is bounded (STREAM_INCOMPLETE_RETRY_LIMIT = 3, existing backoff) because a provider that truncates every response must fail the turn (nonzero exit) rather than retry forever or exit 0 with half a turn. Legitimate unknown finish reasons (unrecognized raw reasons from real finish frames) flow through unchanged.

  2. chunkTimeout now bounds the parsed-chunk gap. The existing fetch-level wrapSSE timer watches raw bytes, so keepalive comments reset it while the model stream delivers nothing, and stalls above the byte layer never trip it. LLMAISDK.boundChunkGaps wraps fullStream consumption in session/llm.ts with a per-event deadline from the same chunkTimeout provider option (no new config). The deadline is disarmed while locally executed tool calls are outstanding — their results arrive on the same stream and a long-running local tool is not a stalled provider. On expiry it aborts the request's AbortController and fails the stream with ProviderError.ResponseStreamError, surfaced like any provider failure. I considered the AI SDK's native timeout: { chunkMs } instead, but its timer spans tool execution inside each step (resetChunkTimeout only ticks on stream chunks and is cleared at step flush), which would abort any local tool that runs longer than the chunk deadline.

  3. Provider error bodies survive normalization. ProviderError.message() previously returned the SDK message alone whenever it differed from the bare status text, discarding responseBody — which is how a 400 surfaced as just Invalid request.. It now appends the response body, bounded to 2000 chars, skipping HTML bodies and bodies already contained in the message; the existing behavior for empty messages, status-text messages, and the HTML 401/403 hints is unchanged.

Two existing tests (unknown stream finish preserves partial output and exits 0 and its --format json twin) pinned the old exit-0-on-truncation behavior and are updated to the new contract: retry within the turn (exit 0 once the retry succeeds, with the partial output preserved), and a new test asserts nonzero exit when every retry is truncated too.

How did you verify your code works?

New regression tests:

  • test/session/llm.test.ts: mock SSE server streaming partial content then bare EOF → stream fails with StreamIncompleteError; stream that stalls behind 50ms SSE keepalives with chunkTimeout: 400 → aborted at ~400ms with the deadline error (raw-byte timers provably can't catch this one); a local tool call running longer than chunkTimeout → no false abort; streamFailure unit cases (raw-reason/usage-carrying finish frames are kept).
  • test/session/processor-effect.test.ts: truncated stream is retried within the turn and the retry's output completes the turn without error.
  • test/session/retry.test.ts: incomplete-stream errors map to retryable APIError with the marker code; the retry schedule stops after STREAM_INCOMPLETE_RETRY_LIMIT; other retryable errors stay unbounded.
  • test/cli/run/run-process.test.ts: subprocess-level — truncated stream retries and exits 0 when the retry succeeds; four consecutive truncations exit nonzero with the finish-frame error on stderr.
  • test/session/message-v2.test.ts: 400 with a JSON body keeps Invalid request. plus the body's code/param in the surfaced message; a 10KB body is truncated with a marker.

Full packages/opencode suite: 3181 pass / 1 fail — the one failure is tool.write > sets file permissions when writing sensitive data, which fails identically on the untouched v1.18.2 checkout in this environment (umask-dependent), unrelated to this change. bun run test:httpapi gates: 208 pass / 0 fail. bun turbo typecheck: 30/30 packages pass. oxlint: 0 errors.

Screenshots / recordings

Not a UI change.

Checklist

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

Made with Cursor

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
opencode and others added 2 commits July 15, 2026 16:15
opencode
release: v1.18.2
70b56a0
@hubert-marek @cursoragent
fix(core): make long-lived provider streams robust to silent SSE term…
8ffd287
…inations

Three related defects around long-lived SSE completion streams:

- The chunkTimeout provider option was only enforced by the fetch-level SSE
  wrapper, which watches raw bytes: keepalive comments reset its timer while
  the parsed model stream delivers nothing, and a half-open connection could
  stall a session indefinitely. The deadline is now also enforced where the
  AI SDK fullStream is consumed, disarmed while locally executed tool calls
  are outstanding, and aborts the request on expiry as a terminal provider
  error.

- A stream that hit EOF without a finish frame surfaced as the AI SDK's
  synthesized finish-step (reason "other"/"unknown", no raw finish reason,
  zero usage) and concluded the turn as if it had completed, silently
  dropping the rest of the response. It is now a retryable provider error
  with a bounded in-turn retry budget; exhausting the budget fails the turn
  with a nonzero exit instead of exiting 0 with a truncated turn.

- Provider rejections whose SDK message is a single generic sentence (for
  example a bare "Invalid request.") discarded the response body during
  normalization, making 400-class failures undiagnosable. The bounded body
  is now retained in the surfaced error message.

Co-authored-by: Cursor <[email protected]>
@hubert-marek
hubert-marek requested review from Brendonovich and Hona as code owners July 31, 2026 22:32
@axisrow axisrow mentioned this pull request Aug 1, 2026
SSE stream silently dropped mid-response hangs session/subagents forever — chunkTimeout has no default on the openai path #37580
Closed
This was referenced Aug 1, 2026
fix(provider): recover stalled model streams #40010
Closed
fix(opencode): fail runs when the model stream ends without a finish frame #40032
Closed
@axisrow axisrow mentioned this pull request Aug 1, 2026
kimi-k3 sessions hang indefinitely with no visible indication axisrow/opencode#1
Open
This was referenced Aug 1, 2026
fix(opencode): fail runs when the model stream ends without a finish … #40061
Closed
fix(session): retry top-level stream request timeouts #40268
Closed
fix(core): fail steps with empty provider output after bounded retries #40437
Closed
This was referenced Aug 9, 2026
Http2 stream retry #41390
Closed
fix(opencode): retry empty unknown responses #41466
Closed
This was referenced Aug 21, 2026
fix(session): retry empty unknown-finish streams instead of stopping #43881
Closed
fix(opencode): retry empty OpenRouter streams #44611
Closed
fix(core): recover missing assistant responses #44806
Closed
fix(provider): handle SSE reader cancel rejections #44912
Closed
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Sep 1, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Hona Hona Awaiting requested review from Hona
@Brendonovich Brendonovich Awaiting requested review from Brendonovich

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Silent SSE terminations: EOF without a finish frame completes the turn, chunkTimeout misses stalled streams, provider error bodies are discarded

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@hubert-marek
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.