{"record":{"id":"5ad201425f45018f","repo":"github/copilot-sdk","slug":"failed-to-unmarshal-session-metadata-response-w","errorCode":null,"errorMessage":"failed to unmarshal session metadata response: %w","messagePattern":"failed to unmarshal session metadata response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1584,"sourceCode":"//\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)\n//\t}\nfunc (c *Client) GetSessionMetadata(ctx context.Context, sessionID string) (*SessionMetadata, 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.getMetadata\", getSessionMetadataRequest{SessionID: sessionID})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar response getSessionMetadataResponse\n\tif err := json.Unmarshal(result, &response); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal session metadata response: %w\", err)\n\t}\n\n\treturn response.Session, nil\n}\n\n// DeleteSession permanently deletes a session and all its data from disk,\n// including conversation history, planning state, and artifacts.\n//\n// Unlike [Session.Disconnect], which only releases in-memory resources and\n// preserves session data for later resumption, DeleteSession is irreversible.\n// The session cannot be resumed after deletion. If the session is in the local\n// sessions map, it will be removed.\n//\n// Example:\n//\n//\tif err := client.DeleteSession(context.Background(), \"session-123\"); err != nil {\n//\t    log.Fatal(err)\n//\t}","sourceCodeStart":1566,"sourceCodeEnd":1602,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1566-L1602","documentation":"GetSessionMetadata returns this error when the 'session.getMetadata' result fails to decode into getSessionMetadataResponse. It indicates the backend's metadata payload did not match the expected struct, with the decode error wrapped for diagnosis.","triggerScenarios":"Calling GetSessionMetadata with a sessionID whose backend response shape differs from getSessionMetadataResponse (wrong field types, missing session object).","commonSituations":"Querying a session created by a newer/older backend version with extra or renamed metadata fields; stale session data on disk.","solutions":["Print the raw result to compare against getSessionMetadataResponse fields","Verify the session exists via ListSessions before fetching metadata","Align client and backend versions","If the session was created by a different product version, recreate or migrate it"],"exampleFix":"// before\nmeta, err := client.GetSessionMetadata(ctx, id)\n// after\nmeta, err := client.GetSessionMetadata(ctx, id)\nif err != nil {\n    if strings.Contains(err.Error(), \"unmarshal session metadata\") {\n        log.Printf(\"unexpected metadata shape for %s: %v\", id, err)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if sessionID == \"\" {\n    return nil, fmt.Errorf(\"GetSessionMetadata: empty sessionID\")\n}","typeGuard":"func isMetadataUnmarshalError(err error) bool {\n    return strings.Contains(err.Error(), \"unmarshal session metadata response\")\n}","tryCatchPattern":"meta, err := client.GetSessionMetadata(ctx, id)\nif err != nil {\n    if isMetadataUnmarshalError(err) {\n        // fall back to partial info from ListSessions\n        return nil, fmt.Errorf(\"metadata for %s undecodable: %w\", id, err)\n    }\n    return nil, err\n}","preventionTips":["Verify the session exists before fetching metadata","Avoid mixing sessions created across incompatible product versions","Log raw payloads in debug builds"],"tags":["json","unmarshal","metadata"],"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"}