Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(python): persist usage_info on session create/resume and update v…
…ia events
  • Loading branch information
Coderxrohan committed Feb 4, 2026
commit 1738727b6250b7fa5a6848c6eb7190ec9e0b2900
5 changes: 4 additions & 1 deletion python/copilot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ async def create_session(self, config: Optional[SessionConfig] = None) -> Copilo
session_id = response["sessionId"]
workspace_path = response.get("workspacePath")
session = CopilotSession(session_id, self._client, workspace_path)
usage_info = response.get("usageInfo")
if usage_info:
session.usage_info = usage_info
session._register_tools(tools)
if on_permission_request:
session._register_permission_handler(on_permission_request)
Expand Down Expand Up @@ -634,7 +637,7 @@ async def resume_session(
resumed_session_id = response["sessionId"]
workspace_path = response.get("workspacePath")
session = CopilotSession(resumed_session_id, self._client, workspace_path)
usage_info = response.get("usageInfo") or response.get("usage_info")
usage_info = response.get("usageInfo")
if usage_info:
session.usage_info = usage_info
session._register_tools(cfg.get("tools"))
Expand Down
4 changes: 4 additions & 0 deletions python/copilot/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(self, session_id: str, client: Any, workspace_path: Optional[str] =
self._user_input_handler_lock = threading.Lock()
self._hooks: Optional[SessionHooks] = None
self._hooks_lock = threading.Lock()
self.usage_info = None

@property
def workspace_path(self) -> Optional[str]:
Expand Down Expand Up @@ -232,6 +233,9 @@ def _dispatch_event(self, event: SessionEvent) -> None:
Args:
event: The session event to dispatch to all handlers.
"""
if hasattr(event, "usage_info") and event.usage_info:
self.usage_info = event.usage_info

with self._event_handlers_lock:
handlers = list(self._event_handlers)

Expand Down