Name the subject a conflict is actually about

A shared verb is not a shared fact. 「客厅的恒温器调到 22 度」 and
「卧室的恒温器调到 24 度」 agree with each other; the store had been
recording them as one thermostat moving, and the older side then left the
answer page — asking about the living room returned the bedroom's reading
as the only evidence. A conflict now requires the two memories to lead
with the same subject, and the subject is the first content word rather
than the first word, so 「The router forwards 220 packets」 still leads
with its router behind the article.

The rule trades one error for another, and both directions are measured
and pinned: a qualifier on the subject reads as a different thing, and
the first number under a label is the value that gets compared. Neither
hides a memory — each leaves a disagreement unrecorded for a person to
supersede by hand.

Six review findings, all measured before being changed:
- the archive rule string hid that an unset importance archives too
- a never-archived id reported {"restored": 1} while nothing moved
- the suppression condition (both sides in the page) was undocumented
- a determinism claim had no reproducible path, two latency numbers were
  never committed, and one cited test name did not exist

Gates: 374 passed, six acceptance files 73 passed, ruff clean, mypy cold
cache 24 errors in 9 files (the recorded 9cb46c1 baseline, net 0),
pyright 0 on the touched files, go build/vet/test + gofmt clean, npm
bundle unchanged, product audit clean, MCP smoke passing across processes.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 09:49:25 -04:00
1 parent deabbf76b8
commit 3daface332
7 files changed
+185 -26

No files matched your search

