Skip to content

fix(queuefs): keep stale-recovery sweeping while mounted, not only at startup - #4751

Open
now-ing wants to merge 1 commit into
volcengine:mainfrom
now-ing:fix/iss-4303-runtime-stale-sweep
Open

now-ing wants to merge 1 commit into
volcengine:mainfrom
now-ing:fix/iss-4303-runtime-stale-sweep

Conversation

@now-ing

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

Copy link
Copy Markdown
Contributor

Problem

The queuefs stale recovery currently only runs at backend open time:

  • the SQLite backend (crates/ragfs/src/plugins/queuefs/backend.rs) calls recover_stale() once inside SQLiteQueueBackend::open, and
  • the cache (Redis) backend runs three bounded startup sweeps (0s / 30s / 60s) to cover the heartbeat-expiry window after a container restart, then stops (STARTUP_RECOVERY_SWEEPS = 3).

A worker that wedges after mounting — alive but no longer processing — therefore leaves its in-flight messages stuck in processing until every process restarts. This is one of the mechanisms behind the 47-minute silent queue stall analyzed in #4303: nothing crashes, so no mount-time recovery ever fires again.

Change

Recovery becomes a runtime property instead of a mount-time event, on both backends:

  • SQLite backend (recover_stale_sec > 0): a background sweep thread re-runs the exact same atomic recovery UPDATE every recover_stale_sec seconds. The thread holds a Weak handle to the shared connection and exits as soon as the backend is dropped; a failed sweep (e.g. transient SQLite busy) is logged and retried on the next tick. recover_stale_sec <= 0 keeps the historical mount-time-only behavior, so existing deployments see zero behavior change.
  • Cache backend: the recovery task now runs for the lifetime of the storage (immediately at startup, then every heartbeat TTL) instead of stopping after three sweeps. The per-instance heartbeat check inside the recover_stale script is unchanged, so messages owned by live instances are never re-queued.

Both sweeps reuse the existing recovery predicates verbatim. There are no wire-format, FFI, or configuration changes — this is purely a scheduling change.

Relationship to related work

Residual risks (documented trade-offs)

  • Delivery is at-least-once: a legitimately slow handler that exceeds recover_stale_sec may see its message re-queued and processed again. This trade-off already exists in the mount-time recovery; the periodic sweep only widens when it can trigger. Consumers must stay idempotent, as with any crash-recovery queue.
  • The SQLite predicate is a pure age threshold — it cannot distinguish a wedged worker from a slow one (no per-worker lease exists in the shared queue.db). The Redis backend is stricter (per-instance heartbeat), but a worker whose tokio runtime still refreshes its heartbeat while its processing logic is wedged will not be detected. A lease/heartbeat protocol for the SQLite backend would be a larger follow-up; this PR deliberately does not change any protocol.

Tests

  • test_sqlite_backend_periodic_recovery_recovers_stale_in_flight_message — a dequeued (wedged) message is re-queued by the periodic sweep after crossing the threshold, without reopening the database; below the threshold it is left alone.
  • test_sqlite_backend_no_periodic_recovery_when_recover_stale_disabled — with recover_stale_sec = 0 (current default) an in-flight message stays processing: zero behavior change when disabled.
  • recovery_loop_offsets_never_overflow_at_large_sweep_indexes — the now-unbounded sweep counter saturates instead of panicking/wrapping.
  • periodic_recovery_returns_message_from_dead_instance_without_reopen — Redis integration test (REDIS_URL-gated, skipped by default like the existing shutdown-recovery test): after waiting past the three legacy startup sweeps, a message from an instance whose heartbeat disappeared is still re-queued by the long-running loop.

Full local suites: cargo test -p ragfs --features cache → 471 passed / 0 failed; default-feature run → 437 passed / 0 failed; tests/misc/test_config_validation.py → 51 passed.

Fixes the runtime self-heal leg of #4303.

… startup

The queuefs stale recovery only ever ran at backend open time: the SQLite
backend recovered 'processing' rows once per process start, and the cache
(Redis) backend ran three bounded startup sweeps covering the
heartbeat-expiry window. A worker that wedged after mounting — alive but
no longer processing — left its in-flight messages stuck until every
process restarted, which is one of the mechanisms behind the 47-minute
silent stall in volcengine#4303.

Recovery is now a runtime property instead of a mount-time event:

- SQLite backend (recover_stale_sec > 0): a background sweep thread
  re-runs the exact same atomic recovery UPDATE every recover_stale_sec
  seconds. The thread holds a Weak handle to the connection and exits as
  soon as the backend is dropped; failed sweeps are logged and retried
  on the next tick. recover_stale_sec <= 0 keeps the historical
  mount-time-only behavior, so existing deployments are unchanged.
- Cache backend: the recovery task now runs for the lifetime of the
  storage (immediately, then every heartbeat TTL) instead of stopping
  after three sweeps. The per-instance heartbeat check inside the
  recover_stale script is unchanged, so live workers are never robbed.

Both sweeps reuse the existing recovery predicates verbatim — no wire
format, FFI, or configuration changes. Enabling the periodic sweep is
purely a scheduling change, which pairs naturally with volcengine#3989 (default
recover_stale_sec=300): once that lands, every bounded-recovery
deployment also self-heals wedged workers at runtime.

Delivery remains at-least-once: a legitimately slow handler that exceeds
the threshold may see its message re-queued and processed again, the
same trade-off the mount-time recovery already makes.

Fixes runtime self-heal leg of volcengine#4303.

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.

1 participant