Skip to content

fix(assistant): persist failed stream progress#42

Merged
omarluq merged 2 commits into
mainfrom
fix/retry-stream-errors-only
May 23, 2026
Merged

fix(assistant): persist failed stream progress#42
omarluq merged 2 commits into
mainfrom
fix/retry-stream-errors-only

Conversation

@omarluq

@omarluq omarluq commented May 23, 2026

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2cdc346b-3028-450b-85f7-9ef0cf6c4b55

📥 Commits

Reviewing files that changed from the base of the PR and between d3d4235 and 540c884.

📒 Files selected for processing (2)
  • internal/assistant/runtime.go
  • internal/assistant/runtime_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of transient HTTP/2 stream and provider errors to enable automatic retry.
  • New Features

    • Partial assistant output is now captured and saved when model calls fail, preventing loss of progress.
  • Tests

    • Added test coverage for HTTP/2 stream error resilience and partial progress persistence on provider failures.

Walkthrough

This PR expands transient error detection for provider messages and captures partial streamed assistant output during prompt execution, persisting accumulated blocks and appending a custom error message when provider streaming fails.

Changes

Partial Progress Persistence on Transient Errors

Layer / File(s) Summary
Extended retryable error patterns
internal/assistant/retry.go, internal/assistant/retry_internal_test.go
New error substrings (internal_error, stream error, stream id, received from peer, http2) are classified as transient/retryable. A new test validates HTTP/2 stream internal errors are treated as transient.
Partial progress buffering and persistence implementation
internal/assistant/runtime.go, internal/assistant/runtime_lifecycle_test.go
The Prompt method now routes through respondWithPartialProgress, which buffers streamed output blocks (merging adjacent assistant/thinking deltas), supports retry snapshot/reset, and persists accumulated partial blocks and a RoleCustom error message on provider failure using errors.Join. Lifecycle expectations updated to include message_append during error flows.
Test coverage for partial progress persistence
internal/assistant/runtime_test.go
A shared recoveredResponseText constant unifies recovery assertions. Adds TestRuntime_PromptRetriesProviderStreamError, a partialFailureCompletionClient test stub that streams events then fails, and TestRuntime_PromptPersistsPartialProgressOnProviderFailure to validate persisted message roles and contents after partial streaming plus provider failure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I buffered words mid-stream, a careful hare,
When HTTP2 stuttered, I kept a spare—
Partial thoughts saved, so nothing's lost,
On retries swift, we count the cost.
A stitched-together message, warm and neat.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, so the check cannot evaluate whether the description relates to the changeset. Provide a description explaining the changes, such as the retry behavior for stream errors and persistence of partial progress during failures.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(assistant): persist failed stream progress' accurately and concisely summarizes the main change: persisting partial assistant output when model calls fail due to stream errors.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/retry-stream-errors-only

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

codecov-commenter commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.75510% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.31%. Comparing base (ec4b5d5) to head (540c884).

Files with missing lines Patch % Lines
internal/assistant/runtime.go 87.09% 7 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   60.16%   60.31%   +0.14%     
==========================================
  Files         168      168              
  Lines       16665    16755      +90     
==========================================
+ Hits        10027    10105      +78     
- Misses       5628     5635       +7     
- Partials     1010     1015       +5     
Flag Coverage Δ
unittests 60.31% <87.75%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/assistant/runtime.go`:
- Around line 358-365: The current partialPromptProgress.append method drops
chunks consisting only of whitespace because it uses strings.TrimSpace(content);
change the early-return check to only skip truly empty strings (e.g., content ==
"" or len(content) == 0) so whitespace-only deltas are preserved; keep the
existing merge logic that appends content into
progress.blocks[lastIndex].Content and continue to use
canMergePartialPromptBlock(role) — i.e., remove the TrimSpace filtering so
partialPromptProgress.append, progress.blocks and canMergePartialPromptBlock are
left intact but whitespace content is not discarded.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9016ff19-a2a8-4193-b260-25c8242c8013

📥 Commits

Reviewing files that changed from the base of the PR and between ec4b5d5 and d3d4235.

📒 Files selected for processing (5)
  • internal/assistant/retry.go
  • internal/assistant/retry_internal_test.go
  • internal/assistant/runtime.go
  • internal/assistant/runtime_lifecycle_test.go
  • internal/assistant/runtime_test.go

Comment thread internal/assistant/runtime.go
@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants