fix(dotnet): handle unknown session event types gracefully#881
fix(dotnet): handle unknown session event types gracefully#881Ron537 wants to merge 2 commits intogithub:mainfrom
Conversation
Add UnknownSessionEvent type and TryFromJson method so that unrecognized event types from newer CLI versions do not crash GetMessagesAsync or real-time event dispatch.
|
Thanks for proposing this, @Ron537! I was chatting with @stephentoub and, while we definitely agree that we need to add forward-compatibility with unknown event types, we suspect a preferred solution is to use We don't think it's desirable to add a general |
|
Thanks @SteveSandersonMS & @stephentoub ! Great suggestion — I've updated the PR to use Changes are now entirely in the codegen ( |
Summary
When the Copilot CLI introduces new session event types before the SDK is updated,
SessionEvent.FromJson()throws aJsonException(due toFailSerializationpolicy),breaking both
GetMessagesAsyncand real-time event dispatch.Fixes #880
Changes
UnknownSessionEvent— concrete fallback type preservingRawTypeandRawJsonSessionEvent.TryFromJson— public partial method that returnsUnknownSessionEventinstead of throwing, with warning loggingGetMessagesAsync— usesTryFromJsonso unknown events don't fail the entire historyOnSessionEvent— usesTryFromJsonso unknown real-time events don't crash the RPC handlerApproach
Follows the Python SDK pattern (
SessionEventType.UNKNOWN+_missing_()) — unknown events are handled gracefully by default with no opt-in parameter needed.No generated code changes required —
TryFromJsonis added via partial class extension.