vxcontrol/pentagi · error

failed to create flow term log: %w

Error message

failed to create flow term log: %w

What it means

Fourth step of newFlowProviderWorkers: the terminal log worker is created via cnts.tlc.NewFlowTermLog(ctx, flowID, pub). An error is wrapped with this message and flow startup aborts, since terminal command/session output cannot be persisted without it.

Source

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

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

	sw, err := cnts.sc.NewFlowScreenshot(ctx, flowID, pub)
	if err != nil {
		return nil, fmt.Errorf("failed to create flow screenshot: %w", err)
	}

	return &flowProviderWorkers{

View on GitHub (pinned to ea665308ba)

Solutions

  1. Check the wrapped cause and Postgres server logs
  2. Apply pending migrations so the terminal-log schema is present
  3. Verify DB connectivity and retry flow creation
  4. Confirm the flow still exists in the DB

Example fix

// before: retries absent; transient DB blip kills flow start
tlw, err := cnts.tlc.NewFlowTermLog(ctx, flowID, pub)
if err != nil { return nil, fmt.Errorf("failed to create flow term log: %w", err) }
// after: bounded retry for transient DB errors
var tlw *termlog.Worker
gofmt // pseudo: retry helper
err = retry(3, time.Second, func() error {
    var e error
    tlw, e = cnts.tlc.NewFlowTermLog(ctx, flowID, pub)
    return e
})
if err != nil { return nil, fmt.Errorf("failed to create flow term log: %w", err) }
Defensive patterns

Strategy: retry

Validate before calling

var t int
if err := db.QueryRowContext(ctx, `SELECT COUNT(1) FROM information_schema.tables WHERE table_name='terminal_logs'`).Scan(&t); err != nil || t == 0 {
    return errors.New("terminal log schema missing: run migrations")
}

Type guard

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

Try / catch

tlw, err := cnts.tlc.NewFlowTermLog(ctx, flowID, pub)
if err != nil {
    if isTransientDBError(err) { /* retry up to 3x */ }
    return nil, fmt.Errorf("failed to create flow term log (flow=%d): %w", flowID, err)
}

Prevention

When it happens

Trigger: NewFlowTermLog fails during flow startup — DB error initializing terminal log storage for the flow, nonexistent flowID, or context cancellation before this step.

Common situations: PostgreSQL unreachable or restarting during flow creation; terminal_logs table missing from an incomplete migration; concurrent flow deletion; ctx deadline exceeded after earlier slow worker-creation steps.

Related errors


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