Skip to content

The agent that grows with you

chore: stack on #115817 to resolve agent/codex_runtime.py conflict

teknium1359a8f25c734
diff --cc agent/codex_runtime.py
index ee611eebfc7,192f490bb0f..98f31897a77
--- a/agent/codex_runtime.py
+++ b/agent/codex_runtime.py
@@@ -862,10 -884,8 +884,10 @@@ def run_codex_stream(agent, api_kwargs
if watchdog_state is not None
else getattr(agent, "_active_codex_stream_request_token", None)
)
- # Delta-sink claim for the CURRENT physical attempt (None until the stream opens).
- writer_token = {"value": None}
+ # Delta-sink claim for the CURRENT physical attempt (None until the stream opens). A newer attempt that
+ # claims the sink supersedes this token; that only silences OUR live callbacks — consumption continues,
+ # because stopping here handed the gateway a "completed" response missing its tail (#69486).
- writer_token = {"value": None, "superseded_logged": False}
++ writer_token = {"value": None, "raw_stream": None, "superseded_logged": False}
def _request_is_current() -> bool:
return request_token is None or getattr(agent, "_active_codex_stream_request_token", None) is request_token
@@@ -937,7 -941,16 +959,8 @@@
def _codex_stream_created(_raw_stream: Any) -> None:
# Claim the delta sink for THIS attempt; a newer attempt supersedes this token.
writer_token["value"] = claim_stream_writer(agent)
+ writer_token["raw_stream"] = _raw_stream
- def _accept_codex_chunk(_chunk: Any) -> bool:
- token = writer_token["value"]
- if token is None or stream_writer_is_current(agent, token):
- return True
- logger.warning("Codex streaming attempt superseded by a newer stream; stopping consumption to preserve "
- "the single-writer invariant (model=%s).", api_kwargs.get("model", "unknown"))
- return False
-
def _drain_for_finalizer(event_stream: Any) -> None:
# ``final`` is already assembled; draining only lets Relay run its finalizer. A transport error
# here must NOT discard the completed, already-billed response.
@@@ -978,7 -1016,7 +1026,8 @@@
with watchdog_state.lock:
watchdog_state.retry_started_ts = time.time()
intercepted_events: list = []
- writer_token["value"], writer_token["superseded_logged"], event_stream = None, False, None
+ writer_token["value"] = writer_token["raw_stream"] = event_stream = None
++ writer_token["superseded_logged"] = False
try:
try:
event_stream = relay_llm.stream(