vxcontrol/pentagi · error

failed to get all flows: %w

Error message

failed to get all flows: %w

What it means

Cleanup starts by fetching every flow row to mark flows finished and stop containers; this error wraps a failure of that initial GetFlows query. No cleanup work has been performed when it is returned.

Source

Thrown at backend/pkg/docker/client.go:791

		Status: database.ContainerStatusDeleted,
		ID:     dbID,
	})
	if err != nil {
		return fmt.Errorf("failed to update container status to deleted: %w", err)
	}

	logger.Info("container removed")

	return nil
}

func (dc *dockerClient) Cleanup(ctx context.Context) error {
	logger := dc.logger.WithContext(ctx).WithField("docker", "cleanup")
	logger.Info("cleaning up containers and making all flows finished...")

	flows, err := dc.db.GetFlows(ctx)
	if err != nil {
		return fmt.Errorf("failed to get all flows: %w", err)
	}

	containers, err := dc.db.GetContainers(ctx)
	if err != nil {
		return fmt.Errorf("failed to get all containers: %w", err)
	}

	flowsStatusMap := make(map[int64]database.FlowStatus)
	for _, flow := range flows {
		flowsStatusMap[flow.ID] = flow.Status
	}
	flowContainersMap := make(map[int64][]database.Container)
	for _, container := range containers {
		flowContainersMap[container.FlowID] = append(flowContainersMap[container.FlowID], container)
	}

	var wg sync.WaitGroup
	removeContainer := func(containerID string, dbID int64) {

View on GitHub (pinned to ea665308ba)

Solutions

  1. Verify database connectivity and that all goose migrations are applied
  2. Check for table-level locks on flows (`pg_locks`) and terminate blocking sessions
  3. Retry Cleanup after the database is healthy — it is safe to re-run since it is idempotent in intent
  4. Review backend logs for the underlying pq/pgx error code to distinguish connectivity vs schema issues
Defensive patterns

Strategy: retry

Validate before calling

if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("database unavailable, deferring cleanup: %w", err)
}

Try / catch

if err := dc.Cleanup(ctx); err != nil {
    if strings.Contains(err.Error(), "failed to get all flows") {
        // DB was unavailable; re-run cleanup after recovery
        scheduleRetry(ctx, dc.Cleanup)
    }
}

Prevention

When it happens

Trigger: dc.db.GetFlows fails at Cleanup start: database unreachable, query timeout, corrupted/locked table, or a schema mismatch (migration not applied).

Common situations: Postgres down or restarting at backend shutdown/startup when Cleanup runs; network partition to the DB; pending goose migration leaving the flows table in an unexpected schema; connection pool exhausted.

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/0ebd1f23d6b60f5e. Report an issue: GitHub.