Skip to content

Commit 45a3964

Browse files
patnikoCopilot
andcommitted
fix: gracefully handle unknown event types in Python SDK
The v3 server broadcasts new event types like permission.completed that the generated session_events.py can't deserialize yet. Wrap session_event_from_dict in try/except so unknown events are silently skipped instead of crashing the notification handler. This affects both the stdio and TCP connection handlers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 27d05f1 commit 45a3964

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

python/copilot/client.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,11 +1348,14 @@ def handle_notification(method: str, params: dict):
13481348
if method == "session.event":
13491349
session_id = params["sessionId"]
13501350
event_dict = params["event"]
1351-
# Convert dict to SessionEvent object
1352-
event = session_event_from_dict(event_dict)
1351+
# Convert dict to SessionEvent object (skip unknown event types)
1352+
try:
1353+
event = session_event_from_dict(event_dict)
1354+
except Exception:
1355+
event = None
13531356
with self._sessions_lock:
13541357
session = self._sessions.get(session_id)
1355-
if session:
1358+
if session and event:
13561359
session._dispatch_event(event)
13571360

13581361
# v3 protocol: intercept tool/permission broadcast events
@@ -1442,10 +1445,13 @@ def handle_notification(method: str, params: dict):
14421445
if method == "session.event":
14431446
session_id = params["sessionId"]
14441447
event_dict = params["event"]
1445-
# Convert dict to SessionEvent object
1446-
event = session_event_from_dict(event_dict)
1448+
# Convert dict to SessionEvent object (skip unknown event types)
1449+
try:
1450+
event = session_event_from_dict(event_dict)
1451+
except Exception:
1452+
event = None
14471453
session = self._sessions.get(session_id)
1448-
if session:
1454+
if session and event:
14491455
session._dispatch_event(event)
14501456

14511457
# v3 protocol: intercept tool/permission broadcast events

0 commit comments

Comments
 (0)