Skip to content

fix: close errored stream response in tool loop + correct cache-hit icon re-sync#15

Merged
sena-labs merged 1 commit into
mainfrom
claude/brave-thompson-rbct71
Jun 18, 2026
Merged

fix: close errored stream response in tool loop + correct cache-hit icon re-sync#15
sena-labs merged 1 commit into
mainfrom
claude/brave-thompson-rbct71

Conversation

@sena-labs

Copy link
Copy Markdown
Owner

Summary

Code audit found two genuine correctness defects (both low severity).

1. Resource leak — errored streaming response not closed in the native-tool loop

_retryable_request does not close the streaming response on its final raise. The plain-stream path _stream_response compensates by caching the body and calling exc.response.close(), but the native-tool streaming path _stream_one_round only did yield self._format_http_error(exc) — leaking the pooled connection on every failed tool-stream round. Fix mirrors _stream_response's cleanup (cache .content, then close()).

2. Premature icon re-sync stop on cache hits

The cache-hit re-sync guard compared len(self._icons_synced) < len(self._models_cache). But _icons_synced also accumulates orphan model IDs from _sync_orphan_db_icons() (IDs not in the catalog), so the set size can exceed the catalog count and the comparison becomes False — stopping re-sync while some catalog models are still unsynced, leaving their icons on the OWUI default placeholder until the 5-minute cache TTL forces a refresh. Fix checks whether any catalog model id is missing from _icons_synced (ignoring the error sentinel) instead of comparing sizes.

Tests

Standalone python test_pipe.py: 944/944 pass (+5 new regression tests, 0 regressions).

🤖 Generated with Claude Code

https://claude.ai/code/session_01HuonivE5ofaGiFVUy2Z39E


Generated by Claude Code

…con re-sync

Two verified residual bugs:

1. Resource leak in _stream_one_round (native tool-call streaming path):
   when _retryable_request raises HTTPError, it does not close the
   streaming response on its final raise. _stream_response handles this
   by caching the body and closing exc.response, but _stream_one_round's
   HTTPError handler did not, leaking the pooled connection on every
   failed tool-stream round. Mirror _stream_response's cleanup.

2. Premature icon re-sync stop in pipes() cache-hit path: the guard used
   len(_icons_synced) < len(_models_cache), but _icons_synced also
   accumulates orphan model IDs from _sync_orphan_db_icons(), so its size
   can exceed the catalog count and stop re-syncing before all catalog
   models are confirmed (leaving some icons on the OWUI default until the
   5-min cache TTL forces a full refresh). Check whether any catalog model
   is still unsynced instead of comparing set sizes.

Adds focused regression tests for both. 939 -> 944 tests, all green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HuonivE5ofaGiFVUy2Z39E
@sena-labs sena-labs marked this pull request as ready for review June 18, 2026 15:48
@sena-labs sena-labs merged commit 8359c47 into main Jun 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants