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
When the Copilot CLI introduces new session event types before the SDK is updated, SessionEvent.FromJson() throws a JsonException because the generated SessionEvents.cs uses JsonUnknownDerivedTypeHandling.FailSerialization.
This breaks two call-sites:
GetMessagesAsync — the entire conversation history fails to load because .Select(e => SessionEvent.FromJson(...)) throws on the first unrecognized event.
OnSessionEvent (real-time events) — the RPC handler crashes with no try-catch,
propagating the exception into the StreamJsonRpc layer.
Expected behavior
Unknown event types should be handled gracefully. The Python SDK already does this via a SessionEventType.UNKNOWN enum value with a _missing_() fallback — no events are lost and no exceptions are thrown.
Proposed solution
Add an UnknownSessionEvent concrete type that preserves the raw JSON and type discriminator for events the SDK can't deserialize.
Add a SessionEvent.TryFromJson method (via partial class, no generated code changes) that returns UnknownSessionEvent instead of throwing.
Update GetMessagesAsync and OnSessionEvent to use TryFromJson.
Log a warning when an unknown event is encountered.
Reproduction
Occurs whenever the CLI version is ahead of the SDK version and emits a new event type. Can be reproduced by manually injecting a JSON event with an unregistered "type"
value and calling GetMessagesAsync.
Original approach: Custom UnknownSessionEvent type + TryFromJson wrapper method in runtime code.
New approach: Set IgnoreUnrecognizedTypeDiscriminators = true on the [JsonPolymorphic] attribute and make SessionEvent non-abstract. Unknown event types now deserialize as the base SessionEvent with Type = "unknown" — no custom types or runtime code changes needed.
The fix is a 3-line change in the codegen script (scripts/codegen/csharp.ts) plus the regenerated output.
Activity
Ron537 commentedon Mar 19, 2026
Original approach: Custom
UnknownSessionEventtype +TryFromJsonwrapper method in runtime code.New approach: Set
IgnoreUnrecognizedTypeDiscriminators = trueon the[JsonPolymorphic]attribute and makeSessionEventnon-abstract. Unknown event types now deserialize as the baseSessionEventwithType = "unknown"— no custom types or runtime code changes needed.The fix is a 3-line change in the codegen script (
scripts/codegen/csharp.ts) plus the regenerated output.