fix: audit fixes — 5 bugs found and resolved
Thorough code review found 5 issues across run_agent.py, cli.py, and gateway/: 1. CRITICAL — Gateway stream consumer task never started: stream_consumer_holder was checked BEFORE run_sync populated it. Fixed with async polling pattern (same as track_agent). 2. MEDIUM-HIGH — Streaming fallback after partial delivery caused double-response: if streaming failed after some tokens were delivered, the fallback would re-deliver the full response. Now tracks deltas_were_sent and only falls back when no tokens reached consumers yet. 3. MEDIUM — Codex mode lost on_first_delta spinner callback: _run_codex_stream now accepts on_first_delta parameter, fires it on first text delta. Passed through from _interruptible_streaming_api_call via _codex_on_first_delta instance attribute. 4. MEDIUM — CLI close-tag after-text bypassed tag filtering: text after a reasoning close tag was sent directly to _emit_stream_text, skipping open-tag detection. Now routes through _stream_delta for full filtering. 5. LOW — Removed 140 lines of dead code: old _streaming_api_call method (superseded by _interruptible_streaming_api_call). Updated 13 tests in test_run_agent.py and test_openai_client_lifecycle.py to use the new method name and signature. 4573 tests passing.
This commit is contained in:
parent
99369b926c
commit
8e07f9ca56
5 changed files with 75 additions and 176 deletions
|
|
@ -4371,10 +4371,19 @@ class GatewayRunner:
|
|||
if tool_progress_enabled:
|
||||
progress_task = asyncio.create_task(send_progress_messages())
|
||||
|
||||
# Start stream consumer task if configured
|
||||
# Start stream consumer task — polls for consumer creation since it
|
||||
# happens inside run_sync (thread pool) after the agent is constructed.
|
||||
stream_task = None
|
||||
if stream_consumer_holder[0] is not None:
|
||||
stream_task = asyncio.create_task(stream_consumer_holder[0].run())
|
||||
|
||||
async def _start_stream_consumer():
|
||||
"""Wait for the stream consumer to be created, then run it."""
|
||||
for _ in range(200): # Up to 10s wait
|
||||
if stream_consumer_holder[0] is not None:
|
||||
await stream_consumer_holder[0].run()
|
||||
return
|
||||
await asyncio.sleep(0.05)
|
||||
|
||||
stream_task = asyncio.create_task(_start_stream_consumer())
|
||||
|
||||
# Track this agent as running for this session (for interrupt support)
|
||||
# We do this in a callback after the agent is created
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue