Skip to content

fix(observability): keep original SQLite error when auto-rollback empties the transaction - #4748

Open
now-ing wants to merge 1 commit into
volcengine:mainfrom
now-ing:fix/iss-4303-audit-rollback-resilience
Open

now-ing wants to merge 1 commit into
volcengine:mainfrom
now-ing:fix/iss-4303-audit-rollback-resilience

Conversation

@now-ing

@now-ing now-ing commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Production incident in #4303: the whole async worker pool went silent for 47 minutes (460 pending jobs untouched, in_progress frozen, /health still 200) after a storage disruption during a model-swap rollout. The only diagnostic in the server logs was:

cannot rollback - no transaction is active

That message is not the root cause — it is this repository's own error path masking the root cause.

Root cause chain (code-level)

SQLiteUsageAuditStore wraps every write batch in an explicit transaction:

conn.execute("BEGIN")
try:
    ...
    conn.execute("COMMIT")
except Exception:
    conn.execute("ROLLBACK")   # <-- here
    raise

SQLite auto-rolls-back the active transaction after fatal errors (SQLITE_FULL, SQLITE_IOERR, …). When that happens on a PVC/network-backed volume (the reporter's environment: K8s/Talos + Ceph RBD), by the time the except block runs there is no transaction left, so conn.execute("ROLLBACK")") itself raises sqlite3.OperationalError: cannot rollback - no transaction is active — which replaces the real storage error (disk I/O error, etc.) via the standard exception-replacement rule. Three call sites were affected:

Additionally, the audit worker logged flush failures with exc_info=logger.isEnabledFor(logging.DEBUG), so at production log levels even the surviving message had no traceback — contributing to the "silent" post-mortem.

Fix

  • New _rollback_safely(conn, context=...) helper: skips the explicit ROLLBACK when conn.in_transaction is already False (SQLite already rolled back), and converts a failing ROLLBACK into a warning instead of letting it shadow the exception being handled. Applied to all three sites.
  • UsageAuditWorker._flush now always logs the traceback for flush failures.

The store's asyncio lock is released and the worker loop keeps running in both cases, so after this fix a transient storage fault leaves behind the original error in the logs and the next batch succeeds on the same connection.

Testing

New tests/observability/test_usage_audit_rollback_resilience.py (conftest-free):

  • auto-rollback fault during a batch → the raised exception is the original disk I/O error, not cannot rollback
  • fault without auto-rollback → the still-active transaction is rolled back (in_transaction False afterwards)
  • transient fault → a later batch succeeds on the same connection (no wedged store)
  • same guarantee for the delete_user_data path

All 4 tests fail on main (they surface cannot rollback - no transaction is active) and pass with this change; existing suites (test_usage_audit_store.py, test_usage_audit_worker.py, test_usage_audit_runtime.py) stay green (13 passed).

Relation to #4303

This fixes the diagnostic-masking half of the incident: the reporter only ever saw the rollback error, never the underlying storage fault. The other halves are tracked in the cross-referenced chain: worker-liveness detection (#3542), manual recovery while wedged (#4627), orphaned-row hardening (#3989 / #4621), and the Python-side in-progress bookkeeping leak (#4745). A runtime (non-mount-time-only) stale sweep for QueueFS remains the open gap.

Closes #4303 (diagnostic half).

…ties the transaction

SQLite auto-rolls-back a transaction after fatal errors (SQLITE_FULL,
SQLITE_IOERR). The usage/audit store error paths issued a bare
conn.execute("ROLLBACK") that then raised
'cannot rollback - no transaction is active', replacing the underlying
storage failure with a misleading secondary error. Production instance
of this signature: volcengine#4303 (worker pool silent for
47min after storage disruption; logs only showed the rollback error).

- Skip the explicit ROLLBACK when conn.in_transaction is already False
- Never let ROLLBACK failures shadow the exception being handled
- Always log the flush-failure traceback (was DEBUG-gated, hiding the
  origin at production log levels)

Fixes the diagnostic-masking half of volcengine#4303; the wedged-worker recovery
gap is tracked separately.

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

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Bug] Crash-orphaned processing queue rows survive restarts and permanently block queue workers (RecoverStale never fires)

1 participant