{"record":{"id":"121b29d99ed1047d","repo":"github/copilot-sdk","slug":"failed-to-unmarshal-response-w","errorCode":null,"errorMessage":"failed to unmarshal response: %w","messagePattern":"failed to unmarshal response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1152,"sourceCode":"\t\t\tregisteredSessionID = early.SessionID\n\t\t\treturn nil\n\t\t}\n\t}\n\n\tresult, err := c.client.RequestWithInlineResponse(ctx, \"session.create\", req, inlineCb)\n\tif err != nil {\n\t\tif registeredSessionID != \"\" {\n\t\t\tunregisterSession(registeredSessionID, session)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to create session: %w\", err)\n\t}\n\n\tvar response createSessionResponse\n\tif err := json.Unmarshal(result, &response); err != nil {\n\t\tif registeredSessionID != \"\" {\n\t\t\tunregisterSession(registeredSessionID, session)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal response: %w\", err)\n\t}\n\n\tif session == nil {\n\t\treturn nil, fmt.Errorf(\"session.create response did not include a sessionId\")\n\t}\n\n\tif localSessionID != \"\" && response.SessionID != \"\" && response.SessionID != localSessionID {\n\t\tunregisterSession(registeredSessionID, session)\n\t\treturn nil, fmt.Errorf(\"session.create returned sessionId %s but the caller requested %s\", response.SessionID, localSessionID)\n\t}\n\tif config.OnMCPAuthRequest != nil {\n\t\tif _, err := c.client.Request(ctx, \"session.eventLog.registerInterest\", map[string]any{\n\t\t\t\"sessionId\": session.SessionID,\n\t\t\t\"eventType\": \"mcp.oauth_required\",\n\t\t}); err != nil {\n\t\t\tunregisterSession(registeredSessionID, session)\n\t\t\treturn nil, err\n\t\t}","sourceCodeStart":1134,"sourceCodeEnd":1170,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1134-L1170","documentation":"After a successful session.create request, CreateSession unmarshals the result payload into createSessionResponse. This error wraps a json.Unmarshal failure, meaning the final result field of the response could not be decoded into the expected response struct. The request succeeded at transport level but the payload shape is unexpected.","triggerScenarios":"session.create returns a successful result whose JSON does not match createSessionResponse's fields/types — e.g. sessionId as a number instead of string, or extra incompatible field types.","commonSituations":"Server/SDK version skew changing the response schema; a proxy mangling the body; tests with hand-written fixture responses that don't match the struct.","solutions":["Capture and inspect the raw result JSON returned by session.create","Align server and SDK versions so the response schema matches createSessionResponse","Fix test fixtures/mocks to emit JSON compatible with createSessionResponse","Check for proxy middleware that rewrites or truncates response bodies"],"exampleFix":"// fixture before\n{\"sessionId\": 123}\n// after\n{\"sessionId\": \"sess_123\"}","handlingStrategy":"validation","validationCode":"var probe map[string]json.RawMessage\nif err := json.Unmarshal(result, &probe); err != nil {\n    return fmt.Errorf(\"non-object result: %s\", string(result))\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to unmarshal response\") {\n    log.Printf(\"unexpected session.create result schema: %s\", rawResult)\n    return checkVersionSkew(err)\n}","preventionTips":["Run integration tests against the real server version","Validate fixture JSON against createSessionResponse in unit tests","Avoid middleware that rewrites response bodies"],"tags":["json","rpc","unmarshal","schema"],"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"}