Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(ultrawiki): let a backend switch resume the queue at once

Ruben Lütkedd1a00eca4fe
diff --git a/jarvis/ultrawiki/health.py b/jarvis/ultrawiki/health.py
index bfb1c1a7cf..58a113f0af 100644
--- a/jarvis/ultrawiki/health.py
+++ b/jarvis/ultrawiki/health.py
@@ -449,7 +449,16 @@ def _processing_check(status: dict[str, Any]) -> HealthCheck:
or "The background pipeline is not running, so the queue is "
"standing still."
),
- facts=facts,
+ # A refused provider is the one paused case with somewhere to go:
+ # the row's own sentence says "switch the embedding backend", so
+ # it has to offer the way there rather than leave the reader
+ # hunting for the tab.
+ action=(
+ {"kind": "open_settings", "tab": "embedding"}
+ if pipeline.get("blocked")
+ else None
+ ),
+ facts={**facts, "blocked": bool(pipeline.get("blocked"))},
)
if waiting:
return HealthCheck(
diff --git a/jarvis/ultrawiki/pipeline.py b/jarvis/ultrawiki/pipeline.py
index a5c7731d35..9e4935e48a 100644
--- a/jarvis/ultrawiki/pipeline.py
+++ b/jarvis/ultrawiki/pipeline.py
@@ -243,6 +243,10 @@ class PipelineWorker:
#: monotonic deadline until which the embedding-dependent stages rest
#: after a rate/quota rejection (0.0 = no cooldown).
self._embed_cooldown_until = 0.0
+ #: ``name:model`` of the embedding slot the stages last resolved. The
+ #: identity of a vector space, and therefore of whatever is refusing
+ #: to fill it.
+ self._embed_slot_key = ""
#: The live provider-level embedding block, or ``None`` while vectors
#: are coming back. Survives the individual cooldown naps: what matters
#: to a reader is "this has been refused since yesterday evening", not
@@ -318,8 +322,32 @@ class PipelineWorker:
# deference; it does not raise the batch size.
if not attempted or self._media_mode() == "eager":
attempted += await self._media_pass()
+ await self._promote_pass()
return attempted
+ async def _promote_pass(self) -> None:
+ """Swap in a finished embedding rebuild (see
+ ``UltraStore.promote_pending_space``).
+
+ A model switch builds the new vector space alongside the live one, so
+ SOMETHING has to notice when the shadow is complete. This runs after
+ every pass and costs one meta read when no rebuild is going on. A store
+ without the capability (an older embedded one) simply never promotes.
+ """
+ promote = getattr(self._store, "promote_pending_space", None)
+ if promote is None:
+ return
+ try:
+ await promote()
+ except asyncio.CancelledError:
+ raise
+ except Exception: # noqa: BLE001 — a failed swap retries next pass
+ log.warning(
+ "UltraWiki embedding-space promotion failed; the current "
+ "vectors keep serving search",
+ exc_info=True,
+ )
+
# -- shared helpers ------------------------------------------------------
def _claim_now(self) -> datetime | None:
@@ -380,6 +408,11 @@ class PipelineWorker:
# ten-minute rest began a moment ago.
"since": str(previous.get("since") or _utc_now_iso()),
"rejections": int(previous.get("rejections") or 0) + 1,
+ # WHOSE refusal this is. A block belongs to the slot that produced
+ # it, and answering "switch your embedding backend" while still
+ # reporting the old backend's complaint is worse than saying
+ # nothing (see _forget_block_from_another_slot).
+ "slot": self._embed_slot_key,
}
# Only the FIRST rejection of a streak warns. A permanent block would
# otherwise write a fresh warning every ten minutes forever, and a log
@@ -399,6 +432,34 @@ class PipelineWorker:
),
)
+ def _forget_block_from_another_slot(self, slot_key: str) -> None:
+ """Drop a block (and its cooldown) once the slot itself has changed.
+
+ The advice a blocked stage gives is "add credit, or switch the
+ embedding backend". Taking that advice used to change nothing for up
+ to ten minutes: the cooldown was a global nap, and the block was
+ remembered without recording WHOSE it was — so a freshly chosen,
+ perfectly healthy backend sat out the dead one's rest while the UI
+ went on quoting the dead one's complaint (observed live 2026-07-27,
+ switching from a depleted key to a local backend).
+
+ A block belongs to the slot that earned it. A different slot has
+ earned nothing, and starts clean.
+ """
+ block = self._embed_block
+ if block is None or block.get("slot") == slot_key:
+ return
+ log.info(
+ "UltraWiki embedding slot changed to %s — dropping the standstill "
+ "recorded for %s and resuming immediately",
+ slot_key or "(none)",
+ block.get("slot") or "(unknown)",
+ )
+ self._embed_block = None
+ self._embed_cooldown_until = 0.0
+ self._clear_stage_pause("embed")
+ self._clear_stage_pause("distill")
+
def _note_embed_success(self) -> None:
"""A vector came back — whatever the provider was refusing is over.
@@ -470,6 +531,11 @@ class PipelineWorker:
ok, reason = await self._backend_ready(backend)
if not ok:
return None, "", reason
+ # The identity of the vector space this pass will write into. Recorded
+ # before any call, so a rejection can be attributed to the slot that
+ # earned it rather than to whatever is configured when it is read.
+ self._embed_slot_key = f"{getattr(backend, 'name', '?')}:{model}"
+ self._forget_block_from_another_slot(self._embed_slot_key)
return backend, model, ""
async def _backend_ready(self, backend: Any) -> tuple[bool, str]:
diff --git a/tests/unit/ultrawiki/test_pipeline.py b/tests/unit/ultrawiki/test_pipeline.py
index fd9c73e7f5..e9e84cddf1 100644
--- a/tests/unit/ultrawiki/test_pipeline.py
+++ b/tests/unit/ultrawiki/test_pipeline.py
@@ -548,6 +548,68 @@ async def test_a_vector_coming_back_clears_the_block_without_a_restart(store):
assert worker.processed_counts()["embed"] == 1
+async def test_switching_the_backend_resumes_at_once_instead_of_serving_the_nap(store):
+ """Taking the advice has to work immediately.
+
+ A blocked stage tells the user to add credit *or switch the embedding
+ backend*. Following that used to change nothing for up to ten minutes: the
+ cooldown was global and the block did not record whose it was, so a
+ freshly chosen, healthy backend sat out the dead one's rest while the UI
+ kept quoting the dead one's complaint (observed live 2026-07-27).
+ """
+ from jarvis.ultrawiki.embeddings import EmbeddingError
+
+ await store.upsert_items("src1", [make_item(1)])
+ healthy = FakeEmbeddingBackend()
+ healthy.name = "other-provider"
+ worker = PipelineWorker(
+ store,
+ make_cfg(),
+ embedding_backend_factory=lambda: healthy,
+ distill_fn=distill_never,
+ distill_ready_fn=DISTILL_READY,
+ )
+ # A standstill earned by the PREVIOUS slot, cooldown still running.
+ worker._embed_slot_key = "dead-provider:some-model" # noqa: SLF001
+ worker._begin_embed_cooldown( # noqa: SLF001
+ EmbeddingError("dead-provider: embedding request failed with HTTP 429 (insufficient_quota)")
+ )
+ assert worker.embed_block() is not None
+
+ await worker._keyword_pass() # noqa: SLF001
+ await worker._embed_pass() # noqa: SLF001 — the NEW slot owes nothing
+
+ assert worker.embed_block() is None, "a new backend starts clean"
+ assert worker.processed_counts()["embed"] == 1
+ item = await store.get_item_by_external_id("src1", "ext-0001")
+ assert item["state"] == ItemState.EMBEDDED.value
+
+
+async def test_a_block_survives_a_pass_on_the_same_slot(store):
+ """The other half: forgetting on every pass would forget everything."""
+ from jarvis.ultrawiki.embeddings import EmbeddingError
+
+ backend = FakeEmbeddingBackend()
+ worker = PipelineWorker(
+ store,
+ make_cfg(),
+ embedding_backend_factory=lambda: backend,
+ distill_fn=distill_never,
+ distill_ready_fn=DISTILL_READY,
+ )
+ await worker._embedding_slot() # noqa: SLF001 — record the live slot
+ worker._begin_embed_cooldown( # noqa: SLF001
+ EmbeddingError("fake: embedding request failed with HTTP 429 (insufficient_quota)")
+ )
+
+ await worker._embed_pass() # noqa: SLF001 — same slot, still resting
+
+ block = worker.embed_block()
+ assert block is not None
+ assert block["slot"] == "fake:fake-model"
+ assert backend.embed_calls == [], "the cooldown still holds"
+
+
async def test_a_standstill_is_logged_once_not_every_countdown_tick(store, caplog):
"""The pause sentence carries a live countdown, so deduplicating on the
text logged the same standstill every time the minute changed — 2 614
@@ -561,6 +623,9 @@ async def test_a_standstill_is_logged_once_not_every_countdown_tick(store, caplo
distill_fn=distill_never,
distill_ready_fn=DISTILL_READY,
)
+ # Resolve the slot first: a rejection can only ever be earned by a slot
+ # the stage already resolved, and the block is attributed to it.
+ await worker._embedding_slot() # noqa: SLF001
worker._begin_embed_cooldown( # noqa: SLF001
EmbeddingError("fake: embedding request failed with HTTP 429 (insufficient_quota)")
)