{"record":{"id":"1f827ec9f79cf9ed","repo":"vxcontrol/pentagi","slug":"failed-to-load-user-prompts-w","errorCode":null,"errorMessage":"failed to load user prompts: %w","messagePattern":"failed to load user prompts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/prompter.go","lineNumber":19,"sourceCode":"package controller\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"pentagi/pkg/database\"\n\t\"pentagi/pkg/templates\"\n)\n\n// newUserPrompter loads the user's custom prompts from the database and\n// overlays them onto the compiled default templates. Prompt types that\n// the user has not customized continue to use the defaults. A database\n// error is returned to the caller so that session creation fails\n// explicitly instead of silently falling back to defaults.\nfunc newUserPrompter(ctx context.Context, db database.Querier, userID int64) (templates.Prompter, error) {\n\tuserPrompts, err := db.GetUserPrompts(ctx, userID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load user prompts: %w\", err)\n\t}\n\n\tdefaults, err := templates.LoadDefaultPromptsMap()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load default templates: %w\", err)\n\t}\n\n\treturn buildUserPrompter(defaults, userPrompts), nil\n}\n\n// buildUserPrompter is the pure merge step extracted from newUserPrompter so\n// it can be unit-tested without a database fake or filesystem access. It\n// mutates the supplied defaults map by overlaying each non-empty user\n// override on top, then returns a Prompter backed by that map. Callers must\n// pass a fresh map (e.g., from templates.LoadDefaultPromptsMap) so the\n// embedded defaults are not modified.\nfunc buildUserPrompter(defaults templates.PromptsMap, userPrompts []database.Prompt) templates.Prompter {\n\tfor _, p := range userPrompts {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/prompter.go#L1-L37","documentation":"newUserPrompter loads a user's custom prompt overrides via db.GetUserPrompts(ctx, userID) and overlays them on the embedded default templates. If that database query fails, session/worker creation fails explicitly with \"failed to load user prompts: %w\" — by design it does NOT silently fall back to defaults, because running agents with wrong (default-only) prompts would be worse than failing loudly.","triggerScenarios":"Any call path that creates or loads a flow/assistant worker (NewFlowWorker, LoadFlowWorker, NewAssistantWorker, LoadAssistantWorker) when GetUserPrompts fails: DB connection error, context cancellation, missing user row constraints, or connection pool exhaustion.","commonSituations":"PostgreSQL down or restarting when a user starts a flow; expired/cancelled request context; DB pool exhausted under heavy concurrent flow creation; misconfigured DATABASE_URL after deployment.","solutions":["Inspect the wrapped cause to identify the SQL/driver error.","Verify PostgreSQL connectivity and DATABASE_URL configuration.","Retry worker creation once the DB is healthy — nothing is cached from the failed attempt.","Check DB pool settings if errors appear only under load."],"exampleFix":"null","handlingStrategy":"retry","validationCode":"// check DB reachability before creating workers\nif err := db.Ping(ctx); err != nil {\n    return fmt.Errorf(\"database unavailable: %w\", err)\n}","typeGuard":"null","tryCatchPattern":"prompter, err := newUserPrompter(ctx, db, userID)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || isTransientDBError(err) {\n        // brief backoff then retry session creation\n        time.Sleep(time.Second)\n        prompter, err = newUserPrompter(ctx, db, userID)\n    }\n    return err\n}","preventionTips":["Monitor PostgreSQL connectivity; every flow/assistant start depends on this query.","Size the DB connection pool for concurrent flow creation bursts.","Pass a context with enough budget for the GetUserPrompts query.","Note the deliberate no-fallback design: workers fail loudly rather than run with default prompts."],"tags":["database","go","prompts","worker-creation"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}