Repository navigation
fix(copilot): clamp reasoning effort to nearest supported level instead of capping xhigh #51480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
arminanton
wants to merge
1
commit into
NousResearch:main
from
arminanton:feat/copilot-plugin-effort-nearest-down
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| """Unit tests for the Copilot provider profile's reasoning-effort wiring. | ||
|
|
||
| GitHub Copilot serves different models with different supported reasoning-effort | ||
| sets (the live ``/models`` catalog reports them per model). The profile must | ||
| forward the requested effort when the catalog lists it as supported, and only | ||
| downgrade to the nearest weaker supported level when it does not, rather than | ||
| unconditionally collapsing ``xhigh`` to ``high`` (which silently capped models | ||
| that actually support the higher level). | ||
|
|
||
| These tests pin that contract without going live, by stubbing the catalog | ||
| lookup ``github_model_reasoning_efforts``. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def copilot_profile(): | ||
| """Resolve the registered Copilot profile. | ||
|
|
||
| Importing ``model_tools`` triggers plugin discovery, which registers the | ||
| Copilot profile. Going through ``get_provider_profile`` keeps the test | ||
| honest: if the registered class is ever swapped for a plain | ||
| ``ProviderProfile`` the assertions below collapse. | ||
| """ | ||
| import model_tools # noqa: F401 | ||
| import providers | ||
|
|
||
| profile = providers.get_provider_profile("copilot") | ||
| assert profile is not None, "copilot provider profile must be registered" | ||
| return profile | ||
|
|
||
|
|
||
| def _patch_efforts(monkeypatch, efforts): | ||
| """Stub the catalog lookup the profile calls for supported efforts.""" | ||
| import hermes_cli.models as models_mod | ||
| monkeypatch.setattr( | ||
| models_mod, "github_model_reasoning_efforts", lambda model: list(efforts) | ||
| ) | ||
|
|
||
|
|
||
| class TestCopilotReasoningEffortClamp: | ||
| def test_supported_effort_forwarded_verbatim(self, copilot_profile, monkeypatch): | ||
| """xhigh is forwarded unchanged when the catalog lists it.""" | ||
| _patch_efforts(monkeypatch, ["minimal", "low", "medium", "high", "xhigh"]) | ||
| extra_body, _ = copilot_profile.build_api_kwargs_extras( | ||
| model="gpt-5.5", | ||
| reasoning_config={"effort": "xhigh"}, | ||
| supports_reasoning=True, | ||
| ) | ||
| assert extra_body["reasoning"] == {"effort": "xhigh"} | ||
|
|
||
| def test_xhigh_downgrades_to_high_when_unsupported(self, copilot_profile, monkeypatch): | ||
| """A model whose catalog lacks xhigh gets the nearest weaker level.""" | ||
| _patch_efforts(monkeypatch, ["low", "medium", "high"]) | ||
| extra_body, _ = copilot_profile.build_api_kwargs_extras( | ||
| model="o-series-model", | ||
| reasoning_config={"effort": "xhigh"}, | ||
| supports_reasoning=True, | ||
| ) | ||
| assert extra_body["reasoning"] == {"effort": "high"} | ||
|
|
||
| def test_minimal_downgrades_to_low_when_unsupported(self, copilot_profile, monkeypatch): | ||
| _patch_efforts(monkeypatch, ["low", "medium", "high"]) | ||
| extra_body, _ = copilot_profile.build_api_kwargs_extras( | ||
| model="o-series-model", | ||
| reasoning_config={"effort": "minimal"}, | ||
| supports_reasoning=True, | ||
| ) | ||
| assert extra_body["reasoning"] == {"effort": "low"} | ||
|
|
||
| def test_unsupported_effort_falls_back_to_medium(self, copilot_profile, monkeypatch): | ||
| """An effort not in the set, with no specific rule, falls to medium.""" | ||
| _patch_efforts(monkeypatch, ["low", "medium", "high"]) | ||
| extra_body, _ = copilot_profile.build_api_kwargs_extras( | ||
| model="some-model", | ||
| reasoning_config={"effort": "garbage"}, | ||
| supports_reasoning=True, | ||
| ) | ||
| assert extra_body["reasoning"] == {"effort": "medium"} | ||
|
|
||
| def test_falls_back_to_first_supported_when_no_medium(self, copilot_profile, monkeypatch): | ||
| """If medium isn't supported either, pick the first supported level.""" | ||
| _patch_efforts(monkeypatch, ["low", "high"]) | ||
| extra_body, _ = copilot_profile.build_api_kwargs_extras( | ||
| model="weird-model", | ||
| reasoning_config={"effort": "xhigh"}, | ||
| supports_reasoning=True, | ||
| ) | ||
| # xhigh not supported, high IS supported → high wins via the xhigh rule. | ||
| assert extra_body["reasoning"] == {"effort": "high"} | ||
|
|
||
| def test_first_supported_when_no_rule_matches(self, copilot_profile, monkeypatch): | ||
| _patch_efforts(monkeypatch, ["low", "high"]) | ||
| extra_body, _ = copilot_profile.build_api_kwargs_extras( | ||
| model="weird-model", | ||
| reasoning_config={"effort": "garbage"}, | ||
| supports_reasoning=True, | ||
| ) | ||
| assert extra_body["reasoning"] == {"effort": "low"} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes only the chat-completions profile. GPT-5 Copilot models use
codex_responses(hermes_cli/models.py:3293-3307), whose payload still comes fromrun_agent.py:_github_models_reasoning_extra_body()and unconditionally clampsxhighatrun_agent.py:5454-5455; update both paths (as carried by #62028).