python: add create_cloud_session#1397
Closed
tclem wants to merge 2 commits into
Closed
Conversation
Port create_cloud_session to the Python SDK, following the Rust (PR #1394) and TypeScript (PR #1395) reference implementations. Key additions: - CopilotClient.create_cloud_session(): creates a Mission Control-backed cloud session. The runtime owns the session ID (omitting sessionId from the wire payload); the caller must not set session_id or provider. - Pending-routing infrastructure: session.event notifications and inbound JSON-RPC requests that arrive before the session is fully registered are buffered (up to _PENDING_SESSION_BUFFER_LIMIT = 128) and replayed once the session is ready. _PendingSessionRoutingGuard + _begin_pending_session_routing + _flush_pending_for_session + _resolve_session implement this. - CopilotSession.remote_url property: exposes the remoteUrl returned in the session.create response for cloud sessions. - create_session() now rejects cloud= being set; callers must use create_cloud_session() instead. - test_cloud_session.py: 7 new unit tests covering wire shape, validation, early notification buffering, and parked inbound request handling. - Updated test_client.py: test_create_session_forwards_cloud_options updated to test create_cloud_session instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Two symmetric fixes ported from Rust SDK (commits 491b442, e0ff254) and TS SDK (commit c167bc3, PR #1395): 1. Pending request buffer overflow: when _resolve_session would push the waiter list past _PENDING_SESSION_BUFFER_LIMIT (128), evict the oldest future and call set_exception(ValueError('pending session buffer overflow')). The JSON-RPC dispatch layer (_dispatch_request) catches the raised exception and sends a proper -32603 error response so the runtime doesn't hang on the request id. 2. Guard drop without registration: _PendingSessionRoutingGuard.dispose() already called set_exception on parked waiters, but used a generic message. Changed to the cross-SDK canonical message 'pending session routing ended before session was registered' so the two failure paths are distinguishable in logs and error messages. Notifications retain warn-and-drop-oldest behaviour (no response needed — they carry no id). Add two unit tests: - TestPendingRequestBufferOverflow: 129 concurrent waiters; oldest raises with the overflow message; remaining 128 resolve after registration. - TestPendingRequestGuardDropWithoutRegistration: session.create fails; parked request raises with the routing-ended message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Cross-SDK Consistency Review ✅This PR correctly ports Python ↔ Rust alignment ✅
Remaining SDK gaps
|
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports
create_cloud_sessionto the Python SDK, following the Rust and TypeScript reference implementations.What changed
python/copilot/client.pycreate_cloud_session(): new method for Mission Control–backed cloud sessions. The runtime owns the session ID sosessionIdis omitted from thesession.createwire payload; caller must not setsession_idorprovider(both raiseValueError).create_session()now rejectscloud=being set — callers must usecreate_cloud_session()instead._PendingSessionRoutingGuard,_begin_pending_session_routing(),_flush_pending_for_session(),_resolve_session()buffersession.eventnotifications and park inbound JSON-RPC requests (up to_PENDING_SESSION_BUFFER_LIMIT = 128) while a cloud session create is in flight, then replay them once the session is registered._resolve_session().python/copilot/session.pyCopilotSession.remote_urlproperty exposing theremoteUrlfrom thesession.createresponse.python/test_cloud_session.py— 7 new unit tests: wire shape,session_id/providerrejection,cloud=required, early notification buffering, parked inbound request handling.python/test_client.py— updatedtest_create_cloud_session_forwards_cloud_optionsto callcreate_cloud_sessioninstead ofcreate_session(cloud=...).python/README.md— added## Cloud Sessionssection.