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): stop event derivation filling the People view with software

Ruben Lütkeb1aecc54e8ec
diff --git a/jarvis/ultrawiki/event_store.py b/jarvis/ultrawiki/event_store.py
index 98a7d3659b..3187946d46 100644
--- a/jarvis/ultrawiki/event_store.py
+++ b/jarvis/ultrawiki/event_store.py
@@ -21,7 +21,9 @@ The contract this module keeps:
- **Participants link through the identity layer, never around it.** Names are
resolved with :meth:`IdentityMixin.resolve_identity`, which merges only on
deterministic evidence and otherwise proposes; an unresolvable participant
- keeps its spelling and stays searchable rather than being dropped.
+ keeps its spelling and stays searchable rather than being dropped. Linking
+ is cheap and always allowed; CREATING a person is gated on the event's own
+ confidence, because a new entity outlives the guess that produced it.
- **The keyword card is stored, not recomputed.** ``search_text`` lives on the
row, so both dialects index the identical text and a search cannot depend
on which engine answered.
@@ -129,9 +131,12 @@ class EventMixin:
store against itself.
``create_entities=False`` links participants and places only to
- entities that already exist — the conservative mode for low-confidence
- derivations, where creating a row per mentioned name would flood the
- People view with noise.
+ entities that already exist — a hard "read-only identity" switch for
+ callers that must not touch the People view at all. Leaving it on does
+ NOT mean every name becomes a person: an event below
+ :data:`~jarvis.ultrawiki.events.ENTITY_CREATE_CONFIDENCE` links but
+ never creates, so a low-confidence derivation cannot flood the People
+ view with whatever it happened to name.
"""
item_id = int(item_id)
resolved = await self._ev_resolve_names(events, create_entities=create_entities)
@@ -162,32 +167,47 @@ class EventMixin:
to ``None`` and is stored by its spelling — an honest "I know the name,
not who it is" beats guessing, and guessing is the wrong-merge failure
the whole identity layer exists to prevent.
+
+ Creating an entity is gated TWICE, because it is the only irreversible
+ half of this: the caller has to allow it at all, and the name has to
+ appear in at least one event confident enough to be worth a row
+ (:data:`~jarvis.ultrawiki.events.ENTITY_CREATE_CONFIDENCE`). Below
+ that the name still LINKS to whoever the user already curated and is
+ otherwise stored as plain text — searchable, and nobody new in the
+ People view.
"""
+ from jarvis.ultrawiki.events import ( # noqa: PLC0415 — lazy (AP-26)
+ ENTITY_CREATE_CONFIDENCE,
+ )
from jarvis.ultrawiki.identity import EntityKind # noqa: PLC0415 — lazy (AP-26)
- wanted: list[tuple[str, str]] = []
- seen: set[tuple[str, str]] = set()
+ wanted: list[tuple[str, Any]] = []
+ best: dict[tuple[str, str], float] = {}
for event in events:
+ confidence = float(event.confidence)
for name in event.participants:
- key = ("person", name.casefold())
- if key not in seen:
- seen.add(key)
+ slot = ("person", name.casefold())
+ if slot not in best:
wanted.append((name, EntityKind.PERSON))
+ best[slot] = max(best.get(slot, 0.0), confidence)
if event.place:
- key = ("place", event.place.casefold())
- if key not in seen:
- seen.add(key)
+ slot = ("place", event.place.casefold())
+ if slot not in best:
wanted.append((event.place, EntityKind.PLACE))
+ best[slot] = max(best.get(slot, 0.0), confidence)
out: dict[tuple[str, str], int | None] = {}
for name, kind in wanted:
slot = ("person" if kind is EntityKind.PERSON else "place", name.casefold())
+ may_create = create_entities and (
+ best.get(slot, 0.0) >= ENTITY_CREATE_CONFIDENCE
+ )
try:
resolution = await self.resolve_identity( # type: ignore[attr-defined]
name=name,
kind=kind,
source_ref="uw_events",
- create=create_entities,
+ create=may_create,
)
except Exception: # noqa: BLE001 — a refused link never fails an event
log.debug("event identity resolution failed for %r", name, exc_info=True)
@@ -446,7 +466,9 @@ class EventMixin:
as one more ranked list (design doc 01, principle 5: no single scorer
is trusted). ``timestamp_utc`` carries the event's OWN ``occurred_at``
rather than the evidence item's — the date the user asked about is the
- date the answer should be ordered and decayed by.
+ date the answer should be SHOWN with — while ``recorded_utc`` keeps
+ the item's own stamp, so ranking can still tell an old note from a
+ fresh note about an old day.
"""
if not query or not query.strip():
return []
@@ -458,7 +480,7 @@ class EventMixin:
"SELECT e.id AS event_id, e.item_id, e.kind, e.title,"
" e.summary, e.occurred_at, e.occurred_end, e.occurred_precision,"
" e.place_raw, e.search_text,"
- " i.source_id, i.permalink, i.areas_json,"
+ " i.source_id, i.permalink, i.areas_json, i.timestamp_utc,"
" ts_rank(e.search_tsv, websearch_to_tsquery('simple', ?)) AS raw_score"
" FROM uw_events e JOIN uw_items i ON i.id = e.item_id"
" WHERE e.search_tsv @@ websearch_to_tsquery('simple', ?)"
@@ -473,7 +495,7 @@ class EventMixin:
"SELECT e.id AS event_id, e.item_id, e.kind, e.title,"
" e.summary, e.occurred_at, e.occurred_end, e.occurred_precision,"
" e.place_raw, e.search_text,"
- " i.source_id, i.permalink, i.areas_json,"
+ " i.source_id, i.permalink, i.areas_json, i.timestamp_utc,"
" bm25(uw_event_fts, 0.0, 3.0, 1.0) AS raw_score"
" FROM uw_event_fts JOIN uw_events e ON e.id = uw_event_fts.event_id"
" JOIN uw_items i ON i.id = e.item_id"
@@ -524,8 +546,52 @@ class EventMixin:
timestamp_utc=str(data.get("occurred_at") or ""),
score=round(score, 4),
matched_by=("event",),
+ recorded_utc=str(data.get("timestamp_utc") or ""),
)
+ # -- backfill over an ALREADY distilled corpus ---------------------------
+
+ async def items_with_distillation(
+ self, *, after_id: int = 0, limit: int = 50
+ ) -> list[dict[str, Any]]:
+ """Distilled items whose stored distillation can yield events, by id.
+
+ The reader behind the backfill lane. An install that distilled its
+ corpus before the event tables existed never passes through the
+ distillation stage again — that stage claims items that are NOT yet
+ distilled — so without this its events would only ever appear for
+ content imported afterwards.
+
+ Nothing here costs a model call: the distillation JSON is already on
+ the row, and ``events.derive_events`` is pure arithmetic over it. The
+ cursor is the caller's (``after_id``), so the pass is resumable and
+ each item is visited once.
+ """
+ conn = await self._ensure_open() # type: ignore[attr-defined]
+ rows = await self._ev_rows(
+ conn,
+ "SELECT i.id AS id, i.title AS title, i.timestamp_utc AS timestamp_utc,"
+ " d.distill_json AS distill_json"
+ " FROM uw_items i JOIN uw_documents d ON d.item_id = i.id"
+ " WHERE i.id > ? AND i.deleted_at IS NULL AND d.doc_type = 'summary'"
+ " AND d.distill_json IS NOT NULL AND d.distill_json != ''"
+ " ORDER BY i.id, d.id DESC LIMIT ?",
+ (int(after_id), max(1, int(limit))),
+ )
+ out: dict[int, dict[str, Any]] = {}
+ for row in rows:
+ data = dict(row)
+ item_id = _as_int(data.get("id"))
+ if item_id is None or item_id in out:
+ continue # one item can hold several summary documents
+ out[item_id] = {
+ "id": item_id,
+ "title": str(data.get("title") or ""),
+ "timestamp_utc": str(data.get("timestamp_utc") or ""),
+ "distill_json": str(data.get("distill_json") or ""),
+ }
+ return [out[key] for key in sorted(out)]
+
async def event_counts(self) -> dict[str, int]:
"""``{kind: n}`` over live events, plus ``total`` — the surface's badge."""
conn = await self._ensure_open() # type: ignore[attr-defined]
diff --git a/jarvis/ultrawiki/events.py b/jarvis/ultrawiki/events.py
index c612838c71..d911ff1471 100644
--- a/jarvis/ultrawiki/events.py
+++ b/jarvis/ultrawiki/events.py
@@ -47,6 +47,7 @@ from typing import Any
from jarvis.ultrawiki.types import content_hash_for
__all__ = [
+ "ENTITY_CREATE_CONFIDENCE",
"EVENT_KIND_VALUES",
"EVENT_VERSION",
"MAX_EVENTS_PER_ITEM",
@@ -144,10 +145,19 @@ MAX_LEGACY_EVENTS = 2
#: Confidence floor/ceiling and the values the two derivation paths assign
#: when the source offers none. The legacy path scores LOW on purpose: it
-#: knows a date and some names, and nothing about what actually happened.
+#: knows a date, and nothing about what actually happened.
DEFAULT_CONFIDENCE = 0.5
LEGACY_CONFIDENCE = 0.35
+#: An event below this confidence may LINK its participants and place to
+#: entities that already exist, but never CREATES one. Creating is the
+#: expensive direction: a new row shows up in the People view, seeds the merge
+#: queue with its near-names, and outlives the guess that produced it — while
+#: linking a name the user already curated costs nothing and is reversible by
+#: re-derivation. So an uncertain event enriches what is known and never
+#: invents anybody.
+ENTITY_CREATE_CONFIDENCE = 0.5
+
# ---------------------------------------------------------------------------
# Absolute time parsing
@@ -856,6 +866,13 @@ def _legacy_events(
recognized without understanding the sentence; guessing a KIND from words
would need a per-language lexicon, and shipping one for two languages is
how a feature quietly stops existing for everyone else.
+
+ **No participants.** The pre-v2 document has no field that means "people
+ who were there". ``entities`` is defined as *mentioned people, places,
+ organizations, projects, systems* — one bag of everything the item names —
+ so reading it as a guest list turns cities, vendors and file formats into
+ people, and the People view fills up with software. An event with a date
+ and no names is worth having; an event with the wrong names is not.
"""
question = _clean(distill.get("question"), MAX_TITLE_CHARS)
summary = _clean(distill.get("summary"), MAX_SUMMARY_CHARS)
@@ -864,7 +881,6 @@ def _legacy_events(
dates = scan_absolute_dates(haystack)
if not dates:
return []
- participants = tuple(_names(distill.get("entities")))
title = question or fallback_title or summary[:MAX_TITLE_CHARS]
return [
DerivedEvent(
@@ -874,7 +890,6 @@ def _legacy_events(
time=EventTime.build(
moment, precision, TimeAnchor.ABSOLUTE, recorded_at=recorded
),
- participants=participants,
confidence=LEGACY_CONFIDENCE,
)
for moment, precision in dates
diff --git a/tests/unit/ultrawiki/test_event_store.py b/tests/unit/ultrawiki/test_event_store.py
index f36f12aa82..07dbf63195 100644
--- a/tests/unit/ultrawiki/test_event_store.py
+++ b/tests/unit/ultrawiki/test_event_store.py
@@ -490,3 +490,79 @@ async def test_a_distillation_payload_lands_as_an_absolute_dated_row(store):
assert stored["occurred_at"] == "2026-03-13T19:30:00Z"
assert stored["recorded_at"] == RECORDED_ISO
assert stored["time_anchor"] == "relative"
+
+
+async def test_a_low_confidence_event_links_but_never_invents_a_person(store):
+ """The People view is a curated surface. An uncertain derivation may
+ enrich what the user already has; it must not add rows to it."""
+ known = await store.resolve_identity(name="Marlow Vance")
+ item_id = await add_item(store)
+ await store.replace_events(
+ item_id,
+ [
+ DerivedEvent(
+ kind=EventKind.OTHER,
+ title="Something happened",
+ summary="",
+ time=EventTime.build(
+ datetime(2026, 3, 13, tzinfo=UTC),
+ TimePrecision.DAY,
+ TimeAnchor.ABSOLUTE,
+ recorded_at=RECORDED,
+ ),
+ participants=("Marlow Vance", "Somebody Unknown"),
+ place="Nowhere Town",
+ confidence=0.35,
+ )
+ ],
+ )
+ stored = (await store.list_events())[0]
+ by_name = {p["display_name"]: p["entity_id"] for p in stored["participants"]}
+ assert by_name["Marlow Vance"] == known.entity_id # linked to the known one
+ assert by_name["Somebody Unknown"] is None # spelling kept, no new row
+ assert stored["place"] == "Nowhere Town"
+ assert stored["place_entity_id"] is None
+ assert [p["display_name"] for p in await store.list_people(kind=None, limit=50)] == [
+ "Marlow Vance"
+ ]
+
+
+async def test_a_confident_event_still_creates_the_people_it_names(store):
+ item_id = await add_item(store)
+ await store.replace_events(item_id, [event(participants=("Nadia Brix",))])
+ stored = (await store.list_events())[0]
+ assert stored["participants"][0]["entity_id"] is not None
+ assert "Nadia Brix" in {
+ person["display_name"]
+ for person in await store.list_people(kind=None, limit=50)
+ }
+
+
+async def test_the_event_leg_reports_both_clocks(store):
+ """``timestamp_utc`` is what the hit is about; ``recorded_utc`` is how old
+ the record is. Ranking may only ever decay by the second one."""
+ item_id = await add_item(store, timestamp_utc="2026-03-14T08:00:00Z")
+ await store.replace_events(item_id, [event()])
+ hits = await store.search_events("Marlow", k=5)
+ assert hits[0].timestamp_utc == "2026-03-13T19:30:00Z"
+ assert hits[0].recorded_utc == "2026-03-14T08:00:00Z"
+
+
+async def test_the_backfill_reader_walks_distilled_items_once(store):
+ """The lane that gives an ALREADY distilled corpus its events without a
+ single model call — it reads the distillation that is already stored."""
+ from jarvis.ultrawiki.types import DocType
+
+ first = await add_item(store, "chat-a")
+ second = await add_item(store, "chat-b")
+ await add_item(store, "chat-c") # no distillation at all
+ await store.add_document(
+ first, DocType.SUMMARY, "text", distill_json='{"summary": "on 2026-02-02"}'
+ )
+ await store.add_document(second, DocType.SUMMARY, "text", distill_json='{"a": 1}')
+
+ rows = await store.items_with_distillation(limit=50)
+ assert [row["id"] for row in rows] == [first, second]
+ assert rows[0]["distill_json"] == '{"summary": "on 2026-02-02"}'
+ assert rows[0]["timestamp_utc"] == RECORDED_ISO
+ assert await store.items_with_distillation(after_id=second, limit=50) == []
diff --git a/tests/unit/ultrawiki/test_events.py b/tests/unit/ultrawiki/test_events.py
index 70e35a8a30..3f5acd8897 100644
--- a/tests/unit/ultrawiki/test_events.py
+++ b/tests/unit/ultrawiki/test_events.py
@@ -361,8 +361,22 @@ def test_a_pre_v2_distillation_still_yields_an_event_when_it_states_a_date():
assert events[0].time.occurred_at == "2026-02-02T00:00:00Z"
assert events[0].time.anchor is TimeAnchor.ABSOLUTE
assert events[0].kind is EventKind.OTHER # no kind can be known without a lexicon
- assert events[0].participants == ("Marlow Vance", "Porto Verde")
- assert events[0].confidence < 0.5 # honest: a date and some names, no story
+ assert events[0].confidence < 0.5 # honest: a date and no story
+
+
+def test_the_legacy_path_never_turns_mentioned_entities_into_participants():
+ """``entities`` is one bag of people, places, organizations AND systems —
+ reading it as a guest list is how a city and a database end up in the
+ People view. A legacy event carries a date and no names."""
+ legacy = {
+ "question": "When did the Porto Verde trip start?",
+ "summary": "The trip began on 2026-02-02 and ran for a week.",
+ "entities": ["Marlow Vance", "Porto Verde", "Postgres", "Acme GmbH"],
+ }
+ events = derive_events(distill=legacy, recorded_at=ANCHOR_ISO)
+ assert len(events) == 1
+ assert events[0].participants == ()
+ assert events[0].place == ""
def test_a_pre_v2_distillation_without_a_date_yields_nothing():