The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: replay frames carry the canonical session id after main froze the ring
Tekniumc41717f034f6
diff --git a/gateway/session_events.py b/gateway/session_events.pyindex 3dc150657d3..870100e422c 100644--- a/gateway/session_events.py+++ b/gateway/session_events.py@@ -16,6 +16,7 @@ class SessionEvents:self._key = uuid.uuid4().hexself.epoch = uuid.uuid4().hexself.sequence = 0+ self._public_id = Noneself.execution = {}# Synchronous same-thread recipients (API run projections): unlike fanout peers they# cannot lose a frame to a detach that races the writer thread.@@ -44,9 +45,10 @@ class SessionEvents:# Another publisher may evict us after watermark's lookup.self.epoch = uuid.uuid4().hexframe['params']['replay_epoch'] = self.epoch- # The ring owns this same event object; its lookup key remains- # private while both replay and live recipients see canonical IDs.+ # The ring froze the frame under its private lookup key; live recipients see the+ # canonical ID here and ``since`` restores it on the thawed replay copies.frame['params']['session_id'] = session_id+ self._public_id = session_idself.sequence = frame['params']['seq']def overflow(transport):@@ -71,7 +73,9 @@ class SessionEvents:missing = (epoch != current_epoch or sequence > latestor event_replay.is_truncated(self._key, sequence)or event_replay.latest_seq(self._key) != latest)- events = [] if missing else deepcopy(frames)+ events = [] if missing else [+ {**frame, 'session_id': self._public_id} if frame.get('session_id') == self._key else frame+ for frame in frames]return {'events': events, 'latest_seq': latest, 'last_sequence': latest,'epoch': current_epoch, 'replay_epoch': current_epoch,'truncated': missing, 'snapshot_required': missing, 'count': len(events)}diff --git a/tests/gateway/test_authority_events.py b/tests/gateway/test_authority_events.pyindex 4909646c7bc..f8703b8b068 100644--- a/tests/gateway/test_authority_events.py+++ b/tests/gateway/test_authority_events.py@@ -116,7 +116,10 @@ async def test_replay_matches_subscription_watermark_or_requires_snapshot(tmp_paawait turn(6)raced = (await since(before_race['replay_epoch'], before_race['last_sequence']))['result']assert raced['snapshot_required'], 'eviction during stamp reused an old epoch/sequence'- assert raced['replay_epoch'] != before_race['replay_epoch']+ # No (epoch, sequence) is ever reused: the replay ring keeps a session's sequence+ # monotonic across eviction (#126988), else the epoch must rotate.+ assert (raced['replay_epoch'] != before_race['replay_epoch']+ or raced['last_sequence'] > before_race['last_sequence'])finally:await a.close()await b.close()