-
Notifications
You must be signed in to change notification settings - Fork 23
Use lower thinking/effort for cron and hook sessions under OAuth #129
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
Open
constkolesnyak
wants to merge
1
commit into
ClickHouse:main
Choose a base branch
from
constkolesnyak:upstream/cron-effort-oauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+165
−2
Open
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
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
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,112 @@ | ||
| """Tests for engine option helpers — thinking/effort selection per source. | ||
|
|
||
| Regression for the issue where every cron run failed with | ||
| ``API Error: 400 level "max" not supported, valid levels: low, medium, high`` | ||
| because the global ``effort=max`` / ``thinking=max`` settings were applied | ||
| to cron sessions that run on ``cron_model`` (Sonnet) under Claude OAuth, | ||
| which caps non-flagship models at ``high``. | ||
|
|
||
| The fix introduces dedicated ``agent.cron_thinking`` / ``agent.cron_effort`` | ||
| fields and a ``_select_thinking_effort`` helper that picks the right pair | ||
| based on ``source`` (``cron`` / ``hook`` get the cron overrides, everything | ||
| else keeps the main settings). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from nerve.agent.engine import _select_thinking_effort | ||
| from nerve.config import AgentConfig | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def agent_config() -> AgentConfig: | ||
| """Default AgentConfig — main = max, cron = high.""" | ||
| return AgentConfig() | ||
|
|
||
|
|
||
| class TestSelectThinkingEffort: | ||
| """``_select_thinking_effort`` routes settings by session source.""" | ||
|
|
||
| def test_defaults_match_documented_values(self, agent_config: AgentConfig): | ||
| """Sanity check: the defaults are the ones the docs promise.""" | ||
| assert agent_config.thinking == "max" | ||
| assert agent_config.effort == "max" | ||
| assert agent_config.cron_thinking == "high" | ||
| assert agent_config.cron_effort == "high" | ||
|
|
||
| @pytest.mark.parametrize("source", ["web", "telegram", "discord", "api", ""]) | ||
| def test_interactive_sources_use_main_settings( | ||
| self, agent_config: AgentConfig, source: str, | ||
| ): | ||
| """Anything that isn't cron/hook keeps the main thinking/effort.""" | ||
| thinking, effort = _select_thinking_effort(agent_config, source) | ||
| assert thinking == "max" | ||
| assert effort == "max" | ||
|
|
||
| @pytest.mark.parametrize("source", ["cron", "hook"]) | ||
| def test_cron_and_hook_use_cron_overrides( | ||
| self, agent_config: AgentConfig, source: str, | ||
| ): | ||
| """Cron and hook sessions must use ``cron_thinking`` / ``cron_effort``. | ||
|
|
||
| This is the regression — the original code always passed | ||
| ``effort=max`` regardless of source, blocking every cron run. | ||
| """ | ||
| thinking, effort = _select_thinking_effort(agent_config, source) | ||
| assert thinking == "high" | ||
| assert effort == "high" | ||
|
|
||
| def test_overrides_propagate_from_config(self): | ||
| """Custom values in AgentConfig are honored, not overwritten.""" | ||
| config = AgentConfig( | ||
| thinking="medium", | ||
| effort="medium", | ||
| cron_thinking="low", | ||
| cron_effort="low", | ||
| ) | ||
| assert _select_thinking_effort(config, "web") == ("medium", "medium") | ||
| assert _select_thinking_effort(config, "cron") == ("low", "low") | ||
| assert _select_thinking_effort(config, "hook") == ("low", "low") | ||
|
|
||
| def test_main_and_cron_can_differ_independently(self): | ||
| """Cron settings don't have to mirror main settings.""" | ||
| config = AgentConfig( | ||
| thinking="max", effort="max", | ||
| cron_thinking="medium", cron_effort="low", | ||
| ) | ||
| thinking_main, effort_main = _select_thinking_effort(config, "web") | ||
| thinking_cron, effort_cron = _select_thinking_effort(config, "cron") | ||
| assert (thinking_main, effort_main) == ("max", "max") | ||
| assert (thinking_cron, effort_cron) == ("medium", "low") | ||
|
|
||
|
|
||
| class TestAgentConfigFromDict: | ||
| """``AgentConfig.from_dict`` accepts the new cron_* fields.""" | ||
|
|
||
| def test_omitted_cron_fields_default_to_high(self): | ||
| """Configs predating this fix still load — defaults kick in.""" | ||
| config = AgentConfig.from_dict({}) | ||
| assert config.cron_thinking == "high" | ||
| assert config.cron_effort == "high" | ||
|
|
||
| def test_cron_fields_are_loaded_from_dict(self): | ||
| config = AgentConfig.from_dict({ | ||
| "cron_thinking": "medium", | ||
| "cron_effort": "low", | ||
| }) | ||
| assert config.cron_thinking == "medium" | ||
| assert config.cron_effort == "low" | ||
|
|
||
| def test_main_settings_unaffected_by_cron_fields(self): | ||
| config = AgentConfig.from_dict({ | ||
| "thinking": "max", | ||
| "effort": "max", | ||
| "cron_thinking": "low", | ||
| "cron_effort": "low", | ||
| }) | ||
| assert config.thinking == "max" | ||
| assert config.effort == "max" | ||
| assert config.cron_thinking == "low" | ||
| assert config.cron_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 will change the behavior for API users. We should keep it
maxby default and switch tohighwhen OAuth subscription is used.