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.

feat(wiki): let a profile update create its missing topic page in the same batch

Ruben Lütkef45cd9b7fe94
diff --git a/jarvis/memory/wiki/consolidator.py b/jarvis/memory/wiki/consolidator.py
index 395efafb3c..9e03d3cc8e 100644
--- a/jarvis/memory/wiki/consolidator.py
+++ b/jarvis/memory/wiki/consolidator.py
@@ -464,9 +464,10 @@ class Consolidator:
write_plan: dict[int, tuple[str | None, str | None]] = {}
noop_ids: list[int] = []
required_targets: dict[int, set[str]] = {}
- # Secondary invalidate targets (extra writes beyond a candidate's
- # primary decision); counted only after the write actually lands.
+ # Secondary targets (extra writes beyond a candidate's primary
+ # decision); counted only after the write actually lands.
secondary_invalidations: list[str] = []
+ secondary_adds: list[str] = []
# Never submit two independently generated full-page bodies for the
# same target in one AtomicWriter call: the later body was based on the
@@ -511,12 +512,13 @@ class Consolidator:
continue
if cid in deferred_ids or cid in duplicate_target_ids:
continue
- # One PRIMARY decision per candidate; additional "invalidate"
- # items are allowed as secondary actions — a contradiction
+ # One PRIMARY decision per candidate; "invalidate" and companion
+ # "add" items are allowed as secondary actions — a contradiction
# typically ADDs/UPDATEs the corrected page AND invalidates the
- # superseded one in the same batch, for the same candidate.
+ # superseded one, and a profile update may create the missing
+ # topic page in the same batch, for the same candidate.
is_secondary = cid in judged_ids
- if is_secondary and decision != "invalidate":
+ if is_secondary and decision not in ("invalidate", "add"):
continue
judged_ids.add(cid)
@@ -536,7 +538,8 @@ class Consolidator:
if decision in ("add", "update"):
new_body = item.get("new_body")
if not isinstance(new_body, str) or not new_body.strip():
- write_plan[cid] = (None, None)
+ if not is_secondary:
+ write_plan[cid] = (None, None)
continue
new_body = self._with_source_marker(new_body, by_id[cid])
updates_by_candidate.setdefault(cid, []).append(
@@ -547,7 +550,10 @@ class Consolidator:
reason=str(item.get("reason", ""))[:200],
)
)
- write_plan[cid] = (decision, target)
+ if is_secondary:
+ secondary_adds.append(target)
+ else:
+ write_plan[cid] = (decision, target)
required_targets.setdefault(cid, set()).add(target)
else: # invalidate
superseded_by = str(item.get("superseded_by", "") or "").strip()
@@ -592,6 +598,9 @@ class Consolidator:
for target in secondary_invalidations:
if target in applied_rel:
telemetry.inc("wiki_consolidator_invalidate")
+ for target in secondary_adds:
+ if target in applied_rel:
+ telemetry.inc("wiki_consolidator_add")
transient_ids: set[int] = set()
# Close out every candidate unless it is intentionally deferred or hit
@@ -710,8 +719,8 @@ class Consolidator:
A transport-successful JSON array is not necessarily a usable answer.
Reject the whole response (and let the provider chain try another
family) unless every candidate has exactly one valid primary decision.
- Secondary actions are limited to distinct invalidations for the same
- candidate.
+ Secondary actions are limited to distinct invalidations and companion
+ "add" pages (the graph-visibility rule) for the same candidate.
"""
expected = {row.id for row in rows}
by_id = {row.id: row for row in rows}
@@ -731,7 +740,13 @@ class Consolidator:
secondary = cid in primary_seen
if secondary:
- if primary_decisions[cid] == "noop" or decision != "invalidate":
+ # Secondary actions: extra invalidations for a contradiction,
+ # or a companion "add" that creates a missing topic page in
+ # the same batch (graph-visibility rule in the prompt).
+ if primary_decisions[cid] == "noop" or decision not in (
+ "invalidate",
+ "add",
+ ):
return "candidate has more than one primary decision"
else:
primary_seen.add(cid)
@@ -769,8 +784,8 @@ class Consolidator:
target_path = self._vault_root / target
if decision in ("add", "update"):
- if secondary:
- return "secondary decision is not an invalidation"
+ if secondary and decision != "add":
+ return "secondary decision must be an add or an invalidation"
body = item.get("new_body")
if not isinstance(body, str) or not body.strip():
return "page decision is missing a full new_body"
diff --git a/jarvis/memory/wiki/prompt.py b/jarvis/memory/wiki/prompt.py
index 0b1dae9c23..07eeaf99a9 100644
--- a/jarvis/memory/wiki/prompt.py
+++ b/jarvis/memory/wiki/prompt.py
@@ -468,9 +468,11 @@ languages (English, German, and Spanish):
request itself remains non-durable.
Return ONLY a JSON array. Emit exactly one PRIMARY object per candidate. A
-primary "add" or "update" may be followed by one or more SECONDARY
-"invalidate" objects with the same candidate_id when a contradiction must
-retire existing pages. No other duplicate candidate_id is allowed:
+primary "add", "update" or "invalidate" may be followed by SECONDARY objects
+with the same candidate_id: "invalidate" objects when a contradiction must
+retire existing pages, and/or "add" objects that create a missing companion
+topic page in the same batch (see graph visibility below). No other
+duplicate candidate_id is allowed:
{"candidate_id": <int>, "decision": "add" | "update" | "noop" | "invalidate",
"target": "<dir>/<slug>.md", "new_body": "<full page markdown>",
"superseded_by": "<slug>", "reason": "<short why>"}
@@ -503,6 +505,20 @@ Decision semantics:
"add" or "update" in this same batch). Do NOT provide "new_body"; the
system marks the page superseded mechanically. Nothing is ever deleted.
+Graph visibility (binding): the vault graph shows only PAGES and
+[[wikilinks]] — a fact stored solely as a bullet on the user's profile is
+invisible there. A durable non-user TOPIC the user actively pursues
+deserves its own page in addition to the profile note: an undertaking or
+acquisition hunt (researching a major purchase, planning a trip or event)
+belongs in projects/; an adopted tool, service, organization, or other
+named thing in entities/; a recurring theme or standing decision in
+concepts/. When the correct primary decision is "update" on the user
+profile but the candidate's subjects name such a durable topic with NO
+existing page, ALSO emit a secondary "add" for that topic page in the same
+batch and cross-link it with the profile in both directions. Do not create
+topic pages for one-off mentions, smalltalk themes, or unsupported guesses
+— the evidence rules above still apply.
+
Page-type templates (frontmatter keys are mandatory):
- entities/<slug>.md: type: entity, entity_kind (person|tool|repository|
service|device|asset|vehicle|place|organization), slug, aliases, created,
diff --git a/tests/unit/memory/wiki/test_consolidator.py b/tests/unit/memory/wiki/test_consolidator.py
index 7102c5df10..9d681b4db2 100644
--- a/tests/unit/memory/wiki/test_consolidator.py
+++ b/tests/unit/memory/wiki/test_consolidator.py
@@ -326,6 +326,156 @@ async def test_update_merges_in_place_and_judge_saw_the_body(stack) -> None:
assert "- Lena works at the animal clinic." in content
+RUBEN_FULL_BODY = (
+ "---\n"
+ "type: entity\n"
+ "entity_kind: person\n"
+ "slug: ruben\n"
+ "aliases: [Ruben]\n"
+ "created: 2026-06-01\n"
+ "updated: 2026-06-01\n"
+ "---\n"
+ "\n"
+ "# Ruben\n"
+ "\n"
+ "## Summary\n"
+ "\n"
+ "The user.\n"
+ "\n"
+ "## Facts\n"
+ "\n"
+ "- Enjoys great coffee.\n"
+ "\n"
+ "## Relationships\n"
+ "\n"
+ "## Sources\n"
+ "\n"
+ "- conversation\n"
+)
+
+
+def _espresso_project_body() -> str:
+ today = dt.date.today().isoformat()
+ return (
+ "---\n"
+ "type: project\n"
+ "slug: espresso-machine\n"
+ "status: active\n"
+ f"started: {today}\n"
+ f"last_activity: {today}\n"
+ "---\n\n"
+ "# Espresso Machine\n\n"
+ "## Goal\n\n"
+ "Find a high-end espresso machine for the kitchen.\n\n"
+ "## Current Status\n\n"
+ "Researching options.\n\n"
+ "## Recent Activity\n\n"
+ "- The user disclosed the pursuit.\n\n"
+ "## Open Threads\n\n"
+ "- None recorded.\n\n"
+ "## Related\n\n"
+ "- [[entities/ruben]]\n\n"
+ "## Sources\n\n"
+ "- conversation\n"
+ )
+
+
+async def test_companion_add_creates_topic_page_beside_profile_update(stack) -> None:
+ """Graph-visibility rule: a profile update may CREATE the missing topic
+ page as a secondary "add" in the same batch, cross-linked both ways."""
+ vault_root, _curator, journal = stack
+ _write_aged(vault_root / "entities" / "ruben.md", RUBEN_FULL_BODY)
+ journal.append(
+ [CandidateFact(
+ fact="The user is pursuing a high-end espresso machine for the kitchen.",
+ kind="preference", subjects=("ruben", "espresso-machine"),
+ )],
+ source_label="realtime-aggressive:1", turn_hash="h-espresso",
+ )
+ cid = journal.pending()[0].id
+
+ updated_profile = RUBEN_FULL_BODY.replace(
+ "- Enjoys great coffee.\n",
+ "- Enjoys great coffee.\n"
+ "- Pursuing a high-end espresso machine for the kitchen.\n",
+ ).replace(
+ "## Relationships\n\n",
+ "## Relationships\n\n- [[projects/espresso-machine]] — active pursuit\n\n",
+ )
+ brain = FakeBrain([_judge_json([
+ {
+ "candidate_id": cid,
+ "decision": "update",
+ "target": "entities/ruben.md",
+ "new_body": updated_profile,
+ "reason": "profile note",
+ },
+ {
+ "candidate_id": cid,
+ "decision": "add",
+ "target": "projects/espresso-machine.md",
+ "new_body": _espresso_project_body(),
+ "reason": "companion topic page (graph visibility)",
+ },
+ ])])
+ consolidator = _consolidator(stack, brain)
+
+ label = await consolidator.run_once()
+
+ assert label == "journal-batch:1"
+ topic = vault_root / "projects" / "espresso-machine.md"
+ assert topic.is_file()
+ assert "Find a high-end espresso machine" in topic.read_text(encoding="utf-8")
+ profile = (vault_root / "entities" / "ruben.md").read_text(encoding="utf-8")
+ assert "- Enjoys great coffee." in profile # existing fact survived
+ assert "- Pursuing a high-end espresso machine for the kitchen." in profile
+ # The cross-link survives demotion because the target page is created
+ # in the SAME batch.
+ assert "[[projects/espresso-machine]]" in profile
+ assert journal.pending() == []
+
+
+async def test_secondary_update_is_still_rejected(stack) -> None:
+ """Only "add" and "invalidate" may ride as secondary actions — a
+ secondary "update" of another existing page stays invalid."""
+ vault_root, _curator, journal = stack
+ _write_aged(vault_root / "entities" / "ruben.md", RUBEN_FULL_BODY)
+ journal.append(
+ [CandidateFact(
+ fact="The user is pursuing a high-end espresso machine.",
+ kind="preference", subjects=("ruben",),
+ )],
+ source_label="realtime-aggressive:2", turn_hash="h-espresso-2",
+ )
+ cid = journal.pending()[0].id
+
+ brain = FakeBrain([_judge_json([
+ {
+ "candidate_id": cid,
+ "decision": "update",
+ "target": "entities/ruben.md",
+ "new_body": RUBEN_FULL_BODY,
+ "reason": "profile note",
+ },
+ {
+ "candidate_id": cid,
+ "decision": "update",
+ "target": "entities/lena.md",
+ "new_body": LENA_BODY,
+ "reason": "sneaky second update",
+ },
+ ])])
+ consolidator = _consolidator(stack, brain)
+
+ label = await consolidator.run_once()
+
+ assert label == "judge-unavailable" # rejected response, chain exhausted
+ assert not (vault_root / "entities" / "lena.md").exists()
+ assert journal.pending() != [] # candidate stays visible for the next pass
+
+
@pytest.mark.asyncio
async def test_partial_decision_array_crosses_to_complete_provider(stack) -> None:
_vault_root, _curator, journal = stack
diff --git a/tests/unit/memory/wiki/test_prompt.py b/tests/unit/memory/wiki/test_prompt.py
index 01be384914..a2b9c87b19 100644
--- a/tests/unit/memory/wiki/test_prompt.py
+++ b/tests/unit/memory/wiki/test_prompt.py
@@ -431,6 +431,22 @@ def test_consolidator_prompt_rechecks_question_derived_user_claims() -> None:
assert "What are the benefits of Vitamin D?" in user
+def test_consolidator_prompt_carries_the_graph_visibility_rule() -> None:
+ candidate = SimpleNamespace(
+ id=9,
+ fact="The user is pursuing a high-end espresso machine.",
+ kind="preference",
+ subjects=("user", "espresso-machine"),
+ )
+
+ system, _user = build_consolidator_prompt([candidate], {})
+
+ assert "Graph visibility (binding)" in system
+ assert 'ALSO emit a secondary "add"' in system
+ assert "cross-link it with the profile in both directions" in system
+ assert "one-off mentions, smalltalk themes, or unsupported guesses" in system
+
+
def test_consolidator_prompt_elevates_explicit_persistence_requests() -> None:
candidate = SimpleNamespace(
id=8,