Skip to content

Map iOS 27 typed Foundation Models errors to stable codes #20

Closed

Description

@corasan

Why

iOS 27 deprecates LanguageModelSession.GenerationError and throws new typed errors instead:

  • LanguageModelError (contextSizeExceeded(contextSize:tokenCount:), rateLimited(resetDate), guardrailViolation, refusal, unsupportedCapability, unsupportedTranscriptContent, unsupportedGenerationGuide, unsupportedLanguageOrLocale, timeout)
  • LanguageModelSession.Error (concurrentRequests, transcriptMutationWhileResponding)
  • SystemLanguageModel.Error.assetsUnavailable
  • GeneratedContent.ParsingError

HybridLanguageModelSession.mapGenerationError only matches GenerationError. On iOS 27 a guardrail violation or context overflow may fall through to the generic SESSION_RESPONSE_ERROR / SESSION_STREAMING_ERROR, and the context-overflow recovery path (catch GenerationError.exceededContextWindowSize) may never run.

Proposal

  • Map each iOS 27 error type to the existing stable codes (CONTEXT_EXCEEDED, GUARDRAIL_VIOLATION, REFUSAL, RATE_LIMITED, SESSION_BUSY, ASSETS_UNAVAILABLE, DECODING_FAILURE, UNSUPPORTED_LANGUAGE_OR_LOCALE, UNSUPPORTED_GUIDE) so JS callers see the same codes on iOS 26 and 27.
  • Add codes for the new cases: UNSUPPORTED_CAPABILITY, UNSUPPORTED_TRANSCRIPT_CONTENT, TIMEOUT.
  • Run context-overflow recovery for LanguageModelError.contextSizeExceeded too.
  • Put the iOS 27 symbols behind #if compiler(>=6.4) so the module still builds with Xcode 26. A #available check alone does not hide symbols the SDK does not declare (see apple-llm fails to compile on Xcode 26.2: countTokens uses an iOS 26.4 SDK symbol callstackincubator/ai#227).

References

  • iOS 27.1 SDK FoundationModels.swiftinterface: LanguageModelError, LanguageModelSession.Error, GenerationError deprecation messages.

Activity

  1. added
    bugSomething isn't working
    ios-27Foundation Models APIs added in iOS 27
    on Sep 23, 2026
  2. corasan commented on Oct 16, 2026

    @corasan
    CollaboratorAuthor

    Confirmed on a real device model (macOS 27, AFM 3 Core, Xcode 27 SDK). This is not a "may": the iOS 26 catch blocks never fire on OS 27.

    Trigger Thrown type on OS 27 is GenerationError
    respond with a 20k-token prompt LanguageModelError.contextSizeExceeded false
    streamResponse with the same prompt LanguageModelError false
    Second respond while the first is in flight GeneratedContent.ParsingError ("Session ended without producing a response") false
    Tool call throws LanguageModelSession.ToolCallError (unchanged) n/a

    The result was the same with a deployment target of 26.0 and of 27.0, so the runtime picks the new types no matter what the app links against. On iOS 27 today, context overflow returns SESSION_RESPONSE_ERROR, recovery never runs, and wasContextReset stays false.

  3. added a commit that references this issue on Oct 16, 2026
    4538ea6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingios-27Foundation Models APIs added in iOS 27

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions