{"record":{"id":"85c7f84cd6836665","repo":"vxcontrol/pentagi","slug":"failed-to-get-assistant-use-agents-w","errorCode":null,"errorMessage":"failed to get assistant use agents: %w","messagePattern":"failed to get assistant use agents: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/providers/assistant.go","lineNumber":147,"sourceCode":"\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()\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\t\"msg_chain_id\": ap.msgChainID,\n\t})\n\n\tuseAgents, err := ap.getAssistantUseAgents(ctx)\n\tif err != nil {\n\t\tlogger.WithError(err).Error(\"failed to get assistant use agents\")\n\t\treturn fmt.Errorf(\"failed to get assistant use agents: %w\", err)\n\t}\n\n\tmsgChain, err := ap.fp.DB().GetMsgChain(ctx, ap.msgChainID)\n\tif err != nil {\n\t\tlogger.WithError(err).Error(\"failed to get primary agent msg chain\")\n\t\treturn fmt.Errorf(\"failed to get primary agent msg chain %d: %w\", ap.msgChainID, err)\n\t}\n\n\tvar chain []llms.MessageContent\n\tif err := json.Unmarshal(msgChain.Chain, &chain); err != nil {\n\t\tlogger.WithError(err).Error(\"failed to unmarshal primary agent msg chain\")\n\t\treturn fmt.Errorf(\"failed to unmarshal primary agent msg chain %d: %w\", ap.msgChainID, err)\n\t}\n\n\tadviser, err := ap.fp.GetAskAdviceHandler(ctx, nil, nil)\n\tif err != nil {\n\t\tlogger.WithError(err).Error(\"failed to get ask advice handler\")\n\t\treturn fmt.Errorf(\"failed to get ask advice handler: %w\", err)","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/providers/assistant.go#L129-L165","documentation":"PerformAgentChain wraps the error from ap.getAssistantUseAgents(ctx), which calls DB().GetAssistantUseAgents(ctx, ap.id) to read the assistant's `use_agents` flag from PostgreSQL. This error means the database lookup for that flag failed, aborting the assistant agent-chain run before any LLM call.","triggerScenarios":"Database query in GetAssistantUseAgents errors: Postgres connection down/reset, assistant row with ap.id deleted mid-run, permission/schema issue, context canceled during shutdown.","commonSituations":"Postgres container restarting or unreachable; flow running while the assistant record was removed; connection-pool exhaustion under many concurrent flows; ctx canceled by graceful shutdown of the server.","solutions":["Check Postgres connectivity and that the backend can reach the DB (env DSN, docker network).","Verify the assistant row with ap.id still exists in the assistants table; re-create the flow if it was deleted.","Check server logs for the wrapped sql/GORM error to distinguish connection vs no-rows vs context-cancel.","Increase connection pool limits or retry transient connection errors."],"exampleFix":"// before\nuseAgents, err := ap.getAssistantUseAgents(ctx)\nif err != nil {\n    return fmt.Errorf(\"failed to get assistant use agents: %w\", err)\n}\n// after\nuseAgents, err := ap.getAssistantUseAgents(ctx)\nif err != nil {\n    if errors.Is(err, context.Canceled) {\n        return err // do not wrap shutdown cancels\n    }\n    logger.WithError(err).Error(\"failed to get assistant use agents\")\n    return fmt.Errorf(\"failed to get assistant use agents: %w\", err)\n}","handlingStrategy":"retry","validationCode":"var exists bool\nerr := db.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM assistants WHERE id=$1)`, assistantID).Scan(&exists)\nif err != nil || !exists { return fmt.Errorf(\"assistant %d unavailable: %w\", assistantID, err) }","typeGuard":"func dbReady(err error) bool { return err == nil || errors.Is(err, context.Canceled) }","tryCatchPattern":"useAgents, err := ap.getAssistantUseAgents(ctx)\nif err != nil {\n    if isTransientDBError(err) { return retryWithBackoff(ctx) }\n    return fmt.Errorf(\"failed to get assistant use agents: %w\", err)\n}","preventionTips":["Health-check Postgres before starting flows","Use connection-pool monitoring to catch exhaustion","Avoid deleting assistant rows while flows run","Always run DB migrations before deploy"],"tags":["database","postgres","agent-chain"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}