Skip to content

fix(core): instantiate each sub-client exactly once in _spawn_completion_context - #163

Merged
alexzhang13 merged 1 commit into
mainfrom
fix/dedupe-sub-client-instantiation
May 13, 2026
Merged

fix(core): instantiate each sub-client exactly once in _spawn_completion_context#163
alexzhang13 merged 1 commit into
mainfrom
fix/dedupe-sub-client-instantiation

Conversation

@alexzhang13

@alexzhang13 alexzhang13 commented May 13, 2026

Copy link
Copy Markdown
Owner

Summary

Why it matters

  • Backends with expensive underlying state (HTTP connection pools, async clients, OS sockets) paid the cost twice. With multi-backend Anthropic on macOS this surfaced as a ~3-min hang at iter 2 of every multi-backend trajectory.
  • Usage tracking merges via dict.update in lm_handler.py, so the duplicate instance overwrote one of the two clients' usage summaries.

…ion_context

Previously the first sub-client was constructed twice — once for
`other_backend_client` and again inside the registration loop. With
backends that hold expensive underlying state (HTTP connection pools,
async clients, OS sockets), the duplicate carried real cost; with
multi-backend Anthropic on macOS this showed up as a ~3-min hang at
iter 2 of every multi-backend trajectory. Usage tracking also merged
via dict.update, so the duplicate overwrote one of the two instances'
usage summaries.

Reuse `other_backend_client` for the first registration and only
construct the remaining sub-clients in the loop.
@alexzhang13
alexzhang13 merged commit 7b7e127 into main May 13, 2026
3 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.

1 participant