fix(listen/v2): allow extra fields on TurnInfo models (5.3.x)#736
Merged
Conversation
Flux (flux-general-en) now returns additional per-word fields `start` and `end` (type double) on every word in a `TurnInfo` message — see the Flux API reference. The 5.3.x socket models declare only `word`/`confidence` with `extra = "forbid"`, so each TurnInfo frame fails pydantic validation in `listen/v2/socket_client.py` (`parse_obj_as(V2SocketClientResponse, ...)`). On 5.3.0 this raises an uncaught ValidationError that tears down `start_listening()` (it only catches WebSocketException/JSONDecodeError); on 5.3.2/5.3.3 (construct_type) the frame is silently mis-resolved to `ListenV2ConnectedEvent`, dropping the transcript and words. Relax `extra` to "allow" on `ListenV2TurnInfoEventWordsItem` and `ListenV2TurnInfoEvent` so unknown additive fields are tolerated (and retained), matching the `extra="allow"` posture already shipped on main (6.x/7.x). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dg-coreylweathers
added a commit
that referenced
this pull request
Jun 26, 2026
Maintenance release of the 5.3.x line. Bumps the version `5.3.3` → `5.3.4` (manifest, `pyproject.toml`, `client_wrapper.py` SDK header) and adds the CHANGELOG entry for #736. ### Included - #736 — fix(listen/v2): allow extra fields on Flux `TurnInfo` models (`extra="forbid"` → `"allow"`), preventing the crash (5.3.0) / silent transcript drop (5.3.2/5.3.3) when Flux emits per-word `start`/`end`. ### Release mechanism After this merges, pushing tag `v5.3.4` triggers `.github/workflows/maintenance-release.yml`, which compiles, tests, builds, and publishes to PyPI. A GitHub Release will be created with `--latest=false` so `7.3.1` keeps the repo "Latest" badge. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Corey Weathers <coreyweathers@coreys-mbp.mynetworksettings.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
The v2 listen (Flux)
TurnInfomessage can include additional per-word fieldsstartandend(typedouble) beyond theword/confidencethe 5.3.x models declare. This was observed intermittently against the live API (roughly 1 in 6 connections in testing); I have not confirmed the full server-side rollout scope.The model
ListenV2TurnInfoEventWordsItemdeclares onlyword+confidencewithextra = "forbid", so any frame carrying extra fields fails pydantic validation inlisten/v2/socket_client.py(parse_obj_as(V2SocketClientResponse, ...)).Observed impact on the released 5.3.x line:
ValidationErrorpropagates out ofstart_listening()(which only catchesWebSocketException/JSONDecodeError) and tears down the listen loop; it never reaches theEventType.ERRORhandler.construct_typedoesn't raise, but the strict word model still fails the union's validated pass, so the frame is silently mis-resolved toListenV2ConnectedEvent— transcript and words dropped, no error (silent data loss).Fix
Relax
extrafrom"forbid"to"allow"onListenV2TurnInfoEventWordsItemandListenV2TurnInfoEvent, so unknown additive fields are tolerated and retained. Model-agnostic — it doesn't assume which model or which fields. Verified: a frame withstart/endthen parses asListenV2TurnInfoEventwith the fields preserved.class Config: frozen = True - extra = "forbid" + extra = "allow"(applied to both models in the file)
Safety / side-effect analysis
extra="allow"only stores unknown JSON values as data attributes (__pydantic_extra__); it does not eval/import/instantiate types. Not pickle/YAML-style gadget deserialization. Inbound data also comes from the Deepgram API over TLS, not arbitrary user input.V2SocketClientResponse = Union[Connected, TurnInfo, FatalError].TurnInfohas required fields thatConnected/FatalErrorlack, and those two keepextra="forbid", so a permissiveTurnInfocannot greedily capture them. Verified:Connected→ListenV2ConnectedEvent,Error→ListenV2FatalErrorEvent,TurnInfo+start/end→ListenV2TurnInfoEvent.TurnInfoframe missing a required field (e.g.transcript) still raisesValidationError. Only unknown additive fields are now tolerated.json.loadsalready materializes the full payload before pydantic runs;allowjust retains references (bounded by message size).main's posture.allowvsignoreallow(chosen): tolerates and exposes the new fields, so callers can readword.start/word.end. Matchesmain(6.x/7.x).ignore: also fixes the crash/mis-typing but discards extras — more conservative (nothing unvalidated retained or re-serialized), at the cost of the timestamps being unavailable.Happy to switch to
ignoreif the team prefers minimal surface.Notes for reviewers
main(6.x/7.x) already shipsextra="allow"on the equivalent model, so this only affects the released 5.3.x line — hence targetingv5.# auto-generated by Fern from our API Definition); ifv5is regenerated the proper fix belongs in the API definition. This is a direct patch on the frozen maintenance branch.🤖 Generated with Claude Code