@@ -794,7 +794,8 @@ class CompressionFailureAction:
794794 reason : str
795795 """Short machine-readable label for telemetry. One of:
796796 ``timeout``, ``oversize:bytes=<n>>threshold=<m>``,
797- ``small_frame_transient``, or ``env_override:fail_open``."""
797+ ``small_frame_transient``, ``client_override:codex``, or
798+ ``env_override:fail_open``."""
798799
799800 frame_bytes : int
800801 """Original frame size in bytes (for logging / metrics)."""
@@ -803,6 +804,8 @@ class CompressionFailureAction:
803804def decide_compression_failure_action (
804805 exception : BaseException ,
805806 frame_bytes : int ,
807+ * ,
808+ client : str | None = None ,
806809) -> CompressionFailureAction :
807810 """Decide whether to refuse-and-close vs forward-original after the
808811 proxy's compression pipeline fails on a Realtime WebSocket frame
@@ -812,6 +815,10 @@ def decide_compression_failure_action(
812815
813816 * env :data:`WS_COMPRESSION_FAIL_OPEN_ENV` truthy → forward (legacy
814817 behaviour, opt-in for debugging or strict compatibility).
818+ * Codex client compression timeout → forward. Codex currently treats
819+ the proxy's 1009/413 refusal path as a hard connection failure, so
820+ fail-open is safer for Codex sessions even when the proxy is run
821+ standalone rather than through ``headroom wrap codex``.
815822 * exception is :class:`asyncio.TimeoutError` → refuse (the compression
816823 stage hit its own timeout, which only fires on frames Headroom
817824 thought were big enough to need compression in the first place).
@@ -834,6 +841,15 @@ def decide_compression_failure_action(
834841 frame_bytes = frame_bytes ,
835842 )
836843
844+ if (client or "" ).strip ().lower () == "codex" and isinstance (
845+ exception , asyncio .TimeoutError
846+ ):
847+ return CompressionFailureAction (
848+ refuse = False ,
849+ reason = "client_override:codex" ,
850+ frame_bytes = frame_bytes ,
851+ )
852+
837853 threshold = WS_COMPRESSION_OVERSIZE_BYTES_DEFAULT
838854 raw_threshold = os .environ .get (WS_COMPRESSION_OVERSIZE_BYTES_ENV , "" ).strip ()
839855 if raw_threshold :
0 commit comments