Skip to content

fix(runtime): retry output-free unmetered stop finishes - #5849

Closed
garvit-arora wants to merge 2 commits into
apache:mainfrom
garvit-arora:fix/3772-output-free-stop-retry
Closed

garvit-arora wants to merge 2 commits into
apache:mainfrom
garvit-arora:fix/3772-output-free-stop-retry

Conversation

@garvit-arora

Copy link
Copy Markdown
Contributor

Summary

Providers can end a model step with finishReason: stop (or raw network_error) while emitting no text, reasoning, tool calls, or authoritative usage. Maka previously settled those frames as completed / end_turn, so unfinished work could appear successful.

This change tracks per-step output during stream translation and updates settleModelStepOutcome() to:

  • treat output-free, unmetered stop as retryable provider_unavailable
  • route output-free network_error through the existing network retry policy
  • preserve legitimate completions (text with missing usage, authoritative zero usage)

Fixes #3772

Happy to coordinate with @sunrioa if work is already in progress elsewhere.

Verification

npm run lint
npm run format:check
npm --workspace @maka/runtime run build
npm --workspace @maka/runtime run typecheck
npm --workspace @maka/runtime run test:dist
  • lint and format:check pass
  • @maka/runtime build, typecheck, and full test:dist suite pass (274 tests)
  • root typecheck fails locally on an unrelated @maka/eval resolution in packages/cli (pre-existing in this checkout)

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope:

Cursor — implementation and tests for runtime step settlement and backend retry coverage.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Treat output-free, unmetered provider stop frames as retryable failures
instead of successful end_turn completions, and route output-free
network_error finishes through the existing network retry policy.

Generated-by: Cursor
Co-authored-by: Cursor <[email protected]>

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed exact head 68d6d29a71f90d6f342500b0787393483b705634. The change records step output in the model adapter, retries an output-free unmetered stop as provider_unavailable, and routes an output-free network_error through network retry. It preserves an explicit zero-usage stop and adds adapter/backend regressions. One P2 boundary remains, inline, so I would not merge this head yet.

Node 24 core/storage/runtime builds passed. Twelve focused output-free/settlement tests passed. A broader two-file test run was stopped after it stalled without further output; it is not counted as a pass. Fetched-main merge-tree and git diff --check are clean. Hosted CI is action_required, so there is no current-head test result. I did not run a live provider or full Runtime suite.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

Comment thread packages/runtime/src/model-adapter.ts Outdated
return event.text.length > 0;
case 'tool-call':
case 'provider-tool-result':
case 'tool-input':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Do not treat a tool-input marker as completed step output. The SDK can emit tool-input-start before any tool-call or provider result. With {stream-start, tool-input-start, finish(stop, unavailable usage)}, the stream exposes only a tool-input marker, yet this branch sets sawStepOutput and settleModelStepOutcome() returns completed. I reproduced that on this head with providerExecuted both false and true. With no returned tool call, the Runtime takes the success path and ends the Turn without an answer, retry, or error—the failure this change is meant to prevent. Keep the marker for replay-safety accounting, but require actual text/reasoning or a completed tool call/result for successful settlement; a provider-executed partial input must fail rather than blindly retry. Please cover this terminal sequence in the adapter/backend tests.

Output-free stop settlement must not treat a bare tool-input-start marker
as completed step output. Cover the terminal tool-input + stop sequences in
adapter and backend regressions.

Generated-by: Cursor
Co-authored-by: Cursor <[email protected]>
@garvit-arora

Copy link
Copy Markdown
Contributor Author

Addressed in 7d18949: removed \ ool-input\ from \streamEventCountsAsStepOutput()\ and added adapter/backend regressions for tool-input-start + output-free \stop\ (both \providerExecuted\ false and true).

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed commit 7d18949563aca7a95349972039465534f24e700b. This update fixes the issue I reported on the previous head: a bare tool-input-start no longer counts as completed step output (packages/runtime/src/model-adapter.ts:710-720), so an unmetered, output-free stop fails rather than silently completing an empty turn. The new adapter cases cover client and provider-executed markers (packages/runtime/src/__tests__/model-adapter-onerror.test.ts:486-507); backend cases verify retry/recovery for the client marker and refusal to retry after provider-side effects (packages/runtime/src/__tests__/ai-sdk-backend.test.ts:8877-8977). I found no new substantiated P0–P3 issue in this increment and the previously reported P2 is resolved on this head.

The Runtime build and 15 focused output-free/retry tests passed locally. A broader two-file test run did not complete: 172 tests passed, then one backend file was cancelled with a pending-promise diagnostic, so I do not count it as a full-suite pass. No hosted checks are currently attached to this head. The branch merges cleanly with current main; I did not test a live provider or the complete Runtime suite. This is not merge approval.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@github-actions github-actions Bot added effort/L Under 1000 readable lines and removed effort/M Under 500 readable lines labels Sep 30, 2026
@garvit-arora

Copy link
Copy Markdown
Contributor Author

Closing as superseded by merged #3777, which resolves #3772 and covers the output-free stop and raw network_error paths. Thanks to everyone who reviewed this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/L Under 1000 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime treats output-free provider finish frames as successful completion

2 participants