{"record":{"id":"47bd9da443072c41","repo":"github/copilot-sdk","slug":"failed-to-unmarshal-sessions-response-w","errorCode":null,"errorMessage":"failed to unmarshal sessions response: %w","messagePattern":"failed to unmarshal sessions response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1552,"sourceCode":"//\n//\tsessions, err := client.ListSessions(context.Background(), &SessionListFilter{Repository: \"owner/repo\"})\nfunc (c *Client) ListSessions(ctx context.Context, filter *SessionListFilter) ([]SessionMetadata, error) {\n\tif err := c.ensureConnected(ctx); err != nil {\n\t\treturn nil, err\n\t}\n\n\tparams := listSessionsRequest{}\n\tif filter != nil {\n\t\tparams.Filter = filter\n\t}\n\tresult, err := c.client.Request(ctx, \"session.list\", params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar response listSessionsResponse\n\tif err := json.Unmarshal(result, &response); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal sessions response: %w\", err)\n\t}\n\n\treturn response.Sessions, nil\n}\n\n// GetSessionMetadata returns metadata for a specific session by ID.\n//\n// This provides an efficient O(1) lookup of a single session's metadata\n// instead of listing all sessions. Returns nil if the session is not found.\n//\n// Example:\n//\n//\tmetadata, err := client.GetSessionMetadata(context.Background(), \"session-123\")\n//\tif err != nil {\n//\t    log.Fatal(err)\n//\t}\n//\tif metadata != nil {\n//\t    fmt.Printf(\"Session started at: %s\\n\", metadata.StartTime)","sourceCodeStart":1534,"sourceCodeEnd":1570,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1534-L1570","documentation":"ListSessions wraps json.Unmarshal failures of the 'session.list' result with this error. The library expects a listSessionsResponse (sessions array); if the backend returns anything not decodable into that struct, this error is surfaced. The underlying decode error is preserved for errors.As inspection.","triggerScenarios":"Calling ListSessions when the backend result cannot decode into listSessionsResponse — e.g. sessions field is an object instead of an array, or the result is an error string.","commonSituations":"Backend/client version mismatch after upgrade; corrupted IPC stream; backend returning an error payload where a list was expected.","solutions":["Dump the raw result and compare its shape to listSessionsResponse","Update the client library and backend to matching versions","Decode into json.RawMessage and check the 'sessions' field type manually to diagnose","Retry once in case of a transient truncated response"],"exampleFix":"// before\nsessions, err := client.ListSessions(ctx)\n// after\nsessions, err := client.ListSessions(ctx)\nif err != nil && strings.Contains(err.Error(), \"unmarshal sessions response\") {\n    log.Printf(\"backend returned unexpected list shape: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isSessionsUnmarshalError(err error) bool {\n    return strings.Contains(err.Error(), \"unmarshal sessions response\")\n}","tryCatchPattern":"sessions, err := client.ListSessions(ctx)\nif err != nil {\n    if isSessionsUnmarshalError(err) {\n        // treat as unknown list shape: retry once, then surface backend/version mismatch\n        return nil, fmt.Errorf(\"list sessions: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Keep client and backend versions in lockstep","Log raw results when upgrading","Validate backend output shape after any backend schema change"],"tags":["json","unmarshal","list-sessions"],"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-15T23:17:13.987Z"}