{"record":{"id":"d5ef30b223d95fc1","repo":"charmbracelet/crush","slug":"coder-agent-is-not-initialized","errorCode":null,"errorMessage":"coder agent is not initialized","messagePattern":"coder agent is not initialized","errorType":"exception","errorClass":"ErrAgentNotInitialized","httpStatus":null,"severity":"error","filePath":"internal/workspace/workspace.go","lineNumber":34,"sourceCode":"\t\"github.com/charmbracelet/crush/internal/config\"\n\t\"github.com/charmbracelet/crush/internal/history\"\n\t\"github.com/charmbracelet/crush/internal/lsp\"\n\t\"github.com/charmbracelet/crush/internal/message\"\n\t\"github.com/charmbracelet/crush/internal/oauth\"\n\t\"github.com/charmbracelet/crush/internal/permission\"\n\t\"github.com/charmbracelet/crush/internal/proto\"\n\t\"github.com/charmbracelet/crush/internal/question\"\n\t\"github.com/charmbracelet/crush/internal/session\"\n\t\"github.com/charmbracelet/crush/internal/skills\"\n)\n\n// Reasons the coder agent may be unavailable, returned by\n// Workspace.AgentReadyErr so callers can tell a genuinely\n// uninitialized agent apart from a lost server connection.\nvar (\n\t// ErrAgentNotInitialized means the workspace exists but its coder\n\t// agent has not been configured/initialized (e.g. no model set).\n\tErrAgentNotInitialized = errors.New(\"coder agent is not initialized\")\n\t// ErrServerUnreachable means the client could not reach the server\n\t// to determine the agent's status (server down, or the workspace was\n\t// torn down out from under the client).\n\tErrServerUnreachable = errors.New(\"lost connection to the crush server\")\n\t// ErrWorkspaceGone means the server is reachable but no longer knows\n\t// this client's workspace: it was torn down, or the server was\n\t// replaced underneath the client. The subscription loop re-registers\n\t// the workspace in the background when it sees this.\n\tErrWorkspaceGone = errors.New(\"the server reset this workspace; reconnecting\")\n\t// ErrStreamClosed means an established event stream ended.\n\t// Resubscribing usually succeeds immediately, but events published in\n\t// the meantime are lost for good, so the client treats it as a\n\t// degraded link that requires a resync.\n\tErrStreamClosed = errors.New(\"the event stream closed; reconnecting\")\n)\n\n// ConnectionState describes the health of the client-server link as\n// reported by the [ClientWorkspace] subscription loop.","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/workspace/workspace.go#L16-L52","documentation":"ErrAgentNotInitialized is a sentinel error (errors.New) in internal/workspace indicating the workspace object exists but its coder agent was never configured or initialized — typically because no model was set. It is returned by AgentReadyErr so callers can distinguish this condition from connection-level problems like ErrServerUnreachable.","triggerScenarios":"Calling SendMessage or SummarizeSession on a workspace whose coder agent has no model configured; any code path (including handleError and AgentReadyErr) that checks agent readiness before the agent exists.","commonSituations":"Running a client against a workspace created before a model was chosen; config files missing a provider/model entry; racing a workspace start before agent setup completes in tests like TestSendMessage_AgentNotInitialized.","solutions":["Initialize/configure the coder agent for the workspace (set a model) before calling SendMessage or SummarizeSession","Call Workspace.AgentReadyErr first and branch on errors.Is to surface a user-facing 'pick a model' prompt","Check your crush config defines a provider and model so agent initialization succeeds at startup"],"exampleFix":"// before\nresp, err := ws.SendMessage(ctx, sessionID, text)\n// after\nif err := ws.AgentReadyErr(ctx); err != nil {\n    if errors.Is(err, workspace.ErrAgentNotInitialized) {\n        return nil, fmt.Errorf(\"select a model before chatting: %w\", err)\n    }\n    return nil, err\n}\nresp, err := ws.SendMessage(ctx, sessionID, text)","handlingStrategy":"type-guard","validationCode":"if err := ws.AgentReadyErr(ctx); err != nil {\n    if errors.Is(err, workspace.ErrAgentNotInitialized) {\n        // prompt user to configure a model\n    }\n}","typeGuard":"func isAgentNotInitialized(err error) bool { return errors.Is(err, workspace.ErrAgentNotInitialized) }","tryCatchPattern":"if err != nil {\n    if errors.Is(err, workspace.ErrAgentNotInitialized) { /* configure model */ }\n    return err\n}","preventionTips":["Always gate SendMessage/SummarizeSession behind AgentReadyErr","Ensure crush config sets a provider and model at startup","Distinguish via errors.Is among the four workspace sentinel errors"],"tags":["workspace","agent-lifecycle","sentinel-error"],"backgroundTag":"agent-not-initialized","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}