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): bound the rerank stage and keep the search tool LLM-free

Ruben Lütke8654521ae340
diff --git a/jarvis/plugins/tool/ultrawiki_search.py b/jarvis/plugins/tool/ultrawiki_search.py
index 6704a4df98..e92b95f280 100644
--- a/jarvis/plugins/tool/ultrawiki_search.py
+++ b/jarvis/plugins/tool/ultrawiki_search.py
@@ -153,9 +153,12 @@ class UltraWikiSearchTool:
)
try:
- hits = await service.search(query, k=k, area_id=area)
+ # rerank=False by design (doc 03 "primitive tools"): this tool's
+ # consumer IS a model and judges relevance itself — paying a
+ # second model call to pre-grade for it is pure added latency.
+ hits = await service.search(query, k=k, area_id=area, rerank=False)
except Exception as exc: # noqa: BLE001 — surface honestly, never crash the turn
- log.warning("ultrawiki-search failed for %r: %s", query, exc)
+ log.warning("ultrawiki-search failed: %s", exc)
return ToolResult(
success=False,
output="",
@@ -179,7 +182,8 @@ class UltraWikiSearchTool:
output = "\n".join(lines)
if len(output) > _MAX_OUTPUT_CHARS:
output = output[:_MAX_OUTPUT_CHARS].rstrip() + "…"
- log.info("ultrawiki-search: %d hit(s) for %r", len(hits), query)
+ # Hit count only — what the user asks their own memory stays out of logs.
+ log.info("ultrawiki-search: %d hit(s)", len(hits))
return ToolResult(success=True, output=output)
diff --git a/jarvis/ultrawiki/search.py b/jarvis/ultrawiki/search.py
index 4514109fba..8f7252b8c0 100644
--- a/jarvis/ultrawiki/search.py
+++ b/jarvis/ultrawiki/search.py
@@ -165,6 +165,11 @@ def ranking_settings(cfg: Any) -> dict[str, float]:
0.0, _float_setting(cfg, "recency_half_life_days", 180.0)
),
"rerank_min_score": max(0.0, _float_setting(cfg, "rerank_min_score", 4.0)),
+ # Hard wall-clock bound on the WHOLE rerank stage (all provider
+ # attempts together). Without it, a chain of dead/hung providers can
+ # burn its per-attempt timeout once per family — minutes, not the
+ # design's sub-second budget. 0 disables the bound.
+ "rerank_timeout_s": max(0.0, _float_setting(cfg, "rerank_timeout_s", 10.0)),
}
@@ -662,8 +667,19 @@ async def _maybe_rerank(cfg: Any, query: str, ranked: list[SearchResult]) -> lis
return ranked
pool = ranked[:RERANK_POOL]
documents = [_rerank_document(hit) for hit in pool]
+ timeout_s = ranking_settings(cfg)["rerank_timeout_s"]
try:
- pairs = await reranker.rerank(query, documents, top_k=len(documents))
+ grading = reranker.rerank(query, documents, top_k=len(documents))
+ if timeout_s > 0:
+ pairs = await asyncio.wait_for(grading, timeout=timeout_s)
+ else:
+ pairs = await grading
+ except TimeoutError:
+ log.warning(
+ "rerank stage exceeded its %.1f s budget — keeping the fusion order",
+ timeout_s,
+ )
+ return ranked
except rerank_mod.RerankError as exc:
log.warning("rerank failed (%s) — keeping the fusion order", exc)
return ranked
diff --git a/tests/unit/plugins/tool/test_ultrawiki_search_tool.py b/tests/unit/plugins/tool/test_ultrawiki_search_tool.py
index 6b8bb5e1a8..89bd317c18 100644
--- a/tests/unit/plugins/tool/test_ultrawiki_search_tool.py
+++ b/tests/unit/plugins/tool/test_ultrawiki_search_tool.py
@@ -34,8 +34,10 @@ class _FakeService:
self._error = error
self.calls: list[dict[str, Any]] = []
- async def search(self, query: str, *, k: int, area_id: str | None) -> list[Any]:
- self.calls.append({"query": query, "k": k, "area_id": area_id})
+ async def search(
+ self, query: str, *, k: int, area_id: str | None, rerank: bool = True
+ ) -> list[Any]:
+ self.calls.append({"query": query, "k": k, "area_id": area_id, "rerank": rerank})
if self._error is not None:
raise self._error
return self._hits
@@ -97,7 +99,18 @@ async def test_hits_render_with_citation_and_legs() -> None:
assert "Project Phoenix" in result.output
assert "uw://item/1" in result.output # citation permalink
assert "keyword" in result.output # matched_by legs stay visible
- assert service.calls == [{"query": "phoenix", "k": 3, "area_id": "work"}]
+ assert service.calls == [
+ {"query": "phoenix", "k": 3, "area_id": "work", "rerank": False}
+ ]
+
+
+async def test_tool_searches_llm_free() -> None:
+ """doc 03 'primitive tools': the consumer is a model and judges relevance
+ itself — the tool must never pay a second model call to pre-grade."""
+ service = _FakeService(hits=[_Hit()])
+ tool = _tool(service, enabled=True)
+ await tool.execute({"query": "phoenix"}, ctx=None)
+ assert service.calls[0]["rerank"] is False
async def test_k_is_clamped_to_schema_bounds() -> None:
diff --git a/tests/unit/ultrawiki/test_search.py b/tests/unit/ultrawiki/test_search.py
index e4a2ae6e25..c579876cda 100644
--- a/tests/unit/ultrawiki/test_search.py
+++ b/tests/unit/ultrawiki/test_search.py
@@ -545,6 +545,7 @@ def test_search_status_reports_the_live_ranking_knobs():
rrf_vector_weight=0.5,
recency_half_life_days=30,
rerank_min_score=6,
+ rerank_timeout_s=8,
)
)
@@ -553,6 +554,7 @@ def test_search_status_reports_the_live_ranking_knobs():
"vector_weight": 0.5,
"recency_half_life_days": 30.0,
"rerank_min_score": 6.0,
+ "rerank_timeout_s": 8.0,
}
@@ -818,6 +820,32 @@ async def test_ungraded_hits_pass_the_floor_visibly_rather_than_silently(
assert any("rerank failed" in rec.message for rec in caplog.records)
+async def test_rerank_stage_budget_bust_keeps_the_fusion_order(
+ store, monkeypatch, caplog
+):
+ """The 45s-per-provider trap: a hung rerank chain must never hold the
+ search hostage — the stage has ONE wall-clock budget, then fusion order
+ stands."""
+ import asyncio
+
+ id_0, id_1, id_2 = await seed_three_ranked_items(store)
+
+ class HungReranker(FakeReranker):
+ async def rerank(self, query, documents, top_k):
+ await asyncio.sleep(5.0)
+ return [(2, 9.0)]
+
+ monkeypatch.setattr(rerank_mod, "resolve_reranker", lambda cfg: HungReranker())
+ cfg = make_cfg(rerank_provider="voyage", rerank_timeout_s=0.05)
+
+ with caplog.at_level(logging.WARNING, logger="jarvis.ultrawiki.search"):
+ results = await hybrid_search(store, cfg, "alpha")
+
+ assert [hit.item_id for hit in results] == [id_0, id_1, id_2] # fusion order
+ assert all(hit.rerank_score is None for hit in results)
+ assert any("exceeded its" in rec.message for rec in caplog.records)
+
+
async def test_voice_path_can_skip_the_rerank_stage(store, monkeypatch):
"""doc 03 latency budget: realtime voice degrades stages, never blocks."""
id_0, id_1, id_2 = await seed_three_ranked_items(store)