vxcontrol/pentagi · error

failed to create flow msg log

Error message

failed to create flow msg log: %w

What it means

Second step of newFlowProviderWorkers: the message log worker is created via cnts.mlc.NewFlowMsgLog(ctx, flowID, pub). A failure here is wrapped with this message and stops flow worker construction, meaning the flow cannot start without message logging persistence.

Solutions

  1. Read the wrapped cause in backend logs to identify the failing SQL
  2. Check PostgreSQL health and message_logs table status
  3. Apply pending migrations and retry flow creation
  4. Re-check that the flow row still exists (concurrent deletion)

Example fix

// before: sequential creation, partial failure leaves nothing behind
mlw, err := cnts.mlc.NewFlowMsgLog(ctx, flowID, pub)
if err != nil { return nil, fmt.Errorf("failed to create flow msg log: %w", err) }
// after: ensure ctx deadline so failures surface as timeouts, and log flowID
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
mlw, err := cnts.mlc.NewFlowMsgLog(ctx, flowID, pub)
if err != nil {
    return nil, fmt.Errorf("failed to create flow msg log (flow=%d): %w", flowID, err)
}
Defensive patterns

Strategy: retry

Validate before calling

var exists int
if err := db.QueryRowContext(ctx, `SELECT COUNT(1) FROM flows WHERE id=$1`, flowID).Scan(&exists); err != nil || exists == 0 {
    return fmt.Errorf("flow %d missing before creating msg log", flowID)
}

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: NewFlowMsgLog fails during flow startup — DB error creating/accessing the message log storage for this flow, invalid flowID, or context cancellation after the agent log step succeeded.

Common situations: Postgres connection dropped between the agent-log and msg-log steps; flow was deleted concurrently; oversized/backlogged message_logs table causing timeouts; missing migration for the message log schema.

Related errors


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

Appendix: source

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

	}

	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)
	if err != nil {
		return nil, fmt.Errorf("failed to create flow vector store log: %w", err)
	}

	tclw, err := cnts.tclc.NewFlowToolCallLog(ctx, flowID, pub)

View on GitHub (pinned to ea665308ba)