Worker starves when a source is deleted before processing: NotFoundError retried as transient (the `if not source` guard is unreachable)

Author: GF-2025Created Sep 19, 2026Updated Sep 19, 2026

Environment

  • Open Notebook Desktop v1.1.1 (macOS 14/arm64, bundled API + worker + SurrealDB), reproduced against main @ 3127f14 (v1.14.0) by reading the code path below.
  • Also applies to any deployment: the code path is the shared worker command.

What happens

If a source is deleted while its process_source job is still queued, the worker stops consuming jobs entirely. Every subsequent source stays status=new / embedded=false forever, while the API keeps returning success for new uploads.

Reproduction

  1. Create a source via the API (POST /api/sources, async_processing=true) — or upload a file the way our integration does.
  2. Before the worker picks the job up, delete that source (DELETE /api/sources/{id}).
  3. The worker then processes the (now missing) source:
open_notebook.exceptions.NotFoundError: source with id source:nr9oq6dq5pa3i87z7hyg not found
... Transient error processing source source:nr9oq6dq5pa3i87z7hyg: Object with id ... not found
  1. After this line the worker never logs anything again. In our run: last worker log line at 18:19:30; a source created at 19:41 was still embedded=false / status=new 10+ minutes later (/api/sources/{id}), and /api/sources/{id}/retry did not help.
  2. Restarting the desktop app fixes it: the same source immediately becomes embedded=true / status=completed, and the backlog drains.

Not a resource problem on the machine: api, worker and surrealdb processes were all alive, and the embedding endpoint was healthy (/v1/models OK, 0 failures, thousands of successful requests).

Root cause

commands/source_commands.py (lines 76–78):

python
source = await Source.get(input_data.source_id)
if not source:
    raise ValueError(f"Source '{input_data.source_id}' not found")

Source.get() raises NotFoundError instead of returning None, so the guard that was clearly written for this case is unreachable. The raised error then falls into:

python
except ValueError as e:   # permanent → re-raise, stop_on prevents retries
except Exception as e:    # transient → re-raise, will be retried

and NotFoundError is neither a ValueError (see open_notebook/exceptions.py: NotFoundError(OpenNotebookError) where OpenNotebookError(Exception)) nor in stop_on=[ValueError, ConfigurationError, ContextLengthExceededError].

So the job is treated as transient and retried under:

python
retry={
    "max_attempts": 15,
    "wait_strategy": "exponential_jitter",
    "wait_min": 1,
    "wait_max": 120,
    "stop_on": [ValueError, ConfigurationError, ContextLengthExceededError],
}

A job that can never succeed therefore occupies the worker for up to 15 attempts with waits growing to 120s, and with a single worker consumer every later job starves behind it. The user-visible symptom is the worst kind: uploads report success, the UI shows the source, but its content is never searchable.

Deleting a source right after creating it is not exotic — any sync/cleanup integration that mirrors an upstream folder does exactly this (file created, job queued, file removed a moment later ⇒ source deleted). In our case it was triggered by a delete-propagation step in our sync tool.

Proposed fix (small and targeted)

diff
-from open_notebook.exceptions import ConfigurationError, ContextLengthExceededError
+from open_notebook.exceptions import (
+    ConfigurationError,
+    ContextLengthExceededError,
+    NotFoundError,
+)
@@
-        source = await Source.get(input_data.source_id)
-        if not source:
-            raise ValueError(f"Source '{input_data.source_id}' not found")
+        try:
+            source = await Source.get(input_data.source_id)
+        except NotFoundError as e:
+            # The source was removed after the job was queued (e.g. a sync tool
+            # deleted it). This can never succeed, so fail permanently instead
+            # of consuming 15 retries and blocking every job behind it.
+            raise ValueError(
+                f"Source '{input_data.source_id}' no longer exists "
+                f"(deleted before processing?): {e}"
+            ) from e
+        if not source:
+            raise ValueError(f"Source '{input_data.source_id}' not found")

This keeps the existing design intact (permanent errors → ValueError → stop_on → job marked failed, no retries) and only fixes the unreachable guard. A test asserting "missing source raises ValueError, not NotFoundError" would lock it in.

Trade-off worth your call: if you consider a missing record to be possibly transient (SurrealDB visibility/timing), the alternative is to keep it retryable but capped — e.g. add NotFoundError to stop_on only after N attempts, or lower max_attempts/wait_max for this command. I went with the permanent-failure route because the guard you already wrote implies that intent, and because "job that can never succeed must not hold the queue" is the property that matters for the stall.

Workaround for users hitting it today

Restart the app — the pending sources are picked up immediately (no re-upload needed). /api/sources/{id}/retry does not help while the consumer is stuck.

Extra evidence (from the downstream integration that hit it)

  • Worker log excerpt of the failure and of the silence afterwards (worker.log has no line after the Transient error retry entry).
  • Embedding side was healthy at the same moment: GET /v1/embeddings served thousands of requests with 0 failures, so this is not an embedding-provider problem.
  • After the fix is in, a downstream tool of ours would also stop needing its "detect stalled worker + restart app" watchdog.

Happy to open a PR with the patch (and the test) if this approach looks right to you — just say the word and I'll send it.