Skip to content

Add get_last_session_id() to Python and Go SDKs#671

Merged
patniko merged 2 commits intomainfrom
copilot/add-copilotclient-get-last-session-id
Mar 5, 2026
Merged

Add get_last_session_id() to Python and Go SDKs#671
patniko merged 2 commits intomainfrom
copilot/add-copilotclient-get-last-session-id

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

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 | None in CopilotClient
last_id = await client.get_last_session_id()
if last_id:
    session = await client.resume_session(last_id, {"on_permission_request": PermissionHandler.approve_all})

Go

  • GetLastSessionID(ctx context.Context) (*string, error) on *Client
  • Added getLastSessionIDRequest / getLastSessionIDResponse types
lastID, err := client.GetLastSessionID(ctx)
if err != nil {
    log.Fatal(err)
}
if lastID != nil {
    session, err := client.ResumeSession(ctx, *lastID, &copilot.ResumeSessionConfig{
        OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
    })
}

Tests & Docs

  • E2E tests added for both languages using shared snapshot test/snapshots/session/should_get_last_session_id.yaml
  • Go README updated to list the new method

Warning

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
    • Triggering command: /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)
    • Triggering command: /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)
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>Python and Go lack CopilotClient.get_last_session_id()</issue_title>
<issue_description>TS and .NET have it. I'm not sure if that's on purpose or an accident.</issue_description>

<agent_instructions>Review issue, implement across the SDKs and make sure we cover it appropriately with tests.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 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.

Co-authored-by: patniko <26906478+patniko@users.noreply.github.com>
Copilot AI changed the title [WIP] Add CopilotClient.get_last_session_id() to Python and Go SDKs Add get_last_session_id() to Python and Go SDKs Mar 5, 2026
@patniko patniko marked this pull request as ready for review March 5, 2026 01:04
@patniko patniko requested a review from a team as a code owner March 5, 2026 01:04
Copilot AI review requested due to automatic review settings March 5, 2026 01:04
@patniko patniko merged commit 3a00c02 into main Mar 5, 2026
28 of 32 checks passed
@patniko patniko deleted the copilot/add-copilotclient-get-last-session-id branch March 5, 2026 01:05
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

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 calls session.getLastId.
  • Go: add (*Client).GetLastSessionID(...) plus request/response types for session.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) {
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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:
}

Copilot uses AI. Check for mistakes.
- `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
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
- `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

Copilot uses AI. Check for mistakes.
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 and Go lack CopilotClient.get_last_session_id()

3 participants