{"record":{"id":"c59ea578635ddb8b","repo":"github/copilot-sdk","slug":"session-error-s","errorCode":null,"errorMessage":"session error: %s","messagePattern":"session error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/session.go","lineNumber":523,"sourceCode":"\n\tunsubscribe := s.On(func(event SessionEvent) {\n\t\tswitch d := event.Data.(type) {\n\t\tcase *AssistantMessageData:\n\t\t\tmu.Lock()\n\t\t\teventCopy := event\n\t\t\tlastAssistantMessage = &eventCopy\n\t\t\tmu.Unlock()\n\t\tcase *SessionIdleData:\n\t\t\tif d.Mode != nil && *d.Mode == SessionModeAutopilot {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tselect {\n\t\t\tcase idleCh <- struct{}{}:\n\t\t\tdefault:\n\t\t\t}\n\t\tcase *SessionErrorData:\n\t\t\tselect {\n\t\t\tcase errCh <- fmt.Errorf(\"session error: %s\", d.Message):\n\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t})\n\tdefer unsubscribe()\n\n\t_, err := s.Send(ctx, options)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tselect {\n\tcase <-idleCh:\n\t\tmu.Lock()\n\t\tresult := lastAssistantMessage\n\t\tmu.Unlock()\n\t\treturn result, nil\n\tcase err := <-errCh:","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/session.go#L505-L541","documentation":"This error is created when the session's event dispatcher receives a *SessionErrorData event from the Copilot CLI process and converts it into a Go error carrying the CLI's message. It represents a fatal/terminal error reported by the underlying CLI session (crash, protocol failure, model or configuration problem), surfaced to callers of Session.SendAndWait via the errCh. The wrapping select-with-default means the error is dropped if no one is listening on errCh.","triggerScenarios":"The CLI sends a session.error event during a Session.SendAndWait/SendPromptAndWait call; the message text is whatever the CLI attached as SessionErrorData.Message.","commonSituations":"The copilot CLI binary crashes or exits mid-conversation; invalid model or session configuration rejected server-side; network/auth failures reported by the CLI as a session-level error; CLI protocol version mismatches between SDK and installed CLI.","solutions":["Inspect the inner %s message for the actual CLI-reported cause and fix that (model name, auth, network).","Check the installed copilot CLI version matches what the Go SDK expects; upgrade the CLI and SDK together.","Verify authentication (run the CLI manually once) and network/proxy settings before starting the session.","Enable SDK/CLI debug logging to capture the full session.error payload."],"exampleFix":"// before\nresult, err := session.SendPromptAndWait(ctx, prompt)\n// after\nresult, err := session.SendPromptAndWait(ctx, prompt)\nif err != nil {\n    var serr *copilot.SessionError\n    if errors.As(err, &serr) {\n        log.Printf(\"CLI session failed: %v\", err) // diagnose underlying CLI cause\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"result, err := session.SendPromptAndWait(ctx, prompt)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"session error:\") {\n        // CLI-reported session failure; log err and recreate the session\n    }\n}","preventionTips":["Keep CLI and SDK versions in lockstep","Validate auth and model configuration before creating sessions","Subscribe to Session.On events to observe session.error data directly","Test CLI connectivity standalone before embedding in the app"],"tags":["cli","session","upstream-error"],"backgroundTag":"upstream-api-error","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"}