{"record":{"id":"9fcaf74c05db29be","repo":"vxcontrol/pentagi","slug":"failed-to-get-assistant-system-prompt-w","errorCode":null,"errorMessage":"failed to get assistant system prompt: %w","messagePattern":"failed to get assistant system prompt: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/providers/assistant.go","lineNumber":117,"sourceCode":"\nfunc (ap *assistantProvider) SetFlowWorker(flowWorker FlowWorker) {\n\tap.flowWorker = flowWorker\n}\n\nfunc (ap *assistantProvider) PrepareAgentChain(ctx context.Context) (int64, error) {\n\tctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, \"providers.flowProvider.PrepareAssistantChain\")\n\tdefer span.End()\n\n\tlogger := logrus.WithContext(ctx).WithFields(logrus.Fields{\n\t\t\"provider\":     ap.fp.Type(),\n\t\t\"assistant_id\": ap.id,\n\t\t\"flow_id\":      ap.fp.ID(),\n\t})\n\n\tsystemPrompt, err := ap.getAssistantSystemPrompt(ctx)\n\tif err != nil {\n\t\tlogger.WithError(err).Error(\"failed to get assistant system prompt\")\n\t\treturn 0, fmt.Errorf(\"failed to get assistant system prompt: %w\", err)\n\t}\n\n\toptAgentType := pconfig.OptionsTypeAssistant\n\tmsgChainType := database.MsgchainTypeAssistant\n\tap.msgChainID, _, err = ap.fp.restoreChain(\n\t\tctx, nil, nil, optAgentType, msgChainType, systemPrompt, \"\",\n\t)\n\tif err != nil {\n\t\tlogger.WithError(err).Error(\"failed to restore assistant msg chain\")\n\t\treturn 0, fmt.Errorf(\"failed to restore assistant msg chain: %w\", err)\n\t}\n\n\treturn ap.msgChainID, nil\n}\n\nfunc (ap *assistantProvider) PerformAgentChain(ctx context.Context) error {\n\tctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, \"providers.assistantProvider.PerformAgentChain\")\n\tdefer span.End()","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/providers/assistant.go#L99-L135","documentation":"PrepareAgentChain of the assistant provider failed while fetching the assistant agent's system prompt (ap.getAssistantSystemPrompt). The prompt template is stored/config-backed; failure here aborts building the assistant message chain, and the error is wrapped after being logged.","triggerScenarios":"getAssistantSystemPrompt returns an error: the assistant prompt record is missing from the database (prompt settings table), the DB query fails (connection down, migration not applied), or the context is cancelled during the fetch.","commonSituations":"Fresh deployment where the default prompts were never seeded; user deleted the 'assistant' prompt in Settings UI; database migrations incomplete; Postgres outage.","solutions":["Check the wrapped cause: DB error vs not-found","Verify prompt settings in the UI (Settings → Prompts) — restore/create the assistant prompt","Confirm goose migrations ran (backend/migrations/sql) and the prompts table is seeded","Check database connectivity from the backend container"],"exampleFix":"// before\nsystemPrompt, err := ap.getAssistantSystemPrompt(ctx)\nif err != nil { return 0, err }\n// after\nsystemPrompt, err := ap.getAssistantSystemPrompt(ctx)\nif err != nil {\n    if errors.Is(err, sql.ErrNoRows) {\n        systemPrompt = defaultAssistantPrompt // seed fallback\n    } else {\n        return 0, fmt.Errorf(\"failed to get assistant system prompt: %w\", err)\n    }\n}","handlingStrategy":"try-catch","validationCode":"// before creating the flow, ensure the assistant prompt exists\n// SELECT count(*) FROM prompts WHERE type='assistant'","typeGuard":null,"tryCatchPattern":"id, err := ap.PrepareAgentChain(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to get assistant system prompt\") {\n        // re-seed default prompts or surface a settings error to the user\n    }\n    return err\n}","preventionTips":["Seed default prompts via migrations and idempotent bootstrap","Protect built-in prompts from deletion in the Settings UI","Check DB health before spawning agent workers","Handle the error before PerformAgentChain and fail the flow cleanly"],"tags":["database","prompts","assistant","agent-chain"],"backgroundTag":"prompt-not-found","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}