{"record":{"id":"f9042d6e5de31ad1","repo":"vxcontrol/pentagi","slug":"failed-to-load-flows-w","errorCode":null,"errorMessage":"failed to load flows: %w","messagePattern":"failed to load flows: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"backend/pkg/controller/flows.go","lineNumber":115,"sourceCode":"\t\tflows:  make(map[int64]FlowWorker),\n\t\tdocker: docker,\n\t\tprovs:  provs,\n\t\tsubs:   subs,\n\t\talc:    NewAgentLogController(db),\n\t\tmlc:    NewMsgLogController(db),\n\t\taslc:   NewAssistantLogController(db),\n\t\tslc:    NewSearchLogController(db),\n\t\ttlc:    NewTermLogController(db),\n\t\tvslc:   NewVectorStoreLogController(db),\n\t\ttclc:   NewToolCallLogController(db),\n\t\tsc:     NewScreenshotController(db),\n\t}\n}\n\nfunc (fc *flowController) LoadFlows(ctx context.Context) error {\n\tflows, err := fc.db.GetFlows(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load flows: %w\", err)\n\t}\n\n\tfor _, flow := range flows {\n\t\tfw, err := LoadFlowWorker(ctx, flow, flowWorkerCtx{\n\t\t\tdb:     fc.db,\n\t\t\tcfg:    fc.cfg,\n\t\t\tdocker: fc.docker,\n\t\t\tprovs:  fc.provs,\n\t\t\tsubs:   fc.subs,\n\t\t\tflowProviderControllers: flowProviderControllers{\n\t\t\t\tmlc:  fc.mlc,\n\t\t\t\taslc: fc.aslc,\n\t\t\t\talc:  fc.alc,\n\t\t\t\tslc:  fc.slc,\n\t\t\t\ttlc:  fc.tlc,\n\t\t\t\tvslc: fc.vslc,\n\t\t\t\ttclc: fc.tclc,\n\t\t\t\tsc:   fc.sc,","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/flows.go#L97-L133","documentation":"LoadFlows reloads all flows from the database at startup and rebuilds in-memory flow workers. This error wraps a failure of fc.db.GetFlows(ctx), i.e., the initial DB query listing flows failed. Since LoadFlows typically runs during server bootstrap, this error usually means the application cannot restore its flow state.","triggerScenarios":"Calling LoadFlows when the database is unreachable, credentials are wrong, the flows table is missing (migrations not run), or the query times out.","commonSituations":"App started before PostgreSQL is ready (container orchestration race); wrong DB_* env vars; failed/pending goose migrations; network partition to the DB.","solutions":["Verify PostgreSQL is reachable and credentials in env config are correct.","Run backend migrations (goose) so the flows table exists.","Add startup retry/backoff so DB readiness races don't abort boot.","Check the wrapped cause in logs for the precise driver error."],"exampleFix":"// before\nif err := fc.LoadFlows(ctx); err != nil {\n\treturn fmt.Errorf(\"load flows: %w\", err)\n}\n// after\nerr := retry.Do(func() error { return fc.LoadFlows(ctx) }, retry.Attempts(5), retry.Delay(time.Second))\nif err != nil {\n\treturn fmt.Errorf(\"load flows after retries: %w\", err)\n}","handlingStrategy":"retry","validationCode":"// before boot\nif err := db.PingContext(ctx); err != nil {\n\tlog.Fatal(\"database unreachable: \", err)\n}","typeGuard":"func isLoadFlowsError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"failed to load flows\")\n}","tryCatchPattern":"if err := fc.LoadFlows(ctx); err != nil {\n\t// retry with backoff — DB may not be ready at startup\n\treturn retry.Do(func() error { return fc.LoadFlows(ctx) },\n\t\tretry.Attempts(5), retry.Delay(2*time.Second))\n}","preventionTips":["Add DB readiness checks/wait-for-db logic before app boot in Docker Compose/K8s.","Validate DB env vars (host, user, password, dbname) at startup.","Run goose migrations as part of deployment, before the server starts.","Implement startup retry/backoff for LoadFlows."],"tags":["database","startup","flow-lifecycle"],"backgroundTag":"database-unavailable","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}