fix(retry): @database_retry should not retry AutomationProfileSchemaVersionError #600

Closed
opened 2026-03-05 10:42:10 +00:00 by hurui200320 · 0 comments
Member

Background

Discovered during #495 (M4 acceptance gate). Parent Epic: #401.

Problem

AutomationProfileSchemaVersionError extends DatabaseError (repositories.py:4112). The @database_retry decorator (retry_patterns.py:233) retries on all DatabaseError subclasses. This means schema version mismatch errors — which are deterministic business logic errors, not transient failures — are retried 3 times with wait_fixed(0.5) before being re-raised.

The upsert method has except AutomationProfileSchemaVersionError: raise (line 4222) which correctly re-raises from the inner try/except, but the outer @database_retry decorator catches it and retries.

Expected Behavior

AutomationProfileSchemaVersionError should NOT be retried. It is a deterministic business logic error (optimistic concurrency guard), not a transient database failure.

Possible Solutions

  1. Change inheritance: Make AutomationProfileSchemaVersionError extend a non-retried base (e.g., ValueError or a new BusinessLogicError)
  2. Exclude from retry: Add retry_if_not_exception_type(AutomationProfileSchemaVersionError) to the decorator
  3. Apply pattern consistently: Audit all DatabaseError subclasses for similar issues (DuplicateAutomationProfileError, AutomationProfileNotFoundError, etc.)

Files

  • src/cleveragents/infrastructure/database/repositories.py:4112-4113 — Error class
  • src/cleveragents/infrastructure/database/repositories.py:4179-4236upsert method
  • src/cleveragents/core/retry_patterns.py:233-245@database_retry decorator
## Background Discovered during #495 (M4 acceptance gate). Parent Epic: #401. ## Problem `AutomationProfileSchemaVersionError` extends `DatabaseError` (`repositories.py:4112`). The `@database_retry` decorator (`retry_patterns.py:233`) retries on all `DatabaseError` subclasses. This means schema version mismatch errors — which are deterministic business logic errors, not transient failures — are retried 3 times with `wait_fixed(0.5)` before being re-raised. The `upsert` method has `except AutomationProfileSchemaVersionError: raise` (line 4222) which correctly re-raises from the inner try/except, but the outer `@database_retry` decorator catches it and retries. ## Expected Behavior `AutomationProfileSchemaVersionError` should NOT be retried. It is a deterministic business logic error (optimistic concurrency guard), not a transient database failure. ## Possible Solutions 1. **Change inheritance**: Make `AutomationProfileSchemaVersionError` extend a non-retried base (e.g., `ValueError` or a new `BusinessLogicError`) 2. **Exclude from retry**: Add `retry_if_not_exception_type(AutomationProfileSchemaVersionError)` to the decorator 3. **Apply pattern consistently**: Audit all `DatabaseError` subclasses for similar issues (`DuplicateAutomationProfileError`, `AutomationProfileNotFoundError`, etc.) ## Files - `src/cleveragents/infrastructure/database/repositories.py:4112-4113` — Error class - `src/cleveragents/infrastructure/database/repositories.py:4179-4236` — `upsert` method - `src/cleveragents/core/retry_patterns.py:233-245` — `@database_retry` decorator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#600
No description provided.