Skip to content

fix(opencode): seal partial reasoning/text parts before stream retries - #44884

Open
ob1-s wants to merge 1 commit into
anomalyco:devfrom
ob1-s:fix/seal-partial-parts-on-retry
Open

fix(opencode): seal partial reasoning/text parts before stream retries#44884
ob1-s wants to merge 1 commit into
anomalyco:devfrom
ob1-s:fix/seal-partial-parts-on-retry

Conversation

@ob1-s

@ob1-sob1-s commented Aug 25, 2026

Copy link
Copy Markdown

Issue for this PR

Closes#44894

Type of change

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

What does this PR do?

When an attempt fails mid-stream, parts persisted during that attempt were left without time.end: the retry path reset the in-memory maps without finalizing them. This extracts the existing finalization logic from cleanup() into sealPartialParts() and calls it before each stream attempt (no-op on the first), so each failed attempt's parts are closed before the next starts. Retry behavior is otherwise unchanged.

How did you verify your code works?

  • bun test test/session/: 420 passing, identical results on this branch and on dev
  • bun turbo typecheck --filter=opencode: clean
  • Inspected stored parts around retry storms before/after: previously-open reasoning parts now receive end timestamps

Screenshots / recordings

Not a UI change.

Checklist

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

When a provider stream dies mid-attempt, reasoning/text parts already
persisted during streaming kept no end timestamp: the in-memory maps
were dropped on retry without finalizing them, leaving dangling blocks
in the transcript for every failed attempt (visible after retry storms
on unstable endpoints).
Extract the finalization logic into sealPartialParts() and invoke it
before each retry attempt, so each dead attempt's parts are closed
before the next one starts. Behavior of retries themselves is
unchanged.
@github-actionsgithub-actionsBot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Aug 25, 2026
@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:

Potential Duplicate PRs Found

I found several related PRs that address similar issues with streaming, retries, and partial parts:

  1. PR fix(session): retry empty stream truncations and discard partial parts #26167 - fix(session): retry empty stream truncations and discard partial parts

    • Directly addresses handling partial parts during retries; involves discarding partial parts
  2. PR fix(session): recover orphan reasoning stream parts #41630 - fix(session): recover orphan reasoning stream parts

    • Focuses on orphan/unclosed reasoning parts from streaming, which is closely related to the "partial parts without end timestamp" issue
  3. PR fix(opencode): surface truncated turns instead of ending the loop #40142 - fix(opencode): surface truncated turns instead of ending the loop

    • Related to handling truncated streaming attempts

Why they might be related: These PRs all address problems with incomplete or orphaned stream parts from failed provider attempts. Your PR seals partial parts before retries, while these others handle recovery or cleanup of abandoned parts. There may be overlap in the problem domain.

@github-actionsgithub-actionsBot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for freeto 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.

Stream failures between retry attempts leave reasoning/text parts permanently unclosed in transcripts

1 participant

@ob1-s