From 0931058fa282360aa4ed3bdf43638a53ad370980 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 06:34:09 +0000 Subject: [PATCH] Keep only the current WebSocket message in the secrets proxy mitmproxy keeps every message of a WebSocket connection for its life, so a long Codex session grows the proxy without bound (DRU-888). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01ENMdnx74hgYh4bWfsm44WV --- deploy/proxy/swap.py | 5 +++++ src/secrets_exchange/tests/test_swap.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/deploy/proxy/swap.py b/deploy/proxy/swap.py index 88e0cbc..79cdbb9 100644 --- a/deploy/proxy/swap.py +++ b/deploy/proxy/swap.py @@ -216,5 +216,10 @@ async def swap(self, flow: http.HTTPFlow, found: list[tuple[str, str]]) -> None: def responseheaders(self, flow: http.HTTPFlow) -> None: flow.response.stream = True + def websocket_message(self, flow: http.HTTPFlow) -> None: + """mitmproxy keeps every message of a connection for its life. Only the + current one is kept: the dumper reads it after this hook.""" + del flow.websocket.messages[:-1] + addons = [Swap()] diff --git a/src/secrets_exchange/tests/test_swap.py b/src/secrets_exchange/tests/test_swap.py index 87eae43..517b4b2 100644 --- a/src/secrets_exchange/tests/test_swap.py +++ b/src/secrets_exchange/tests/test_swap.py @@ -652,6 +652,14 @@ def test_responses_stream(swap: ModuleType) -> None: assert flow.response.stream is True +def test_a_websocket_keeps_only_the_current_message(swap: ModuleType) -> None: + flow = SimpleNamespace(websocket=SimpleNamespace(messages=["earlier", "current"])) + + swap.Swap().websocket_message(flow) + + assert flow.websocket.messages == ["current"] + + async def test_the_exchange_client_reads_the_answers(swap: ModuleType) -> None: exchange = swap.Exchange("http://exchange.test/") fetched: list[Any] = []