{"record":{"id":"a9efca24daa9e8cf","repo":"vxcontrol/pentagi","slug":"failed-to-check-flow-status-w","errorCode":null,"errorMessage":"failed to check flow status: %w","messagePattern":"failed to check flow status: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/flow_manager.go","lineNumber":558,"sourceCode":"}\n\nfunc (t *waitFlowCompletionTool) Handle(ctx context.Context, name string, args json.RawMessage) (string, error) {\n\tvar action WaitFlowCompletionAction\n\tif err := json.Unmarshal(args, &action); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse %s args: %w\", WaitFlowCompletionToolName, err)\n\t}\n\n\ttimeout := time.Duration(action.Timeout.Int64()) * time.Second\n\tswitch {\n\tcase timeout <= 0:\n\t\ttimeout = waitFlowDefaultTimeout\n\tcase timeout > waitFlowMaxTimeout:\n\t\ttimeout = waitFlowMaxTimeout\n\t}\n\n\ttasks, err := t.db.GetFlowTasks(ctx, t.flowID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to check flow status: %w\", err)\n\t}\n\n\tif len(tasks) == 0 {\n\t\treturn fmt.Sprintf(\n\t\t\t\"The automation has not been created yet — no tasks exist. \"+\n\t\t\t\t\"Use %s to submit the first task description and start the automation.\",\n\t\t\tSubmitFlowInputToolName), nil\n\t}\n\n\tisRunning := false\n\tfor _, task := range tasks {\n\t\tif task.Status == database.TaskStatusRunning {\n\t\t\tisRunning = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif !isRunning {","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/flow_manager.go#L540-L576","documentation":"After parsing the wait arguments, the tool calls db.GetFlowTasks(flowID) to inspect the flow's task list and that database query failed. The error is wrapped so callers can match the underlying GORM/SQL error (connection loss, cancelled context, missing table). Without the task list the tool cannot report flow status.","triggerScenarios":"Calling wait_flow_completion (or stop_flow, which shares this message) while the PostgreSQL connection is down, the context is cancelled, the flows/tasks tables are missing, or GetFlowTasks returns any store-level error for the tool's bound flowID.","commonSituations":"Database container restarted or unreachable during a long agent run; DB credentials/network misconfigured in the environment; migration not applied so tables are absent; context cancelled by an upstream shutdown racing the query.","solutions":["Check PostgreSQL availability and connectivity (docker compose ps, logs of the db service) and restart the DB if it crashed.","Verify DB credentials and connection settings in the environment (.env: POSTGRES_* variables).","Run the migrations (they apply at startup via goose) and confirm the flows/tasks tables exist.","Retry the tool call once the database is healthy; if the wrapped error is context.Canceled, re-issue the request in a live session."],"exampleFix":"// before: db unreachable\n// after: ensure db is up then retry\n$ docker compose up -d postgres\n$ docker compose logs pentagi  # confirm reconnection","handlingStrategy":"retry","validationCode":"// Pre-check DB reachability before invoking flow tools\nawait fetch(`${baseUrl}/api/health`).then(r => { if (!r.ok) throw new Error('backend unhealthy'); });","typeGuard":null,"tryCatchPattern":"try {\n  await tool.call('wait_flow_completion', { timeout: 60 });\n} catch (err) {\n  if (String(err).includes('failed to check flow status')) {\n    await sleep(2000); // transient DB issue — retry with backoff\n  }\n}","preventionTips":["Ensure PostgreSQL is up and healthy before long agent runs","Keep DB credentials/connection env vars correct","Verify migrations ran at startup","Avoid cancelling the session context while flow tools are in flight"],"tags":["database","postgresql","persistence","flow-status"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}