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(wiki): canonicalise Sources citations at write time and in the preservation guard

Ruben Lütke5d252bcd45d4
diff --git a/jarvis/core/config.py b/jarvis/core/config.py
index 2df39a13db..68f4e01539 100644
--- a/jarvis/core/config.py
+++ b/jarvis/core/config.py
@@ -983,7 +983,11 @@ class WikiCuratorConfig(BaseModel):
# needs several thousand tokens (live 2026-07-17: 4000 truncated on
# every provider and stalled the whole chain).
max_output_tokens: int = 8000
- timeout_s: float = 90.0
+ # Background path — latency-insensitive. CLI-login providers (codex
+ # via ChatGPT OAuth) regularly need >90 s for a full 8-candidate
+ # batch with complete page bodies; a timeout that always fires turns
+ # the fallback provider into a 90 s tax on every failed primary.
+ timeout_s: float = 180.0
class SessionRollupConfig(BaseModel):
diff --git a/jarvis/memory/wiki/consolidator.py b/jarvis/memory/wiki/consolidator.py
index c63e46a9ee..493a527b8e 100644
--- a/jarvis/memory/wiki/consolidator.py
+++ b/jarvis/memory/wiki/consolidator.py
@@ -47,6 +47,7 @@ from jarvis.memory.wiki.curator_llm import (
)
from jarvis.memory.wiki.intent import match_wiki_intent
from jarvis.memory.wiki.journal import JournalRow, normalise_subjects
+from jarvis.memory.wiki.page import normalise_sources_section
from jarvis.memory.wiki.prompt import (
build_consolidator_prompt,
resolve_user_entity_slug,
@@ -1302,11 +1303,19 @@ class Consolidator:
schema-valid full-page replacement may therefore change ``updated:``
metadata and add content, but it may not silently delete identity
metadata, headings, prose, facts, links, or source lines.
+
+ Both sides are compared through ``normalise_sources_section``: the
+ write path canonicalises Sources citations anyway, so noise the
+ normaliser strips from the CURRENT page is not required to survive
+ — otherwise a page carrying pre-normalisation junk rejects every
+ tidying update forever (the live user.md wedge of 2026-07-20).
"""
try:
current = path.read_text(encoding="utf-8")
except OSError:
return False
+ current = normalise_sources_section(current)
+ proposed = normalise_sources_section(proposed)
def _required_lines(raw: str) -> set[str]:
lines = raw.splitlines()
diff --git a/jarvis/memory/wiki/curator.py b/jarvis/memory/wiki/curator.py
index e3d148d170..2ac1c50d7c 100644
--- a/jarvis/memory/wiki/curator.py
+++ b/jarvis/memory/wiki/curator.py
@@ -36,6 +36,7 @@ from pathlib import Path
from jarvis.core.events import WikiPageChanged
from .log_writer import LogWriter
+from .page import normalise_sources_section
from .protocols import (
AtomicWriter,
CuratorLLM,
@@ -218,6 +219,24 @@ class WikiCurator:
# no I/O — mirrors the session-rollup post-pass.
updates = self._demote_dangling_links(updates)
+ # ----- 1c. canonicalise Sources citations ----------------------
+ # Deterministic tidy of the ## Sources section (dedupe, drop
+ # fabricated session==turn pairs, collapse gaps) so judge noise
+ # never lands on disk — where the consolidator's preservation
+ # guard would otherwise require every later update to keep it.
+ updates = [
+ upd
+ if (tidied := normalise_sources_section(upd.new_body)) == upd.new_body
+ else PageUpdate(
+ target_path=upd.target_path,
+ operation=upd.operation,
+ new_body=tidied,
+ rename_from=upd.rename_from,
+ reason=upd.reason,
+ )
+ for upd in updates
+ ]
+
# ----- 2. hand the proposal to the writer ----------------------
# The writer takes the snapshot, applies each update via
# tempfile+rename, re-validates each written page through repo,
diff --git a/jarvis/memory/wiki/page.py b/jarvis/memory/wiki/page.py
index 3fe74c62d2..bc33cbaa87 100644
--- a/jarvis/memory/wiki/page.py
+++ b/jarvis/memory/wiki/page.py
@@ -187,6 +187,99 @@ def parse_sections(body: str) -> tuple[tuple[str, str], ...]:
return tuple(out)
+_SOURCES_HEADING_RE = re.compile(r"^##\s+Sources\s*$")
+_SOURCE_ID_RE = re.compile(r"`([^`\s]+)`")
+_DEGENERATE_SOURCE_PAIR_RE = re.compile(
+ r"session\s+`([^`]+)`\s*,\s*turn\s+`\1`"
+)
+
+
+def normalise_sources_section(text: str) -> str:
+ """Deterministically tidy the ``## Sources`` section of a page.
+
+ Judge models synthesise citation bullets imperfectly: duplicated
+ lines, blank-line gaps between bullets, fabricated pairs citing one
+ id as both session AND turn, and single-id bullets repeating a turn
+ already cited by a full pair. The consolidator's preservation guard
+ would otherwise lock that noise into the page forever — every later
+ update that tidies it gets rejected as "removes existing page
+ content" (live 2026-07-20: ``entities/user.md`` became unwritable).
+ Normalising keeps the section canonical so there is nothing left for
+ a model to tidy.
+
+ Applied transforms, bullets only, first Sources section only:
+
+ * ``session `X`, turn `X``` (same id) → ``turn `X``` — the pair was
+ fabricated; the turn reference itself is kept.
+ * exact duplicates (whitespace-normalised) collapse to the first;
+ * a bullet citing exactly one id is dropped when a bullet with two
+ or more ids already cites that id;
+ * blank lines between bullets collapse.
+
+ Prose lines inside the section and everything outside it pass
+ through verbatim. Pure text transform — no I/O, no LLM (AP-9/11).
+ """
+ lines = text.splitlines()
+ heading_index = next(
+ (
+ index
+ for index, line in enumerate(lines)
+ if _SOURCES_HEADING_RE.match(line.strip())
+ ),
+ None,
+ )
+ if heading_index is None:
+ return text
+ end = next(
+ (
+ index
+ for index in range(heading_index + 1, len(lines))
+ if lines[index].lstrip().startswith("#")
+ ),
+ len(lines),
+ )
+
+ bullets: list[str] = []
+ prose: list[str] = []
+ seen: set[str] = set()
+ for line in lines[heading_index + 1 : end]:
+ if not line.strip():
+ continue
+ if not line.lstrip().startswith("- "):
+ prose.append(line)
+ continue
+ bullet = _DEGENERATE_SOURCE_PAIR_RE.sub(r"turn `\1`", line)
+ key = " ".join(bullet.split())
+ if key in seen:
+ continue
+ seen.add(key)
+ bullets.append(bullet)
+
+ strong_ids = {
+ cited_id
+ for bullet in bullets
+ for ids in (_SOURCE_ID_RE.findall(bullet),)
+ if len(set(ids)) >= 2
+ for cited_id in ids
+ }
+ kept = [
+ bullet
+ for bullet in bullets
+ if not (
+ len(set(_SOURCE_ID_RE.findall(bullet))) == 1
+ and _SOURCE_ID_RE.findall(bullet)[0] in strong_ids
+ )
+ ]
+
+ section = [lines[heading_index], "", *kept, *prose]
+ if end < len(lines):
+ section.append("")
+ out = "\n".join([*lines[:heading_index], *section, *lines[end:]])
+ if text.endswith("\n") and not out.endswith("\n"):
+ out += "\n"
+ return out
+
+
# ──────────────────────────────────────────────────────────────────────
# internals
# ──────────────────────────────────────────────────────────────────────
@@ -280,6 +373,7 @@ __all__ = [
"parse_markdown",
"render_page",
"parse_sections",
+ "normalise_sources_section",
"DIR_TO_TYPE",
"REQUIRED_KEYS",
"CANONICAL_SECTIONS",
diff --git a/tests/unit/memory/wiki/test_consolidator.py b/tests/unit/memory/wiki/test_consolidator.py
index 6847f58df0..b02d4d5784 100644
--- a/tests/unit/memory/wiki/test_consolidator.py
+++ b/tests/unit/memory/wiki/test_consolidator.py
@@ -1350,6 +1350,54 @@ async def test_numeric_value_already_in_existing_page_remains_valid(stack) -> No
assert "installed in the desktop" in content
+async def test_update_may_drop_sources_noise_the_normaliser_strips(stack) -> None:
+ """A page carrying pre-normalisation Sources junk (duplicate bullets,
+ fabricated session==turn pairs) must not hold itself hostage: an
+ update that tidies exactly what the write-path normaliser strips
+ anyway passes the preservation guard."""
+ vault_root, _curator, journal = stack
+ junky = LENA_BODY.replace(
+ "## Sources\n\n- conversation\n",
+ "## Sources\n\n"
+ "- Realtime transcript: session `s1`, turn `t1`.\n"
+ "\n"
+ "- Realtime transcript: session `s1`, turn `t1`.\n"
+ "- Realtime transcript: session `t1`, turn `t1`.\n",
+ )
+ _write_aged(vault_root / "entities" / "lena.md", junky)
+ journal.append(
+ [CandidateFact(fact="Lena enjoys hiking.", kind="person", subjects=("lena",))],
+ source_label="voice:tidy-update",
+ turn_hash="tidy-update",
+ )
+ cid = journal.pending()[0].id
+
+ tidied = LENA_BODY.replace(
+ "- Lena lives in Hamburg.\n",
+ "- Lena lives in Hamburg.\n- Lena enjoys hiking.\n",
+ ).replace(
+ "## Sources\n\n- conversation\n",
+ "## Sources\n\n- Realtime transcript: session `s1`, turn `t1`.\n",
+ )
+ brain = FakeBrain([_judge_json([{
+ "candidate_id": cid,
+ "decision": "update",
+ "target": "entities/lena.md",
+ "new_body": tidied,
+ "reason": "merge + tidy",
+ }])])
+ consolidator = _consolidator(stack, brain)
+
+ label = await consolidator.run_once()
+
+ assert label == "journal-batch:1"
+ content = (vault_root / "entities" / "lena.md").read_text(encoding="utf-8")
+ assert "- Lena enjoys hiking." in content
+ assert content.count("session `s1`, turn `t1`") == 1
+ assert journal.pending() == []
+
+
def test_source_citation_uuid_in_inline_code_is_not_a_numeric_claim() -> None:
"""A schema-style Sources line cites opaque ids in inline code
(``session `f260abcc-…```` ). Fragmenting those ids into pseudo-numbers
diff --git a/tests/unit/memory/wiki/test_page.py b/tests/unit/memory/wiki/test_page.py
index 763b0088a7..13a6a2b8b5 100644
--- a/tests/unit/memory/wiki/test_page.py
+++ b/tests/unit/memory/wiki/test_page.py
@@ -17,6 +17,7 @@ from jarvis.memory.wiki.page import (
DIR_TO_TYPE,
REQUIRED_KEYS,
MarkdownPageRepository,
+ normalise_sources_section,
parse_markdown,
parse_sections,
render_page,
@@ -468,3 +469,59 @@ def test_repository_render_round_trip(tmp_path: Path) -> None:
text = repo.render(page)
re_parsed = asyncio.run(repo.parse(text, _entity_page(tmp_path)))
assert re_parsed == page
+
+
+# ──────────────────────────────────────────────────────────────────────
+# normalise_sources_section
+# ──────────────────────────────────────────────────────────────────────
+
+
+def test_sources_normaliser_collapses_gaps_and_duplicates() -> None:
+ body = (
+ "# User\n\n## Facts\n\n- A fact.\n\n## Sources\n\n"
+ "- Realtime transcript: session `aaa`, turn `bbb`.\n"
+ "\n"
+ "- Realtime transcript: session `aaa`, turn `bbb`.\n"
+ "- Realtime transcript: session `ccc`, turn `ddd`.\n"
+ )
+ out = normalise_sources_section(body)
+ assert out == (
+ "# User\n\n## Facts\n\n- A fact.\n\n## Sources\n\n"
+ "- Realtime transcript: session `aaa`, turn `bbb`.\n"
+ "- Realtime transcript: session `ccc`, turn `ddd`.\n"
+ )
+
+
+def test_sources_normaliser_rewrites_fabricated_session_turn_pair() -> None:
+ body = "## Sources\n\n- Realtime transcript: session `xxx`, turn `xxx`.\n"
+ out = normalise_sources_section(body)
+ assert "- Realtime transcript: turn `xxx`.\n" in out
+ assert "session `xxx`" not in out
+
+
+def test_sources_normaliser_drops_single_id_bullet_subsumed_by_pair() -> None:
+ body = (
+ "## Sources\n\n"
+ "- Realtime transcript: session `sss`, turn `ttt`.\n"
+ "- User evidence turn `ttt`.\n"
+ "- User evidence turn `zzz`.\n"
+ )
+ out = normalise_sources_section(body)
+ assert "- User evidence turn `ttt`.\n" not in out
+ # An id no pair covers keeps its own line.
+ assert "- User evidence turn `zzz`.\n" in out
+
+
+def test_sources_normaliser_without_sources_section_is_identity() -> None:
+ body = "# Page\n\n## Facts\n\n- 1\n- 1\n"
+ assert normalise_sources_section(body) == body
+
+
+def test_sources_normaliser_preserves_following_sections() -> None:
+ body = (
+ "## Sources\n\n- a `x1`, b `y1`.\n- a `x1`, b `y1`.\n\n"
+ "## Appendix\n\nKeep me.\n"
+ )
+ out = normalise_sources_section(body)
+ assert out.endswith("## Appendix\n\nKeep me.\n")
+ assert out.count("- a `x1`, b `y1`.") == 1
diff --git a/wiki/obsidian-vault/10-notes/Evergreen Notes.md b/wiki/obsidian-vault/10-notes/Evergreen Notes.md
deleted file mode 100644
index 12f5491f85..0000000000
--- a/wiki/obsidian-vault/10-notes/Evergreen Notes.md
+++ /dev/null
@@ -1,31 +0,0 @@
----
-tags: [pkm, method, modern]
-aliases: [Evergreen, Permanent Notes]
-created: 2026-05-12
----
-
-# Evergreen Notes
-
-A reinterpretation of permanent notes coined by Andy Matuschak. The defining shift: notes should be evaluated by maturity, not by count. A vault of fifty evergreen notes beats a vault of five thousand fleeting ones.
-
-## Defining Properties
-
-- **Concept-oriented** — each note's title is a claim or concept, never a topic or container ("Sleep regulates emotional reactivity", not "Sleep").
-- **Densely linked** — at least three connections to other notes before a note is considered evergreen.
-- **Atomic** — same atomicity rule as the [[Zettelkasten Method]], but explicit about *single claims* rather than single ideas.
-- **Continuously rewritten** — notes are gardened, not authored. Re-editing yesterday's note is a feature, not waste.
-
-## Relationship to Tools
-
-Evergreen Notes need an editor that makes linking effortless — typing `[[` should surface candidates instantly. Obsidian, Roam, and Logseq all bake this in, and all sit on top of [[Markdown as Foundation]]. The [[Graph View Visualisation]] becomes a diagnostic: clusters of orphaned notes signal areas you have not yet thought through.
-
-## Adoption Curve
-
-Most beginners start with the [[Zettelkasten Method]] and migrate to evergreen practice when they realise their note count is growing faster than their understanding. That gap is the entire problem PKM was invented to solve — see [[Personal Knowledge Management]] for the wider context.
-
-## See Also
-
-- [[Zettelkasten Method]] — the predecessor
-- [[Personal Knowledge Management]] — the umbrella
-- [[Graph View Visualisation]] — the diagnostic
-- [[Markdown as Foundation]] — the substrate
diff --git a/wiki/obsidian-vault/10-notes/Graph View Visualisation.md b/wiki/obsidian-vault/10-notes/Graph View Visualisation.md
deleted file mode 100644
index 098bac94b3..0000000000
--- a/wiki/obsidian-vault/10-notes/Graph View Visualisation.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-tags: [tooling, visualisation, feedback-loop]
-aliases: [Graph View, Knowledge Graph]
-created: 2026-05-12
----
-
-# Graph View Visualisation
-
-A force-directed diagram of your notes, drawn live from the Wikilinks between them. Obsidian renders it in real time; Roam and Logseq have their own variants. The visual exists less for navigation and more as a *diagnostic*.
-
-## What the Graph Tells You
-
-- **Dense clusters** = topics you have already thought through.
-- **Bridges between clusters** = the unexpected connections that produce new ideas.
-- **Orphan nodes** = notes that were captured but never integrated. They are the working list of what to think about next.
-- **Hubs** (high-degree nodes) = your core concepts. Their stability is a sign your model is solidifying.
-
-## Why It Matters for PKM
-
-Without the graph, [[Personal Knowledge Management]] feels like writing into a void. The visualisation provides the feedback loop that makes the practice self-reinforcing — see also the maturity argument in [[Evergreen Notes]].
-
-## Technical Substrate
-
-Every modern PKM tool builds its graph on top of two layers: [[Markdown as Foundation]] for storage, and a Wikilink parser for edges. The original idea — that ideas surface through neighbours — predates the tooling and traces back to the [[Zettelkasten Method]].
-
-## Anti-patterns
-
-- **Optimising for the graph instead of for thought.** A pretty graph with shallow notes is a vanity metric.
-- **Adding "MOC" (Map of Content) hub-notes too early.** They inflate the visualisation without earning their place.
-
-## See Also
-
-- [[Personal Knowledge Management]] — the context
-- [[Zettelkasten Method]] — the origin
-- [[Evergreen Notes]] — the discipline
-- [[Markdown as Foundation]] — the substrate
diff --git a/wiki/obsidian-vault/10-notes/Markdown as Foundation.md b/wiki/obsidian-vault/10-notes/Markdown as Foundation.md
deleted file mode 100644
index 79bc8e05c5..0000000000
--- a/wiki/obsidian-vault/10-notes/Markdown as Foundation.md
+++ /dev/null
@@ -1,31 +0,0 @@
----
-tags: [format, foundational, tooling]
-aliases: [Markdown, CommonMark]
-created: 2026-05-12
----
-
-# Markdown as Foundation
-
-Markdown is the lowest-friction format that survives a tool migration. A vault written in Markdown today opens in any editor in 2040, which is exactly the longevity a knowledge base needs.
-
-## Why It Won
-
-- **Human-readable in raw form** — even without a renderer, the structure is obvious.
-- **Plain-text durability** — no proprietary binary blob between you and your text.
-- **Tool-agnostic** — Obsidian, Bear, iA Writer, and `vim` all read the same files.
-- **Extensible without breaking** — frontmatter, callouts, and Wikilinks compose with the base spec.
-
-## Wikilinks as the Killer Extension
-
-The CommonMark spec does not define `[[…]]` syntax. Obsidian and Roam adopted it as a deliberate convention to make linking cheaper than the standard `[label](url)` form. This single ergonomic shift is what makes the [[Zettelkasten Method]] practical at scale, and is what powers the [[Graph View Visualisation]].
-
-## Trade-offs
-
-Markdown's flexibility is also its trap — every tool dialect (GFM, MDX, Pandoc) extends the spec slightly differently. Treat it like a contract: stick to the [[Evergreen Notes]] subset that all your tools agree on, and your vault outlives any single editor.
-
-## See Also
-
-- [[Zettelkasten Method]] — what cheap linking enables
-- [[Evergreen Notes]] — the discipline that runs on this substrate
-- [[Personal Knowledge Management]] — the broader context
-- [[Graph View Visualisation]] — what cheap linking renders into
diff --git a/wiki/obsidian-vault/10-notes/Personal Knowledge Management.md b/wiki/obsidian-vault/10-notes/Personal Knowledge Management.md
deleted file mode 100644
index da3a75b3fd..0000000000
--- a/wiki/obsidian-vault/10-notes/Personal Knowledge Management.md
+++ /dev/null
@@ -1,31 +0,0 @@
----
-tags: [pkm, overview, workflow]
-aliases: [PKM]
-created: 2026-05-12
----
-
-# Personal Knowledge Management
-
-The deliberate practice of collecting, processing, and connecting information so that a single human can reuse it across years. PKM is less about storage and more about turning fleeting attention into compoundable understanding.
-
-## Defining Activities
-
-1. **Capture** — get raw signal out of your head and into a trusted place fast.
-2. **Distill** — restate the signal in your own words so it becomes searchable later.
-3. **Connect** — link the new note to existing notes, creating navigable structure.
-4. **Express** — write something new, leaning on what you have already connected.
-
-## Method Variants
-
-Different communities have crystallised the same skeleton into named recipes. The [[Zettelkasten Method]] of Niklas Luhmann was the original; [[Evergreen Notes]] is the Andy Matuschak rework that emphasises maturity over count. Both depend on tooling that makes linking cheap — the breakthrough that [[Markdown as Foundation]] enabled.
-
-## Why People Stick With It
-
-Most knowledge workers re-read the same articles three times. A PKM system pays for itself the moment it surfaces something you would otherwise re-discover. The dopamine of [[Graph View Visualisation]] helps too — seeing your own thinking shape into a network is unexpectedly motivating.
-
-## See Also
-
-- [[Zettelkasten Method]] — the foundational recipe
-- [[Evergreen Notes]] — the modern variant
-- [[Markdown as Foundation]] — why the file format matters
-- [[Graph View Visualisation]] — feedback loop that keeps users engaged
diff --git a/wiki/obsidian-vault/10-notes/Zettelkasten Method.md b/wiki/obsidian-vault/10-notes/Zettelkasten Method.md
deleted file mode 100644
index 1375671081..0000000000
--- a/wiki/obsidian-vault/10-notes/Zettelkasten Method.md
+++ /dev/null
@@ -1,29 +0,0 @@
----
-tags: [pkm, method, foundational]
-aliases: [Slip-Box, Zettelkasten]
-created: 2026-05-12
----
-
-# Zettelkasten Method
-
-A note-taking workflow that emphasises atomic notes, dense linking, and the absence of a fixed hierarchy. Each note captures a single idea and earns its value through the explicit connections it carries to other notes.
-
-## Core Principles
-
-- **Atomicity** — one note, one idea. Splitting compound topics into separate notes makes them recombinable later.
-- **Linking over filing** — relationships beat folders. A note's location matters less than the notes it points to.
-- **Permanent rewriting** — the act of restating ideas in your own words is where understanding compounds.
-
-## Relationship to Other Practices
-
-The method is the spiritual predecessor of the modern [[Personal Knowledge Management]] movement. Its mechanic of "ideas surface through neighbours" is what powers the [[Graph View Visualisation]] in tools like Obsidian. Newer thinkers like Tiago Forte have rebranded the practice as [[Evergreen Notes]], adding emphasis on note maturity over note count.
-
-## Practical Setup
-
-A working slip-box needs three layers: fleeting notes (inbox), literature notes (sources), and permanent notes (your own thinking). All three live in plain [[Markdown as Foundation]] today, but the discipline predates the format by half a century.
-
-## See Also
-
-- [[Personal Knowledge Management]] — the umbrella framework
-- [[Evergreen Notes]] — modern reinterpretation
-- [[Graph View Visualisation]] — how dense linking becomes visible