Skip to content

Remove Codable conformance from GenerationOptions - #269

Open
mattt wants to merge 1 commit into
mainfrom
mattt/generation-options-not-codable
Open

mattt wants to merge 1 commit into
mainfrom
mattt/generation-options-not-codable

Conversation

@mattt

@mattt mattt commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Foundation Models declares GenerationOptions and GenerationOptions.SamplingMode as Sendable and Equatable only. AnyLanguageModel also makes both Codable, and decoding GenerationOptions drops any custom options set with options[custom:], so an encode and decode round trip doesn't give back the same value.

This PR removes Codable from GenerationOptions and SamplingMode, along with the code that encoded custom options by type name. Transcript.Prompt stays Codable and now codes its options itself. The sampling mode, temperature, and maximum response tokens use the same format as before, custom options are no longer written, and prompts encoded by earlier releases still decode.

This is source-breaking for code that encodes or decodes GenerationOptions or SamplingMode directly, or that uses them in its own synthesized Codable types. Encoded transcripts no longer include custom options such as extraBody, and an earlier release can't decode a prompt encoded by this one, because it expects a customOptionsStorage key.

Foundation Models declares GenerationOptions and its SamplingMode as
Sendable and Equatable only. AnyLanguageModel also made both Codable,
and decoding GenerationOptions dropped any custom options set for a
model, so a round trip didn't preserve the value.

Remove Codable from GenerationOptions and SamplingMode, along with the
code that encoded custom options by type name. Transcript.Prompt is
still Codable, so it now codes its options itself: the sampling mode,
temperature, and maximum response tokens use the same format as
before, and custom options are no longer written. Prompts encoded by
earlier releases still decode.

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The focused implementation preserves the documented transcript format and is adequately tested.

Review effort: Balanced
Findings: None

What changed in this PR

Removes misleading Codable conformances while preserving transcript serialization compatibility.

Changes:

  • Removes direct coding support for generation and custom options.
  • Adds transcript-specific option coding that omits custom options.
  • Adds compatibility and round-trip tests.
File Description
GenerationOptions.swift Removes conformances and adds transcript coding representation.
Transcript.swift Implements explicit prompt coding.
TranscriptTests.swift Tests encoding and backward-compatible decoding.
CustomGenerationOptionsTests.swift Removes obsolete direct-coding tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants