You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JsonPatch.TryGetValue("$.choices[0]...") throws ArgumentOutOfRangeException on empty array (regression in 2.12.0-alpha.803)Β #1281
TryGetValue on an indexed path throws when the array is empty/out-of-range, instead of returning false. Regression between 2.12.0 and 2.12.0-alpha.803. Hits streaming chat easily, since services emit empty-choices chunks (role/filter chunk + final usage chunk when include_usage=true).
System.ArgumentOutOfRangeException: Index was out of range...
at System.Collections.Generic.List`1.get_Item(Int32 index)
at OpenAI.Chat.StreamingChatCompletionUpdate.PropagateGet(...)
at System.ClientModel.Primitives.JsonPatch.TryGetEncodedValueInternal(...)
at System.ClientModel.Primitives.JsonPatch.TryGetValue(...)
Root cause
PropagateGet indexes the backing list with no bounds check (Choices[index]) β byte-identical in both versions, so the bug was latent. #1246 (TypeSpec generator bump) changed array backing from raw-JSON to typed-list+propagation:
Hi @jozkee. Thanks for reaching out and we regret that you're experiencing difficulties.
Thanks for the detailed report and repro. We reviewed this and confirmed the root cause. The generated PropagateGet method indexes the backing list directly (e.g. Choices[index]) after only validating that the JSON Pointer segment is a syntactically well-formed array index (TryGetIndex). There is no check of that index against the collection's actual length, so any indexed path against an empty or shorter than expected array throws ArgumentOutOfRangeException instead of TryGetValue returning false.
This same unguarded indexer shape is present in every generated dynamic model with an array of model property, not just StreamingChatCompletionUpdate.Choices. We also confirmed it in ChatCompletion, InternalChatCompletionMessageList, and ResponseResult (Tools, OutputItems, Instructions). Your root cause and regression analysis, the #1246 generator bump changing array serialization from raw JSON pass through to typed list propagation, matches what we found.
Because this code is generated, the durable fix needs to land in the TypeSpec C# emitter itself (BuildCollectionIfStatements in MrwSerializationTypeDefinition.Dynamic.cs, in microsoft/typespec), not as a local patch here. A local fix would be overwritten on the next generator run. We opened an upstream issue with the full technical writeup, evidence, and a suggested bounds check fix.
The initial fix was applied to the generator yesterday and will flow in early next week with our scheduled generator update. Once validated, we'll close this out as fully complete.
Activity
jsquire commentedon Aug 11, 2026
Hi @jozkee. Thanks for reaching out and we regret that you're experiencing difficulties.
Thanks for the detailed report and repro. We reviewed this and confirmed the root cause. The generated
PropagateGetmethod indexes the backing list directly (e.g.Choices[index]) after only validating that the JSON Pointer segment is a syntactically well-formed array index (TryGetIndex). There is no check of that index against the collection's actual length, so any indexed path against an empty or shorter than expected array throwsArgumentOutOfRangeExceptioninstead ofTryGetValuereturningfalse.This same unguarded indexer shape is present in every generated dynamic model with an array of model property, not just
StreamingChatCompletionUpdate.Choices. We also confirmed it inChatCompletion,InternalChatCompletionMessageList, andResponseResult(Tools,OutputItems,Instructions). Your root cause and regression analysis, the #1246 generator bump changing array serialization from raw JSON pass through to typed list propagation, matches what we found.Because this code is generated, the durable fix needs to land in the TypeSpec C# emitter itself (
BuildCollectionIfStatementsinMrwSerializationTypeDefinition.Dynamic.cs, inmicrosoft/typespec), not as a local patch here. A local fix would be overwritten on the next generator run. We opened an upstream issue with the full technical writeup, evidence, and a suggested bounds check fix.microsoft/typespec#11616
We will track that issue and pull in the generator update here once it is fixed upstream.
π€ jsquire-copilot
jsquire commentedon Aug 13, 2026
The initial fix was applied to the generator yesterday and will flow in early next week with our scheduled generator update. Once validated, we'll close this out as fully complete.
chore: align Server's OpenAI package version with ClientWin (2.12.0)
MaiLinhP commentedon Sep 9, 2026
The generator fix has been applied through the generator upgrade and validated!