Skip to content

fix(agent): strip _moa_prepared_request before dispatching to native client (#78382) - #80132

Closed
RelaxJonh wants to merge 1 commit into
NousResearch:mainfrom
RelaxJonh:fix/moa-prepared-request-leak-78382
Closed

fix(agent): strip _moa_prepared_request before dispatching to native client (#78382)#80132
RelaxJonh wants to merge 1 commit into
NousResearch:mainfrom
RelaxJonh:fix/moa-prepared-request-leak-78382

Conversation

@RelaxJonh

Copy link
Copy Markdown
Contributor

Summary

After a client replacement (credential rotation, dead-connection cleanup, or fallback+restore via _replace_primary_openai_client), agent.client becomes a native OpenAI client while agent.provider stays "moa". The _moa_prepared_request key was passed through to the native SDK at chat_completion_helpers.py:509, causing TypeError: Completions.create() got an unexpected keyword argument _moa_prepared_request on every turn.

Fix

Pop _moa_prepared_request from api_kwargs at the dispatch point before calling agent.client.chat.completions.create(). The MoAClient.create() facade already handles a missing key by falling through to its normal resolution path (moa_loop.py:1852), so the fix is safe for both the real facade and replaced native clients.

Test

  • test_moa_key_stripped_from_native_client — verifies the key is removed before reaching a native client
  • test_no_moa_key_when_absent — verifies normal non-MoA calls work without the key

Root cause

conversation_loop.py:2326-2327 injects _moa_prepared_request into api_kwargs when agent.provider == "moa". After client replacement, the provider stays "moa" but the client is native — the key leaks through.

Closes #78382

…client

After a client replacement (credential rotation, dead-connection cleanup,
or fallback+restore), agent.client may become a native OpenAI client
while agent.provider stays "moa".  The _moa_prepared_request key was
passed through to the native SDK, causing TypeError on every turn.

Pop the key at the dispatch point (chat_completion_helpers.py:509).
The MoAClient facade already handles a missing key by falling through
to its normal resolution path.

Closes NousResearch#78382
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API labels Aug 6, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: #78409 and #79795 preserve the MoA facade across client-rebuild paths; this PR instead adds a dispatch-layer guard against the leaked private kwarg. The approaches are complementary.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks! Your dispatch-point strip and regression test were cherry-picked into #83088 with your authorship preserved in git history. One note: we gated the pop on a facade-capability probe, because the unconditional pop also stripped the handshake from the live MoA facade, forcing a duplicate reference fan-out (caught by the existing aggregator-actor test). Closing as superseded by #83088.

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 P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MOA: _moa_prepared_request leaked to native OpenAI client when agent.client is replaced (fallback/rotation)

3 participants