vxcontrol/pentagi · error

wait for flow completion failed: %w

Error message

wait for flow completion failed: %w

What it means

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.

Source

Thrown at backend/pkg/tools/flow_manager.go:597

				"Call %s with detail='summary' to assess the current flow state before proceeding.",
			GetFlowStatusToolName), nil
	}

	waitCtx, waitCancel := context.WithTimeout(ctx, timeout)
	defer waitCancel()

	if err := t.handler(waitCtx); err != nil {
		if errors.Is(err, context.DeadlineExceeded) {
			return fmt.Sprintf(
				"The automation task is still running after waiting %s. "+
					"Call %s with detail='running' to see what the agent is doing right now.",
				timeout, GetFlowStatusToolName), nil
		}
		if errors.Is(err, context.Canceled) {
			return "", fmt.Errorf(
				"wait cancelled — the assistant session was interrupted while waiting for the automation")
		}
		return "", fmt.Errorf("wait for flow completion failed: %w", err)
	}

	return fmt.Sprintf(
		"The automation task has completed. "+
			"Call %s with detail='summary' to see the final status and results.",
		GetFlowStatusToolName), nil
}

// stopFlowTool implements stop_flow.
type stopFlowTool struct {
	flowID  int64
	db      database.Querier
	handler func(ctx context.Context, reason string) error
}

func NewStopFlowTool(flowID int64, db database.Querier, handler func(ctx context.Context, reason string) error) *stopFlowTool {
	return &stopFlowTool{flowID: flowID, db: db, handler: handler}
}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Read the wrapped cause with errors.Is/As or the message text to identify whether it is a DB or polling error.
  2. Check database health and connectivity, then retry the wait.
  3. Call get_flow_status as an alternative to determine the flow's state without waiting.
  4. If it persists, check pentagi backend logs for the underlying store error and restart the affected service.

Example fix

// diagnose the wrapped cause
if err != nil {
    if errors.Is(err, context.DeadlineExceeded) { /* retry wait */ }
    log.Printf("wait failed: %v", err)
}
Defensive patterns

Strategy: retry

Validate before calling

// ensure DB is reachable before long waits
await checkDatabaseHealth();

Try / catch

try {
  await tool.call('wait_flow_completion', { timeout: 120 });
} catch (err) {
  if (String(err).includes('wait for flow completion failed')) {
    const cause = parseWrappedCause(err);
    log.error('wait failed', cause);
    await sleep(3000); // retry after transient failure
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/b524a6e70f255270. Report an issue: GitHub.