fix: recover orphaned job status when worker pod is killed mid-execution#102
Merged
fix: recover orphaned job status when worker pod is killed mid-execution#102
Conversation
When a SimpleWorker process is killed (OOMKill, node eviction, etc.) the
in-flight job is permanently frozen in STARTED state because the main
thread is blocked during conversion and RQ's built-in heartbeat stops
being refreshed. The job previously remained stuck for 4 hours (the job
timeout), with no pub/sub notification ever reaching polling or WebSocket
clients.
Two components fix this:
1. Per-job heartbeat thread in CustomRQWorker.perform_job()
A daemon thread (_heartbeat_loop) is started when perform_job() begins
and stopped in the finally block. Every 20 s it writes
docling:job:alive:{job_id} with a 60 s TTL to Redis via a dedicated
connection. If the process is killed the thread dies with it and the
key expires naturally.
2. Watchdog asyncio task in RQOrchestrator.process_queue()
_watchdog_task() runs alongside the existing pub/sub listener. Every
30 s it scans all STARTED tasks older than the 90 s grace period and
checks whether their liveness key still exists. A missing key means
the worker is dead: a FAILURE _TaskUpdate is published to the
docling:updates channel, which is received by _listen_for_updates(),
persisted, and delivered to WebSocket subscribers — reducing the
detection window from 4 hours to ~90 s.
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Contributor
|
✅ DCO Check Passed Thanks @cau-git, all your commits are properly signed off. 🎉 |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
dolfim-ibm
reviewed
Mar 1, 2026
Watchdog now queries RQ's StartedJobRegistry instead of per-pod self.tasks to detect orphaned jobs, closing the coverage gap when the enqueue pod is recycled during rolling updates. Also adds _on_task_status_changed() hook (no-op by default) called after every pub/sub status update, allowing subclasses to persist terminal states to durable storage. Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
…hdog
- Make `task_result()` use deterministic fallback key (`{results_prefix}:{task_id}`) when in-memory result-key cache is missing.
- Return `None` when result blob is absent and cache resolved key when present.
- Run watchdog `StartedJobRegistry.get_job_ids()` with cleanup enabled to clear abandoned STARTED entries during scans.
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
dolfim-ibm
approved these changes
Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a
SimpleWorkerprocess is killed (OOMKill, node eviction, etc.), the in-flight job is permanently frozen inSTARTEDstate because the main thread is blocked during conversion and RQ's built-in heartbeat stops being refreshed. The job previously remained stuck for 4 hours (the job timeout), with no pub/sub notification ever reaching polling or WebSocket clients.Two components fix this:
Per-job heartbeat thread in
CustomRQWorker.perform_job(): a daemon thread (_heartbeat_loop) is started whenperform_job()begins and stopped in thefinallyblock. Every 20 s it writesdocling:job:alive:{job_id}with a 60 s TTL to Redis via a dedicated connection. If the process is killed, the thread dies with it and the key expires naturally.Watchdog asyncio task in
RQOrchestrator.process_queue():_watchdog_task()runs alongside the existing pub/sub listener. Every 30 s it scans allSTARTEDtasks older than the 90 s grace period and checks whether their liveness key still exists. A missing key means the worker is dead: aFAILURE_TaskUpdateis published to thedocling:updateschannel, which is received by_listen_for_updates(), persisted, and delivered to WebSocket subscribers, reducing the detection window from 4 hours to ~90 s.With this fix, a worker that is killed mid-execution will still lose the task and no retry-mechanism is in place yet, so the conversion will track as failed instead of stale.