{"record":{"id":"b524a6e70f255270","repo":"vxcontrol/pentagi","slug":"wait-for-flow-completion-failed-w","errorCode":null,"errorMessage":"wait for flow completion failed: %w","messagePattern":"wait for flow completion failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/flow_manager.go","lineNumber":597,"sourceCode":"\t\t\t\t\"Call %s with detail='summary' to assess the current flow state before proceeding.\",\n\t\t\tGetFlowStatusToolName), nil\n\t}\n\n\twaitCtx, waitCancel := context.WithTimeout(ctx, timeout)\n\tdefer waitCancel()\n\n\tif err := t.handler(waitCtx); err != nil {\n\t\tif errors.Is(err, context.DeadlineExceeded) {\n\t\t\treturn fmt.Sprintf(\n\t\t\t\t\"The automation task is still running after waiting %s. \"+\n\t\t\t\t\t\"Call %s with detail='running' to see what the agent is doing right now.\",\n\t\t\t\ttimeout, GetFlowStatusToolName), nil\n\t\t}\n\t\tif errors.Is(err, context.Canceled) {\n\t\t\treturn \"\", fmt.Errorf(\n\t\t\t\t\"wait cancelled — the assistant session was interrupted while waiting for the automation\")\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"wait for flow completion failed: %w\", err)\n\t}\n\n\treturn fmt.Sprintf(\n\t\t\"The automation task has completed. \"+\n\t\t\t\"Call %s with detail='summary' to see the final status and results.\",\n\t\tGetFlowStatusToolName), nil\n}\n\n// stopFlowTool implements stop_flow.\ntype stopFlowTool struct {\n\tflowID  int64\n\tdb      database.Querier\n\thandler func(ctx context.Context, reason string) error\n}\n\nfunc NewStopFlowTool(flowID int64, db database.Querier, handler func(ctx context.Context, reason string) error) *stopFlowTool {\n\treturn &stopFlowTool{flowID: flowID, db: db, handler: handler}\n}","sourceCodeStart":579,"sourceCodeEnd":615,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/flow_manager.go#L579-L615","documentation":"The polling wait for flow completion failed with an error that is neither timeout-with-running-tasks nor context.Canceled. The raw store/poll error is wrapped, so the underlying cause (DB failure, unexpected poll error) is preserved and matchable via errors.Is/As.","triggerScenarios":"Calling wait_flow_completion when GetFlowTasks or the internal wait mechanism returns a non-context error mid-poll — e.g. the database connection drops while polling, or the polling helper returns an unexpected error condition.","commonSituations":"Database instability during long waits; infrastructure failure (db restart, network partition) while the tool polls; an unexpected error from the store layer that is not classified as timeout or cancellation.","solutions":["Read the wrapped cause with errors.Is/As or the message text to identify whether it is a DB or polling error.","Check database health and connectivity, then retry the wait.","Call get_flow_status as an alternative to determine the flow's state without waiting.","If it persists, check pentagi backend logs for the underlying store error and restart the affected service."],"exampleFix":"// diagnose the wrapped cause\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) { /* retry wait */ }\n    log.Printf(\"wait failed: %v\", err)\n}","handlingStrategy":"retry","validationCode":"// ensure DB is reachable before long waits\nawait checkDatabaseHealth();","typeGuard":null,"tryCatchPattern":"try {\n  await tool.call('wait_flow_completion', { timeout: 120 });\n} catch (err) {\n  if (String(err).includes('wait for flow completion failed')) {\n    const cause = parseWrappedCause(err);\n    log.error('wait failed', cause);\n    await sleep(3000); // retry after transient failure\n  }\n}","preventionTips":["Keep the database stable during long-running waits","Use get_flow_status as a fallback when wait fails","Log wrapped causes for diagnosis","Add connection-pool headroom to avoid store errors under load"],"tags":["database","polling","flow-wait","persistence"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}