Skip to content

[codex] fix OpenAI client isolation across agents#165

Open
Flamki wants to merge 1 commit into
enliven17:mainfrom
Flamki:fix/openai-client-isolation
Open

[codex] fix OpenAI client isolation across agents#165
Flamki wants to merge 1 commit into
enliven17:mainfrom
Flamki:fix/openai-client-isolation

Conversation

@Flamki

@Flamki Flamki commented Jul 1, 2026

Copy link
Copy Markdown

What changed

  • Replaced the single module-level _openai_client singleton with a cache keyed by (api_key, base_url).
  • Normalized empty base_url values to None so default OpenAI clients reuse correctly.
  • Added regression coverage proving same credentials reuse a client while different API keys or base URLs get isolated clients.

Closes #53

Why

In single-process run_multi deployments, multiple agents can run concurrently with different LLM credentials. The old singleton reused the first initialized AsyncOpenAI client for every later agent, which could send subsequent agents' traffic through the first agent's API key.

Validation

  • PYTHONPATH=src uv run pytest tests/test_openai_client_isolation.py passed.
  • PYTHONPATH=src uv run ruff check src tests passed.
  • PYTHONPATH=src uv run --extra dev pytest passed: 177 tests.

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@Flamki is attempting to deploy a commit to the Cankat's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jul 1, 2026

Copy link
Copy Markdown

@Flamki Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

fix: Prevent LLM client sharing across multiple agents in single-process mode

1 participant