diff --git a/src/adn_server/application/routing/hbp_forward.py b/src/adn_server/application/routing/hbp_forward.py index 65fe3a7..76e4501 100644 --- a/src/adn_server/application/routing/hbp_forward.py +++ b/src/adn_server/application/routing/hbp_forward.py @@ -133,6 +133,15 @@ class HbpForwardMixin: self._silent_activation_log_key(system_name, peer_id, dst_id), ) + def _forget_ingress_drop_logs(self, system_name: str, stream_ids: list[bytes]) -> None: + """Drop log-once keys of streams the trimmer removed (OBP has no per-slot VTERM hook).""" + cache = getattr(self, "_ingress_drop_logged", None) + if not cache: + return + gone = set(stream_ids) + for key in [k for k in cache if len(k) > 4 and k[1] == system_name and k[4] in gone]: + cache.discard(key) + def _clear_ingress_drop_log( self, system_name: str, diff --git a/src/adn_server/application/routing/timers.py b/src/adn_server/application/routing/timers.py index 535ad82..011f2aa 100644 --- a/src/adn_server/application/routing/timers.py +++ b/src/adn_server/application/routing/timers.py @@ -322,6 +322,13 @@ class RoutingTimerMixin: elif isinstance(st_rem, dict) and _obp_status_is_ingress(st_rem): self._obp_emit_end_tx_for_forward_legs(stream_id, system_name, now) obp_status.pop(stream_id, None) + # Per-stream TA state (DMRA/embedded buffers, relay dedupe) is only + # released on HBP VTERM; OBP streams must be freed here. + self.clear_talker_alias_stream(system_name, stream_id) + if to_remove: + self._forget_ingress_drop_logs(system_name, to_remove) + if hasattr(protocol, "trim_dmra_streams"): + protocol.trim_dmra_streams() continue for slot in (1, 2): _slot = protocol.STATUS.get(slot) diff --git a/tests/application/test_obp_monitor_voice_end.py b/tests/application/test_obp_monitor_voice_end.py index f5d1ca1..0ef53e8 100644 --- a/tests/application/test_obp_monitor_voice_end.py +++ b/tests/application/test_obp_monitor_voice_end.py @@ -277,3 +277,36 @@ def test_idle_forward_leg_without_end_tx_is_trimmed() -> None: assert stream_id not in protocols["OBP-ES"].STATUS assert len(_end_tx_for(factory.events, "OBP-ES")) == 1 + + +def test_trimmed_obp_stream_releases_talker_alias_state() -> None: + """OBP streams have no HBP VTERM hook: per-stream TA and log-once state must go with the row.""" + routing, _factory, clock, protocols = _obp_stack(("OBP-ES",)) + proto = protocols["OBP-ES"] + cleared: list[bytes] = [] + trims: list[bool] = [] + proto.clear_ta_stream_buffer = cleared.append + proto.trim_dmra_streams = lambda: trims.append(True) + stream_id = bytes_4(0x0A0B0C0D) + other_id = bytes_4(0x0A0B0C0E) + tgid = bytes_3(213) + now = clock.time() + proto.STATUS[stream_id] = _ingress_leg( + peer_id=bytes_4(71411), rf_src=bytes_3(2130035), tgid=tgid, start=now - 10, last=now - 6, + ) + routing._passthrough_relayed.add(routing._both_ta_key("OBP-ES", stream_id)) + busy_key = routing._ingress_drop_key("tg_busy", "OBP-ES", bytes_4(71411), tgid, stream_id) + other_key = routing._ingress_drop_key("tg_busy", "OBP-ES", bytes_4(71411), tgid, other_id) + routing._ingress_drop_log_cache().update({busy_key, other_key}) + + with _patch_wall_time(clock): + routing.stream_trimmer_loop() + clock.advance(181) + routing.stream_trimmer_loop() + + assert stream_id not in proto.STATUS + assert cleared == [stream_id] + assert trims + assert routing._both_ta_key("OBP-ES", stream_id) not in routing._passthrough_relayed + assert busy_key not in routing._ingress_drop_log_cache() + assert other_key in routing._ingress_drop_log_cache()