Repository navigation
fix(ios): map iOS 27 typed errors to stable codes - #34
Merged
Merged
Conversation
iOS 27 traps apps that do not adopt the scene lifecycle. Enable expo-build-properties enableSceneSupport and update Expo to the SDK 57 patch that ships EXExpoAppSceneDelegate.
iOS 27 throws LanguageModelError, LanguageModelSession.Error, SystemLanguageModel.Error and GeneratedContent.ParsingError instead of the deprecated GenerationError. These fell through to the generic SESSION_RESPONSE_ERROR and SESSION_STREAMING_ERROR codes, and context overflow never ran recovery. Map every family in one AppleAIError initializer so respond and streamResponse share one catch. Add UNSUPPORTED_CAPABILITY, UNSUPPORTED_TRANSCRIPT_CONTENT and TIMEOUT. Guard iOS 27 symbols with Closes #20
…n model overflow Restores two behaviors from #40: TRANSCRIPT_MUTATION_WHILE_RESPONDING is its own code instead of SESSION_BUSY, and a passed-through AppleAIError.contextExceeded no longer resets the session. Tests now check every iOS 26 GenerationError against a literal code on every host and cover ToolCallError.
corasan
force-pushed
the
fm27/typed-errors
branch
from
October 16, 2026 23:04
1b4314c to
aa8a3ae
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.
Relation to #40
#40 landed a smaller fix for the same issue on main. This PR is rebased onto it and replaces
FoundationModelsErrorMapping.swiftwithGenerationFailure.swift, which the rest of the stack builds on. It keeps #40's distinctTRANSCRIPT_MUTATION_WHILE_RESPONDINGcode, its rule that only a model overflow triggers recovery, and its literal-code andToolCallErrortest coverage.Why
iOS 27 deprecates
LanguageModelSession.GenerationError. It throwsLanguageModelError,LanguageModelSession.Error,SystemLanguageModel.Error, andGeneratedContent.ParsingErrorinstead. The session mapped onlyGenerationError, so on iOS 27 these errors got the genericSESSION_RESPONSE_ERRORorSESSION_STREAMING_ERRORcode. Context-overflow recovery also did not run.I reproduced this on main on the iOS 27.0 simulator. A prompt larger than the 4096-token context rejected with
SESSION_RESPONSE_ERROR("The session's transcript exceeded the model's context size."), andwasContextResetstayedfalse.Scope
package/ios/GenerationFailure.swiftaddsAppleAIError(generationFailure:during:). It is the one place that turns any thrown error into anAppleAIError. It has one mapping function per error family.GenerationFailureCodeenum inAppleAIErrors.swift. Each case has one summary line, and onefailedbuilder writes every message.AppleAIError.generationErrorcarries the enum, not a free string, so a typo in a code does not compile. The unusedErrorInfostruct is removed.respondandstreamResponsenow have onecatcheach. That catch calls the initializer. Context recovery runs only whenAppleAIError.requiresContextRecovery(after:)is true, which means the model itself overflowed (GenerationError.exceededContextWindowSizeorLanguageModelError.contextSizeExceeded). AnAppleAIErrorpassed through directly or inside aToolCallErrornever resets the session.CONTEXT_EXCEEDED,GUARDRAIL_VIOLATION,REFUSAL,RATE_LIMITED,SESSION_BUSY,ASSETS_UNAVAILABLE,DECODING_FAILURE,UNSUPPORTED_GUIDE,UNSUPPORTED_LANGUAGE_OR_LOCALE).UNSUPPORTED_CAPABILITY,UNSUPPORTED_TRANSCRIPT_CONTENT,TIMEOUT,TRANSCRIPT_MUTATION_WHILE_RESPONDING.#if compiler(>=6.4)and#available(iOS 27.0, *).docs/docs/api-reference.mdnow lists all error codes.enableSceneSupport, Expo SDK 57 patch update). Without this change the app traps at launch on iOS 27. The later PRs in this stack need the example app to run.errors.tsdoes not list the codes (codeis astring), so the TS layer did not need a change.Tradeoffs
rateLimited.resetDateandcontextSizeExceeded.tokenCountgo into the message text only. To send them asdetails, the Nitro error bridge must change. I kept that out of this PR.Blast Radius
The change touches only the error path of
respondandstreamResponse. Successful responses do not change. On iOS 26,GenerationErrorgives the same codes and messages as before. On iOS 27, callers that matched onSESSION_RESPONSE_ERROR/SESSION_STREAMING_ERRORfor these failures now get the specific codes. The example app dependency update affects onlyexample/.Verification
bun run test(35 pass),bun run typecheck,bun run lint, andbun run format:checkpass.bun run test:swiftpasses. It includes the newGenerationFailureTests. The tests check that each iOS 27 error gets the same code as its deprecated iOS 26 equivalent, that both overflow errors produce.contextExceeded, and that unmapped errors fall back to the correct code for each operation. A mutation that drops theParsingErrormapping makes the tests fail.#elsebranch on the host (I set the guard to an impossible compiler version), and its tests pass. I did not build with Xcode 26, because it is not installed.checkFoundationModelsAvailability()givesavailable):respondrejects withCONTEXT_EXCEEDED, andwasContextResetistrue. Before this change it wasSESSION_RESPONSE_ERROR/false.streamResponserejects withCONTEXT_EXCEEDED, andwasContextResetistrue. Before this change it wasSESSION_STREAMING_ERROR/false.Closes #20