Repository navigation
Studio: Show an error when Anthropic fails a reply partway through - #10811
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4a2756ce9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| yield { | ||
| content: partialContent, |
There was a problem hiding this comment.
Restrict empty interrupted turns to started streams
When any request fails before producing a chunk—for example, streamChatCompletions receives a non-200 response for an invalid API key, unavailable model, or oversized prompt—this unconditional yield now persists an empty assistant message marked interrupted and offers Continue even though generation never started. This changes every provider and preflight failure merely to preserve Anthropic's streamed error case; retain the prior nonempty guard for ordinary early failures and use a dedicated signal for the Anthropic error event that needs an empty persisted turn.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping this as is. Continue is only offered when the partial has text (resumable requires partial.trim() in thread.tsx), so a turn that fails before any output shows the error with Retry, not Continue. Saving it as interrupted also matches server-managed runs, which already mark any failed run interrupted whatever its content, and it is what keeps the failure visible after a reload.
Review + GitHub Actions UI evidencePinned review: Codex round on
Real Studio flow on GitHub Actions (ubuntu-latest, Chromium, 1280×820) on fresh upstream
Other reds: Minor, not blocking: after a reload the error box keeps Retry but its text becomes the generic "An error occurred", because the provider's message is not saved. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76993d58ea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| yield _error_sse_line( | ||
| _ANTHROPIC_ERROR_STATUS.get(error_type, 502), | ||
| _json.dumps(event), | ||
| self.provider_type, | ||
| ) |
There was a problem hiding this comment.
Stop the Studio tool loop after relaying an Anthropic error
When Studio tools are enabled, this error frame passes through stream_with_studio_tools, which relays payloads without choices but does not mark the provider turn as failed. After Anthropic's generator closes, the loop can therefore execute a completed local tool call collected before the error, or nudge a short partial response and open another billed provider request; durable chat generation drains that entire stream, so client disconnect does not stop this behavior. Treat this frame as terminal inside the tool loop rather than merely yielding it—the new test calls _stream_anthropic directly and does not cover the public tool-loop path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
An Anthropic connection never reaches stream_with_studio_tools. The route only opens the loop when provider_model_runs_local_tools(provider_type, model) is true, and that returns False for anthropic because its registry entry has no studio_tools flag (every other provider sets it). providers.py documents why: _stream_anthropic never forwards function-tool schemas, so there are no local tool calls to collect or run, and no Studio nudge turn on this path. This error frame goes straight to the chat stream.
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Confirmed the Anthropic stream loop in studio/backend/core/inference/external_provider.py handles no error event today, so a mid-stream overload ends the reply as if it finished, and the status mapping now keeps a rate limit at 429 for the research backoff. Will get this reviewed. |
An in-stream error whose type is not a string (a list or a dict, from a gateway standing in for Anthropic) raised TypeError out of _stream_anthropic on the dict lookup. The route's catch-all turned that into "An internal error occurred" with type server_error, so the provider's own message was lost and the status Deep Research backs off on never arrived. Non-string types now fall back to 502 like any unknown type. Also adds conflict_error 409, the one type in the repo's own ANTHROPIC_TYPE_BY_STATUS that the streamed map did not name.
3b6ffb5 to
1bef48b
Compare
|
@codex security review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Reviewed this end to end and pushed two fixes onto the branch. The change is correct and I am happy with it. The defect is real, not theoreticalI reverted only the two production hunks in a worktree and re-ran the PR's tests against that tree: all six fail on the merge base and pass on head. Anthropic's docs confirm the wire shape the branch handles, Two fixes pushed
Both fixes have regression tests that fail on What I checked beyond the diff
On the two items I marked downThe tool loop one does not apply: Two follow ups, neither blocking
PlatformsThe per OS staging jobs pass on ubuntu-latest, macos-15 and windows-latest. There is no hardware path here: the diff contains no device, CUDA, ROCm or torch code, and the changed frontend region touches no browser API, so there is nothing for a GPU vendor or a browser engine to vary. No dependency, schema or migration changes, and |
…ai#10365 conflicts) unslothai#10365 landed on main after this branch forked from the shared dev base, so its reviewed durable-turns code collided with the copy carried here. Resolved per file: - backend state/tool_approvals.py, tests/test_tool_approvals.py and tests/studio/test_desktop_reliability_frontend_contract.py: take main's reviewed version (this PR has no unique work in them). - core/inference/chat_generation_runs.py: take main's reviewed park/lease logic. - routes/chat_generation_runs.py, durable-gate.ts, durable-gate.test.ts and test_multi_chat_prompt_queue_contract.py: keep THIS PR's media-turns work - UNSLOTH_STUDIO_DURABLE_MEDIA_TURNS toggle (default on), media removed from the frontend gate, and the matching "media turns are durable" assertions. - chat-adapter.ts: keep shapeToolResult shaper + media-durable gate args; take main for import formatting and the partial-yield block (unslothai#10811 removed that guard); drop the duplicate local isMcpImageToolResult (imported from utils/tool-result-shape). - runtime-provider.tsx: keep this PR's self-consistent recovery impl. - generation-tool-recovery.test.ts: union the mock store stubs. REVIEW NOTE: main's media-refusal branch also detects input-audio / embedded-image / video inside messages[] (added after this branch forked); this branch's toggle-off refusal only checks top-level _MEDIA_FIELDS. Decide whether to fold those in. Follow-ups before landing: tsc -b + npm test; backend test_chat_generation_runs + test_tool_approvals; reconcile the shared replay files with unslothai#10910 (keep unslothai#10910's).

When Anthropic failed a reply after it had started, for example with an overloaded error, Studio saved the partial answer as if it had finished. There was no error and no way to continue it. If the failure came before any text, the reply was left blank. Anthropic sends these failures inside the reply stream, and Studio ignored that message and ended the reply normally.
Now Studio passes the error on to the chat, the same way it already does for OpenAI replies. The chat shows the error with a Retry button, and the partial answer is marked as interrupted so it can be continued. A reply that fails before any text is also saved as interrupted, so the error is still there after a page reload.
Replies that finish normally are unchanged. Tested in the Studio chat with a stand-in Anthropic server that fails partway through. Before, the half answer was saved as complete. After, the error, Retry, and Continue are shown, and they stay after a reload.
Before / after in Studio
Both sides are a full
install.sh --localbuild, BEFORE from this PR's merge base8ee07d6aeand AFTER from7b9be3578, each pointed at the same stand-in Anthropic Messages API that streamsThe three causes areand then the documented in-stream frame{"type": "error", "error": {"type": "overloaded_error", "message": "Overloaded"}}. No key is used and no request leaves the machine. Each side recorded exactly onePOST /v1/messages, so both builds saw identical bytes.Live, once the turn settles. BEFORE saves the half answer as a finished turn: no error, no Retry, no Continue. AFTER shows
Overloaded (overloaded_error)with Retry, theResponse interrupted. Continuebar, and a Generation failed toast.After a full page reload, reopening the thread from Recents. BEFORE is still a finished turn. AFTER still carries the error box, Retry and Continue; its message falls back to the generic
An error occurred, because the provider's own text is not persisted.