-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(config): prevent .pr_agent.toml state leak between repositories #2346
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
tharatynowicz
wants to merge
1
commit into
The-PR-Agent:main
from
tharatynowicz:fix/apply-repo-settings-state-leak
+251
−2
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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -11,7 +11,9 @@ | |
| from dynaconf.loaders import env_loader | ||
| from starlette_context import context | ||
|
|
||
| from pr_agent.config_loader import get_settings | ||
| from pr_agent.config_loader import (get_settings, | ||
| note_repo_setting_override, | ||
| reset_repo_settings_overrides) | ||
| from pr_agent.custom_merge_loader import (MAX_TOML_SIZE_IN_BYTES, | ||
| validate_file_security) | ||
| from pr_agent.git_providers import get_git_provider_with_context | ||
|
|
@@ -218,6 +220,9 @@ def _apply_settings_from_file(path: str, label: str): | |
| continue | ||
| section_dict = copy.deepcopy(get_settings().as_dict().get(section, {})) | ||
| for key, value in contents.items(): | ||
| # Record the pre-override value first so it can be reverted on the | ||
| # next apply_repo_settings() (prevents cross-repo state leaks). | ||
| note_repo_setting_override(section, key) | ||
| section_dict[key] = value | ||
| get_settings().unset(section) | ||
| get_settings().set(section, section_dict, merge=False) | ||
|
|
@@ -240,6 +245,12 @@ def _apply_settings_from_file(path: str, label: str): | |
| def apply_repo_settings(pr_url): | ||
| os.environ["AUTO_CAST_FOR_DYNACONF"] = "false" | ||
|
|
||
| # Revert keys overridden by a previously-reviewed repo's .pr_agent.toml (or the extra | ||
| # config merged below) so they cannot leak into this call via the shared settings | ||
| # singleton. Only repo-settings-managed keys are touched — see | ||
| # reset_repo_settings_overrides(). | ||
| reset_repo_settings_overrides() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Stale claude model keys With the new selective reset, only keys recorded via note_repo_setting_override() are reverted, but apply_repo_settings() can also mutate config.model_weak and config.fallback_models via set_claude_model() without recording them. This allows repo-specific model_weak/fallback_models to leak into subsequent repos even after config.model is reverted, creating inconsistent model selection. Agent Prompt
|
||
|
|
||
| # Apply external/shared config FIRST, before constructing the git provider: | ||
| # provider initialisers (e.g. GitLabProvider reads GITLAB.PERSONAL_ACCESS_TOKEN | ||
| # at __init__) need to see any provider-critical settings that come from the | ||
|
|
@@ -365,6 +376,9 @@ def _apply_repo_settings_file(repo_settings_file): | |
| continue | ||
| section_dict = copy.deepcopy(get_settings().as_dict().get(section.upper(), {})) | ||
| for key, value in contents.items(): | ||
| # Record the pre-override value first so it can be reverted on the next | ||
| # apply_repo_settings() (prevents cross-repo state leaks, issue #2345). | ||
| note_repo_setting_override(section, key) | ||
| section_dict[key] = value | ||
| get_settings().unset(section) | ||
| get_settings().set(section, section_dict, merge=False) | ||
|
|
@@ -440,6 +454,11 @@ def set_claude_model(): | |
| set the claude-sonnet-3.5 model easily (even by users), just by stating: --config.model='claude-3-5-sonnet' | ||
| """ | ||
| model_claude = "bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0" | ||
| # Record the pre-override values so these derived keys are reverted alongside | ||
| # config.model on the next apply_repo_settings() — otherwise a repo that selects | ||
| # the claude shorthand would leak model_weak/fallback_models into later repos. | ||
| for key in ("model", "model_weak", "fallback_models"): | ||
| note_repo_setting_override("config", key) | ||
| get_settings().set('config.model', model_claude) | ||
| get_settings().set('config.model_weak', model_claude) | ||
| get_settings().set('config.fallback_models', [model_claude]) | ||
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
Oops, something went wrong.
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.
1. Override ledger crosses requests
🐞 Bug⛨ SecurityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools