vxcontrol/pentagi · error

failed to delete provider: %w

Error message

failed to delete provider: %w

What it means

DeleteProvider removes the provider row owned by (ID, UserID) via pc.db.DeleteUserProvider. Any database error is wrapped as "failed to delete provider: %w". Note this path only fails on DB errors — deleting a non-existent row typically succeeds with 0 affected rows rather than erroring, depending on the SQLC query.

Source

Thrown at backend/pkg/providers/providers.go:826

	}

	return result, nil
}

func (pc *providerController) DeleteProvider(
	ctx context.Context,
	userID int64,
	prvID int64,
) (database.Provider, error) {
	ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "providers.DeleteProvider")
	defer span.End()

	result, err := pc.db.DeleteUserProvider(ctx, database.DeleteUserProviderParams{
		ID:     prvID,
		UserID: userID,
	})
	if err != nil {
		return result, fmt.Errorf("failed to delete provider: %w", err)
	}

	return result, nil
}

func (pc *providerController) TestAgent(
	ctx context.Context,
	prvtype provider.ProviderType,
	agentType pconfig.ProviderOptionsType,
	config *pconfig.AgentConfig,
) (tester.AgentTestResults, error) {
	ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "providers.TestAgent")
	defer span.End()

	var result tester.AgentTestResults

	// Create provider config with single agent configuration
	testConfig := &pconfig.ProviderConfig{}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Inspect the wrapped error for a foreign-key/constraint violation message
  2. Delete or reassign dependent rows (flows, logs) that reference the provider first
  3. Retry on transient connection errors with backoff
  4. Verify DB connectivity and pool status

Example fix

// before
_, err := ctrl.DeleteProvider(ctx, userID, prvID) // FK violation
// after
if err := deleteDependentRecords(ctx, userID, prvID); err != nil {
    return err
}
_, err = ctrl.DeleteProvider(ctx, userID, prvID)
Defensive patterns

Strategy: try-catch

Validate before calling

// no pre-call validation applies; at most confirm existence
if _, err := db.GetUserProvider(ctx, database.GetUserProviderParams{ID: prvID, UserID: userID}); err != nil {
    return err
}

Try / catch

result, err := ctrl.DeleteProvider(ctx, userID, prvID)
if err != nil {
    if isForeignKeyViolation(err) {
        return fmt.Errorf("provider is still referenced by flows; reassign or delete them first: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling DeleteProvider with a DB connection failure, foreign-key restriction (provider still referenced), or other SQL error.

Common situations: Postgres unavailable; a foreign key from flows/logs referencing the provider blocks deletion (if a RESTRICT constraint exists); transient network error to the database.

Related errors


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