fix(obp): release per-stream talker-alias state when OBP streams are trimmed

Talker-alias buffers (_dmra_by_stream, _ta_voice_acc, _ta_complete), the
passthrough relay dedupe set and log-once ingress keys are only released on
the HBP VTERM hook. OPENBRIDGE streams never hit it, and the OBP branch of
stream_trimmer_loop returned before trim_dmra_streams(), so every stream seen
on an OBP left one entry per structure behind (~38k after 35 h on a live
master, ~2 KB per call).

- On stage-2 removal of an OBP stream, call clear_talker_alias_stream() and
  drop the stream's log-once ingress keys.
- Run trim_dmra_streams() for OBP protocols too (catches buffers keyed by
  streams that never got a STATUS row).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JnjAx7G27d9q88j9PFLj11
pull/111/head
yo 2 months ago
parent c3db5b4c42
commit 59ae137b60

@ -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,

@ -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)

@ -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()

Loading…
Cancel
Save

Powered by TurnKey Linux.