{"record":{"id":"e180033ca9a764a2","repo":"charmbracelet/crush","slug":"failed-to-initialize-coder-agent-w","errorCode":null,"errorMessage":"failed to initialize coder agent: %w","messagePattern":"failed to initialize coder agent: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/app/app.go","lineNumber":171,"sourceCode":"\t\tMessages:          app.Messages,\n\t})\n\n\t// Release the shared database connection on shutdown. The pool\n\t// closes the underlying *sql.DB when the last reference is released.\n\tdataDir := cfg.Options.DataDirectory\n\tapp.cleanupFuncs = append(\n\t\tapp.cleanupFuncs,\n\t\tfunc(context.Context) error { return db.Release(dataDir) },\n\t\tfunc(ctx context.Context) error { return mcp.Close(ctx) },\n\t)\n\n\t// TODO: remove the concept of agent config, most likely.\n\tif !cfg.IsConfigured() {\n\t\tslog.Warn(\"No agent configuration found\")\n\t\treturn app, nil\n\t}\n\tif err := app.InitCoderAgent(ctx); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to initialize coder agent: %w\", err)\n\t}\n\n\t// Set up callback for LSP state updates.\n\tapp.LSPManager.SetCallback(func(name string, client *lsp.Client) {\n\t\tif client == nil {\n\t\t\tupdateLSPState(name, lsp.StateUnstarted, nil, nil, 0)\n\t\t\treturn\n\t\t}\n\t\tclient.SetDiagnosticsCallback(updateLSPDiagnostics)\n\t\tupdateLSPState(name, client.GetServerState(), nil, client, 0)\n\t})\n\n\t// TrackConfigured must run after SetCallback so the callback is already\n\t// installed when configured-but-not-yet-started LSPs are announced.\n\tgo app.LSPManager.TrackConfigured(ctx)\n\n\treturn app, nil\n}","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/app/app.go#L153-L189","documentation":"App.New wraps any failure from app.InitCoderAgent — the step that constructs the primary 'coder' agent (model/provider wiring, tool registration, prompt loading). This means configuration was present (cfg.IsConfigured() passed) but agent construction failed, so the whole application cannot start.","triggerScenarios":"InitCoderAgent returns an error: invalid provider/model IDs in crushrc/crush.json, missing API key env vars, failed provider catalog fetch, or a tool/LSP dependency failing to initialize.","commonSituations":"Renamed or removed model IDs after a provider catalog update; API keys not exported in the shell; malformed provider config block in crushrc; offline environments unable to fetch the model catalog.","solutions":["Read the wrapped cause (%w chain) printed below this message — it names the actual failure.","Validate crushrc/crush.json: provider and model IDs must match the provider catalog (crush models).","Ensure required API key env vars are set in the shell running crush (ANTHROPIC_API_KEY, etc.).","Check network access to the provider catalog; configure a local snapshot if offline."],"exampleFix":"// before (crushrc)\nprovider anthropic\nmodel anthropic/claude-3-7-sonnet-typo\n\n// after\nprovider anthropic\n  api_key_env ANTHROPIC_API_KEY\nmodel anthropic/claude-sonnet-4-20250514","handlingStrategy":"validation","validationCode":"if !cfg.IsConfigured() {\n    return fmt.Errorf(\"configure a provider and model in crushrc before starting\")\n}\n// verify required keys\nfor _, k := range []string{\"ANTHROPIC_API_KEY\"} {\n    if os.Getenv(k) == \"\" {\n        return fmt.Errorf(\"%s is not set\", k)\n    }\n}","typeGuard":null,"tryCatchPattern":"app, err := app.New(ctx, opts)\nif err != nil {\n    slog.Error(\"startup failed\", \"err\", err) // %w chain names the real cause\n    os.Exit(1)\n}","preventionTips":["Run `crush models` to confirm provider/model IDs exist in the catalog before referencing them.","Export API keys in the shell profile that launches crush.","Validate crushrc syntax after edits; keep model IDs updated after catalog changes.","Provide an offline catalog snapshot for air-gapped environments."],"tags":["go","configuration","agent","startup","provider"],"backgroundTag":"agent-init-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}