vxcontrol/pentagi · error

failed to get flow %d status: %w

Error message

failed to get flow %d status: %w

What it means

Wrap in CreateAssistant when fw.GetStatus(ctx) fails for an existing in-memory flow. GetStatus reads the flow's status (via the worker/subscriber state), and a failure is wrapped with the flow ID so the caller knows which flow's status could not be read.

Source

Thrown at backend/pkg/controller/flows.go:282

		fw, err = LoadFlowWorker(ctx, flow, flowWorkerCtx)
		if err != nil {
			return fmt.Errorf("failed to load flow %d: %w", flowID, err)
		}

		fc.flows[flowID] = fw

		return nil
	}

	if flowID == 0 {
		if err := newFlow(); err != nil {
			return nil, err
		}
	} else if fw, ok = fc.flows[flowID]; ok {
		status, err := fw.GetStatus(ctx)
		if err != nil {
			return nil, fmt.Errorf("failed to get flow %d status: %w", flowID, err)
		}

		switch status {
		case database.FlowStatusCreated:
			return nil, fmt.Errorf("flow %d is not completed", flowID)
		case database.FlowStatusFinished, database.FlowStatusFailed:
			if err := loadFlow(); err != nil {
				return nil, err
			}
		case database.FlowStatusRunning, database.FlowStatusWaiting:
			break
		default:
			return nil, fmt.Errorf("flow %d is in unknown status: %s", flowID, status)
		}
	} else {
		if err := loadFlow(); err != nil {
			return nil, err
		}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Check the wrapped cause for a DB or context error and fix accordingly (DB up, longer deadline).
  2. Confirm the flow worker is still running and not torn down mid-request.
  3. Retry the CreateAssistant call; transient DB hiccups resolve on retry.
  4. Verify PostgreSQL health and connection pool limits.

Example fix

// before
ctx with 100ms deadline -> GetStatus times out
aw, err := ctl.CreateAssistant(shortCtx, userID, flowID, ...)
// after
aw, err := ctl.CreateAssistant(context.WithTimeout(ctx, 10*time.Second), userID, flowID, ...)
Defensive patterns

Strategy: try-catch

Try / catch

aw, err := ctl.CreateAssistant(ctx, userID, flowID, ...)
if err != nil {
    if strings.Contains(err.Error(), "failed to get flow") {
        // transient DB/ctx issue: retry with backoff
    }
    return err
}

Prevention

When it happens

Trigger: CreateAssistant with a flowID present in fc.flows whose GetStatus call errors — typically the underlying DB/status read fails, or the request context is canceled before the status can be fetched.

Common situations: Database connectivity problems while the worker reads persisted status, request context timeout, or the worker being shut down concurrently while its state is being queried.

Related errors


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