Repository navigation
feat: add secure per-review model selection - #2818
elijahchancey wants to merge 6 commits into
Conversation
PR Summary by QodoAdd secure per-review model and effort selection
AI Description
Diagram
High-Level Assessment
Files changed (18)
|
Code Review by Qodo
1. Concurrent reviews swap selected models
|
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Off by default, with only an operator able to list the allowed models, is the right way round.
I'd hold this on Qodo's "unbounded chain" finding. Qodo says a comment could trigger it; I checked that it really can. Comment /review followed by opus+high repeated 5000 times and all 5000 reach the reviewer. CliArgs.validate_user_args blocks --pr_reviewer.enable_command_model_overrides=..., but it only looks at arguments starting with --, so plain tokens walk past.
How bad it gets depends on failure. pr_processing.py:373 stops at the first call that works, so normally it's one call. If the model is down or an alias is broken, it tries all 5000, each retried again on top.
Suggested fix inline. I went with rejecting duplicates rather than silently dropping them, since your docs describe the list as "try these in order", so a deliberate repeat is a fair thing to type.
One more worth doing: the new pr_agent import at the top of langchain_ai_handler.py trips a ruff warning main doesn't have. Moving it into the pr_agent group at the bottom of the import block clears it. I'd skip Qodo's "line too long" note on the docs, there's no markdown linter here.
|
Addressed all review findings in 19b77b5:
Verification: scoped pre-commit and flake8 checks pass; 117 focused tests pass; full unit suite passes with 2413 passed, 1 skipped, and 1 xfailed. |
|
Code review by qodo was updated up to the latest commit 19b77b5 |
|
Code review by qodo was updated up to the latest commit 9c35f51 |
|
Addressed the latest review findings in 33ebaf9:
|
|
Code review by qodo was updated up to the latest commit 33ebaf9 |
|
Code review by qodo was updated up to the latest commit 6e50207 |
|
Code review by qodo was updated up to the latest commit 1461134 |
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Qodo's unbounded-chain finding is closed, checked.
The rebase is now the blocker rather than tidiness: the conflict stops GitHub building a merge ref, so build-and-test has never run on 1461134, which carries only update_release_draft against five green checks on your previous head.
The conflict is one import block, from #2817. Watch MockResponse on the way through, since #2817 removed its last use. This merges, at 2582 passed with only the test_litellm_callback_drain failure main already has:
from pr_agent.algo.ai_handlers.litellm_helpers import (
_get_azure_ad_token, _handle_streaming_response,
_process_litellm_extra_body, _response_field)
from pr_agent.algo.review_model_selection import \
get_active_review_model_selection
from pr_agent.algo.run_details import _as_decimal_cost, record_ai_callQodo's 2 and 3 are your call; both lines are 203 characters and those files already carry 28 and 35 over 120. Its finding 4 is real and CodeQL's double import is worth taking, suggestions inline for both.
|
Addressed all current review feedback in
Verification:
GitHub now reports the PR as mergeable. Fresh build-and-test and CodeQL checks are running on exact head |
|
Code review by qodo was updated up to the latest commit 50734c0 |
|
Follow-up review fixes are now in 61d5814.\n\n- Configuration boundary: command-model configuration is loaded through get_settings() at the dispatcher boundary and passed to the pure parser as a typed ReviewModelSelectionConfig value. The selection helper no longer reaches into injected settings/configuration itself.\n- Raw provider selector validation: provider-shaped values such as anthropic/claude-opus-5+extreme can no longer fall through as ordinary command arguments; they are rejected as raw model identifiers. Added parser and routing regression coverage.\n- Documentation formatting: wrapped both flagged GitLab configuration paragraphs to the repository's 120-character limit.\n\nVerification:\n- pre-commit run --all-files\n- PYTHONPATH=. ../pr-agent/.venv/bin/pytest tests/unittest/test_review_model_selection.py tests/unittest/test_pr_agent_routing.py -q — 57 passed\n- PYTHONPATH=. ../pr-agent/.venv/bin/pytest tests/unittest -q — 2617 passed, 1 skipped, 1 xfailed |
|
Code review by qodo was updated up to the latest commit 61d5814 |
|
Addressed the two findings added by Qodo's latest refresh in
Verification:
|
|
Code review by qodo was updated up to the latest commit a7690ff |
There was a problem hiding this comment.
The implementation holds up: rebased and green on a real merge ref, all four suggestions in, both CodeQL alerts clear, and the revert probe goes red across all four surfaces, so the tests genuinely pin the behaviour.
Before it goes further, though, @naorpeled should decide whether this is the direction we want, because it is a second way to do something that already works. /review --config.model=... --config.reasoning_effort=high is permitted from a PR comment today: the denylist in cli_args.py blocks openai.key and api_base but not config.model, and I ran it to confirm. This adds an allowlisted alias syntax alongside that route, at +1118/-61 across 19 files, touching the dispatcher, all three AI handlers and pr_processing. If the worry is that the existing route is unrestricted, putting an allowlist on that route is a much smaller change than adding a syntax.
That is an owner call rather than mine. Sorry I have been too focus on just review review review that sort of missed looking at it at a higher level.
Separately, one defect worth fixing whichever way the call goes. Detail inline.
|
I had no idea That said, I do prefer my simpler human friendly syntax. Open to suggestions on how to help this PR (or a variation of it) move forward. :) |
|
Hey @elijahchancey, What I had in mind was a stringified JSON object but that's not intuitive and easy to mistype 🤔 |
|
My opinion is that the syntax is as simple as it possible can be at this time: Other possible syntaxes: A syntax I would prefer to avoid: I would prefer to avoid this because in the future we may want to support something like: What other syntaxes did you have in mind? |
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Thanks for doing the security homework unprompted; the protected-keys allowlist is careful work.
My hesitation is scope, and I have not decided. What does this give that config.model and fallback_models do not? I checked: both are already settable from a repo .pr_agent.toml, and --config.model=... passes validate_user_args unblocked today. So the door this guards for aliases stands open beside it, which makes the spend-access argument hard to make as stated.
Parking this with @naorpeled for the scope call rather than holding it on my own view.
…el-overrides # Conflicts: # pr_agent/git_providers/utils.py # pr_agent/servers/help.py
|
@IsmaelMartinez do you know how we can get @naorpeled 's attention? I'd love to not have to maintain a fork of pr-agent for my company. :) |
|
Hey, I'll take a look when I'm back home (in few hours) |
|
If I don't reply here, LinkedIn also works |
…el-overrides # Conflicts: # pr_agent/servers/help.py
|
okay. I'll keep merging in main and resolving conflicts until you approve. thanks! |
|
Code review by qodo was updated up to the latest commit c6b92de |
|
Hey, |
|
Code review by qodo was updated up to the latest commit 1d32121 |
|
Code review by qodo was updated up to the latest commit 6c0213a |
|
Addressed the three findings from the review of
CI also exposed a missing generated configuration-reference entry for this PR's alias-enable setting. Commit Verification: 49 focused model-selection/routing tests and 2 configuration-reference tests passed locally. Build-and-test, pre-commit, and CodeQL pass on final head The three newly raised threads about disabled malformed selectors, external configuration, and local checkout configuration remain open pending investigation; this follow-up does not claim those are fixed. |
| settings.set("CONFIG.MODEL", model_selection.model) | ||
| settings.set("CONFIG.REASONING_EFFORT", model_selection.reasoning_effort) | ||
| settings.set("MODEL_ROUTING.ENABLE", False) |
There was a problem hiding this comment.
1. Concurrent reviews swap selected models 📘 Rule violation ☼ Reliability
_run_command snapshots and mutates the get_settings() object before awaiting command execution, then unconditionally restores its snapshot in finally. When callers run without an installed request context, overlapping reviews share global_settings, so one task can execute with another task's selector and the last cleanup can restore a stale model.
Agent Prompt
## Issue description
Temporary model-selection settings are mutated on a potentially shared settings object across an awaited review, allowing concurrent commands to interfere with execution and cleanup.
## Fix Focus Areas
- pr_agent/agent/pr_agent.py[323-374]
- pr_agent/config_loader.py[50-63]
## Recommended Fix
Give each command invocation an isolated context-local settings copy before applying selector overrides, and keep snapshot restoration within that isolated context. Add an asynchronous overlap test proving two selectors retain their own model and leave the baseline settings unchanged.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| model_selection = None | ||
| if action == "review": | ||
| try: | ||
| settings = get_settings() |
There was a problem hiding this comment.
2. Command dispatch owns unrelated work 📘 Rule violation ⚙ Maintainability
_run_command now parses selector configuration, emits rejection responses and telemetry, scopes four settings, and dispatches all command classes. A change to selector validation, cleanup, or ordinary dispatch must edit the same exception path, so these independently evolving behaviors cannot be tested or changed in isolation.
Agent Prompt
## Issue description
The command dispatcher now combines selector resolution, rejection handling, temporary settings management, telemetry, and command execution.
## Fix Focus Areas
- pr_agent/agent/pr_agent.py[298-374]
## Recommended Fix
Extract selector resolution and rejection handling into one helper and temporary model settings into a dedicated context manager. Leave `_run_command` responsible for selecting and invoking the command while preserving the existing telemetry and cleanup behavior.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| try: | ||
| effort = ReasoningEffort(effort).value |
There was a problem hiding this comment.
3. Minimal claude reviews ignore effort 🐞 Bug ≡ Correctness
parse_review_model_selection accepts minimal for every alias even though the adaptive Claude request path cannot transmit that effort. With the shipped fable alias, /review fable+minimal enables adaptive thinking but sends neither an output effort nor a generic reasoning effort, so the provider chooses its default instead.
Agent Prompt
## Issue description
The selector accepts `minimal` for adaptive Claude aliases, but the Claude adaptive-thinking handler does not transmit that value. The review therefore runs with provider-default effort rather than the caller's selected effort.
## Fix Focus Areas
- pr_agent/algo/review_model_selection.py[161-171]
- pr_agent/agent/pr_agent.py[339-344]
- pr_agent/algo/ai_handlers/litellm_ai_handler.py[3571-3579]
## Recommended Fix
Validate model-specific effort compatibility before executing the review. For recognized adaptive Claude models, reject `minimal` with an actionable selector error unless the handler is changed to support an explicit, semantically equivalent provider value; add an integration test covering `/review fable+minimal`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit 399ed8b |
|
Follow-up on the latest review: commit 399ed8b fixes both confirmed findings. Disabled malformed selectors now match configured alias names before effort validation; repository-selected external configuration is blocked by protecting CONFIG.EXTRA_CONFIG_URL from local repository overrides. Regression coverage checks malformed selectors, ordinary plus text, case variations, and repeated settings applications with and without an operator-provided external source. All 73 focused tests and pre-commit checks pass locally, and build-and-test plus CodeQL pass on that exact commit. The separate checkout-alias claim was resolved with reproduction evidence: the pinned configuration disables the TOML core loader, so the cited pyproject load does not change alias controls. |
|
First of all, thanks for the work on this. I appreciate your work on this, but unfortunately we'll have to decline this one 😔❤️ For future work, let's discuss via issues or LinkedIn to make sure no work goes to waste, as I really appreciate the time and effort you put into this 🙏 |
|
Sorry from my side @elijahchancey. I drove you through weeks of hardening and rebases before the scope call was made, and that ordering was backwards. Thank you for the care you put in and apologies again. |
Summary
/review alias+effortsyntax, for example/review fable+highconfig.modelandconfig.reasoning_effortpathScope
Each review accepts at most one selector. The selector changes the primary model and effort for that invocation; the installation's normal configured fallback behavior still applies.
The feature is disabled by default. Alias enablement and mappings are global-only so a reviewed repository cannot redefine operator-managed shorthand. This PR does not change permissions or behavior for the existing
config.modelandfallback_modelssettings.Explicit non-goals
Validation
git diff --checkpassed