Skip to content

fix: use instance prompt variable for user prompt in code suggestions#2270

Open
wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
wishhyt:fix/code-suggestions-user-prompt
Open

fix: use instance prompt variable for user prompt in code suggestions#2270
wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
wishhyt:fix/code-suggestions-user-prompt

Conversation

@wishhyt
Copy link
Copy Markdown

@wishhyt wishhyt commented Mar 18, 2026

Summary

  • In _get_prediction, the system prompt correctly uses self.pr_code_suggestions_prompt_system which respects the decouple_hunks configuration
  • However, the user prompt is hardcoded to get_settings().pr_code_suggestions_prompt.user, always using the decoupled variant regardless of configuration
  • When decouple_hunks is False, the system prompt uses the not_decoupled version while the user prompt uses the decoupled version, creating contradictory instructions for the AI model

Changes

pr_agent/tools/pr_code_suggestions.py: Changed to use self.pr_code_suggestions_prompt_user instead of get_settings().pr_code_suggestions_prompt.user

Test plan

  • Verify that when decouple_hunks is False, both system and user prompts use the not_decoupled variants
  • Verify default behavior (decouple_hunks=True) is unchanged

The system prompt correctly uses `self.pr_code_suggestions_prompt_system`
(which respects the `decouple_hunks` configuration), but the user prompt
was hardcoded to `get_settings().pr_code_suggestions_prompt.user`,
always using the decoupled variant. When `decouple_hunks` is False,
this creates a mismatch between system and user prompts. Use the
instance variable `self.pr_code_suggestions_prompt_user` instead.

Made-with: Cursor
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Fix user prompt to respect decouple_hunks configuration

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix user prompt to respect decouple_hunks configuration
• Use instance variable instead of hardcoded settings
• Align user prompt with system prompt behavior
Diagram
flowchart LR
  A["get_settings().pr_code_suggestions_prompt.user<br/>(hardcoded, always decoupled)"] -->|replaced with| B["self.pr_code_suggestions_prompt_user<br/>(respects decouple_hunks config)"]
  C["System prompt<br/>(uses instance variable)"] -->|now aligned with| B
Loading

Grey Divider

File Changes

1. pr_agent/tools/pr_code_suggestions.py 🐞 Bug fix +1/-1

Use instance variable for user prompt

• Changed user prompt initialization from hardcoded get_settings().pr_code_suggestions_prompt.user
 to instance variable self.pr_code_suggestions_prompt_user
• Ensures user prompt respects the decouple_hunks configuration setting
• Aligns user prompt behavior with system prompt which already uses instance variable

pr_agent/tools/pr_code_suggestions.py


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects bot commented Mar 18, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. No pytest for prompt change 📘 Rule violation ⛯ Reliability
Description
Prompt-selection behavior was changed but no automated pytest coverage was added, increasing
regression risk for decouple_hunks configurations. Add a unit test to assert that both system and
user prompts are sourced consistently for decoupled vs not-decoupled modes.
Code

pr_agent/tools/pr_code_suggestions.py[392]

+        user_prompt = environment.from_string(self.pr_code_suggestions_prompt_user).render(variables)
Evidence
PR Compliance ID 12 requires adding/updating pytest tests when changes warrant coverage. This PR
changes how the user prompt is selected (runtime behavior), and the PR description indicates only
the production file was changed with a manual verification plan, implying no pytest test was added
for this behavior.

AGENTS.md
pr_agent/tools/pr_code_suggestions.py[386-394]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The prompt-selection logic was changed, but there is no pytest coverage ensuring `decouple_hunks=True/False` selects matching system+user prompt variants.

## Issue Context
This behavior is configuration-dependent and can regress silently (e.g., system uses not-decoupled while user uses decoupled).

## Fix Focus Areas
- pr_agent/tools/pr_code_suggestions.py[77-88]
- pr_agent/tools/pr_code_suggestions.py[386-398]
- tests/unittest/test_pr_code_suggestions_prompt_selection.py[1-200]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant