{"record":{"id":"ddeca2c1afea6bcf","repo":"github/copilot-sdk","slug":"failed-to-create-session-w","errorCode":null,"errorMessage":"failed to create session: %w","messagePattern":"failed to create session: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1144,"sourceCode":"\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)\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}","sourceCodeStart":1126,"sourceCodeEnd":1162,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1126-L1162","documentation":"CreateSession wraps any error from the underlying RequestWithInlineResponse(\"session.create\") call in this message. It is the generic failure envelope for the whole session-creation round trip, including transport errors, inline callback failures (490/491), and server-side rejections. Any registered session is unregistered before returning, so no partial state leaks.","triggerScenarios":"Any failure inside CreateSession's RequestWithInlineResponse call: connection failure, timeout, server error response, or an error returned by the inline sessionId-parsing callback.","commonSituations":"Server not running or wrong port; the connection dropped mid-request; the inline callback returned errors 490/491 which surface wrapped here; auth failure rejected by the server.","solutions":["Unwrap with %w (errors.Unwrap / errors.As) to find the root cause","Verify the agent server is running and the client's connection options (address/port) are correct","Check whether the inner error is 'failed to parse sessionId' or 'did not include a sessionId' and follow those fixes","Retry once on transient network errors; check server logs for the session.create request"],"exampleFix":"// before\nif err := create(); err != nil { return err }\n// after\nif err := create(); err != nil {\n    var e *SessionError\n    if errors.As(err, &e) { /* inspect root cause */ }\n    return fmt.Errorf(\"create session: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"conn, err := net.DialTimeout(\"tcp\", serverAddr, 2*time.Second)\nif err != nil { return fmt.Errorf(\"agent server unreachable at %s\", serverAddr) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"s, err := client.CreateSession(ctx, opts)\nif err != nil {\n    root := errors.Unwrap(err)\n    if isTransientNetErr(root) { /* retry with backoff */ }\n    return fmt.Errorf(\"create session: %w\", err)\n}","preventionTips":["Health-check the server before creating sessions","Retry transient network errors with backoff","Always unwrap wrapped errors to find the real cause"],"tags":["rpc","session","wrap","network"],"backgroundTag":"api-request-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"}