+13 -2
View File
@@ -163,7 +163,12 @@ def open_conflicts(database: Database, holder_id: str | None = None) -> list[Con
def losing_sides(database: Database, atom_ids: list[str]) -> dict[str, str]:
"""Among these atoms, which lost to a newer one in a conflict nobody resolved."""
"""Among these atoms, which lost to a newer one in a conflict nobody resolved.
Both sides have to be in the list. A conflict is a claim about a pair, so an unresolved pair
that arrives whole is settled by dropping the older side; if only the older side turned up, the
store has not seen the replacement in this answer and says nothing about it.
"""
if not atom_ids:
return {}
payload = to_json(atom_ids)
@@ -211,11 +216,17 @@ def archive_atoms(database: Database, atom_ids: list[str], at: datetime) -> int:
def restore_atoms(database: Database, atom_ids: list[str]) -> int:
"""Bring archived memories back, counting only the rows that were actually archived.
An id that was never archived changed nothing, so it is not counted: a report that says
「restored 1」 has to mean one memory came back.
"""
if not atom_ids:
return 0
with database.connect() as connection:
cursor = connection.execute(
"UPDATE atoms SET archived_at = NULL WHERE atom_id IN (SELECT value FROM json_each(?))",
"UPDATE atoms SET archived_at = NULL"
" WHERE archived_at IS NOT NULL AND atom_id IN (SELECT value FROM json_each(?))",
(to_json(atom_ids),),
)
return int(cursor.rowcount)
+9 -9
View File
@@ -137,18 +137,18 @@ class MemoryService:
"""A number that moves inside one holder's scenario is a disagreement, not a second fact.
Only a memory that replaces nothing can start a conflict: a supersede has already
picked a side, and recording it as unresolved would contradict that.
picked a side, and recording it as unresolved would contradict that. And only a memory that
leads with the same subject as its neighbour: two rooms' thermostats are two facts.
"""
if atom.supersedes:
return
stated = trust.numeric_values(atom.text)
if not stated:
if not trust.numeric_values(atom.text).values:
return
for earlier in lifecycle_store.lane_atoms(self.db, atom.holder_id, atom.scenario):
if earlier.atom_id == atom.atom_id:
continue
term = trust.conflicting_number(trust.numeric_values(earlier.text), stated)
if term is None:
clash = trust.quantity_conflict(earlier.text, atom.text)
if clash is None:
continue
lifecycle_store.record_conflict(
self.db,
@@ -156,9 +156,9 @@ class MemoryService:
newer_atom_id=atom.atom_id,
holder_id=atom.holder_id,
scenario=atom.scenario,
terms=[term],
older_value=trust.numeric_values(earlier.text)[term],
newer_value=stated[term],
terms=[clash.term],
older_value=clash.older_value,
newer_value=clash.newer_value,
detected_at=utc_now(),
)
@@ -360,7 +360,7 @@ class MemoryService:
moved = 0 if dry_run else lifecycle_store.archive_atoms(self.db, candidates, moment)
if not dry_run and moved != len(candidates):
raise ValueError(f"{len(candidates)} memories were chosen for the archive but {moved} were moved")
floor = "any importance" if max_importance is None else f"importance at or under {max_importance}"
floor = "any importance" if max_importance is None else f"importance unset or at or under {max_importance}"
return ArchiveReport(
atom_ids=candidates,
archived_at=moment,
+4 -1
View File
@@ -185,7 +185,10 @@ class RetrievalService:
Both memories stay in the store and this only filters the page; the conflict row names
which side was dropped and why. Settling is the holder's call, and until it happens the
newer statement is what a reader should be shown.
newer statement is what a reader should be shown. Only a pair seen whole is settled: the
page is ranked from a window wider than itself, so both sides normally arrive together,
and an answer that never recalled the newer memory leaves the older value standing —
stale, but not silently contradicted by nothing.
"""
losers = lifecycle_store.losing_sides(self.db, [hit.atom.atom_id for hit in hits])
if not losers:
+62 -8
View File
@@ -10,6 +10,7 @@ from __future__ import annotations
import re
from collections.abc import Iterable
from dataclasses import dataclass
from typing import TYPE_CHECKING
from unicodedata import normalize
@@ -195,7 +196,28 @@ def _spread(pairs: list[str]) -> list[str]:
return [pairs[0], pairs[len(pairs) // 2], pairs[-1]]
def numeric_values(text: str) -> dict[str, str]:
@dataclass(frozen=True)
class StatedNumbers:
"""What a memory leads with, and every number it states keyed by the label it hangs on.
The subject is kept apart from the other labels because a shared label alone does not make two
memories disagree about one thing: see ``quantity_conflict``.
"""
subject: str
values: dict[str, str]
@dataclass(frozen=True)
class QuantityConflict:
"""One quantity two memories state differently, named by its label and both values."""
term: str
older_value: str
newer_value: str
def numeric_values(text: str) -> StatedNumbers:
"""Every number a memory states, keyed by what it measures, so a moving value can be named.
A number is attributed twice: to the subject the memory leads with, and to the content word
@@ -206,8 +228,14 @@ def numeric_values(text: str) -> dict[str, str]:
try:
tokens = fts_terms(text)
except ValueError:
return {}
subject = _label(tokens[0], first=True) if tokens else ""
return StatedNumbers(subject="", values={})
subject = ""
for token in tokens:
# An English memory usually opens with an article, and a subject behind one is still the
# subject: 「The router forwards 220 packets」 leads with its router, not with 「the」.
subject = _label(token, first=True)
if subject:
break
values: dict[str, str] = {}
beside = ""
for token in tokens:
@@ -220,11 +248,36 @@ def numeric_values(text: str) -> dict[str, str]:
values.setdefault(subject, value)
if beside:
values.setdefault(beside, value)
return values
return StatedNumbers(subject=subject, values=values)
def quantity_conflict(older_text: str, newer_text: str) -> QuantityConflict | None:
"""The quantity two memories state differently, but only while they lead with the same subject.
A shared predicate is not enough. 「客厅的恒温器调到 22 度」 and 「卧室的恒温器调到 24 度」
share 「调到」 and disagree about nothing: they are two thermostats, each steady at its own
number. Requiring the same leading subject lets each keep its own reading and still catches one
thermostat moving. What that does not buy: two memories that lead with the same subject and
measure different things — 「恒温器设定 22 度」 and 「恒温器功率 100 瓦」 — still read as one
moving quantity, because the store compares labels, not meanings.
"""
older = numeric_values(older_text)
newer = numeric_values(newer_text)
if not older.subject or older.subject != newer.subject:
return None
subject = older.subject
if subject in newer.values and _as_float(older.values[subject]) != _as_float(newer.values[subject]):
# The subject carries the value here, so it is named rather than whichever shared label
# sorts first: 「router」 is what the pair disagrees about, not the verb beside it.
return QuantityConflict(term=subject, older_value=older.values[subject], newer_value=newer.values[subject])
term = conflicting_number(older.values, newer.values)
if term is None:
return None
return QuantityConflict(term=term, older_value=older.values[term], newer_value=newer.values[term])
def conflicting_number(older: dict[str, str], newer: dict[str, str]) -> str | None:
"""The one quantity both memories state a different value for, or None if they do not disagree.
"""The one label both sides state a different value for, or None if they do not disagree.
Only a shared label counts: two memories that each mention a number are not in conflict until
they name the same thing. The label is reported, not the verdict — which side is current is a
@@ -244,9 +297,10 @@ def _as_float(value: str) -> float:
def _label(token: str, *, first: bool = False) -> str:
"""The content word a number hangs on: a CJK run's two-character tail, or a plain Latin word.
The subject of a memory is read from the head of its first run instead, because two memories
about the same thing usually phrase the rest differently: 「恒温器放在书房,设定 22 度」 and
「恒温器调到 24 度」 share only their subject, and that is the label which makes them disagree.
The subject of a memory is read from the head of its first content run instead, because two
memories about the same thing usually phrase the rest differently: 「恒温器放在书房,设定 22 度」
and 「恒温器调到 24 度」 share only their subject, and that is the label which makes them
disagree.
"""
letters = "".join(char for char in token if is_cjk(char))
if letters: