[Bug] Crash-orphaned processing queue rows survive restarts and permanently block queue workers (RecoverStale never fires)
[Bug] Crash-orphaned processing queue rows survive restarts and permanently block queue workers
Version: v0.4.16 (local storage backend, QueueFS SQLite at
<workspace>/_system/queue/queue.db)
Summary
When the server is killed mid-processing (crash, OOM, operator restart),
queue_messages rows remain in status='processing' with a stale
processing_started_at. On restart, RecoverStale never re-queues them,
and the worker semaphore (max_concurrent) treats them as live in-flight
work. With the default max_concurrent_add_resource: 4, four orphaned rows
pin all four AddResource workers forever: ~7k queued items sit at 0
completions while the process idles at 0% CPU.
queuefs/named_queue.py documents the intended behavior — "re-queued on
the next startup via RecoverStale" — but nothing recovers these rows in
practice, even across multiple restarts.
Repro
- Enqueue bulk work (e.g. add ~100 resources with
wait: false). - While workers process (
status='processing'rows exist), kill the server ungracefully:pkill -f openviking-server. - Restart the server.
- Observe via
sqlite3 queue.db "SELECT queue_name,status,COUNT(*) FROM queue_messages GROUP BY 1,2": theprocessingrows persist. GET /api/v1/observer/queueshowsIn Progress = Nforever; pending count never drains;GET /api/v1/tasks?status=in_progressreturns[](the task tracker knows they are dead — only the queue rows disagree).
Manual repair (what we run today)
With the server stopped:
UPDATE queue_messages SET status='pending', processing_started_at=NULL
WHERE status='processing';
Expectation
On startup, rows in processing whose owning task no longer exists in the
task tracker (or older than a visibility timeout) should be re-queued as
pending, matching the documented RecoverStale contract.
Related
- The embedding consumer also has an in-memory circuit breaker that stays open after the backend crashes and recovers; worth a look in the same pass (we restart the whole server to clear it).
Hi, thanks for the report.
I tried to reproduce this on v0.4.16, but could not reproduce it.
I simulated a crash after dequeueing a message without acking it. Before remount, the message was left as processing:
db_before_remount= [('AddResource', 'processing', 1)]
After starting a new process and mounting the same QueueFS DB again, it was recovered to pending and could be dequeued again:
db_after_remount= [('AddResource', 'pending', 1)]
I also rebuilt the v0.4.16 ragfs-python native binding from source and got the same result.
Could you share more details about your environment and restart path, especially whether QueueFS is mounted again after restart and whether you are using the PyPI wheel or a locally built package?
Thanks for the detailed reproduction attempt. We've since root-caused our specific incident and it's different from a crash-orphan scenario:
What actually happened (production, k8s/Talos, OpenViking 0.4.16)
The queue workers stalled without any crash — the pod was Running, the HTTP health endpoint returned 200, but all async workers went silent:
- Trigger: an audit-layer SQLite error
cannot rollback - no transaction is activeappeared in the server logs - Effect: the async worker pool stopped processing — 460 pending jobs sat untouched for 47 minutes
- Health endpoint: still 200 (the HTTP server is separate from the async workers)
- Fix: a pod restart (K8s rollout restart) cleared the in-memory worker state; the FS-persisted queue was fully reclaimed and drained normally
Key diagnostic
The observer/queue endpoint showed pending > 0 with in_progress stuck at a constant value, and processed counters frozen across two samples taken 30s apart. This is how we detect the stall — we deployed a Kubernetes CronJob that samples the queue twice and triggers a deployment restart if pending > 5 with zero processed-count delta.
Environment
- OpenViking 0.4.16 (PyPI wheel, custom Docker image with patches)
- Deployment: Kubernetes (Talos), PVC-backed storage (Ceph RBD)
- The stall occurred after multiple container restarts during a model swap (VLM container recreated, connection pool disruption)
The crash-orphan recovery you demonstrated works correctly in our environment too — this is a different failure mode where alive-but-wedged workers stop processing without crashing.
Cross-referencing a mitigation chain that maps directly onto the failure mode you described (workers silent while /health stays 200):
- Detection gap: the health endpoint clearly doesn't observe worker-pool liveness. PR #3542 adds
GET /api/v1/system/idle, which reports queue depth and active workers — an external monitor polling it would have caught "460 pending, 0 active for 47 minutes" instead of a green health check. Extending that signal with alast_processed_attimestamp per worker would make total silence distinguishable from "slowly draining". - Recovery while stalled: once the pool is wedged, restart is currently the only lever. PR #4627 (from #4553's real-world case — a
session_commitwedged inrunningfor 55 minutes, holding the single serial slot and starving everypendingtask behind it) adds the manual cancel action in the Web Studio Task Center on top of the existingPOST /api/v1/tasks/{id}/cancel; in our incident the cancel released the slot and the queue drained normally within seconds, with already-persisted writes kept. - Orphaned-row hardening for the original crash scenario in this issue: #3989 (bounded
recover_stale_secdefault) and #4621 (transient-lock retry on backfill commits) both attack the "rows survive restarts and block workers" family.
The cannot rollback - no transaction is active trigger suggests the audit layer's SQLite session got into a broken transaction state and every subsequent worker operation failed on the same poisoned handle — if the pool shares one connection rather than per-worker sessions, that would explain all-at-once silence. Worth checking whether the audit writer isolates its connection per task.
Follow-up with the code-level path from your cannot rollback - no transaction is active log line to the silent pool — plus a fix for the diagnostic-masking part: PR #4748.
1. Where cannot rollback comes from (and why it hid the real error)
SQLiteUsageAuditStore runs every batch in an explicit transaction (openviking/observability/usage_audit/sqlite_store.py, _record_projection_sync):
conn.execute("BEGIN")
try:
...
conn.execute("COMMIT")
except Exception:
conn.execute("ROLLBACK") # <-- fires here
raise
SQLite auto-rolls-back a transaction after fatal errors (SQLITE_IOERR, SQLITE_FULL, …) — exactly what a PVC-backed volume (your Ceph RBD) produces during a connection-pool disruption. By the time the except block runs there is no transaction left, so the ROLLBACK itself raises cannot rollback - no transaction is active, and Python's exception replacement means the underlying storage error never reaches the log. The audit worker itself survives (_flush catches everything and keeps looping), so that log line is a symptom of the storage disruption, not the thing that killed the queue workers. #4748 guards all three rollback sites (record_batch, delete_user_data, v4→v5 migration) with conn.in_transaction and always logs flush tracebacks — after it, the same incident leaves disk I/O error (or whatever the real fault is) in the log instead.
2. Why the queue workers go silent all at once
Two compounding mechanisms, both matching your symptoms exactly (pending frozen, in_progress constant, 0% CPU, health 200):
- Single serialized native connection: the QueueFS SQLite backend guards its one connection with a single mutex (
crates/ragfs/src/plugins/queuefs/backend.rs,SQLiteQueueBackend { conn: Mutex<Connection> }). Every queue op (size/dequeue/ack/enqueue) from every worker thread funnels through it. One operation parked on a wedged volume I/O holds the mutex indefinitely → every subsequent queue call from all workers blocks inasyncio.to_thread→ the whole pool freezes without spinning CPU. Your post-restart observation ("FS-persisted queue fully reclaimed and drained normally") is consistent: process death releases the lock, and mount-time recovery then resets the interrupted rows. - No in-flight escape in the concurrent worker:
_worker_async_concurrent(openviking/storage/queuefs/queue_manager.py) only dequeues whilelen(active_tasks) < max_concurrent; a task that never completes (awaiting a stuck VLM/AGFS call with no timeout) permanently occupies a slot, andAddResource's default of 4 slots pins all four.
If you see another stall before a fix lands, a py-spy dump of the server process would discriminate between the two: workers parked inside the binding call → mutex path; workers parked inside model/embedding HTTP calls → slot path.
3. Why "RecoverStale never fires" for this failure mode
@sponge225's repro was correct — crash-orphan recovery works. The subtlety: recover_stale runs only at backend open (backend.rs: backend.recover_stale(options.recover_stale_sec) inside SQLiteQueueBackend::open; the Redis cache backend similarly runs only STARTUP_RECOVERY_SWEEPS = 3 startup sweeps and then stops). A wedged-but-alive process never re-opens the backend, so no matter what recover_stale_sec is, nothing re-queues its in-flight rows — only your pod restart did. That's the structural gap #3989 (bounded default) begins to address; a runtime periodic sweep would close it for this class.
One more runtime leak of the same shape: when ack fails transiently, NamedQueue.ack only logs a warning — the message stays processing on disk while the Python side considers the slot free (openviking/storage/queuefs/named_queue.py). Those rows accumulate until the next restart, i.e. the mount-time sweep is also silently load-bearing for transient ack failures on long-running pods.
4. Suggested next steps
- Land #4748 so the next incident log shows the true storage error.
- Runtime stale sweep in QueueFS (periodic
recover_stale, not mount-only) — self-healing for wedged slots/rows without a pod restart. - Liveness detection is already covered by #3542's
GET /api/v1/system/idle; a per-workerlast_processed_atthere would make "total silence" directly observable by your CronJob.
Still reproduces on v0.4.21, and I have a few data points that narrow it further than
the cannot rollback trigger @pperezrubio hit.
Environment
v0.4.21, Python 3.13, linux/arm64 container (OrbStack) on macOS, local storage backend, local llama.cpp embedding, VLM over HTTP to a self-hosted vLLM.
What happened
Bulk-replayed 87 Codex sessions through ov ingest backfill. Result:
session_commit: 65 completed · 25 failed ("Request timed out.") · 8 running · 65 pending
The 8 running tasks then never moved again. Sampled three times over 80s:
20:33:02 completed 65 failed 25 running 8 pending 65
20:33:42 completed 65 failed 25 running 8 pending 65
20:34:23 completed 65 failed 25 running 8 pending 65
Things I was able to rule out
| checked | result |
|---|---|
| VLM backend | /v1/models 200 in 42ms; vllm:num_requests_running and ..._waiting both 0.0, sampled 10× over 80s |
| host CPU | load 1.50 on 10 cores; container at 2.03% CPU |
| path locks | find ... -name '*ovlock*' → 0 files across the whole store |
| HTTP server | /health 200, retrieval queries served normally throughout |
| queue composition | only SessionCommit — no Semantic rows, so it is not a parent-waiting-on-child pool deadlock |
| logs | no cannot rollback, no traceback, no error of any kind in the stall window |
So the trigger is not limited to the SQLite audit path from #4748 — nothing errored at all here.
Two details I think are new
1. The task timeout never fires. Our vlm.timeout is 300s. The 8 running tasks were
past 6 minutes and still sat in running — they never transitioned to failed. The 25 that
did fail with Request timed out. show the timeout works on some paths, so whatever the 8
are blocked on is not covered by it.
2. A restart did not recover it. @pperezrubio reports a pod restart clearing the stall.
Here docker restart brought the server back healthy, but the 8 rows stayed processing
and the 65 pending were still never scheduled — consistent with the original report that
RecoverStale does not re-queue them, now confirmed on v0.4.21.
The only lever that worked was cancelling each stuck task:
POST /api/v1/tasks/{task_id}/cancel → 200
Worth noting for #4553 / #4627: this endpoint already works over the API even though the Studio button is not merged yet. It is currently the only way out of this state.
3. Cancelling frees the slots, and the next batch stalls the same way. After cancelling the 8, pending dropped 66 → 58 and eight fresh tasks were picked up — and those stalled identically within 90 seconds. So orphaned rows are how the state persists, but they are not what creates it.
The workaround that worked
Serialising to one session at a time — submit one, wait for session_commit to reach zero,
submit the next:
87/87 sessions replayed · 0 stalls · memory_diff 20 → 76
Same data, same server, same config. Only the concurrency changed. Individual sessions included a 992-message / 469MB one and a 212-message / 343MB one, so it is not that large sessions are unprocessable — several concurrent ones are.
That points at the worker pool rather than at any single job.
Possibly relevant to v0.4.21 specifically
This release refactored exactly this area:
a681e09fix(queuefs): 隔离后台队列与 HTTP 事件循环 (#5096)192b813refactor(queuefs): centralize queue processing lifecycle (#5019)
Given the symptom — worker blocked, no request ever reaching the backend, no timeout firing, HTTP loop still healthy — an await bound to an event loop that is no longer being driven would fit. #4726 (per-loop OpenAI clients never closed) is still open and describes clients tied to the queue worker's loop. I have not proven that connection, so treat it as a lead rather than a diagnosis.
What would have helped
/api/v1/system/idle from #3542 is exactly the missing signal — /health stayed green for
the entire stall. A last_processed_at per worker would separate "wedged" from "slowly
draining"; in my case 65 pending with 0 progress for minutes was indistinguishable from
normal backlog until I sampled the counts by hand.