Skip to content

Swift: every published failure is an AgentsError - #2798

Merged
martinmitrevski merged 4 commits into
mainfrom
fix/swift-one-failure-type
Dec 1, 2026
Merged

martinmitrevski merged 4 commits into
mainfrom
fix/swift-one-failure-type

Conversation

@martinmitrevski

@martinmitrevski martinmitrevski commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The SDK published failure with three types: AgentsError? on AgentSession, String? on Conversation and (any Error)? on VoiceSession. An app showing why something went wrong handled each differently, and Conversation's string threw away the code the router sends beside the words (prompt_injection, invalid_image), which is what a program should branch on. From the pre-release audit of the Swift SDK.

The question was whether to build on StreamCore's ClientError instead. This keeps AgentsError: ClientError's APIError is Stream Chat and Video's error body (a numeric code, statusCode, details, moreInfo), not the router's (type and code as strings, doc_url), and its subclasses can't be switched over exhaustively.

How it works

failure on Before After
AgentSession AgentsError? unchanged
Conversation String?, the error frame's text AgentsError?: .reported(code:context:message:) (new case)
VoiceSession (any Error)? AgentsError?: Stream Video's, the microphone's and the camera's errors as .transport, the SDK's own as they were, a cancellation never
error frame {"type":"error","context":"llm","code":"prompt_injection","error":"policy: ..."}
-> Conversation.failure = .reported(code: "prompt_injection", context: "llm", message: "policy: ...")
   (kept as a Hashable code and message inside, so Conversation stays Hashable)
  • Conversation.failure is now read-only.
  • .transport reads "could not get through" rather than "could not reach the router", since on a voice session it now also carries what Stream Video, the microphone or the camera failed with; its doc and the skill's rule say so.
  • AgentsError(reporting:) is the one mapping, moved from AgentSession's private helper: a cancellation is no failure, the SDK's own errors keep their case, anything else is .transport. VoiceSession's join, mute and camera paths and AgentSession's socket all use it.
  • swift_assistant's AgentChat shows failure?.localizedDescription.
  • The sdk-swift skill says every failure is an AgentsError, and why not ClientError.
  • .claude/skills/sdk/notes/2026-11-30-one-failure-type.md says where Kotlin and Dart have the same three shapes.

Validation

Test Catches
ConversationTests/aRefusedReplyLosesWhatItWroteBeforeTheVerdictAndKeepsHowItGotThere (now checks the case) a reported failure that loses its code; checked by mutation
ConversationTests/aReportedFailureIsKeptRatherThanThrown (now checks the case) an error frame with no code read as having one
VoiceSessionTests/aJoinTheSDKCannotMakeSaysHowToSetItUp (new) the SDK's own .configuration buried in a .transport; checked by mutation
VoiceSessionTests/aJoinWhileOneIsUnderWayReturnsAtOnce, aJoinThatFailedCanBeTriedAgain (now check the case) a refused token for the video client not kept inside .transport
BackendTests/aCancellationIsNoFailureAndTheSDKsOwnAreNotWrapped (new) a cancellation reported as a failure; an SDK error wrapped
  • Full suite on the iPhone 16 Pro simulator (iOS 18.1), with CI's flags: 249 tests, all pass. One run had detachingClosesTheSocketAndLeavesTheSessionRunning time out on its close frame; it passed alone and in the next full run. That is the known flaky socket-close test, which this PR doesn't touch.
  • swift_demo and swift_assistant build for the simulator. Not run.

Self-review (a fresh read of the diff) changed three things:

  • VoiceSession's mute and camera paths could have stored a CancellationError as .transport; they now share AgentsError(reporting:).
  • .reported keeps the frame's context, the only field a program could branch on for a failure that isn't a refusal.
  • .transport's docs no longer say it is only the network.

It also fixed the note's citations and the test's labels. No test covers a real Stream Video error, since none joins a call.

Breaking:

  • Conversation.failure and VoiceSession.failure change type, and Conversation.failure is read-only.
  • AgentsError gains a case, so a switch over it needs .reported.

One line under # Unreleased → Breaking Changes.

🤖 Generated with Claude Code

Conversation.failure was the error frame's text and is now
.reported(code:message:), and VoiceSession.failure was any Error and now
wraps Stream Video's errors as .transport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@martinmitrevski
martinmitrevski force-pushed the fix/swift-one-failure-type branch from ad62613 to 05bb062 Compare November 30, 2026 17:40
…s context

VoiceSession's mute and camera paths could store a CancellationError as
a transport failure; AgentSession's mapping, which never did, is now
AgentsError(reporting:) and both use it. .reported carries the error
frame's context, and .transport says it also holds a call's failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@martinmitrevski
martinmitrevski marked this pull request as ready for review December 1, 2026 10:17
@getstream-metis

getstream-metis Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

👋 Thanks, Martin! I'm on it.

How to work with me

  • 💬 Disagree with a finding? Reply in its thread and tell me why. I'll withdraw it, or answer with evidence.
  • 🔁 Fixed it? Just push. The next round checks your fix and resolves the thread.
  • 👍 👎 Rate my findings. I learn what your team doesn't want flagged.
  • ✅ I approve once nothing blocking is left: must-fix always blocks, should-fix only in the first two rounds. CI isn't part of that; branch protection still holds the merge until it's green. On repos that require a human approval, a teammate still has to approve too.
Commands

Comment any of these on the PR:

  • /jeffery review · start a review
  • /jeffery next-round · start the next round now
  • /jeffery pause · /jeffery resume · stop or restart reviews on this PR
  • /jeffery status · where things stand
  • /jeffery help · all commands

@getstream-metis getstream-metis 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.

Round 1 · 🆕 3 new · 1 should-fix to go

Finding Where
🟡 Should Fix Kotlin SessionSocket entry is already in the changelog CHANGELOG.md:727

➡️ Round 2 started on 2255e75.

Comment thread CHANGELOG.md Resolved
- An error frame with no sentence for a person gave .reported an empty
  description, so a banner showing it was blank. It now says what the
  frame does say: "the agent reported a failure in llm (rate_limited)",
  or just the first part when it names neither.
- CHANGELOG: drop the Kotlin SessionSocket line the merge from main
  repeated (main keeps the fuller #2775 one), and say that .transport's
  description now starts "could not get through".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@getstream-metis getstream-metis 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.

Round 2 · ✅ 1 fixed · 🎉 Approved

Nice work, Martin! Nothing blocking is left on 2255e75d51ae. Ship it 🚀

@martinmitrevski
martinmitrevski merged commit d658cee into main Dec 1, 2026
10 of 11 checks passed
@martinmitrevski
martinmitrevski deleted the fix/swift-one-failure-type branch December 1, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant