fix(run_agent): use aux provider for compression context length lookup#16918
Closed
rxdxxxx wants to merge 1 commit into
Closed
fix(run_agent): use aux provider for compression context length lookup#16918rxdxxxx wants to merge 1 commit into
rxdxxxx wants to merge 1 commit into
Conversation
baee64f to
88482fc
Compare
76c4057 to
e945211
Compare
Each auxiliary model must be resolved with its own provider so that provider-specific paths (e.g. Bedrock static table, OpenRouter API) are invoked for the correct client, not inherited from the main model. When the main model is Bedrock, passing self.provider unconditionally to get_model_context_length() for the aux model caused the Bedrock static table hard-intercept (step 1b) to fire for non-Bedrock models, returning BEDROCK_DEFAULT_CONTEXT_LENGTH=128K instead of the model's real context window — triggering a false compression warning every session. Fix: pass _aux_cfg_provider when explicitly set, falling back to self.provider only when the aux provider is unset or "auto". Closes NousResearch#12977 Related: NousResearch#13807, NousResearch#17460
e945211 to
5d392b9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the main model is configured with AWS Bedrock (
provider: bedrock),self.provider == "bedrock"was being passed unconditionally toget_model_context_length()for the auxiliary compression model.get_model_context_lengthhas a hard-intercept at step 1b:A non-Bedrock aux model (e.g.
deepseek/deepseek-v4-flashon OpenRouter) isnot in the Bedrock static table, so it falls back to
BEDROCK_DEFAULT_CONTEXT_LENGTH = 128_000. This triggers a false feasibilitywarning every session start:
…even though
deepseek/deepseek-v4-flashnatively supports 1,048,576 tokens.Root Cause
_aux_cfg_provider(the aux model's own provider, resolved via_resolve_task_provider_model("compression")) was already being fetched justabove the call site — but never passed to
get_model_context_length(). Instead,the main model's
self.providerwas passed unconditionally.The invariant that
providermust belong to the model being queried — not thecaller's model — is not enforced at the call site today, which is why this leak
is silent.
Fix
Pass
_aux_cfg_providerwhen it is explicitly set (not empty or"auto"),falling back to the main model's provider only when the aux provider is
unspecified.
Impact
The Bedrock hard-intercept is the most visible trigger, but the root cause is
general: any provider whose resolution path diverges at step 1b (Bedrock static
table) or later steps will produce wrong results when a foreign provider is
passed for an aux model.
Affected: main model = Bedrock + aux compression model on any non-Bedrock
provider (OpenRouter, OpenAI, Anthropic, etc.). Other combinations are not
affected today because non-Bedrock providers don't short-circuit at step 1b.
Functional impact is minor (threshold auto-corrects for the session), but the
warning is misleading, fires every session, and causes users to misconfigure
their setup to suppress it.
Why This Is Not a Duplicate of #17460
PR #17460 fixes
get_model_context_length()to auto-loadcustom_providerswhen the parameter is
None— protecting callers that never passed theargument. This PR fixes a different parameter on the same call:
provideris present at every call site but is being set to the wrong value.
The two fixes are complementary and non-overlapping:
custom_providers=Noneprovider=self.provider(wrong value)custom_providersoverrides ignored for aux modelsNeither PR makes the other redundant. Both should land.
Testing
All 16 existing compression feasibility tests pass unchanged.
Closes #12977
Related: #13807, #17460