Add get_last_session_id() to Python and Go SDKs#671
Conversation
Co-authored-by: patniko <26906478+patniko@users.noreply.github.com>
get_last_session_id() to Python and Go SDKs
There was a problem hiding this comment.
Pull request overview
Adds parity across SDKs by exposing “last updated session id” retrieval in the Python and Go clients (matching existing TS/.NET behavior) and validates via E2E snapshots.
Changes:
- Python: add
CopilotClient.get_last_session_id()that callssession.getLastId. - Go: add
(*Client).GetLastSessionID(...)plus request/response types forsession.getLastId. - Tests/docs: add shared E2E snapshot + language-specific E2E coverage; update Go README API list.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
test/snapshots/session/should_get_last_session_id.yaml |
Snapshot exchange for the new “Say hello” session persistence scenario. |
python/e2e/test_session.py |
Adds Python E2E verifying get_last_session_id() returns the created session ID. |
python/copilot/client.py |
Implements get_last_session_id() via JSON-RPC session.getLastId. |
go/types.go |
Adds internal request/response structs for session.getLastId. |
go/internal/e2e/session_test.go |
Adds Go E2E verifying GetLastSessionID returns the created session ID. |
go/client.go |
Implements GetLastSessionID on the Go client. |
go/README.md |
Documents the new Go client method in the API reference list. |
| // OnPermissionRequest: copilot.PermissionHandler.ApproveAll, | ||
| // }) | ||
| // } | ||
| func (c *Client) GetLastSessionID(ctx context.Context) (*string, error) { |
There was a problem hiding this comment.
GetLastSessionID accepts a ctx but never uses it; if the client is disconnected and AutoStart is enabled, it will start using context.Background() via ensureConnected(), so caller cancellation/deadlines are ignored. Consider following the pattern used by GetForegroundSessionID (start with the provided ctx when c.client == nil) so the method respects the supplied context.
| func (c *Client) GetLastSessionID(ctx context.Context) (*string, error) { | |
| func (c *Client) GetLastSessionID(ctx context.Context) (*string, error) { | |
| if ctx == nil { | |
| ctx = context.Background() | |
| } | |
| // Respect caller cancellation/deadlines before attempting to connect. | |
| select { | |
| case <-ctx.Done(): | |
| return nil, ctx.Err() | |
| default: | |
| } |
| - `ResumeSessionWithOptions(sessionID string, config *ResumeSessionConfig) (*Session, error)` - Resume with additional configuration | ||
| - `ListSessions(filter *SessionListFilter) ([]SessionMetadata, error)` - List sessions (with optional filter) | ||
| - `DeleteSession(sessionID string) error` - Delete a session permanently | ||
| - `GetLastSessionID(ctx context.Context) (*string, error)` - Get the ID of the most recently updated session |
There was a problem hiding this comment.
The API reference list is inconsistent about whether context.Context parameters are shown (e.g., DeleteSession(sessionID string) omits ctx while GetLastSessionID(ctx context.Context) includes it). Please align this new entry with the surrounding documentation style so the list is consistent and not misleading about call signatures.
| - `GetLastSessionID(ctx context.Context) (*string, error)` - Get the ID of the most recently updated session | |
| - `GetLastSessionID() (*string, error)` - Get the ID of the most recently updated session |
Python and Go were missing
CopilotClient.get_last_session_id()which TS and .NET already expose. Adds the method to both SDKs with E2E tests.Python
async def get_last_session_id(self) -> str | NoneinCopilotClientGo
GetLastSessionID(ctx context.Context) (*string, error)on*ClientgetLastSessionIDRequest/getLastSessionIDResponsetypesTests & Docs
test/snapshots/session/should_get_last_session_id.yamlWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/copilot_internal/user/opt/hostedtoolcache/node/22.22.0/x64/bin/node node /home/REDACTED/work/copilot-sdk/copilot-sdk/nodejs/node_modules/@github/copilot/index.js --headless --no-auto-update --log-level info --stdio -nolocalimports -importcfg /tmp/go-build371754144/b135/importcfg -pack /opt/hostedtoolcache/go/1.24.13/x64/src/go/parser/interface.go 0285�� x64/src/net 0285230/b124/ c --gdwarf-5 --64 -o x64/pkg/tool/lin/tmp/go-build371754144/b089/vet.cfg(http block)/opt/hostedtoolcache/node/22.22.0/x64/bin/node node /home/REDACTED/work/copilot-sdk/copilot-sdk/nodejs/node_modules/@github/copilot/index.js --headless --no-auto-update --log-level info -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 --64 -o x64/pkg/tool/lin/tmp/go-build371754144/b061/vet.cfg .cfg�� ache/go/1.24.13/x64/src/os/user -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 --64 -o x64/pkg/tool/lin/tmp/go-build371754144/b168/vet.cfg(http block)/opt/hostedtoolcache/node/22.22.0/x64/bin/node node /home/REDACTED/work/copilot-sdk/copilot-sdk/nodejs/node_modules/@github/copilot/index.js --headless --no-auto-update --log-level info --stdio x64/pkg/tool/linux_amd64/vet --gdwarf-5 --64 -o x64/pkg/tool/lin/tmp/go-build371754144/b091/vet.cfg 0285�� .cfg -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 --64 -o x64/pkg/tool/lin-importcfg(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
CopilotClient.get_last_session_id()#608💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.