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.

perf(ultrawiki): cap what the background import takes from the machine

Ruben Lütke716fe3eb5ba3
diff --git a/jarvis/core/config.py b/jarvis/core/config.py
index 3cab957905..f4ea467974 100644
--- a/jarvis/core/config.py
+++ b/jarvis/core/config.py
@@ -2168,6 +2168,17 @@ class UltraWikiConfig(BaseModel):
rerank_model: str = "" # only for rerank_provider="llm"; empty = cheap tier
ollama_endpoint: str = "http://localhost:11434"
+ # Share of ONE core the ingest pipeline may occupy (0.01-1.0).
+ #
+ # Indexing a corpus is real work, but it is work nobody is waiting for,
+ # and it used to take whatever it could get: a full core, permanently,
+ # with the whole machine sluggish behind it. The worker now sleeps in
+ # proportion to how long each pass ran, so this is an honest ceiling on
+ # any CPU — the same guarantee on a headless VPS as on a workstation.
+ # Raise it to index faster on a machine nobody is sitting at; lower it if
+ # even this is noticeable. See jarvis.ultrawiki.pipeline.
+ cpu_share: float = 0.05
+
# How hard the background lane works at turning pictures into words and
# recordings into transcripts:
# "frugal" (default) - one item at a time, and only while every other
@@ -2606,6 +2617,16 @@ class AgenticIdeConfig(BaseModel):
),
)
+ smart_recaps: bool = Field(
+ default=True,
+ description=(
+ "Let a model write each pane's header recap — what the pane set out "
+ "to do, where it stands, what is outstanding. Off falls back to the "
+ "transcript-derived one, which costs nothing and says much less. An "
+ "install with no reachable provider gets the fallback either way."
+ ),
+ )
+
@field_validator("prompt_writer", mode="before")
@classmethod
def _usable_writer(cls, value: object) -> str:
diff --git a/jarvis/ui/web/wiki_routes.py b/jarvis/ui/web/wiki_routes.py
index 0b3218cc5c..ea74128041 100644
--- a/jarvis/ui/web/wiki_routes.py
+++ b/jarvis/ui/web/wiki_routes.py
@@ -1079,6 +1079,84 @@ async def reindex_wiki(
}
+ "/search-aliases/backfill",
+ openapi_extra={"x-jarvis-dangerous": True},
+)
+async def backfill_search_aliases(
+ request: Request,
+ dry_run: bool = Query(default=True),
+ overwrite: bool = Query(default=False),
+ limit: int | None = Query(default=None, ge=1),
+) -> dict[str, Any]:
+ """Add search aliases to vault pages so questions in the user's own
+ language reach pages written in another one.
+
+ The fact extractor writes pages in English while the user may ask in any
+ language, and a keyword index cannot bridge that on its own. This walks the
+ vault and gives each page the words its owner would actually say, stored in
+ the ``search_aliases`` frontmatter list.
+
+ ``dry_run`` defaults to TRUE and is the safe direction: the field lands in
+ the user's own Obsidian files, so writing is opt-in. Pages that already
+ carry aliases are skipped unless ``overwrite`` is set, and even then
+ existing terms are merged rather than replaced — a hand-curated alias is
+ never lost. Marked dangerous because a non-dry run edits user files.
+
+ Reindexes automatically after a real run, so the new aliases are
+ immediately searchable.
+ """
+ import sqlite3
+
+ from jarvis.brain.provider_registry import BrainProviderRegistry
+ from jarvis.memory.wiki.db_path import resolve_wiki_db_path
+ from jarvis.memory.wiki.fts_index import ensure_schema, index_vault
+ from jarvis.memory.wiki.search_aliases import backfill_vault, target_languages
+
+ vault_root = _resolve_vault_root(request)
+ if vault_root is None or not vault_root.is_dir():
+ return {"ok": False, "error": "vault unavailable"}
+
+ config = getattr(request.app.state, "config", None)
+ if config is None:
+ return {"ok": False, "error": "config unavailable"}
+
+ summary = await backfill_vault(
+ vault_root=vault_root,
+ cfg=config,
+ registry=BrainProviderRegistry(),
+ dry_run=dry_run,
+ overwrite=overwrite,
+ limit=limit,
+ )
+
+ reindexed = 0
+ if not dry_run and summary.get("updated"):
+ data_dir = getattr(getattr(config, "memory", None), "data_dir", "./data")
+ db_path = resolve_wiki_db_path(data_dir)
+
+ def _reindex() -> int:
+ db_path.parent.mkdir(parents=True, exist_ok=True)
+ conn = sqlite3.connect(str(db_path), check_same_thread=False)
+ try:
+ ensure_schema(conn)
+ count = index_vault(vault_root, conn)
+ conn.commit()
+ return count
+ finally:
+ conn.close()
+
+ reindexed = await asyncio.to_thread(_reindex)
+
+ return {
+ "ok": True,
+ "vault_root": str(vault_root),
+ "languages": list(target_languages(config)),
+ "reindexed_pages": reindexed,
+ **summary,
+ }
+
+
@router.get("/health")
async def wiki_health(request: Request) -> dict[str, Any]:
"""Wiki subsystem health for the Wiki tab status panel (spec A5).
diff --git a/jarvis/ultrawiki/pipeline.py b/jarvis/ultrawiki/pipeline.py
index ab7b0cdf10..69a38dee79 100644
--- a/jarvis/ultrawiki/pipeline.py
+++ b/jarvis/ultrawiki/pipeline.py
@@ -63,6 +63,9 @@ __all__ = [
"MAX_MEDIA_BYTES",
"IDLE_SLEEP_S",
"BUSY_SLEEP_S",
+ "DEFAULT_CPU_SHARE",
+ "MIN_CPU_SHARE",
+ "MAX_PACING_SLEEP_S",
"PipelineWorker",
]
@@ -164,9 +167,29 @@ MAX_MEDIA_BYTES = 24 * 1024 * 1024
MAX_EMBED_CHARS = 8000
#: Loop pacing: quick follow-up while there is work, gentle poll when idle.
+#: ``BUSY_SLEEP_S`` is now the FLOOR of the proportional pause, not the pause
+#: itself — see :meth:`PipelineWorker.run`.
IDLE_SLEEP_S = 2.0
BUSY_SLEEP_S = 0.1
+#: Share of ONE core the ingest lane may occupy, when the config names none.
+#:
+#: Five percent, because this lane competes with the thing the user is actually
+#: doing. Ingestion is background work by definition: nobody is waiting for the
+#: 200 000th document to become searchable this second, while everybody notices
+#: a machine that has gone sluggish. At this setting a corpus takes longer to
+#: come online and the app stays responsive throughout, which is the right way
+#: round — and the knob exists for anyone who would rather trade it back.
+DEFAULT_CPU_SHARE = 0.05
+
+#: Floor for the same knob. Zero would be indistinguishable from "UltraWiki is
+#: broken", and that is a support question, not a setting.
+MIN_CPU_SHARE = 0.01
+
+#: Longest proportional pause, so one pathological pass (a huge media file, a
+#: provider timing out inside the window) cannot park the lane for an hour.
+MAX_PACING_SLEEP_S = 30.0
+
#: The embedding ``ready()`` probe may hit the network (Ollama) and the distill
#: probe walks the keyring; cache both verdicts briefly so an idle loop does
#: not hammer a dead endpoint or re-walk the credential chain every 2 seconds.
@@ -331,15 +354,44 @@ class PipelineWorker:
"""
return dict(self._embed_block) if self._embed_block is not None else None
+ def _duty_cycle(self) -> float:
+ """Share of one core the ingest lane may take, from the config.
+
+ Clamped to a sane band rather than trusted: 0 would stop ingestion
+ entirely (a config typo must not silently disable the product), and
+ above 1.0 means nothing — the loop is single-threaded either way.
+ """
+ ultrawiki = getattr(self._cfg, "ultrawiki", None)
+ try:
+ raw = float(getattr(ultrawiki, "cpu_share", DEFAULT_CPU_SHARE))
+ except (TypeError, ValueError):
+ return DEFAULT_CPU_SHARE
+ return min(1.0, max(MIN_CPU_SHARE, raw))
+
async def run(self, cancel_event: asyncio.Event) -> None:
"""The worker loop: run passes until *cancel_event* is set.
A failed pass is logged and the loop continues; ``CancelledError``
(hard task cancel) is always re-raised.
+
+ **Pacing is proportional, not fixed.** Indexing a corpus is real work
+ — tokenizing 236 k documents into FTS5 and embedding them is not a bug
+ to be optimized away — but it is work nobody is waiting for, and a
+ fixed 100 ms pause between passes does not bound it: a pass that takes
+ 900 ms still gets 90 % of a core, which is exactly what it took
+ (observed live 2026-07-27, with the whole machine slowed down behind
+ it). Sleeping in PROPORTION to how long the pass ran caps the lane at a
+ known share of one core no matter how big the corpus, how slow the
+ disk, or how fast the CPU — the same guarantee on a Raspberry Pi and on
+ an M4, with no per-machine tuning and no platform-specific API.
"""
- log.info("UltraWiki pipeline worker started")
+ log.info(
+ "UltraWiki pipeline worker started (cpu_share=%.0f%%)",
+ self._duty_cycle() * 100.0,
+ )
try:
while not cancel_event.is_set():
+ started = time.monotonic()
try:
attempted = await self.run_once()
except asyncio.CancelledError:
@@ -347,7 +399,16 @@ class PipelineWorker:
except Exception:
log.exception("UltraWiki pipeline pass failed; continuing")
attempted = 0
- delay = BUSY_SLEEP_S if attempted else IDLE_SLEEP_S
+ if attempted:
+ # Worked for `elapsed` -> rest until that is only `duty` of
+ # the window. Read per pass, so changing the knob in the
+ # settings takes effect without a restart.
+ elapsed = max(0.0, time.monotonic() - started)
+ duty = self._duty_cycle()
+ delay = max(BUSY_SLEEP_S, elapsed * (1.0 / duty - 1.0))
+ delay = min(delay, MAX_PACING_SLEEP_S)
+ else:
+ delay = IDLE_SLEEP_S
if cancel_event.is_set():
break
try: