vxcontrol/pentagi · error

failed to create flow agent log

Error message

failed to create flow agent log: %w

What it means

newFlowProviderWorkers builds the per-flow log worker set when a flow starts. Its first step creates the agent log worker via cnts.alc.NewFlowAgentLog(ctx, flowID, pub); any error is wrapped with this message and aborts flow worker construction, so the flow fails to start rather than run without agent event logging.

Solutions

  1. Check the wrapped error and Postgres logs for the underlying failure
  2. Run pending goose migrations so the agent-log schema is current
  3. Verify DB connectivity/pool settings, then retry flow creation
  4. Confirm the flow ID exists in the flows table before creating workers

Example fix

// before: create workers with no DB health check
workers, err := newFlowProviderWorkers(ctx, flowID, cnts, pub)
// after: precondition the DB and pass a fresh context with deadline
if err := db.PingContext(ctx); err != nil {
    return nil, fmt.Errorf("db unavailable before flow start: %w", err)
}
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
workers, err := newFlowProviderWorkers(ctx, flowID, cnts, pub)
Defensive patterns

Strategy: retry

Validate before calling

if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("db unavailable, cannot start flow: %w", err)
}

Type guard

func hasValidFlowID(flowID int64) bool { return flowID > 0 }

Try / catch

alw, err := cnts.alc.NewFlowAgentLog(ctx, flowID, pub)
if err != nil {
    if isTransientDBError(err) { /* retry up to 3x with backoff */ }
    return nil, fmt.Errorf("failed to create flow agent log (flow=%d): %w", flowID, err)
}

Prevention

When it happens

Trigger: Creating a new flow (or restoring its workers) calls newFlowProviderWorkers and NewFlowAgentLog fails — usually a database error inserting/initializing the agent log, or the flow ID is invalid/nonexistent.

Common situations: PostgreSQL down or connection pool exhausted at flow creation time; flow row not yet committed when workers are created; concurrent flow deletion; DB schema out of date (missing migration).

Related errors


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

Appendix: source

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

	} else {
		span.End(
			langfuse.WithSpanOutput(result),
			langfuse.WithSpanStatus("success"),
		)
	}

	return nil
}

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

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

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

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

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

View on GitHub (pinned to ea665308ba)