{"record":{"id":"d98031d6e9688c83","repo":"github/copilot-sdk","slug":"failed-to-unmarshal-getlastid-response-w","errorCode":null,"errorMessage":"failed to unmarshal getLastId response: %w","messagePattern":"failed to unmarshal getLastId response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1669,"sourceCode":"//\t}\n//\tif lastID != nil {\n//\t    session, err := client.ResumeSession(context.Background(), *lastID, &copilot.ResumeSessionConfig{\n//\t        OnPermissionRequest: copilot.PermissionHandler.ApproveAll,\n//\t    })\n//\t}\nfunc (c *Client) GetLastSessionID(ctx context.Context) (*string, error) {\n\tif err := c.ensureConnected(ctx); err != nil {\n\t\treturn nil, err\n\t}\n\n\tresult, err := c.client.Request(ctx, \"session.getLastId\", getLastSessionIDRequest{})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar response getLastSessionIDResponse\n\tif err := json.Unmarshal(result, &response); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal getLastId response: %w\", err)\n\t}\n\n\treturn response.SessionID, nil\n}\n\n// GetForegroundSessionID returns the ID of the session currently displayed in the TUI.\n//\n// This is only available when connecting to a server running in TUI+server mode\n// (--ui-server). Returns nil if no foreground session is set.\n//\n// Example:\n//\n//\tsessionID, err := client.GetForegroundSessionID()\n//\tif err != nil {\n//\t    log.Fatal(err)\n//\t}\n//\tif sessionID != nil {\n//\t    fmt.Printf(\"TUI is displaying session: %s\\n\", *sessionID)","sourceCodeStart":1651,"sourceCodeEnd":1687,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1651-L1687","documentation":"GetLastSessionID wraps json.Unmarshal failures of the 'session.getLastId' result with this error. The library expects getLastSessionIDResponse; any deviation in the payload produces this wrapped error.","triggerScenarios":"Calling GetLastSessionID when the backend's last-session-id result cannot decode into getLastSessionIDResponse (wrong type, e.g. number instead of string for sessionId).","commonSituations":"Fresh install where the backend has never created a session and returns an unexpected null/empty shape; version drift after upgrade.","solutions":["Log the raw result to see the actual payload","Verify at least one session exists (ListSessions) before calling","Update client library and backend to matching versions","Handle the error as 'no decodable last session' and fall back to creating a new session"],"exampleFix":"// before\nid, err := client.GetLastSessionID(ctx)\nif err != nil { return err }\n// after\nid, err := client.GetLastSessionID(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"getLastId\") {\n        return client.NewSession(ctx)\n    }\n    return err\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":"func isLastIDUnmarshalError(err error) bool {\n    return strings.Contains(err.Error(), \"getLastId response\")\n}","tryCatchPattern":"id, err := client.GetLastSessionID(ctx)\nif err != nil {\n    if isLastIDUnmarshalError(err) {\n        id = \"\" // fall back to creating a new session\n    } else {\n        return err\n    }\n}","preventionTips":["Check that at least one session exists before calling","Keep client/backend versions aligned","Treat last-session-id as a hint, not a guarantee"],"tags":["json","unmarshal","session-id"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}