Skip to content

fix: recognize transient DB errors and reuse KB embeddings across retries - #39

Open
KeyCOrigin wants to merge 3 commits into
OpenDCAI:mainfrom
KeyCOrigin:dev01
Open

KeyCOrigin wants to merge 3 commits into
OpenDCAI:mainfrom
KeyCOrigin:dev01

Conversation

@KeyCOrigin

Copy link
Copy Markdown

Problem

Read recovery primarily recognizes generic Python exceptions and follows __cause__. It misses database-specific transient errors, including SQLite BUSY, MySQL deadlocks, and PostgreSQL serialization failures, as well as exceptions stored only in SQLAlchemy’s .orig.

KB vector-search retries also recompute an already successful query embedding, adding latency and embedding calls.

Changes

  • Add conservative, code-based classification for:
    • SQLite BUSY and its extended codes.
    • MySQL lock-wait timeouts, deadlocks, and specific connection-loss errors.
    • PostgreSQL connection failures, serialization failures, deadlocks, and temporary startup unavailability.
  • Traverse both __cause__ and SQLAlchemy DBAPIError .orig, with cycle protection.
  • Reject retries for authentication, permission, syntax, and PostgreSQL query-cancellation errors. Keep SQLite LOCKED non-retryable pending more specific handling.
  • Recognize SQLAlchemy connection-pool timeouts while preserving existing shared retry budgets, backoff, and query deadlines.
  • Reuse successful query embeddings within a single KB retrieval when retrying vector search. Failed embedding attempts remain eligible for retry.

Validation

201 tests passed across database, read-recovery, runtime-reliability, and workspace regression suites.

Coverage includes:

  • Raw driver exceptions, SQLAlchemy wrappers, and .orig-only exceptions.
  • Error-code precedence, cyclic exception chains, and shared nested retry budgets.
  • Real SQLite exclusive-lock contention: the initial read raises BUSY, and the retry succeeds after the other connection releases its lock.
  • Retry-budget exhaustion under persistent locking.
  • Single-attempt failure for invalid SQL and missing tables.
  • Recovery through the workspace DB tool while preserving the pinned revision.

MySQL and PostgreSQL tests simulate driver exception contracts; no live-server integration tests were performed.

Scope

This change does not add a PostgreSQL adapter or write retries. Direct calls to DBService.query_sql() remain single-attempt; automatic retries use the existing recover_read wrapper.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant