Skip to content

fix(streaming): never close OpenAI shared client from watchdog#71105

Open
xrwang8 wants to merge 1 commit into
NousResearch:mainfrom
xrwang8:fix/openai-wire-watchdog-shared-client-close
Open

fix(streaming): never close OpenAI shared client from watchdog#71105
xrwang8 wants to merge 1 commit into
NousResearch:mainfrom
xrwang8:fix/openai-wire-watchdog-shared-client-close

Conversation

@xrwang8

@xrwang8 xrwang8 commented Jul 25, 2026

Copy link
Copy Markdown

Summary

Fixes #70773 - OpenAI-wire watchdog closes shared client from non-owner thread

Changes

Testing

  • ✅ Added test_70773_openai_wire_stream_pool_cleanup.py
  • ✅ Updated existing streaming tests
  • ✅ Test suite passed

Related

Fixes #70773

…esearch#70773)

The OpenAI-wire streaming cleanup (stale_stream, stream_retry,
stream_mid_tool_retry) called _replace_primary_openai_client() to
swap self.client and close the old shared pool. The stale site ran
from the poll (stranger) thread, and the retry sites ran from the
request worker — either way, closing the shared pool while sibling
workers held sockets from that pool left FDs live for recycling
when httpx called os.close(). NousResearch#70773 is the production forensic
showing that FD-recycle vector corrupted kanban.db.

Since NousResearch#67142, OpenAI-wire streams run on a per-request client:
the stale watchdog aborts the request-local client's socket (poll
thread) and the worker closes its own client (worker thread) —
the shared self.client is never closed from inside a request.

This commit removes the three _replace_primary_openai_client()
calls and adds regression tests asserting that the shared client
survives cleanup, while the request-local abort/close still fires.

Fixes NousResearch#70773. Extends NousResearch#67142.

Signed-off-by: xrwang8 <xrwang8@gmail.com>
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jul 25, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #70993: the merged current-head repair already removes these three shared-client replacement calls and adds the broader safe-retirement coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

2 participants