{"record":{"id":"988aabe5b9287458","repo":"charmbracelet/crush","slug":"agent-coordinator-not-initialized-988aab","errorCode":null,"errorMessage":"agent coordinator not initialized","messagePattern":"agent coordinator not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/workspace/app_workspace.go","lineNumber":108,"sourceCode":"\tif err := w.app.Messages.FlushAll(ctx); err != nil {\n\t\treturn nil, err\n\t}\n\treturn w.app.Messages.List(ctx, sessionID)\n}\n\nfunc (w *AppWorkspace) ListUserMessages(ctx context.Context, sessionID string) ([]message.Message, error) {\n\treturn w.app.Messages.ListUserMessages(ctx, sessionID)\n}\n\nfunc (w *AppWorkspace) ListAllUserMessages(ctx context.Context) ([]message.Message, error) {\n\treturn w.app.Messages.ListAllUserMessages(ctx)\n}\n\n// -- Agent --\n\nfunc (w *AppWorkspace) AgentRun(ctx context.Context, sessionID, prompt string, attachments ...message.Attachment) error {\n\tif w.app.AgentCoordinator == nil {\n\t\treturn errors.New(\"agent coordinator not initialized\")\n\t}\n\t_, err := w.app.AgentCoordinator.Run(ctx, sessionID, prompt, attachments...)\n\treturn err\n}\n\nfunc (w *AppWorkspace) AgentRunShellCommand(ctx context.Context, sessionID, command string, termWidth int, onProgress func(string), isFirstMessage bool) (proto.ShellCommandResponse, error) {\n\tvar persist shell.PersistFunc\n\tif sessionID != \"\" {\n\t\tpersist = func(cmd, output string, exitCode int) error {\n\t\t\treturn shell.PersistOutput(ctx, w.app.Messages, sessionID, cmd, output, exitCode)\n\t\t}\n\t}\n\n\topts := shell.RunOptions{\n\t\tCommand:   command,\n\t\tCwd:       w.store.WorkingDir(),\n\t\tTermWidth: termWidth,\n\t}","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/workspace/app_workspace.go#L90-L126","documentation":"AppWorkspace.AgentRun refuses to run when the app's AgentCoordinator is nil. The coordinator owns named agents and LLM sessions; without it no prompt can be dispatched, so the workspace returns this sentinel error instead of panicking on a nil pointer.","triggerScenarios":"Calling AgentRun before app.Dial/initialization created the coordinator, or after shutdown cleared it; constructing AppWorkspace with a partially initialized app struct (e.g. in tests or headless/embedded use).","commonSituations":"Invoking agent runs via the workspace API during startup races; embedders calling AgentRun on an app that failed mid-initialization; tests stubbing the app without a coordinator.","solutions":["Ensure app initialization (which builds AgentCoordinator) completed before calling AgentRun","Check startup error handling — a failed init that skipped coordinator creation is the root cause","In tests/embedded use, populate w.app.AgentCoordinator with a real or fake coordinator"],"exampleFix":"// before\n_, err := w.app.AgentCoordinator.Run(ctx, sessionID, prompt, attachments...)\n// after\nif w.app.AgentCoordinator == nil {\n\treturn errors.New(\"agent coordinator not initialized\")\n}\n_, err := w.app.AgentCoordinator.Run(ctx, sessionID, prompt, attachments...)","handlingStrategy":"type-guard","validationCode":"if w.app.AgentCoordinator == nil {\n\treturn errors.New(\"agent coordinator not initialized\")\n}\nerr := w.AgentRun(ctx, sessionID, prompt, attachments...)","typeGuard":"func (w *AppWorkspace) CoordinatorReady() bool { return w.app.AgentCoordinator != nil }","tryCatchPattern":"if err := w.AgentRun(ctx, sessionID, prompt); err != nil {\n\tif err.Error() == \"agent coordinator not initialized\" {\n\t\t// wait for app init or reinitialize the app\n\t}\n}","preventionTips":["Call AgentRun only after app.Dial completes successfully","Use a readiness flag/signal instead of touching the app struct directly","In tests, always inject a coordinator (real or mock) into AppWorkspace"],"tags":["agent","workspace","initialization","go"],"backgroundTag":"service-not-initialized","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}