Skip to content

fix(agent): prevent Anthropic stale-stream SQLite corruption via _abort_anthropic_client (#67142) - #67270

Closed
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/67142-anthropic-stale-stream
Closed

fix(agent): prevent Anthropic stale-stream SQLite corruption via _abort_anthropic_client (#67142)#67270
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/67142-anthropic-stale-stream

Conversation

@webtecnica

Copy link
Copy Markdown
Contributor

Closes #67142

…rt_anthropic_client (NousResearch#67142)

Root cause: 4 watchdog locations in chat_completion_helpers.py called
agent._anthropic_client.close() from the polling thread (stranger thread).
The kernel recycled the freed TLS socket FD to a SQLite database, and the
still-live SSL BIO on the worker thread wrote TLS record bytes into the
SQLite header — same FD-reuse race as NousResearch#29507.

Fix:
- Added _abort_anthropic_client(reason) to run_agent.py — calls
  force_close_tcp_sockets() (shutdown SHUT_RDWR only, never close()) then
  _rebuild_anthropic_client() to preserve NousResearch#28161 pool-cleanup guarantee
- Added _close_anthropic_client(reason) for owner-thread full cleanup
- Replaced 4 watchdog sites: .close()+_rebuild → _abort_anthropic_client()
  + _rebuild_anthropic_client()
- Worker-thread retry paths still use full _close_anthropic_client

Closes NousResearch#67142
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API needs-decision Awaiting maintainer decision before any implementation labels Jul 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Competing with #67210 and #67238 for #67142: this patch centralizes socket abort/rebuild, while #67210 defers close/rebuild to the owner thread and #67238 makes Anthropic request clients local. These are materially different lifecycle mechanisms, so maintainer selection is needed.

@OutThisLife

Copy link
Copy Markdown
Collaborator

Closing as superseded by #67238 (merged), which already lands the fix for #67142: request-local Anthropic clients so the stale/interrupt watchdog never closes a shared client from the poll thread and corrupts SQLite via TLS FD reuse.

Thanks for the parallel work — please reopen if you believe there's a remaining gap on current main that #67238 doesn't cover.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused stale-stream investigation. This is an automated hermes-sweeper review; the requested behavioral guarantee is already implemented on current main through the more comprehensive request-local-client approach.

The maintainer comment identified competing lifecycle mechanisms; main has now selected and merged the request-local implementation.

@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 19, 2026
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 needs-decision Awaiting maintainer decision before any implementation P1 High — major feature broken, no workaround provider/anthropic Anthropic native Messages API sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic stale-stream watchdog can still corrupt SQLite via TLS FD reuse

4 participants