OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

Stale processing rows are never recovered — recover_stale_sec defaults to 0

Open procesd opened this issue 3 months ago • 1 comments

Description

When a worker crashes between dequeue and ack, the queue message stays in processing status forever. The QueueFS plugin has a recover_stale_sec parameter that resets stale processing rows to pending, but it defaults to 0 — disabled. There is no Python-layer fallback: the queue manager has no startup recovery logic, so zombie processing rows accumulate silently with every crash.

The Python docstring at named_queue.py:311-312 claims:

If the process crashes between steps 1 and 3, the backend RecoverStale on the next startup resets the message back to 'pending' for retry.

This is incorrect when recover_stale_sec=0 (the default).

Related: #3891 — in-memory coalesce map, same queue-durability family. (The reporter keeps queue-durability defects in separate issues by preference — that is why #3891 / #3892 / #3893 were filed separately.)

Code

openviking/utils/agfs_utils.py:161:

"recover_stale_sec": getattr(queuefs_config, "recover_stale_sec", 0),

The default of 0 means QueueFS never resets processing→pending. At startup, the Python layer does not call any recovery:

  • QueueManager.start() (queue_manager.py:106-117) — starts worker threads, no queue reconciliation.
  • QueueManager.prepare_task_tracking() (queue_manager.py:119-124) — rebuilds TaskWorkIndex from snapshot(), but does not reset processing→pending.
  • QueueManager.setup_standard_queues() (queue_manager.py:126-160) — creates queue objects, no recovery.

The only recovery path is QueueFS itself, gated on recover_stale_sec > 0.

Steps to Reproduce

  1. Start OpenViking with default config (no [queuefs] section in ov.conf, so recover_stale_sec=0).
  2. Enqueue some jobs and let a worker start processing one (dequeue transitions it to processing).
  3. Kill the worker process (or crash the server) before the worker acks.
  4. Restart the server.
  5. Query queue.db: the row remains status='processing' with its original processing_started_at timestamp. The /dequeue endpoint only returns pending rows, so the zombie is never retried. QueueManager reports 0 or 1 in-progress, but queue.db shows N processing rows — a silent mismatch.

Observed Impact

After a server crash-loop on 2026-08-08, the Semantic queue had 5 rows stuck in processing with timestamps predating the restart. Only 1 had a live worker behind it; the other 4 were orphaned markers that would persist until the queue database was manually cleaned. The same pattern appeared in the AddResource queue (1 row, 160+ minutes without a worker).

A cleanup script reset 9 processing rows to pending (processing_started_at=NULL) before the restart — after the crash-loop those rows reappeared as processing with their original old start times, suggesting QueueFS re-claimed them from WAL state that was not checkpointed, but with recover_stale_sec=0 they were left stuck instead of reset.

Suggested Fix

  1. Change the default recover_stale_sec to a reasonable value (e.g. 300 = 5 minutes). A processing message older than this gets reset to pending on the next dequeue attempt or at QueueFS mount time.
  2. At QueueFS mount time, scan for processing rows older than recover_stale_sec and reset them to pending — this handles the crash-while-processing case cleanly regardless of when the next dequeue arrives.
  3. Update the docstring at named_queue.py:311 to note that recovery depends on recover_stale_sec > 0.

Environment

  • OpenViking v0.4.12, self-hosted, native mode, SQLite queue backend
  • ov.conf has no [queuefs] section, confirming the default of 0 is active
  • Reproduced across multiple crash/restart cycles

procesd avatar Aug 08 '26 21:08 procesd

Thanks for reporting this! The current SQLite QueueFS implementation gives recover_stale_sec=0 the opposite meaning to the one described here: opening the backend always runs recovery, and a value of zero resets all persisted processing rows to pending. A positive value limits that recovery to rows older than the configured cutoff. See startup recovery and the zero-value branch.

Closing this report because the claimed disabled-on-restart recovery is not the current behavior. This does not imply automatic recovery of every worker stalled inside a still-running process; that is a separate case discussed in #4303.

If processing rows survive an actual backend reopen on a current version, please reopen, or comment requesting reopening, with the version, backend/configuration, restart logs and sanitized row states before and after restart.

qin-ctx avatar Sep 18 '26 08:09 qin-ctx