The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: capture peer ACK evidence and trim unused file catalog helpers
Tekniumc86dd71b654e
diff --git a/gateway/hosted_room_attachments.py b/gateway/hosted_room_attachments.pyindex 91346b584e1..9d6ff087618 100644--- a/gateway/hosted_room_attachments.py+++ b/gateway/hosted_room_attachments.py@@ -45,18 +45,7 @@ UNCOMMITTED_TTL_SECONDS = 60 * 60DISBANDED_GRACE_SECONDS = 15 * 60CLASSIC_ATTACHMENT_TTL_SECONDS = 7 * 24 * 60 * 60-DEFAULT_ATTACHMENT_LIST_LIMIT = 8-MAX_ATTACHMENT_LIST_LIMIT = 32-MAX_ATTACHMENT_LIST_QUERY_CHARS = 255-ATTACHMENT_LIST_EVENT_SCAN_LIMIT = 256-MAX_ATTACHMENT_LIST_CURSOR_BYTES = 4 * 1024-MAX_ATTACHMENT_LIST_RESPONSE_BYTES = 128 * 1024_SHA256_RE = re.compile(r"^[0-9a-f]{64}$")-_CURSOR_RESET_MESSAGE = "attachment list cursor is invalid; return to Latest"-_CURSOR_FIELDS = frozenset({- "authority_epoch", "authority_gateway_id", "last_attachment_id", "last_manifest_index", "last_seq",- "producer_member_id", "recipient_member_id", "query_digest", "room_id", "snapshot_seq", "version",-})MAX_ATTACHMENT_NAME_CHARS = 255MAX_ATTACHMENT_MIME_CHARS = 127@@ -1201,11 +1190,6 @@ class HostedRoomAttachmentStore:__all__ = [- "ATTACHMENT_LIST_EVENT_SCAN_LIMIT",- "AttachmentCursorError",- "DEFAULT_ATTACHMENT_LIST_LIMIT",- "MAX_ATTACHMENT_LIST_LIMIT",- "MAX_ATTACHMENT_LIST_RESPONSE_BYTES","AttachmentConflictError","AttachmentData","AttachmentError",@@ -1294,18 +1278,6 @@ def retain_message_attachments()-def _catalog_limit(value: Any) -> int:- if value is None:- return DEFAULT_ATTACHMENT_LIST_LIMIT- if isinstance(value, bool) or not isinstance(value, int):- raise AttachmentError("attachment list limit must be an integer")- if not 1 <= value <= MAX_ATTACHMENT_LIST_LIMIT:- raise AttachmentError(- f"attachment list limit must be between 1 and {MAX_ATTACHMENT_LIST_LIMIT}"- )- return value--def fold_catalog_text(value: str) -> str:if value.isascii():return value.lower()@@ -1313,24 +1285,3 @@ def fold_catalog_text(value: str) -> str:char for char in unicodedata.normalize("NFKD", value).casefold()if not unicodedata.combining(char))---def _catalog_query(value: Any) -> str:- if value is None:- return ""- if not isinstance(value, str):- raise AttachmentError("attachment query must be a string")- if len(value) > MAX_ATTACHMENT_LIST_QUERY_CHARS:- raise AttachmentError("attachment query is too long")- try:- value.encode("utf-8")- except UnicodeError:- raise AttachmentError("attachment query must contain valid Unicode") from None- folded = fold_catalog_text(value.strip())- if len(folded) > MAX_ATTACHMENT_LIST_QUERY_CHARS * 32:- raise AttachmentError("attachment query is too long")- return folded---class AttachmentCursorError(AttachmentError):- """The caller must explicitly restart discovery from Latest."""diff --git a/gateway/hosted_rooms.py b/gateway/hosted_rooms.pyindex 0c239cbc72f..67e5242d6d9 100644--- a/gateway/hosted_rooms.py+++ b/gateway/hosted_rooms.py@@ -784,6 +784,8 @@ def upsert_remote_run_receipt(db_path: DbPath, *, record: Mapping[str, Any], nowtarget_profile, task_id, execution_generation, run_id,session_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", (*immutable, timestamp, timestamp))+ from gateway.hosted_room_work_records import capture_transition_locked+ capture_transition_locked(conn, record["room_id"])def list_remote_run_receipts(diff --git a/tests/gateway/test_room_work_receipt_capture.py b/tests/gateway/test_room_work_receipt_capture.pynew file mode 100644index 00000000000..99e1fff6c3a--- /dev/null+++ b/tests/gateway/test_room_work_receipt_capture.py@@ -0,0 +1,23 @@+"""A real peer receipt insertion immediately updates passive evidence."""+import json+import sqlite3+from contextlib import closing++from gateway import hosted_room_driver as driver, hosted_rooms as rooms+from gateway import hosted_room_work_records as work+++def test_remote_receipt_is_captured_without_another_driver_transition(tmp_path):+ db = tmp_path / 'state.db'+ rooms.create_room(db, room_id='room', name='Room', members=[{'profile':'ops','handle':'ops', 'target': {'kind':'peer','installation_id':'peer','profile':'ops'}}], authority_gateway_id='owner')+ rooms.append_event(db, room_id='room', event_id='input', kind='message.user',+ actor={'kind':'user','id':'alice'}, payload={'text':'hello'}, authority_gateway_id='owner', authority_epoch=1)+ driver.admit_task(db, driver.TaskIdentity('room','task','thread','turn'),+ payload={'target_profile':'ops','prompt':'hello','source_event_seq':1}, clock=lambda: 10)+ record = dict(room_id='room', home_install_id='owner', authority_gateway_id='owner',+ authority_epoch=1, member_id='ops', target_install_id='peer', target_profile='ops',+ task_id='task', execution_generation=1, run_id='run', session_id='session')+ rooms.upsert_remote_run_receipt(db, record=record)+ with closing(sqlite3.connect(db)) as conn:+ evidence = json.loads(conn.execute(f"SELECT record_json FROM {work.SOURCE_TABLE} WHERE disposition='current' ORDER BY revision DESC LIMIT 1").fetchone()[0])+ assert evidence['receipts'] == [record], json.dumps(evidence)diff --git a/tests/tui_gateway/test_hosted_file_publication.py b/tests/tui_gateway/test_hosted_file_publication.pyindex 58f4ebfcb09..038aa0e5639 100644--- a/tests/tui_gateway/test_hosted_file_publication.py+++ b/tests/tui_gateway/test_hosted_file_publication.py@@ -1,5 +1,7 @@"""Service share and raced publication preserve the original durable task."""import time+import sqlite3+from contextlib import closingfrom types import SimpleNamespacefrom gateway import hosted_rooms, hosted_room_driver as driver@@ -27,6 +29,10 @@ def test_service_share_retains_bytes_and_reuses_frozen_task(tmp_path):'text': '@hermes inspect', 'thread_id': 'thread', 'attachments': manifest})before = driver.list_tasks(db, room_id='room')[0]assert before['payload']['attachments'][0]['event_id'] == event['event_id']+ with closing(sqlite3.connect(db)) as conn, conn:+ tables = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'hosted_room_policy_%'").fetchall()+ for (table,) in tables:+ conn.execute(f'DROP TABLE "{table}"')restored = service_at(db)restored.prepare_room(restored.bindings()[0])assert driver.list_tasks(db, room_id='room')[0]['payload'] == before['payload']