Repository navigation
fix(runtime): retry output-free provider finishes - #3777
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
I reviewed this head and found no blocking issues.
The fix correctly classifies output-free stop without usage as incomplete for bounded recovery, and routes network_error raw finishes to retryable network failure. Usage accounting retains failed-request usage and remains fail-closed. Two minor P3 observations remain non-blocking (evidence accumulation across steps, finish-without-step-finish usage fallback).
Checks on fe53c1529 are test: success.
简体中文
该头未发现阻断,两处 P3 观察已记录。|
Reviewed the production diff. The fix is right and the test weight is proportionate — 816 of the 985 added lines are tests, covering the branches that actually fork (metadata-only evidence, authoritative zero usage, exhausted-retry metering). Two non-blocking notes, both about where the new logic lives rather than whether it is correct. P2 —
The owner here is P3 — the Backend recomputes what the adapter has already computed. The adapter's iterator already walks the translated stream and derives
Not raised as a change request here: Reviewed with help from Claude. 简体中文看了生产代码部分。修复方向是对的,测试的分量也匹配——985 行新增里有 816 行是测试,覆盖的都是真会分叉的分支(只有 metadata 的证据、权威零 usage、重试耗尽后的计费)。两条意见,都不阻塞,说的是新逻辑该放在哪里,而不是它对不对。 P2 ——
真正的所有者是 #2297 引入的 P3 —— Backend 重算了一遍 adapter 已经算出来的东西。 adapter 的迭代器已经走过完整的翻译流,算出了
这里不作为修改要求提出: 本次 Review 有 Claude 协助。 |
Dismissing my earlier approval — follow-up review found two non-blocking items (P2/P3) worth settling first; details in the review comment above.
|
Addressed both review notes in 776d3f5.
Local verification is green, including the full affected workspace suites, release contracts, and the installed CLI package smoke. For the broader finish-reason vocabulary consolidation tracked in #3802, this fix does not make further changes at this time. 简体中文已在 776d3f5 中处理两条评审意见。
本地验证全部通过,包括受影响工作区的完整测试、发布契约检查和安装后的 CLI 包冒烟测试。 对于 #3802 中跟踪的更广泛 finish-reason 语义统一工作,本次修复工作暂不作进一步调整。 |
930c5fc to
dad43a9
Compare
Generated-by: OpenAI Codex
dad43a9 to
da4ca95
Compare
…der-finish-merge # Conflicts: # packages/runtime/src/__tests__/model-adapter-onerror.test.ts # packages/runtime/src/model-adapter.ts
Astro-Han
left a comment
There was a problem hiding this comment.
Thanks for tightening the output-free finish recovery path. I reviewed exact head 7df72e5d through the production retry and settlement boundary; the behavior looks sound, the exact-head checks pass, and I’m approving it.
I left two non-blocking P3 simplification suggestions around the tests. The goal is to keep coverage focused on production-reachable regressions and avoid carrying test-driven state or unrelated policy. These do not block the PR, and please push back if there is provider or SDK context I missed.
AI-assisted review: Codex inspected the exact-head diff, production path, and tests; I reviewed the findings and approval decision.
| .map(({ kind, disposition }) => ({ kind, disposition })); | ||
| } | ||
|
|
||
| async function observeAdapterChunks( |
There was a problem hiding this comment.
Thanks — [P3] Could we delete this private-method harness and the two tests that depend on it (uses terminal total usage when no step-finish usage fact exists and resets step evidence without losing request-level retry safety)? Production startStream() configures streamText as a single provider step, and the SDK emits finish-step before terminal finish; these tests manufacture sequences the supported path cannot produce. They consequently pin extra step/request bookkeeping without guarding a real regression. A regression through startStream() would be more valuable and cheaper to maintain. Please push back if there is a supported producer that emits either sequence.
There was a problem hiding this comment.
Agreed. Removed the private-method harness and the two tests that manufactured unsupported stream sequences in bbac012de. The remaining coverage exercises the production-reachable startStream() path.
| const NETWORK_ERROR_FINISH_REASON = 'network-error'; | ||
| const RAW_FINISH_REASON_ALIASES = new Map<string, ModelFinishReason>([ | ||
| ['network_error', NETWORK_ERROR_FINISH_REASON], | ||
| ['sensitive', 'content-filter'], |
There was a problem hiding this comment.
Thanks — [P3] Could we leave sensitive out unless we have a concrete provider contract or sample for it? #3777 demonstrates empty stop and explicit network_error; this alias adds unrelated policy plus a test and branch to maintain. If a supported provider actually emits it, linking that evidence would resolve the concern—please push back with that context.
There was a problem hiding this comment.
Agreed. Removed the sensitive alias and its regression test in bbac012de because this PR does not have concrete evidence from a supported provider for that spelling. The exact network_error mapping remains within the demonstrated scope of this fix.
…der-finish-merge # Conflicts: # packages/runtime/src/ai-sdk-backend.ts
…der-finish-merge # Conflicts: # packages/runtime/src/ai-sdk-backend.ts
Preserve the upstream AiSdkTurn extraction and carry the existing provider-finish retry and usage settlement changes into the new turn owner. Generated-by: OpenAI Codex
me2seeks
left a comment
There was a problem hiding this comment.
Automated review (Command Code) — not an approval
The design is right: finish classification moves into the adapter (ModelFinishDisposition on the step outcome) so there is one authority instead of a per-event check, and the retry reuses the existing bounded recovery rather than adding a parallel path. The retry bounds, the usage double-count guard, the abort path and the tool-replay-not-reexecute tests all check out. Two things block or weaken it.
P2 (Should-Fix) — the branch conflicts with main, which rewrote this exact vocabulary.
main has since redesigned the same union: the outcome kinds are 'truncated' | 'failed' | 'aborted', while this PR introduces 'truncated' | 'retryable-failure' | 'terminal-failure' | 'aborted', and main carries stream_truncated where the PR carries none. git merge-tree --write-tree origin/main review-pr3777 exits 1 with content conflicts in 7 files, including model-protocol.ts, model-adapter.ts, ai-sdk-turn.ts and three of their test files.
So a rebase is not mechanical: the change must be re-expressed in the vocabulary that landed, and the interaction with the related output-free-stream fix needs re-deciding afterwards.
P3 (Nice-to-have) — the alias table does not contain the entry the discussion claims, so a content-policy stop still renders as a normal finished turn.
// packages/runtime/src/model-adapter.ts:933-935
const RAW_FINISH_REASON_ALIASES = new Map<string, ModelFinishReason>([
['network_error', NETWORK_ERROR_FINISH_REASON],
]);I probed this repository's installed SDK and the OpenAI-compatible mapper: a provider finish_reason: "sensitive" arrives with unified 'other', and chunkFinishReason returns the raw spelling — there is no 'sensitive' entry, so it settles as {kind:'completed', finishReason:'sensitive'}. Base behaves the same way, so this is not a regression, but the reply describing sensitive as mapped to content-filter is not what the code does: one map entry would make it true. Worth noting that the two finish-reason vocabularies in this file are what keep drifting; a single mapping table at chunkFinishReason is the durable fix and would cover this case for free.
P3 (Nice-to-have) — the newly added finish-event usage is unreachable in the real stream shape. The usage computed in the finish case (and the totalUsage field that carries it) is consulted only by the adapter's own fallback, which the SDK's actual start → start-step → finish-step(usage) → finish sequence never reaches, so the fallback cannot evaluate it. Its rawFinishReason is also derived from the canonicalised reason rather than the provider spelling, unlike its step-finish sibling — which would persist a Maka-invented value into the usage record. Either drop the finish-case usage and totalUsage, or, if a provider that omits per-step usage is known, add the fixture that exercises it.
P3 (Nice-to-have) — the retry gate's evidence set is now narrower than the turn's. The gates switched from the turn's observable-output check to the adapter's response-evidence check, which does not count a thinking-start that carries provider options while the turn does (emitted for redacted reasoning). Everything else is equivalent. Effect: a redacted-thinking-only stream that died becomes eligible for the plain retry and for overflow recovery where it previously was not, and the failed attempt's un-flushed empty thinking part is not cleared before the retry re-streams, so it can be flushed together with the new content. Add the thinking case to the evidence predicate, or keep the turn's check for the retry disjunct.
Review-relevant risks. model-protocol.ts is an in-process contract, not the host wire protocol, so no compatibility-epoch bump is due. No security, licensing, release or governance effect identified. A user-visible retry-policy change still warrants independent human review under CONTRIBUTING.md.
Required conclusion.
- Optimal for the actual problem? Yes in shape — the adapter owns the classification and the existing bounded recovery is reused. Not mergeable as fetched, and two pieces are not optimal (the unreachable
finishusage, and re-deriving evidence in a second vocabulary). - Production code that can be deleted? The
finish-case usage,AiSdkStreamChunk.totalUsage, and the fallback that exists for it. - Low-quality tests to delete or replace?
none identified— the negative cases (empty stop with usage stays completed; no retry after partial output; no retry after metadata-only evidence) are exactly right, as are the bounded-retry and tool-replay assertions. - Deeper refactor required? Not for this fix; the finish-reason mapping table noted above is the follow-up that stops the drift.
- Ready to merge? No — resolve the conflict with the landed vocabulary first, then re-check the retry interaction.
- Residual risks / verification gaps: I did not run the suite, so the author's red/green claims are unverified here. One interaction a maintainer should note: the recovery budget is shared per step, so landing this alongside the related output-free-stream fix yields one recovery per step for both conditions combined, not one each.
Approval boundary. This is automated review; it is not an approval. Per CONTRIBUTING.md, the merge decision requires an independent human review. No approve was submitted.
Merge current main while preserving its failed outcomes, stream_truncated diagnostics and durable retry decisions. Count redacted thinking metadata as response evidence and remove unreachable terminal finish usage. Cover shared incomplete-stream recovery budgets and retain the reviewed network_error-only alias scope. Generated-by: OpenAI Codex
|
Fixed in commit eb4e262 : ) |
me2seeks
left a comment
There was a problem hiding this comment.
Follow-up (Command Code) — verified resolved
I re-checked the head after your push.
The P2 merge blocker is fixed. The branch now merges cleanly against current main (git merge-tree reports no conflicts), so the vocabulary conflict with the landed finish-classification change is resolved rather than pending.
One thing to keep in mind for the maintainer: the incomplete-stream recovery budget is shared per step with the related output-free fix, so the two conditions compete for one recovery each step rather than each getting their own. That was in my original note and is unchanged.
Thanks. (Automated review; not an approval.)
…ment Validated build, lint, formatting, typecheck, scoped regression suites, ASF headers and protocol guard against main. The merge brings unchanged upstream files that the HEAD-relative pre-commit hook rejects; no upstream formatting or protocol declarations were rewritten. Generated-by: OpenAI Codex
me2seeks
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent operated by me2seeks make. It is not an independent human review and does not replace one.
Summary
Retries output-free provider finishes: classifyModelFinishBoundary now decides retry from per-step evidence with a carefully monotonic rule — start-step resets step evidence and usable-usage, so a PREVIOUS step's response evidence or usage can never authorize a later empty stop (the exact failure mode the comment names). isModelResponseEvidence marks request and step evidence as translated chunks stream by, ModelFinishDisposition types the decision, and the model-adapter/backend/onError tests cover the boundary. The issue (a provider that returns an empty finish with no usable output being treated as final instead of retryable) is real, and the fix is at the right layer — the protocol boundary that sees the actual stream. test lane passes.
Findings
No material findings. The monotonic-evidence design is precisely the adversarially correct one: evidence can only accumulate within a step, never leak across step boundaries to bless an empty finish.
Verdict
merge-ready — correct finish-boundary classification with cross-step contamination explicitly fenced; green CI.
Astro-Han
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.
I found no P0–P2 issue in 87070cf1f311d43fdabacdd7f3886873ef4d5f3f. Empty, unmetered stops and the exact network_error alias reach bounded recovery without consuming logical steps or replaying settled tools. Metered failures remain accounted for, while missing request usage prevents a falsely complete aggregate.
Two P3 cleanups remain:
packages/runtime/src/model-protocol.ts:423:hasResponseEvidenceand its request-wide accumulator no longer have a production consumer. The outcome documentation still claims this fact controls retry safety, but Backend uses its own tool-activity and replay-barrier gates. Remove the unused request-level fact or explain and provide its intended consumer; keep the step-local evidence needed to classify empty stops.- The PR description says empty stops and truncated streams share one recovery per logical step and that adapter response evidence governs Backend side effects. The current integrated retry policy permits up to 10 physical requests (nine retries) per step and does not read that outcome field. Update those claims to match the submitted code; this does not require restoring the obsolete one-retry policy.
The earlier finish-vocabulary conflict, redacted thinking-start evidence omission, and unreachable terminal-usage fallback are resolved. Removing sensitive follows the earlier human review rather than introducing a new missing-alias finding.
Validation: all three complete Adapter/Backend test files passed 308/308 at the exact head. Removing empty-stop classification failed two of three selected cases; removing the network alias failed all eight selected cases. After restoring both mutations, the full 308 tests passed again. A clean local merge with main 685d3ab243fd9a91c774956db6018129040ae667 passed fresh dependency installation, four-package forced compilation and 326/326 tests. All seven changed files passed Biome and the net diff passed whitespace checks.
This changes an internal model outcome, not the Host wire contract; it does not require a protocol-epoch change. The exact-head hosted test check is successful, GitHub reports MERGEABLE, and the local merge is conflict-free. I did not reproduce the intermittent response against a live provider or validate unrelated Host lifecycle behavior.
Astro-Han
left a comment
There was a problem hiding this comment.
Approved at @Astro-Han's explicit request: the automated review of this exact head found no blocking (P0–P2) issues, and CI is green.
Summary
stopwith unavailable usage as an incomplete provider response, recover through the existing bounded path, and reportstream_truncatedif recovery is exhausted. Fixes Runtime treats output-free provider finish frames as successful completion #3772.network_errorat the adapter boundary and use the existing network retry policy.Verification
build:test, production build, lint, formatting, workspace typechecks, Desktop/UI Knip, architecture, ASF headers and locale hygiene pass.--test-concurrency=1Host caveat: two default-concurrency runs were not green: one hit the managed-activation idle-exit deadline; the next passed that case but hit launcher-crash retirement and owned-candidate successor deadlines. An isolated activation run and the complete serial suite passed without changing assertions or timeouts. These lifecycle tests do not issue model requests, but their default-concurrency instability remains unverified by this fix; hosted CI must still pass.
Merge-hook note: the stdin formatter rewrites an unchanged control-character test fixture inherited from main, and an inherited patch has a required blank context line. Those upstream bytes were preserved. Net-PR Biome/whitespace, staged ASF headers and the final-tree epoch check against main passed explicitly before a one-shot merge-commit hook bypass; hook configuration was not changed.
No live OpenRouter/Ox Alpha reproduction was attempted: the empty finish is provider-controlled and intermittent. Deterministic fixtures run through the real SDK
startStream()path. Linux sandbox and Docker live Eval egress require remote CI; Docker/Podman is unavailable on this macOS arm64 host.Review focus
11b93d111, retaining itsfailedoutcome andstream_truncateddiagnostics, including durable retry decisions.thinking-startmetadata counts as response evidence, preventing unsafe plain retries and overflow recovery.finishusage fallback andAiSdkStreamChunk.totalUsage; real step/outcome metering remains.sensitivealias was deliberately removed following the earlier review. It remains outside this demonstrated fix; the older reply claiming it was present does not describe the current code.AI use
Tool(s) and scope: OpenAI Codex assisted with diagnosis, implementation, regression tests, conflict resolution, local verification and this description. The human contributor retains responsibility for the submission, its accuracy, provenance and licensing. Automated validation does not replace independent human review.
Checklist
Does this PR entail a change in behavior?