Skip to content

fix(moa): preserve facade across client rebuilds - #78409

Closed
burak33bb wants to merge 1 commit into
NousResearch:mainfrom
burak33bb:agent/preserve-moa-facade-on-rebuild
Closed

fix(moa): preserve facade across client rebuilds#78409
burak33bb wants to merge 1 commit into
NousResearch:mainfrom
burak33bb:agent/preserve-moa-facade-on-rebuild

Conversation

@burak33bb

@burak33bb burak33bb commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Preserves the virtual MoAClient facade when Hermes rebuilds the shared primary client during credential rotation, timeout updates, or dead-connection recovery.

MoA uses an in-process facade to consume the private _moa_prepared_request argument. The generic _replace_primary_openai_client() path ignored the active provider and rebuilt a native OpenAI SDK client from stale _client_kwargs. The next MoA request then leaked _moa_prepared_request into the OpenAI SDK and crashed with TypeError.

The replacement path is now provider-aware: it rebuilds the MoA facade with build_moa_facade() for the moa provider while preserving the existing OpenAI client behavior for every other provider. Existing safe retirement behavior for the replaced client remains unchanged.

Related Issue

Fixes #78382

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Added a provider-aware shared-client builder in run_agent.py.
  • Preserved MoAClient across the generic primary-client replacement path.
  • Added an end-to-end regression test covering replacement through non-streaming MoA dispatch.

How to Test

  1. Configure an MoA preset and initialize an AIAgent with provider="moa".
  2. Trigger _replace_primary_openai_client() as credential rotation or connection recovery would.
  3. Dispatch a request containing _moa_prepared_request and verify the MoA facade consumes it instead of forwarding it to a native OpenAI client.

Validation performed:

  • Reproduced the current-main failure: TypeError: unexpected _moa_prepared_request.
  • Ran 55 targeted tests across MoA loop mode, request-client reuse, and primary-runtime restore; all passed.
  • Ruff passed for both changed files.
  • git diff --check passed.

Duplicate Check

Searched current open PRs for #78382, _moa_prepared_request, moa client rebuild facade, and moa fallback rotation; no matching open PR was found. Earlier #70280 / #53802 covered restore and recovery paths, but not this generic replacement path.

Checklist

Code

  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix
  • I've added tests for my changes
  • I've tested on Windows 11
  • Full pytest tests/ -q suite run (55 focused regression tests passed)

Documentation & Housekeeping

  • Documentation changes are N/A
  • Config example changes are N/A
  • Contributor-guide changes are N/A
  • Tool description/schema changes are N/A
  • Cross-platform impact was considered; the change is provider/runtime logic with no platform-specific behavior

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have labels Aug 4, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks! Your _replace_primary_openai_client facade helper and the AIAgent-level regression test were cherry-picked into #83088 with your authorship preserved in git history. Closing as superseded by #83088; the create_openai_client-level fix there covers all rebuild entry points, and your helper adds a second layer at the direct replacement path.

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 P3 Low — cosmetic, nice to have 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