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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(wiki): extract shared journal-trigger helper for the age-based flush
Ruben Lütkebb665ff112bc
diff --git a/jarvis/memory/wiki/integration.py b/jarvis/memory/wiki/integration.pyindex 1302641a7f..96897f133b 100644--- a/jarvis/memory/wiki/integration.py+++ b/jarvis/memory/wiki/integration.py@@ -778,6 +778,33 @@ def _build_curator()+def _fire_journal_trigger(scheduler: Any, *, task_name: str, log_context: str) -> None:+ """Fire one background JOURNAL trigger (fire-and-forget, AP-9).++ Shared by every journal-pressure site — the boot-time backlog drain+ (:func:`kick_journal_backlog`) and the age-based flush loop+ (:func:`_journal_age_flush_loop`) — so the actual+ ``scheduler.trigger(...)`` call shape cannot drift between them.+ Callers are responsible for their own preconditions (scheduler present,+ something actually pending) before calling this.+ """+ from jarvis.memory.wiki.scheduler import TriggerSource++ task = asyncio.create_task(+ scheduler.trigger(TriggerSource.JOURNAL),+ name=task_name,+ )++ def _log_outcome(t: "asyncio.Task[Any]") -> None:+ if t.cancelled():+ return+ exc = t.exception()+ if exc is not None:+ log.warning("wiki_integration: %s failed: %s", log_context, exc)++ task.add_done_callback(_log_outcome)++def kick_journal_backlog(journal: Any, scheduler: Any) -> None:"""Boot-time backlog drain (Wave-2 C1).@@ -795,21 +822,9 @@ def kick_journal_backlog(journal: Any, scheduler: Any) -> None:_record_backlog_health(backlog)if backlog <= 0:return- from jarvis.memory.wiki.scheduler import TriggerSource-- task = asyncio.create_task(- scheduler.trigger(TriggerSource.JOURNAL),- name="wiki-journal-boot-drain",+ _fire_journal_trigger(+ scheduler, task_name="wiki-journal-boot-drain", log_context="boot journal drain",)-- def _log_outcome(t: "asyncio.Task[Any]") -> None:- if t.cancelled():- return- exc = t.exception()- if exc is not None:- log.warning("wiki_integration: boot journal drain failed: %s", exc)-- task.add_done_callback(_log_outcome)log.info("wiki_integration: boot drain triggered for %d pending candidate(s)",backlog,@@ -820,6 +835,39 @@ def kick_journal_backlog(journal: Any, scheduler: Any) -> None:log.warning("wiki_integration: boot journal drain skipped: %s", exc)+async def _journal_age_flush_loop(journal: Any, scheduler: Any, sched_cfg: Any) -> None:+ """Fire a JOURNAL trigger when the oldest pending candidate exceeds the+ configured age (spec A4).++ Below-threshold backlogs on a quiet install never cross+ ``consolidate_after_candidates`` on their own — this loop is the+ backstop that still gets them written. Runs off the voice hot path+ (AP-9) and was started off the boot critical path (AP-26); cancelled in+ :meth:`WikiIntegrationHandle.shutdown` exactly like the hourly+ telemetry loop. Never raises — a check failure is logged and the loop+ keeps polling.+ """+ max_age_min = int(getattr(sched_cfg, "flush_pending_max_age_minutes", 10))+ if max_age_min <= 0:+ log.debug("wiki_integration: age-based journal flush disabled (max_age<=0)")+ return+ while True:+ await asyncio.sleep(120)+ try:+ oldest = journal.oldest_pending_ms()+ if oldest is None:+ continue+ age_min = (time.time() * 1000 - oldest) / 60_000+ if age_min >= max_age_min:+ _fire_journal_trigger(+ scheduler,+ task_name="wiki-journal-age-flush-trigger",+ log_context="age-based journal flush",+ )+ except Exception: # noqa: BLE001 — never kill the loop+ log.debug("wiki_integration: journal age flush check failed", exc_info=True)++def _record_backlog_health(count: int) -> None:"""Record the journal backlog on the health singleton (spec A5).diff --git a/tests/unit/memory/wiki/test_scheduler_journal_trigger.py b/tests/unit/memory/wiki/test_scheduler_journal_trigger.pyindex 3315cf4861..739ea50021 100644--- a/tests/unit/memory/wiki/test_scheduler_journal_trigger.py+++ b/tests/unit/memory/wiki/test_scheduler_journal_trigger.py@@ -76,7 +76,7 @@ async def test_journal_trigger_without_consolidator_skips(tmp_path: Path) -> Nondef test_scheduler_config_has_journal_pressure_threshold() -> None:- assert SchedulerConfig().consolidate_after_candidates == 8+ assert SchedulerConfig().consolidate_after_candidates == 3# ---------------------------------------------------------------------------