vxcontrol/pentagi · error

failed to get flow agent log: %w

Error message

failed to get flow agent log: %w

What it means

getFlowProviderWorkers rebuilds the worker set for an existing flow (e.g. on restart/resume); its first step fetches the agent log worker via cnts.alc.GetFlowAgentLog(ctx, flowID). Failure is wrapped with this message and flow resume aborts — the existing flow's agent-log worker could not be reattached.

Source

Thrown at backend/pkg/controller/flow.go:1220

	return &flowProviderWorkers{
		mlw:  mlw,
		alw:  alw,
		slw:  slw,
		tlw:  tlw,
		vslw: vslw,
		tclw: tclw,
		sw:   sw,
	}, nil
}

func getFlowProviderWorkers(
	ctx context.Context,
	flowID int64,
	cnts *flowProviderControllers,
) (*flowProviderWorkers, error) {
	alw, err := cnts.alc.GetFlowAgentLog(ctx, flowID)
	if err != nil {
		return nil, fmt.Errorf("failed to get flow agent log: %w", err)
	}

	mlw, err := cnts.mlc.GetFlowMsgLog(ctx, flowID)
	if err != nil {
		return nil, fmt.Errorf("failed to get flow msg log: %w", err)
	}

	slw, err := cnts.slc.GetFlowSearchLog(ctx, flowID)
	if err != nil {
		return nil, fmt.Errorf("failed to get flow search log: %w", err)
	}

	tlw, err := cnts.tlc.GetFlowTermLog(ctx, flowID)
	if err != nil {
		return nil, fmt.Errorf("failed to get flow term log: %w", err)
	}

	vslw, err := cnts.vslc.GetFlowVectorStoreLog(ctx, flowID)

View on GitHub (pinned to ea665308ba)

Solutions

  1. Confirm an agent log record exists for this flowID (and was not garbage-collected)
  2. Check DB connectivity and the wrapped error for the exact cause
  3. If the flow is genuinely fresh, start it with newFlowProviderWorkers instead of get
  4. Restore from a correct backup or recreate the flow if log rows are lost

Example fix

// before: resume path fails hard when no worker exists yet
workers, err := getFlowProviderWorkers(ctx, flowID, cnts)
if err != nil { return nil, err }
// after: fall back to creating fresh workers when none exist
workers, err := getFlowProviderWorkers(ctx, flowID, cnts)
if err != nil {
    log.Printf("no existing workers for flow %d, creating new: %v", flowID, err)
    workers, err = newFlowProviderWorkers(ctx, flowID, cnts, pub)
    if err != nil { return nil, err }
}
Defensive patterns

Strategy: fallback

Validate before calling

var exists int
if err := db.QueryRowContext(ctx, `SELECT COUNT(1) FROM agent_logs WHERE flow_id=$1`, flowID).Scan(&exists); err != nil {
    return err
}
if exists == 0 { // no prior agent log: use newFlowProviderWorkers instead }

Type guard

func agentLogExists(ctx context.Context, db DB, flowID int64) bool {
    var n int
    _ = db.QueryRowContext(ctx, `SELECT COUNT(1) FROM agent_logs WHERE flow_id=$1`, flowID).Scan(&n)
    return n > 0
}

Try / catch

alw, err := cnts.alc.GetFlowAgentLog(ctx, flowID)
if err != nil {
    if errors.Is(err, sql.ErrNoRows) || database.IsNotFound(err) {
        // fall back to newFlowProviderWorkers to create fresh workers
        return newFlowProviderWorkers(ctx, flowID, cnts, pub)
    }
    return nil, fmt.Errorf("failed to get flow agent log (flow=%d): %w", flowID, err)
}

Prevention

When it happens

Trigger: Resuming/restarting a flow calls getFlowProviderWorkers and GetFlowAgentLog fails — the agent log record for this flowID does not exist (never created or already cleaned up), DB unreachable, or context cancelled.

Common situations: Restarting a flow whose workers were torn down and log rows garbage-collected; DB outage during resume; flowID typo or stale reference from the UI; restore of DB from a dump missing this flow's logs.

Related errors


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