From c4a5951c09a2da79b8b336ac377188a614166c99 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sat, 21 Nov 2026 18:41:26 +0000 Subject: [PATCH] Analysis erasure setup waits for its revision publication A Postgres first write answers at commit. Its ClickHouse row can be visible before publication is acknowledged, leaving erasure to wait for an active publisher beyond the fixture request deadline. Wait for the exact setup revision delivery to disappear before erasure, preserving the deadline and all assertions. Signed-off-by: zlareb1 --- tests/integration/test_analysis_isolation.py | 48 +++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_analysis_isolation.py b/tests/integration/test_analysis_isolation.py index 9f825b871e..d1c5076d42 100644 --- a/tests/integration/test_analysis_isolation.py +++ b/tests/integration/test_analysis_isolation.py @@ -13,6 +13,7 @@ from __future__ import annotations +import asyncio import os import time import uuid @@ -23,7 +24,7 @@ import pytest from server.insights.domain import analysis as boundary -from tests.integration._eventually import wait_until +from tests.integration._eventually import eventually, wait_until from tests.integration._resources import ch_client_from_env, unique_org _REFUSED = {403, 422} @@ -407,6 +408,43 @@ def test_a_revoked_token_stops_new_calls(control_plane_url: str, seed: _Seed) -> ) +async def _wait_for_erasure_setup_publication( + seed: _Seed, user: str, key: str, memory_id: uuid.UUID, version: int +) -> None: + import asyncpg + + conn = await asyncpg.connect(os.environ["LOOM_PG_DSN"], timeout=5, command_timeout=5) + try: + + async def acknowledged() -> bool: + return ( + await conn.fetchval( + "SELECT NOT EXISTS (SELECT 1 FROM loom.memory_deliveries d " + "WHERE (d.org, d.namespace, d.seq) = (r.org, r.namespace, r.seq)) " + "FROM loom.memory_current c JOIN loom.memory_revisions r " + "ON (r.org, r.namespace, r.seq) = (c.org, c.namespace, c.seq) " + "WHERE c.org=$1 AND c.namespace=$2 AND c.agent=$3 AND c.user_id=$4 " + "AND c.session_id=$5 AND c.memory_key=$6 AND c.memory_id=$7 " + "AND c.version=$8 AND r.memory_id=$7 AND r.version=$8", + seed.org_a, + seed.ns_a, + "canary", + user, + "-", + key, + memory_id, + version, + ) + ) is True + + await eventually( + acknowledged, + description="the erased user's exact revision to finish publication", + ) + finally: + await conn.close(timeout=5) + + def test_an_erased_user_is_gone_from_the_next_statement( control_plane_url: str, seed: _Seed ) -> None: @@ -433,6 +471,14 @@ def test_an_erased_user_is_gone_from_the_next_statement( max_wait=30, description="the erased user's memory to be readable before the erasure", ) + if os.environ.get("LOOM_STORAGE_AUTHORITY") == "postgres": + # Row visibility precedes acknowledgement of every publication target. + written = r.json() + asyncio.run( + _wait_for_erasure_setup_publication( + seed, user, key, uuid.UUID(written["memory_id"]), int(written["version"]) + ) + ) r = _call( control_plane_url, _platform_admin(seed.org_a, seed.nonce),