Skip to content

fix(agent): forward custom_providers to context-length probe on fallback activation#25554

Closed
AhmetArif0 wants to merge 1 commit into
NousResearch:mainfrom
AhmetArif0:fix/fallback-forward-custom-providers-to-context-length
Closed

fix(agent): forward custom_providers to context-length probe on fallback activation#25554
AhmetArif0 wants to merge 1 commit into
NousResearch:mainfrom
AhmetArif0:fix/fallback-forward-custom-providers-to-context-length

Conversation

@AhmetArif0

Copy link
Copy Markdown
Contributor

What does this PR do?

Root cause: _try_activate_fallback() updates the context compressor when switching to the fallback model, but called get_model_context_length() without custom_providers. Users who pin context_length on a model via custom_providers in config.yaml (e.g. a 1M-context proxy behind a custom endpoint) saw the compressor silently fall through to the 256K default when the primary provider failed over — shifting the compression threshold to the wrong value for the remainder of the session.

Fix: Mirror the switch_model() pattern — re-read custom_providers from live config and forward the list to get_model_context_length(). This is consistent with the approach used by _check_compression_model_feasibility() (PR #25494) and switch_model() (which both correctly forward custom_providers). The fallback activation path was the remaining gap.

The three call sites now behave consistently:

Related Issue

Closes #8785

Type of Change

  • 🐛 Bug fix

Changes Made

  • run_agent.py: re-read custom_providers from live config and forward to get_model_context_length() in _try_activate_fallback() (+10 lines)
  • tests/run_agent/test_fallback_model.py: regression test verifying custom_providers is passed through when a context compressor is present (+50 lines)

How to Test

pytest tests/run_agent/test_fallback_model.py -v --override-ini="addopts="

Checklist

  • Contributing Guide read | Conventional Commits | No duplicate PR
  • Single fix only | Test added | Platform: macOS
  • Docs — N/A | Cross-platform — N/A

…ack activation

_try_activate_fallback() updates the context compressor for the fallback
model but called get_model_context_length() without custom_providers.
Users who pin context_length on a model in custom_providers (e.g. a 1M-
context proxy behind a custom endpoint) saw the compressor silently fall
back to the 256K default when the primary provider failed over, shifting
the compression threshold to the wrong value for the remainder of the
session.

Fix: mirror the switch_model() pattern — re-read custom_providers from
live config and forward the list to get_model_context_length, matching
the approach used by _check_compression_model_feasibility() (PR NousResearch#25494).
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels May 14, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #8785 (parent issue). Multiple competing PRs for the same custom_providers context_length plumbing: #8786, #18877 (dup of #13540), #14008, #14152. This PR addresses the last remaining gap (fallback activation path).

@teknium1

Copy link
Copy Markdown
Contributor

This appears to be implemented on current main.

Automated hermes-sweeper review evidence:

  • The fallback activation body now lives in agent/chat_completion_helpers.py after the run_agent.py refactor; run_agent.py:4153 is only a forwarder.
  • agent/chat_completion_helpers.py:1275 calls get_model_context_length() while updating the fallback context compressor, and agent/chat_completion_helpers.py:1279 forwards custom_providers=getattr(agent, "_custom_providers", None).
  • Commit b5bcffe1674fa9ab3ba7a754c07ab77bedde83a8 added this fallback-path plumbing with the title fix(fallback): forward custom_providers to fallback model context-length detection.
  • The earliest release tag I found containing that commit is v2026.5.28.

The prior discussion noting this as the remaining fallback activation gap was useful context; main now has the corresponding fix in the post-refactor location.

@teknium1 teknium1 closed this Jun 12, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: compression runtime context_length overrides are not applied consistently

3 participants