Skip to content

Conversation

@SilentDemonSD
Copy link

About-face 

This PR fixes critical Python SDK bugs, updates all cookbook examples to use proper async patterns, implements missing session management methods, and ensures full Python 3.8-3.14 compatibility.

Issues Fixed

Key Changes

1. SDK Enhancements (python/copilot/)

  • Implemented list_sessions() - Returns List[SessionMetadata] with session details (ID, creation time, modification time, summary)
  • Implemented delete_session(session_id) - Permanently deletes a session and its data
  • Added SessionMetadata TypedDict - Proper type definitions for session metadata returned by list_sessions()
  • Python 3.8 compatibility - Added from __future__ import annotations to client.py
  • Updated type hints - Changed X | None to Optional[X] for Python 3.8/3.9 compatibility
  • Exported new types - Added SessionMetadata to public API in __init__.py

2. Cookbook Recipe Fixes (All 5 files)

  • Converted to async patterns - All recipes now use asyncio.run(main()) and await properly
  • Fixed event handling - Events use .type and .event.data.content (not dict access)
  • Replaced non-existent methods - Removed wait_for_idle(), using send_and_wait() instead
  • Updated files:
    • error_handling.py - Proper exception handling with async patterns
    • managing_local_files.py - File organization with async session handling
    • multiple_sessions.py - Multi-session management examples
    • persisting_sessions.py - Session persistence with list_sessions() and delete_session() examples
    • pr_visualization.py - Fixed 60s timeout → 300s timeout for complex GitHub API operations

3. Documentation Updates

  • ✅ Updated all 5 cookbook markdown files with correct async code examples
  • ✅ Added examples for list_sessions() and delete_session() in documentation
  • ✅ Fixed pr_visualization.md with proper timeout configuration

4. Code Quality & Compatibility

  • Ruff linting - All files pass ruff checks
    • Updated pyproject.toml to ignore Python 3.8 incompatible style rules (UP045, UP007)
  • Python 3.8-3.14 support
    • Added Python 3.13 and 3.14 to package classifiers
    • Fixed e2e tests with from __future__ import annotations
    • Verified syntax compilation across all files
  • E2E Tests Updated (e2e/)
    • Added future annotations import to test_mcp_and_agents.py and test_tools.py
    • Fixed type hints for Python 3.8 compatibility
  • All unit tests pass - 15/15 tests passing on Python 3.14.2

Testing

  • python -m ruff check - All SDK and e2e files pass linting
  • python -m pytest - 15 unit tests passing
  • python -m py_compile - All source files compile successfully
  • Cookbook recipes tested with python managing_local_files.py, etc.
  • Verified on Python 3.8+ through 3.14

Files Modified

python/copilot/client.py                  # Added list_sessions/delete_session
python/copilot/types.py                   # Added SessionMetadata
python/copilot/__init__.py                # Exported SessionMetadata
python/pyproject.toml                     # Updated ruff config, added Py3.13/14
python/e2e/test_mcp_and_agents.py        # Added future annotations
python/e2e/test_tools.py                  # Added future annotations
cookbook/python/recipe/error_handling.py
cookbook/python/recipe/managing_local_files.py
cookbook/python/recipe/multiple_sessions.py
cookbook/python/recipe/persisting_sessions.py
cookbook/python/recipe/pr_visualization.py
cookbook/python/*.md                      # Updated all documentation

Breaking Changes

None - All changes are backward compatible.

Benefits

Developers can now:

  • List all available sessions with await client.list_sessions()
  • Delete sessions programmatically with await client.delete_session(session_id)
  • Use all cookbook examples as-is (properly async)
  • Develop on Python 3.8 through 3.14 without compatibility issues

Checklist

  • All unit tests pass
  • Ruff linting passes
  • Cookbook examples tested and working
  • Python 3.8-3.14 compatibility verified (manually)
  • Documentation updated
  • No breaking changes

This Summary is created by Copilot Review and Manually Reviewed Properly.

@SilentDemonSD SilentDemonSD requested a review from a team as a code owner January 23, 2026 12:59
Copilot AI review requested due to automatic review settings January 23, 2026 12:59
@SilentDemonSD SilentDemonSD changed the title refactor(pyhon): update Python Cookbook to Async, add missing methods & Py Bug Fixes (fixes #130, #129, #118) refactor(python): update Python Cookbook to Async, add missing methods & Py Bug Fixes (fixes #130, #129, #118) Jan 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR comprehensively refactors the Python SDK to use async patterns, implements missing session management methods (list_sessions() and delete_session()), and fixes Python 3.8 compatibility issues. The changes address three GitHub issues (#130, #129, #118) that reported broken cookbook examples, missing SDK methods, and Python 3.8 syntax errors.

Changes:

  • Added list_sessions() and delete_session() methods to the CopilotClient with proper async patterns and camelCase-to-snake_case conversion
  • Fixed Python 3.8 compatibility by adding from __future__ import annotations to client.py and e2e test files
  • Converted all 5 cookbook recipes from synchronous to async patterns with proper asyncio.run(), await, and event handling
  • Updated ruff configuration to ignore Python 3.8-incompatible style rules

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
python/pyproject.toml Added Python 3.13/3.14 classifiers, configured ruff to ignore Python 3.8-incompatible rules
python/copilot/types.py Added SessionMetadata TypedDict, changed type hints to Optional[X] for compatibility
python/copilot/client.py Added future annotations import, implemented list_sessions() and delete_session() methods
python/copilot/init.py Exported SessionMetadata type in public API
python/e2e/test_tools.py Added future annotations import for Python 3.8 compatibility
python/e2e/test_mcp_and_agents.py Added future annotations import for Python 3.8 compatibility
cookbook/python/recipe/requirements.txt Fixed SDK path from ../.. to ../../../python
cookbook/python/recipe/pr_visualization.py Converted to async with proper event handling and 300s timeout
cookbook/python/recipe/persisting_sessions.py Converted to async, added list_sessions() and delete_session() examples
cookbook/python/recipe/multiple_sessions.py Converted to async with send_and_wait()
cookbook/python/recipe/managing_local_files.py Converted to async with proper event attribute access
cookbook/python/recipe/error_handling.py Converted to async error handling patterns
cookbook/python/recipe/README.md Updated documentation with async patterns and corrected SDK path
cookbook/python/pr-visualization.md Updated documentation to match async code examples
cookbook/python/persisting-sessions.md Added examples for new list_sessions() and delete_session() methods
cookbook/python/multiple-sessions.md Updated to show async patterns and new session management methods
cookbook/python/managing-local-files.md Updated to show async patterns with proper event handling
cookbook/python/error-handling.md Comprehensive async error handling documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

client.start()
# Create Copilot client
client = CopilotClient({"log_level": "error"})
await client.start()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was working quite similar changes on my local workarea to get this example run. Looks good & approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python SDK client class don't have list_sessions() method Released 01-22-2026 issues setup on windows 11. client.py

2 participants