The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): exclude observations from accepted-turn ownership
Tekniumf120ea714995
diff --git a/evals/gateway_failure_ownership/README.md b/evals/gateway_failure_ownership/README.mdindex aa01ab339fb..c910e80f61a 100644--- a/evals/gateway_failure_ownership/README.md+++ b/evals/gateway_failure_ownership/README.md@@ -51,7 +51,9 @@ separate identical pre-agent inputs, and a healthy follow-up.Two invariant tests are retained. The second uses real SQLite compaction archivesand durable compression lineage with keyed/keyless input. It proves both parentand successor-only ownership; disabling successor lookup makes it RED (3 rows-instead of 2). It does not run provider-driven compaction. Independent review+instead of 2). A new ambient observed row must not masquerade as the accepted+input; that negative control was also RED/GREEN verified. It does not run+provider-driven compaction. Independent reviewidentified baseline-read, content-projection, archive, and successor-only edgecases; ownership now avoids content comparison and includes durable lineage.diff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex 707e2e93861..a0fc7ca6d8e 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -1758,7 +1758,7 @@ class GatewayTurnMixin:if prepared.message_text is not None and session_entry is not None:_rows = await self.async_session_store.load_transcript(prepared.persistence_session_id, raw=True)_owned = any(- row.get("role") == "user" and (+ row.get("role") == "user" and not row.get("observed") and (row.get("platform_message_id") == str(event.message_id) if event.message_idelse row["id"] not in prepared.persisted_user_row_ids) for row in _rowsdiff --git a/tests/gateway/test_failure_writer_ownership.py b/tests/gateway/test_failure_writer_ownership.pyindex cdcc9745580..eff0ad7aca8 100644--- a/tests/gateway/test_failure_writer_ownership.py+++ b/tests/gateway/test_failure_writer_ownership.py@@ -100,6 +100,26 @@ def test_failure_owner_uses_launch_rows_across_compaction(tmp_path):)assert db.message_count() == beforeassert current_id in {r["id"] for r in store.load_transcript(sid, raw=True)}+ source = SessionSource(+ platform=Platform.TELEGRAM, chat_id="observed", user_id="fixture"+ )+ entry = store.get_or_create_session(source)+ sid = entry.session_id+ prepared = runner._PreparedTurn(+ [], "", "accepted", "accepted", 1700000000, None, sid+ )+ db.append_message(sid, "user", "ambient observation", observed=True)+ before = db.message_count()+ await runner._hmwa_agent_error_reply(+ RuntimeError("controlled pre-agent failure"),+ MessageEvent(text="accepted", source=source, message_id=None),+ source,+ entry,+ entry.session_key,+ prepared,+ )+ assert db.message_count() == before + 1+ assert db.get_messages(sid)[-1]["content"] == "accepted"db.close()asyncio.run(check())diff --git a/website/docs/developer-guide/session-storage.md b/website/docs/developer-guide/session-storage.mdindex 84db5c2475c..995e4ec1ff1 100644--- a/website/docs/developer-guide/session-storage.md+++ b/website/docs/developer-guide/session-storage.md@@ -54,7 +54,7 @@ to that turn. Separately accepted identical inputs remain separate, even withidentical timestamps.Ownership reads include the launch session's compression lineage and archived-compaction generations, but not undone rows. This covers both a successful+compaction generations, but not undone rows or ambient observed messages. This covers both a successfulparent write before rotation and a successor-only write after a failed parentflush. An unreadable keyless baseline stops the turn with the existinghistory-unavailable response rather than assuming an empty history. Normal