fix(runtime): recover once from output-free streams closed before completion - #4600
Open
jsiu93 wants to merge 1 commit into
Open
fix(runtime): recover once from output-free streams closed before completion#4600jsiu93 wants to merge 1 commit into
jsiu93 wants to merge 1 commit into
Conversation
jsiu93
marked this pull request as ready for review
September 3, 2026 06:27
jsiu93
force-pushed
the
fix/output-free-stream-close-recovery
branch
from
September 3, 2026 06:36
c56056f to
24721f3
Compare
…pletion Generated-by: pi (gpt-5.6-sol)
jsiu93
force-pushed
the
fix/output-free-stream-close-recovery
branch
from
September 3, 2026 06:45
24721f3 to
c833f48
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Recover once from premature stream disconnections that occur before
response.completedwhen the current provider attempt has produced no observable output.When a provider stream closes unexpectedly before protocol completion without generating text, tool activity, thinking, completed steps, or continuation signatures, Maka initiates a single bounded recovery attempt. Any attempt with observable output triggers fail-closed termination, preserving durable tool side effects and preventing operation replays.
Fixes #4599
Changes
File-by-file changes across 13 files (+556, −23):
packages/runtime/src/provider-error-classification.ts: Identifies protocol-incomplete streams, prioritizing typed causeinvalid_request_errorand dual-phrase matching; enables dual-phrase fallback only when the cause chain lacks structured codes/types; preservesretryablesemantics.packages/runtime/src/model-protocol.ts: Adds optionalrecoveryReason: 'incomplete_stream'toModelFailure.packages/runtime/src/model-adapter.ts: Forwards bounded-recovery reasons across the adapter boundary to Runtime, preserving provider codes and terminal error messages.packages/runtime/src/ai-sdk-backend.ts: Integrates the new reason into the existing single-recovery incomplete-stream counter, backoff, Stop abort, and step-budget paths; triggers fail-closed termination on observable output.packages/core/src/events.ts: Exposes public telemetry reasonincomplete_stream.packages/runtime-host/src/protocol/turn.ts: Strictly decodes the new recovery reason.packages/runtime-host/src/protocol/index.ts: BumpsRUNTIME_HOST_COMPATIBILITY_EPOCHfrom 101 to 102 to isolate closed-union enum decoding for older peers.packages/ui/src/conversation-copy.ts: Adds bilingual copy for the new recovery reason.packages/runtime/src/__tests__/provider-error-classification.test.ts: Covers typed causes, dual-phrase fallbacks, single-phrase rejection, and direct/nested conflicting structured errors.packages/runtime/src/__tests__/model-adapter-onerror.test.ts: Covers reason propagation,retryable=false,providerCode, and terminal message boundary passing.packages/runtime/src/__tests__/ai-sdk-backend.test.ts: Covers successful single recovery, budget exhaustion, five fail-closed guardrails, single execution of tool side effects, and Stop cancellation during backoff.packages/runtime-host/src/__tests__/protocol.test.ts: Covers new reason decoding and compatibility epoch boundaries.packages/ui/src/__tests__/live-turn-projection.test.ts: Covers bilingual distinct reason copy projections.Compatibility
RUNTIME_HOST_COMPATIBILITY_EPOCHincreases from 101 to 102 because addingincomplete_streamto the closed-unionProviderRetryReasoncauses older peers to reject the unknown enum value.Recovery guards
Single automatic recovery activates when the current physical provider attempt meets all 9 conditions:
incomplete_stream, or matches existing graceful truncated-stream branch.attemptSawText === false).attemptSawThinking === false).attemptSawToolActivity === false).stepStartedWithProviderContinuation === false).attemptSawCompletedStep === false).Supplementary invariants:
retryableremainsfalse; new path uses dedicatedrecoveryReason.invalid_request_errorand terminal error message remain preserved verbatim.tool_result, andfunction_responseoccur exactly once.Verification
Targeted regression and quality checks:
packages/runtimefull suite: 3184 items; 3171 pass, 13 skip, 0 fail.git diff --check: pass.Not covered
invalid_request_errorand missingresponse.completedtermination events.AI use
Select exactly one:
Tool(s) and scope: implementation drafted by pi running gpt-5.6-sol under human review; commit trailer
Generated-by: pi (gpt-5.6-sol)Checklist
Does this PR entail a change in behavior?