diff --git a/docs/architecture/memory-architecture.md b/docs/architecture/memory-architecture.md index 5e39d257de5..840fc442a79 100644 --- a/docs/architecture/memory-architecture.md +++ b/docs/architecture/memory-architecture.md @@ -1329,7 +1329,13 @@ usage fold's counters on `memory` are batched lightweight updates; see Under the ClickHouse authority, every memory version insert holds a Keeper fence per identity key. `memory.lock`, `memory.unlock` and `memory.verify` check that the source row is still the head inside the fence, and answer 503 `ADMISSION_CONTENDED` with -no version written when it moved. `memory.verify` first compares `if_match_sha256`, when +no version written when it moved. `memory.update` and `memory.update_by_id` make the +same check on the head they read, with or without `if_match_sha256`, and under Postgres +their commit makes it: a revision carries every column it does not set from that head, +so over another head it would sit below a later version or overwrite what that head +changed. A refused revision writes no version row and no search document, and its +caller reads the row again to decide whether the edit still applies. +`memory.verify` first compares `if_match_sha256`, when sent, with the hash of the head it read and answers 409 `PRECONDITION_FAILED` on another; the fence covers a head that moves after that comparison. All value inserts take the same fences, including diff --git a/docs/architecture/storage-authority.md b/docs/architecture/storage-authority.md index f733879de85..a55f1f39cb4 100644 --- a/docs/architecture/storage-authority.md +++ b/docs/architecture/storage-authority.md @@ -66,8 +66,9 @@ the key, a write drawn later or one from a replica whose clock is ahead. A judge supersession goes one above the version it read; its vector rows take a version the status mirror draws (`mirror_status_to_embeddings(judged=True)`). Under the ClickHouse authority every memory insert takes per-key Keeper fences. `memory.lock`, -`memory.unlock` and `memory.verify` compare the source rows inside those fences and -answer 503 `ADMISSION_CONTENDED` without inserting when a head has moved. Value writers +`memory.unlock`, `memory.verify`, `memory.update` and `memory.update_by_id` compare the +rows they read inside those fences and answer 503 `ADMISSION_CONTENDED` without +inserting when a head has moved. Value writers take the same fences, so another replica cannot insert between that check and the copy. The comparison includes the served value and persisted metadata: clock skew can make two writers choose the same version. Derived usage fields (`recall_count`, @@ -402,9 +403,11 @@ sequenceDiagram ([admission](#admission-under-concurrency)); - each written key's head is locked and rechecked against the row the write read: never a delete, a pin, a lock, a status or a redaction the write did not see; - with `if_match_sha256` also that very version (compare-and-set), otherwise it may - carry a newer value (two unconditional writes of a key: the newer version wins, - as in ClickHouse); else the write starts over; + with `if_match_sha256`, and for every `memory.update` and `memory.update_by_id`, + also that very version (compare-and-set); any other write may find a newer value + there (two unconditional `memory.set` writes of a key: the newer version wins, as in + ClickHouse); else a `memory.set` starts over and a revision answers 503 + `ADMISSION_CONTENDED`; - the heads are upserted, the revisions and their deliveries inserted, and the idempotency key, if any, marked `committed` with the revisions, under its lease token. diff --git a/server/memory/app/update.py b/server/memory/app/update.py index 53d285052ee..6dd977d6e09 100644 --- a/server/memory/app/update.py +++ b/server/memory/app/update.py @@ -790,24 +790,17 @@ async def _land_revision( searchable: bool, high: bool, record: Callable[[], Awaitable[None]], - exact: bool, op: str, ) -> pg_lease.PublicationPending | None: - """Write the revision, record it (`record`: its audit row and announcement) and fence - a 'high' one. Under Postgres a committed revision whose publication failed returns its - PublicationPending, so the caller's follow-ups still run; any other failure raises. - `exact`: committed only over the very head read (`if_match_sha256`).""" + """Write the revision over `existing`, the head it was built from, record it + (`record`: its audit row and announcement) and fence a 'high' one. A head another + write moved since the read refuses it with nothing written (503 + `ADMISSION_CONTENDED`). Under Postgres a committed revision whose publication failed + returns its PublicationPending, so the caller's follow-ups still run; any other + failure raises.""" if pg.enabled(): return await _land_committed( - existing, - memory_row, - emb_rows, - policy, - ch, - high=high, - record=record, - exact=exact, - op=op, + existing, memory_row, emb_rows, policy, ch, high=high, record=record, op=op ) await _land_inserted( existing, @@ -880,7 +873,6 @@ async def _land_committed( *, high: bool, record: Callable[[], Awaitable[None]], - exact: bool, op: str, ) -> pg_lease.PublicationPending | None: """Under Postgres: a commit refused before it ran raises with nothing in; a committed @@ -892,7 +884,7 @@ def _fence() -> list[tuple[Any, int]]: return [(identity_key(existing), int(memory_row["version"]))] if high else [] async with fenced_once_committed(_fence, op=op, ch=ch) as answer: - committed = await _commit_revision(existing, memory_row, emb_rows, policy, exact=exact) + committed = await _commit_revision(existing, memory_row, emb_rows, policy) answer.mark_committed() try: return await _publish_revision(committed, emb_rows, ch) @@ -912,10 +904,18 @@ async def _insert_revision( ) -> list[Any]: """On ClickHouse: the version row, its search document and, for a row no longer searchable (`retire_vectors`), its vectors retired at its version: each one's - outcome. A refused memory insert publishes no search document.""" + outcome. The version row goes in only over `existing`, the head it was built from: + every column it does not set is that head's, so over another head it would bury a + write or sit below one. A refused memory insert publishes no search document.""" import server.memory.store as memory_repo - await insert_memory_versions([memory_row], ch=ch, on_send=on_send, on_inserted=on_inserted) + await insert_memory_versions( + [memory_row], + ch=ch, + expected_heads={identity_key(memory_row): existing}, + on_send=on_send, + on_inserted=on_inserted, + ) writes: list[Awaitable[Any]] = [] if emb_rows: writes.append(memory_repo.insert_embedding_rows(emb_rows, ch=ch)) @@ -930,10 +930,9 @@ async def _commit_revision( memory_row: dict[str, Any], emb_rows: list[dict[str, Any]], policy: dict[tuple[str, str], int] | None, - *, - exact: bool, ) -> pg_memory.Committed: - """Under Postgres: the version row committed over the head the write read and the + """Under Postgres: the version row committed over the very head the write read + (`heads_unchanged(exact=True)`, as `_insert_revision` checks it on ClickHouse) and the policy its guard ran at, owing its document (the commit decides the old vectors' retirement from the head it replaces). Nothing reaches ClickHouse unless it commits.""" from server.memory.app import pg_admission @@ -946,9 +945,7 @@ async def _commit_revision( targets=pg_memory.MEMORY_ROW | pg_memory.AUDIT_ROW | owed, admission=pg_memory.Admission( generations=dict(policy or {}), - recheck=pg_memory.heads_unchanged( - {identity_key(memory_row): existing}, exact=exact - ), + recheck=pg_memory.heads_unchanged({identity_key(memory_row): existing}, exact=True), ), ) except (pg_memory.AdmissionMoved, pg_memory.HeadMoved): @@ -1123,7 +1120,6 @@ async def _write_revision( conflict_result=conflict_result, duplicate_of_id=duplicate_of_id, ), - exact=bool(input.if_match_sha256), op=op, ) follows: list[Follow] = [] diff --git a/tests/integration/test_memory_metadata_contention.py b/tests/integration/test_memory_metadata_contention.py index ae9d7981b06..e4c6fd59a8e 100644 --- a/tests/integration/test_memory_metadata_contention.py +++ b/tests/integration/test_memory_metadata_contention.py @@ -125,3 +125,85 @@ async def captured_head(*args, **kw): await asyncio.gather(task, return_exceptions=True) await first.disconnect() await second.disconnect() + + +# One update and one verify a round: eight racing calls, inside both ops' rate buckets. +ROUNDS = 4 + + +@pytest.mark.asyncio +async def test_update_racing_a_verify_is_the_head_or_is_refused( + control_plane_url, mint_test_token, ch_client +): + """Each round sends memory.update_by_id and memory.verify for one key together, over + HTTP. Fails when an acknowledged write is not in the key's head: an update that + answered 200 under a verify's copy of the old value, or a verify that answered 200 + under an update built from the head before it. A refused update leaves no version + row and no search document.""" + if pg.enabled(): + pytest.skip("exercises the ClickHouse authority") + import httpx + + org, actor = unique_org("update-race"), "process:test-suite" + key = {"namespace": "notes", "agent": "writer", "memory_key": "deploy_window"} + token = mint_test_token(org=org, namespaces=[key["namespace"]]) + landed: list[str] = [] + refused: list[str] = [] + async with httpx.AsyncClient( + base_url=control_plane_url, timeout=60.0, headers={"Authorization": f"Bearer {token}"} + ) as http: + + async def call(op: str, **body): + return await http.post(f"/v1/{op}", json={"org": org, **body}) + + async def update(value: str): + return await call("memory.update_by_id", memory_id=memory_id, value=value) + + created = await call("memory.set", **key, memory_type="semantic", value=uuid4().hex) + assert created.status_code == 200, created.text + memory_id = created.json()["memory_id"] + head = (await call("memory.get", **key)).json() + for _ in range(ROUNDS): + # The opposite of what the head holds, so each verify has a row to write. + revoke = head["verification"] != "none" + value = uuid4().hex + updated, verified = await asyncio.gather( + update(value), call("memory.verify", memory_id=memory_id, revoke=revoke) + ) + head = (await call("memory.get", **key)).json() + if updated.status_code == 200: + assert updated.json()["updated"] and head["value"] == value, (updated.text, head) + landed.append(value) + else: + assert updated.status_code == 503, updated.text + assert updated.json()["detail"]["code"] == "ADMISSION_CONTENDED", updated.text + assert head["value"] != value + refused.append(value) + if verified.status_code == 200: + assert verified.json()["changed"], verified.text + assert head["verified_by"] == ("" if revoke else actor), (verified.text, head) + else: + assert verified.status_code == 503, verified.text + assert verified.json()["detail"]["code"] == "ADMISSION_CONTENDED", verified.text + # One of the two reached the key's fence over the head both read. + assert 200 in (updated.status_code, verified.status_code) + # A write that lands shows both tables hold what an update writes. + sentinel = uuid4().hex + last = await update(sentinel) + assert last.status_code == 200 and last.json()["updated"], last.text + stored = {"select_sequential_consistency": 1} + versions = ch_client.query( + "SELECT value FROM loom.memory_versions WHERE org = {org:String}", + parameters={"org": org}, + settings=stored, + ).result_rows + documents = ch_client.query( + "SELECT content_excerpt FROM loom.memory_embeddings WHERE org = {org:String}", + parameters={"org": org}, + settings=stored, + ).result_rows + written = " ".join(str(value) for (value,) in versions) + searchable = " ".join(str(excerpt) for (excerpt,) in documents) + assert sentinel in written and sentinel in searchable + assert all(value in written for value in landed) + assert not [value for value in refused if value in written or value in searchable] diff --git a/tests/integration/test_vector_retire_race.py b/tests/integration/test_vector_retire_race.py index 291594413cd..134142854ad 100644 --- a/tests/integration/test_vector_retire_race.py +++ b/tests/integration/test_vector_retire_race.py @@ -449,7 +449,8 @@ def __getattr__(self, name: str) -> Any: ("memory.update", True, "write"), ("bulk_set", False, "write"), # the key has a memory row but no vector on the served model (written - # before a model change, say): only the sweep's fence covers it + # before a model change, say) and the sweep labels it 'high': the older + # update is refused over the relabelled head, so it writes no vector ("memory.update", False, "sensitivity_sweep"), ], ) @@ -459,7 +460,8 @@ async def test_an_older_writes_late_vector_stays_under_a_newer_high_write( """An older plain write draws its version, then pauses in its embed call; a newer write labelled 'high' commits; the older one resumes. Its vector carries its own memory version, below the high write's fence, so search stays empty, with or - without a vector for the key before.""" + without a vector for the key before. An older `memory.update` is refused instead: + it writes only over the head it read, which the high write replaced.""" import httpx from server.auth.jwt import mint_token @@ -467,6 +469,7 @@ async def test_an_older_writes_late_vector_stays_under_a_newer_high_write( from server.memory.api.models_bulk import MemoryBulkSetInput, _BulkSetEntry from server.memory.api.models_crud import MemorySetInput, MemoryUpdateInput from server.memory.app import bulk_set, update, write + from server.memory.store.pg_memory import AdmissionContendedError ns = f"itest-{uuid.uuid4().hex[:12]}" key = f"late_vector_{uuid.uuid4().hex[:6]}" @@ -533,7 +536,11 @@ def newer_high_write() -> Any: await newer_high_write() assert await live_vectors() == 0 paused.gate.set() - await asyncio.wait_for(task, 30) + if older == "memory.update": + with pytest.raises(AdmissionContendedError): + await asyncio.wait_for(task, 30) + else: + await asyncio.wait_for(task, 30) row = await ch.query_one( "SELECT sensitivity FROM loom.memory FINAL WHERE org = {o:String}" diff --git a/tests/unit/test_memory_expiry.py b/tests/unit/test_memory_expiry.py index 3e78d92709b..9ce0a1a0109 100644 --- a/tests/unit/test_memory_expiry.py +++ b/tests/unit/test_memory_expiry.py @@ -218,8 +218,9 @@ def __init__(self) -> None: async def insert(self, table: str, rows: list[dict[str, Any]], **_: Any) -> None: self.inserts.append((table, rows)) - async def query_all(self, *_: Any, **__: Any) -> list[dict[str, Any]]: - return [] + async def query_all(self, sql: str, *_: Any, **__: Any) -> list[dict[str, Any]]: + # The revision goes in over the head it read: the key's head is that row. + return [row.model_dump()] if "PREWHERE (org, namespace" in sql else [] async def execute(self, *_: Any, **__: Any) -> None: return None diff --git a/tests/unit/test_memory_fence_publication.py b/tests/unit/test_memory_fence_publication.py index 6709447c5e9..0c266cd5489 100644 --- a/tests/unit/test_memory_fence_publication.py +++ b/tests/unit/test_memory_fence_publication.py @@ -135,7 +135,7 @@ class LostAnswer: async def query_all(self, *args, **kwargs): if "FROM loom.memory_refusals" in args[0]: return [] - return [] + return [source.model_dump()] # the head the revision was built from async def insert(self, *args, **kw): raise TimeoutError("the memory insert may have committed") diff --git a/tests/unit/test_memory_metadata_contention.py b/tests/unit/test_memory_metadata_contention.py index 4f53d5e5f79..f401a1a39dc 100644 --- a/tests/unit/test_memory_metadata_contention.py +++ b/tests/unit/test_memory_metadata_contention.py @@ -407,3 +407,226 @@ async def pause(delay): assert attempts == count * (2 if stage == "retry" and admitted else 1) expected_releases = count if stage == "take" else count - 1 + (count if admitted else 0) assert release.await_count == expected_releases + + +class Sent(Replica): + """A client of the shared table that records each statement it sends and whether a + memory-insert fence was held when it went.""" + + def __init__(self, table: list[dict[str, Any]], keeper: Any) -> None: + super().__init__(table) + self.keeper = keeper + self.sent: list[tuple[str, bool]] = [] + + async def insert(self, table: str, batch: list[dict[str, Any]], **kw: Any) -> None: + self.sent.append((f"insert {table}", bool(self.keeper.keys))) + await super().insert(table, batch, **kw) + + async def query_all(self, sql: str, params: Any = None) -> list[dict[str, Any]]: + kind = "refusals" if "FROM loom.memory_refusals" in sql else "head" + self.sent.append((kind, bool(self.keeper.keys))) + return await super().query_all(sql, params) + + def fenced(self) -> list[str]: + """What went under a fence, the refusal checks every memory insert makes aside.""" + return [kind for kind, held in self.sent if held and kind != "refusals"] + + +class Revising: + """memory.update_by_id and memory.verify on one key, each on its own client, under + either authority. `between_read_and_insert` runs inside the update, after it read the + head and drew its version and before its insert; `after_verify_read` inside the + verify, after it read the head.""" + + def __init__(self, source: Any, keeper: Any, authority: str) -> None: + self.source = source + self.authority = authority + self.table = [self.stored(memory_repo.build_memory_version_row(source))] + self.updater, self.verifier = Sent(self.table, keeper), Sent(self.table, keeper) + self.documents: list[dict[str, Any]] = [] + self.rechecks = 0 + self.between_read_and_insert: Any = None + self.after_verify_read: Any = None + + def stored(self, row: dict[str, Any]) -> dict[str, Any]: + """The row as its authority holds it: Postgres keeps it encoded and sparse.""" + from server.memory.store import pg_memory + + if self.authority != "postgres": + return row + return pg_memory.decode_row(pg_memory.sparse_row(pg_memory.encode_row(row))) + + @property + def head(self) -> dict[str, Any]: + return Replica(self.table).head + + def read(self) -> Any: + from server.memory.store.reads import _hydrate + + return _hydrate(self.head) + + async def commit(self, batch: Any, *, admission: Any = None, **kw: Any) -> Any: + """The Postgres commit as `pg_memory.commit_versions` makes it: each written key's + head is rechecked under its row lock, then the rows are stored.""" + from server.memory.store import pg_memory + + for row in batch: + self.rechecks += 1 + admission.recheck(rows.identity_key(row), self.head) + stored = [self.stored(dict(row)) for row in batch] + self.table.extend(stored) + return pg_memory.Committed(rows=stored, audits=[], seqs=[], targets=[], deadline=1e12) + + async def publish(self, committed: Any, *, documents: Any = (), **kw: Any) -> None: + self.documents.extend(documents) + + def update(self, value: str) -> Any: + from server.memory.api.models_crud import MemoryUpdateByIdInput + from server.memory.app import update + + return update.handle_memory_update_by_id( + MemoryUpdateByIdInput(org=self.source.org, memory_id=self.source.memory_id, value=value) + ) + + def verify(self) -> Any: + return verify.handle_memory_verify( + MemoryVerifyInput( + org=self.source.org, memory_id=self.source.memory_id, actor="human:reviewer" + ) + ) + + +@pytest.fixture(params=["clickhouse", "postgres"]) +def revising( + request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch, memory_insert_keeper: Any +) -> Revising: + import itertools + + from server.memory.app import conflicts, key_supersession, update + from server.memory.domain.conflicts import ConflictResult, WriteConfig + + race = Revising(_row(), memory_insert_keeper, request.param) + versions = itertools.count(300) + monkeypatch.setattr(rows, "next_version", lambda: next(versions)) + monkeypatch.setattr(verify, "_schedule_mirror", lambda *args, **kw: None) + monkeypatch.setattr(update, "get_client", lambda: race.updater) + monkeypatch.setattr(verify, "get_client", lambda: race.verifier) + + async def holders(org: str, memory_id: str, *, strong: bool) -> list[str]: + return [race.source.namespace] + + async def reach(*args: Any, **kw: Any) -> bool: + return True + + async def update_read(memory_id: str, **kw: Any) -> Any: + assert kw["strong"] # the head feeds a write + return race.read() + + async def verify_read(input: Any) -> Any: + head = race.read() + if race.after_verify_read is not None: + await race.after_verify_read() + return head + + async def guard(**kw: Any) -> None: + # The blacklist guard is the update's first await after it drew its version. + if race.between_read_and_insert is not None: + await race.between_read_and_insert() + + async def clear(**kw: Any) -> ConflictResult: + return ConflictResult(verdict="clear", peers=[]) + + async def documents(batch: list[dict[str, Any]], **kw: Any) -> None: + race.documents.extend(batch) + + async def nothing(*args: Any, **kw: Any) -> None: + return None + + async def no_config(*args: Any, **kw: Any) -> WriteConfig: + return WriteConfig() + + monkeypatch.setattr(memory_repo, "namespaces_of_id", holders) + monkeypatch.setattr("server.auth.authz.row_reach", reach) + monkeypatch.setattr(memory_repo, "get_by_id", update_read) + monkeypatch.setattr(verify, "_resolve_row", verify_read) + monkeypatch.setattr("server.memory.app.blacklist_guard.enforce_on_insert", guard) + monkeypatch.setattr(conflicts, "prefetch_write_config", no_config) + monkeypatch.setattr(conflicts, "check_on_commit", clear) + monkeypatch.setattr(memory_repo, "insert_embedding_rows", documents) + # What follows a landed revision is other tests' subject. + monkeypatch.setattr(update, "same_key_mark", nothing) + monkeypatch.setattr(update, "_record_revision", nothing) + monkeypatch.setattr(key_supersession, "supersede_same_key_rows", nothing) + monkeypatch.setattr(update, "project_revised_edges", nothing) + monkeypatch.setattr(update, "project_stated_relations", nothing) + if race.authority == "postgres": + from server.memory.store import pg_memory, pg_publish + from server.settings import settings + + async def generations(org: str) -> dict[tuple[str, str], int]: + return {} + + monkeypatch.setattr(settings, "storage_authority", "postgres") + monkeypatch.setattr(pg_memory, "policy_generations", generations) + monkeypatch.setattr(pg_publish, "commit", race.commit) + monkeypatch.setattr(pg_publish, "publish", race.publish) + return race + + +@pytest.mark.asyncio +async def test_update_is_refused_when_a_verify_lands_between_its_read_and_its_insert( + revising: Revising, +) -> None: + """Fails when the update writes without comparing the head it read with the key's + head: the verify read the old head and drew a later version, so the update answers + 200 and its row sits below a head that holds the old value.""" + revising.between_read_and_insert = revising.verify + with pytest.raises(AdmissionContendedError): + await revising.update("Mon and Wed only.") + attested = revising.head + # The verify's row landed, so the table shows a write; the update left none. + assert len(revising.table) == 2 and attested["verified_by"] == "human:reviewer" + assert attested["value"] == revising.table[0]["value"] + assert revising.documents == [] + assert "insert loom.memory" not in revising.updater.fenced() + assert not revising.updater.keeper.keys + + +@pytest.mark.asyncio +async def test_verify_is_refused_when_an_update_lands_between_its_read_and_its_insert( + revising: Revising, +) -> None: + """The other order of the same race. Fails when the verify's exact check lets its + copy of the old head in over the update: the attestation would restore the value + the update replaced.""" + + async def update() -> None: + assert (await revising.update("Mon and Wed only.")).updated + + revising.after_verify_read = update + with pytest.raises(AdmissionContendedError): + await revising.verify() + revised = revising.head + assert len(revising.table) == 2 + assert revised["value"] == '"Mon and Wed only."' and revised["verified_by"] == "" + assert [d["version"] for d in revising.documents] == [revised["version"]] + assert not revising.verifier.keeper.keys + + +@pytest.mark.asyncio +async def test_update_of_an_idle_key_compares_the_head_once_and_lands(revising: Revising) -> None: + """Fails when the head comparison refuses a head nobody wrote to, or costs a round + trip of its own: on ClickHouse the update sends, under the key's fence, the head read + every memory insert already makes and its insert; under Postgres its commit rechecks + the head once.""" + out = await revising.update("Mon and Wed only.") + revised = revising.head + assert out.updated and out.new_version == revised["version"] == 300 + assert len(revising.table) == 2 and revised["value"] == '"Mon and Wed only."' + assert [d["version"] for d in revising.documents] == [300] + if revising.authority == "postgres": + assert revising.rechecks == 1 and revising.updater.sent == [] + else: + assert revising.updater.fenced() == ["head", "insert loom.memory"] + assert [kind for kind, _held in revising.updater.sent].count("head") == 1 + assert not revising.updater.keeper.keys diff --git a/tests/unit/test_memory_update_by_key.py b/tests/unit/test_memory_update_by_key.py index 827fb716d5d..1c2f078b0d1 100644 --- a/tests/unit/test_memory_update_by_key.py +++ b/tests/unit/test_memory_update_by_key.py @@ -574,7 +574,7 @@ async def test_a_conditional_revision_audits_the_head_it_wrote_from( from server.memory.api.models_crud import MemoryUpdateByIdInput stale, head = _row(source_class="observed"), _row(source_class="derived") - ch = audited([], stale) + ch = audited([], head) # the store holds the head the re-read returns reads = iter([stale, head]) async def _get_by_id(memory_id: str, **_: Any) -> MemoryRow: diff --git a/tests/unit/test_memory_write_path_mirror.py b/tests/unit/test_memory_write_path_mirror.py index f5fceadcd73..859cb4329ce 100644 --- a/tests/unit/test_memory_write_path_mirror.py +++ b/tests/unit/test_memory_write_path_mirror.py @@ -426,6 +426,11 @@ async def _get_by_id(*_: Any, **__: Any) -> MemoryRow: return existing or _mk_row() monkeypatch.setattr("server.memory.store.get_by_id", _get_by_id) + if existing is not None: + from server.memory.store.rows import identity_key + + # The revision goes in over the head it read: the key's head is that row. + ch.memory_heads = {identity_key(existing): existing.model_dump()} async def _namespaces_of_id(*_: Any, **__: Any) -> list[str]: return [(existing or _mk_row()).namespace] diff --git a/tests/unit/test_pg_authority.py b/tests/unit/test_pg_authority.py index 187383ffc87..da3fbdbdb89 100644 --- a/tests/unit/test_pg_authority.py +++ b/tests/unit/test_pg_authority.py @@ -2533,7 +2533,6 @@ async def _never() -> None: searchable=True, high=True, record=_never, - exact=False, op="memory.update", ) assert bool(fences) is fenced @@ -2574,7 +2573,6 @@ async def _never() -> None: searchable=True, high=True, record=_never, - exact=False, op="memory.update", ) # it may never have committed: the drop says the outcome is unknown @@ -2618,7 +2616,6 @@ async def _fence(keys: Any, *, ch: Any) -> None: searchable=True, high=True, record=_record, - exact=False, op="memory.update", ) ) @@ -2674,7 +2671,6 @@ async def _fence(*_a: Any, **_k: Any) -> None: searchable=True, high=high, record=_record, - exact=False, op="memory.update_by_id", ) assert answer is pending and recorded == ["recorded"] @@ -2693,7 +2689,7 @@ async def _commit(*_: Any, **__: Any) -> Any: monkeypatch.setattr(pg_publish, "commit", _commit) with pytest.raises(pg_memory.AdmissionContendedError): - await update._commit_revision(SimpleNamespace(), _row("k"), [], None, exact=False) + await update._commit_revision(SimpleNamespace(), _row("k"), [], None) async def test_a_revision_is_published_with_its_document_and_a_pending_one_returned( @@ -5068,7 +5064,7 @@ async def _commit(rows: Any, *, targets: int, **kw: object) -> Any: row |= {"user_id": "-", "session_id": "-"} existing = SimpleNamespace(memory_type="semantic", sensitivity="") args = (existing, row, [], None, None) - kw = {"searchable": False, "high": False, "record": _ok, "exact": False, "op": "memory.update"} + kw = {"searchable": False, "high": False, "record": _ok, "op": "memory.update"} if authority == "postgres": pending = await update._land_revision(*args, **kw) assert isinstance(pending, pg_lease.PublicationPending)