{"record":{"id":"1a4418eb92a0f7b1","repo":"github/copilot-sdk","slug":"failed-to-parse-sessionid-from-response-w","errorCode":null,"errorMessage":"failed to parse sessionId from response: %w","messagePattern":"failed to parse sessionId from response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1124,"sourceCode":"\t\tsession = s\n\t\tregisteredSessionID = localSessionID\n\t}\n\n\t// For the server-assigned (cloud) path, register the session\n\t// synchronously from the read loop the instant the response arrives,\n\t// before the read loop dispatches the next message. Without this hook\n\t// the awaiter goroutine may not run until after the read loop has\n\t// dispatched the first session.event notification, which would be\n\t// silently dropped because the session id isn't yet in the lookup\n\t// table. Non-cloud sessions are already registered above.\n\tvar inlineCb func(raw json.RawMessage) error\n\tif session == nil {\n\t\tinlineCb = func(raw json.RawMessage) error {\n\t\t\tvar early struct {\n\t\t\t\tSessionID string `json:\"sessionId\"`\n\t\t\t}\n\t\t\tif err := json.Unmarshal(raw, &early); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to parse sessionId from response: %w\", err)\n\t\t\t}\n\t\t\tif early.SessionID == \"\" {\n\t\t\t\treturn fmt.Errorf(\"session.create response did not include a sessionId\")\n\t\t\t}\n\t\t\ts, err := initializeSession(early.SessionID)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tsession = s\n\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)","sourceCodeStart":1106,"sourceCodeEnd":1142,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1106-L1142","documentation":"When a session is created inline (session == nil), the client parses the session.create response body to extract the server-assigned sessionId. This error wraps a json.Unmarshal failure on that raw response payload, meaning the server returned something that is not valid JSON or not shaped as expected. It indicates a protocol/response-format problem rather than a caller mistake.","triggerScenarios":"Calling CreateSession when the underlying RequestWithInlineResponse(\"session.create\") returns a raw payload that fails json.Unmarshal into the {\"sessionId\": string} probe struct — e.g. a proxy or dev server returning HTML error pages, truncated bodies, or non-JSON content types.","commonSituations":"Reverse proxies/auth walls returning HTML login pages; gateway 502 bodies intercepted as raw messages; a server version emitting a non-object (array or string) JSON body; TLS-terminated endpoints returning compression-garbled output.","solutions":["Log the raw response body (raw json.RawMessage) to see what the server actually returned","Verify the endpoint is the real agent server and no proxy/auth redirect is intercepting the request","Check server version compatibility with this client SDK and upgrade/pin accordingly","Inspect network path (VPN, corporate proxy) that could rewrite response bodies"],"exampleFix":"// before: opaque parse failure\ns, err := c.CreateSession(ctx, opts)\n// after: surface the underlying payload\nif err != nil && strings.Contains(err.Error(), \"failed to parse sessionId\") {\n    log.Printf(\"session.create raw response: %s\", debugRawBody)\n}","handlingStrategy":"try-catch","validationCode":"if resp.StatusCode != 200 || !strings.Contains(resp.Header.Get(\"Content-Type\"), \"json\") {\n    return fmt.Errorf(\"unexpected session.create response: %s %s\", resp.Status, resp.Header.Get(\"Content-Type\"))\n}","typeGuard":"func looksLikeJSON(b []byte) bool { t := bytes.TrimSpace(b); return len(t) > 0 && (t[0] == '{' || t[0] == '[') }","tryCatchPattern":"s, err := client.CreateSession(ctx, opts)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to parse sessionId\") {\n        // inspect raw payload / proxy path, do not retry blindly\n        return handleProtocolError(err)\n    }\n    return err\n}","preventionTips":["Log raw response bodies in development","Bypass or authenticate proxies in the request path","Pin server and SDK versions"],"tags":["json","rpc","response-parsing","session"],"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"}