Skip to content

fix(improve): require improved_code to be complete, without ellipsis (#2086) - #2626

Closed
IsmaelMartinez wants to merge 3 commits into
The-PR-Agent:mainfrom
IsmaelMartinez:fix/2086-improved-code-ellipsis
Closed

IsmaelMartinez wants to merge 3 commits into
The-PR-Agent:mainfrom
IsmaelMartinez:fix/2086-improved-code-ellipsis

Conversation

@IsmaelMartinez

Copy link
Copy Markdown
Collaborator

The existing_code brevity instruction leaks ... into improved_code, producing committable suggestions that can't be applied (#2086). This requires improved_code to be a complete replacement in both prompt variants and marks the example placeholders as meta in the system prompt, as sketched by @yefuyou in the issue thread. Fixes #2086.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the bug label Aug 11, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Require improved_code to be complete (no ellipsis) in code suggestion prompts

🐞 Bug fix ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Prevent ... from leaking into improved_code suggestions that should be directly applicable.
• Require improved_code to be a full replacement snippet in both prompt variants.
• Clarify that example ... placeholders are meta text, not output content.
Diagram

graph TD
  U[Reviewer/User] --> P1["pr_code_suggestions_prompts.toml"] --> L{{LLM}}
  U --> P2["pr_code_suggestions_prompts_not_decoupled.toml"] --> L --> O[CodeSuggestion output] --> A[Apply suggestion]
  subgraph Legend
    direction LR
    _file["Prompt file"] ~~~ _ext{{External model}} ~~~ _proc[Processing step]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Add output validation (reject ellipsis/placeholders in improved_code)
  • ➕ Hard guarantees even if the model ignores prompt instructions
  • ➕ Produces actionable error messages and enables retries automatically
  • ➖ Requires changes in parsing/validation path beyond prompt updates
  • ➖ May increase retries/latency if violations are common
2. Post-process to detect `...` and request regeneration
  • ➕ Minimal schema changes; can be layered onto existing flow
  • ➕ Targets the specific failure mode with simple heuristics
  • ➖ Heuristic-based; may miss other placeholder patterns
  • ➖ Adds an extra model call when regeneration is needed

Recommendation: The prompt-level requirement is the simplest and most direct fix for #2086, and it keeps both prompt variants aligned. If ellipsis still appears in practice, add a lightweight validator/regeneration loop to enforce the constraint deterministically.

Files changed (2) +4 / -2

Bug fix (2) +4 / -2
pr_code_suggestions_prompts.tomlRequire complete improved_code and mark example ellipsis as meta +2/-1

Require complete improved_code and mark example ellipsis as meta

• Strengthens the 'improved_code' field description to require a full, ready-to-apply replacement snippet (no ellipsis or placeholders). Adds a note near the YAML example indicating that '...' is a placeholder to be replaced with real content.

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml

pr_code_suggestions_prompts_not_decoupled.tomlEnforce complete improved_code in non-decoupled prompt variant +2/-1

Enforce complete improved_code in non-decoupled prompt variant

• Mirrors the same 'improved_code' completeness requirement in the not-decoupled prompt template. Clarifies the example block by explicitly labeling '...' as placeholder content.

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Non-YAML example footnote ✓ Resolved 🐞 Bug ☼ Reliability
Description
The prompt now includes (replace '...' with actual content) as a standalone line outside the YAML
example block; if the model echoes it, the response may no longer be parseable as pure YAML and
suggestion parsing can fail or rely on fragile fallbacks. This change is duplicated in both prompt
variants, increasing the chance of non-YAML leakage.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[143]

+(replace '...' with actual content)
Evidence
Both prompt templates place the new note as plain text right after the example output. The YAML
loader attempts to parse the full response text with yaml.safe_load() and only then falls back to
heuristic fixes / fenced-snippet extraction, so extra non-YAML text increases parse failure risk.

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[125-146]
pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[114-135]
pr_agent/algo/utils.py[753-768]
pr_agent/algo/utils.py[818-829]

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 prompts add a non-YAML line `(replace '...' with actual content)` immediately after the fenced YAML example. If a model copies it into the response, it can break YAML parsing or force reliance on fallback extraction.
### Issue Context
`load_yaml()` first attempts `yaml.safe_load()` on the response text and only then tries fallback repairs/extraction; avoiding non-YAML artifacts in examples reduces parse failures and variability.
### Fix Focus Areas
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[125-146]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[114-135]

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


2. Ellipsis replacement mismatch 🐞 Bug ≡ Correctness
Description
The prompt still permits existing_code to be shortened with ellipsis while requiring
improved_code to be a complete, ready-to-apply replacement with no ellipsis/placeholders, which
makes the “replacement” contract internally inconsistent for long snippets. This also disables the
tool’s stale one-liner guard (it early-returns when existing_code contains ...), increasing the
likelihood of publishing stale/unhelpful suggestions.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[111]

+    improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion. Must be a complete, ready-to-apply replacement for 'existing_code': never shorten it with ellipsis (...) or use placeholders for omitted code.")
Evidence
The prompt explicitly allows existing_code ellipsis but forbids it for improved_code. In
runtime, the stale one-liner validator bails out when existing_code includes ..., and the
publisher uses improved_code directly for inline suggestions, so shortened existing_code
undermines both contract and validation.

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[104-112]
pr_agent/tools/pr_code_suggestions.py[643-648]
pr_agent/tools/pr_code_suggestions.py[572-590]

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 updated prompt forbids ellipsis/placeholders in `improved_code` but still encourages ellipsis in `existing_code`. When ellipsis is used, `improved_code` cannot be a true ready-to-apply replacement for the real PR lines, and runtime validation explicitly skips checks when `existing_code` contains `...`.
### Issue Context
Inline suggestions publish `improved_code` verbatim inside a ```suggestion``` block; the system relies on clean, applyable snippets.
### Fix Focus Areas
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[104-112]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[93-101]
- pr_agent/tools/pr_code_suggestions.py[643-648]
- pr_agent/tools/pr_code_suggestions.py[572-590]

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


3. Truncation breaks applyability 🐞 Bug ☼ Reliability
Description
The prompt now guarantees improved_code is complete and ready-to-apply, but the tool can truncate
improved_code and append a truncation marker, producing an incomplete/non-applyable suggestion.
This directly contradicts the strengthened prompt contract and can reintroduce “not committable”
suggestions for long edits.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[100]

+    improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion. Must be a complete, ready-to-apply replacement for 'existing_code': never shorten it with ellipsis (...) or use placeholders for omitted code.")
Evidence
The truncation helper can cut improved_code and append an arbitrary marker line. Since the
publishing path embeds improved_code directly as the suggested replacement, truncation can yield
broken, non-applyable code despite the prompt’s new “ready-to-apply” requirement.

pr_agent/tools/pr_code_suggestions.py[499-508]
pr_agent/tools/pr_code_suggestions.py[572-590]
pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[109-112]

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 requires `improved_code` be a complete, ready-to-apply replacement. However, runtime logic may truncate `improved_code` and append a message, which makes the code snippet incomplete and not directly applicable.
### Issue Context
Inline code suggestions render the truncated `improved_code` verbatim inside a ```suggestion``` block.
### Fix Focus Areas
- pr_agent/tools/pr_code_suggestions.py[499-508]
- pr_agent/tools/pr_code_suggestions.py[572-590]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[109-112]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[98-101]

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


Grey Divider

Context

Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.
Tip of the day
💡 Did you know, you can group findings by type and pick your Finding display, from Minimal to Full

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit 3a85481 ⚖️ Balanced

Results up to commit d6c208d


🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)


Remediation recommended
1. Non-YAML example footnote ✓ Resolved 🐞 Bug ☼ Reliability
Description
The prompt now includes (replace '...' with actual content) as a standalone line outside the YAML
example block; if the model echoes it, the response may no longer be parseable as pure YAML and
suggestion parsing can fail or rely on fragile fallbacks. This change is duplicated in both prompt
variants, increasing the chance of non-YAML leakage.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[143]

+(replace '...' with actual content)
Evidence
Both prompt templates place the new note as plain text right after the example output. The YAML
loader attempts to parse the full response text with yaml.safe_load() and only then falls back to
heuristic fixes / fenced-snippet extraction, so extra non-YAML text increases parse failure risk.

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[125-146]
pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[114-135]
pr_agent/algo/utils.py[753-768]
pr_agent/algo/utils.py[818-829]

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 prompts add a non-YAML line `(replace '...' with actual content)` immediately after the fenced YAML example. If a model copies it into the response, it can break YAML parsing or force reliance on fallback extraction.
### Issue Context
`load_yaml()` first attempts `yaml.safe_load()` on the response text and only then tries fallback repairs/extraction; avoiding non-YAML artifacts in examples reduces parse failures and variability.
### Fix Focus Areas
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[125-146]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[114-135]

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


2. Ellipsis replacement mismatch 🐞 Bug ≡ Correctness
Description
The prompt still permits existing_code to be shortened with ellipsis while requiring
improved_code to be a complete, ready-to-apply replacement with no ellipsis/placeholders, which
makes the “replacement” contract internally inconsistent for long snippets. This also disables the
tool’s stale one-liner guard (it early-returns when existing_code contains ...), increasing the
likelihood of publishing stale/unhelpful suggestions.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[111]

+    improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion. Must be a complete, ready-to-apply replacement for 'existing_code': never shorten it with ellipsis (...) or use placeholders for omitted code.")
Evidence
The prompt explicitly allows existing_code ellipsis but forbids it for improved_code. In
runtime, the stale one-liner validator bails out when existing_code includes ..., and the
publisher uses improved_code directly for inline suggestions, so shortened existing_code
undermines both contract and validation.

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[104-112]
pr_agent/tools/pr_code_suggestions.py[643-648]
pr_agent/tools/pr_code_suggestions.py[572-590]

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 updated prompt forbids ellipsis/placeholders in `improved_code` but still encourages ellipsis in `existing_code`. When ellipsis is used, `improved_code` cannot be a true ready-to-apply replacement for the real PR lines, and runtime validation explicitly skips checks when `existing_code` contains `...`.
### Issue Context
Inline suggestions publish `improved_code` verbatim inside a ```suggestion``` block; the system relies on clean, applyable snippets.
### Fix Focus Areas
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[104-112]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[93-101]
- pr_agent/tools/pr_code_suggestions.py[643-648]
- pr_agent/tools/pr_code_suggestions.py[572-590]

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


3. Truncation breaks applyability 🐞 Bug ☼ Reliability
Description
The prompt now guarantees improved_code is complete and ready-to-apply, but the tool can truncate
improved_code and append a truncation marker, producing an incomplete/non-applyable suggestion.
This directly contradicts the strengthened prompt contract and can reintroduce “not committable”
suggestions for long edits.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[100]

+    improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion. Must be a complete, ready-to-apply replacement for 'existing_code': never shorten it with ellipsis (...) or use placeholders for omitted code.")
Evidence
The truncation helper can cut improved_code and append an arbitrary marker line. Since the
publishing path embeds improved_code directly as the suggested replacement, truncation can yield
broken, non-applyable code despite the prompt’s new “ready-to-apply” requirement.

pr_agent/tools/pr_code_suggestions.py[499-508]
pr_agent/tools/pr_code_suggestions.py[572-590]
pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[109-112]

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 requires `improved_code` be a complete, ready-to-apply replacement. However, runtime logic may truncate `improved_code` and append a message, which makes the code snippet incomplete and not directly applicable.
### Issue Context
Inline code suggestions render the truncated `improved_code` verbatim inside a ```suggestion``` block.
### Fix Focus Areas
- pr_agent/tools/pr_code_suggestions.py[499-508]
- pr_agent/tools/pr_code_suggestions.py[572-590]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[109-112]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[98-101]

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


Context used
Results up to commit d2dfa01


🐞 Bugs (3) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)


Remediation recommended
1. Non-YAML example footnote 🐞 Bug ☼ Reliability
Description
The prompt now includes (replace '...' with actual content) as a standalone line outside the YAML
example block; if the model echoes it, the response may no longer be parseable as pure YAML and
suggestion parsing can fail or rely on fragile fallbacks. This change is duplicated in both prompt
variants, increasing the chance of non-YAML leakage.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[143]

+(replace '...' with actual content)
Evidence
Both prompt templates place the new note as plain text right after the example output. The YAML
loader attempts to parse the full response text with yaml.safe_load() and only then falls back to
heuristic fixes / fenced-snippet extraction, so extra non-YAML text increases parse failure risk.

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[125-146]
pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[114-135]
pr_agent/algo/utils.py[753-768]
pr_agent/algo/utils.py[818-829]

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 prompts add a non-YAML line `(replace '...' with actual content)` immediately after the fenced YAML example. If a model copies it into the response, it can break YAML parsing or force reliance on fallback extraction.

### Issue Context
`load_yaml()` first attempts `yaml.safe_load()` on the response text and only then tries fallback repairs/extraction; avoiding non-YAML artifacts in examples reduces parse failures and variability.

### Fix Focus Areas
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[125-146]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[114-135]

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


2. Ellipsis replacement mismatch 🐞 Bug ≡ Correctness
Description
The prompt still permits existing_code to be shortened with ellipsis while requiring
improved_code to be a complete, ready-to-apply replacement with no ellipsis/placeholders, which
makes the “replacement” contract internally inconsistent for long snippets. This also disables the
tool’s stale one-liner guard (it early-returns when existing_code contains ...), increasing the
likelihood of publishing stale/unhelpful suggestions.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[111]

+    improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion. Must be a complete, ready-to-apply replacement for 'existing_code': never shorten it with ellipsis (...) or use placeholders for omitted code.")
Evidence
The prompt explicitly allows existing_code ellipsis but forbids it for improved_code. In
runtime, the stale one-liner validator bails out when existing_code includes ..., and the
publisher uses improved_code directly for inline suggestions, so shortened existing_code
undermines both contract and validation.

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[104-112]
pr_agent/tools/pr_code_suggestions.py[643-648]
pr_agent/tools/pr_code_suggestions.py[572-590]

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 updated prompt forbids ellipsis/placeholders in `improved_code` but still encourages ellipsis in `existing_code`. When ellipsis is used, `improved_code` cannot be a true ready-to-apply replacement for the real PR lines, and runtime validation explicitly skips checks when `existing_code` contains `...`.

### Issue Context
Inline suggestions publish `improved_code` verbatim inside a ```suggestion``` block; the system relies on clean, applyable snippets.

### Fix Focus Areas
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[104-112]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[93-101]
- pr_agent/tools/pr_code_suggestions.py[643-648]
- pr_agent/tools/pr_code_suggestions.py[572-590]

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


3. Truncation breaks applyability 🐞 Bug ☼ Reliability
Description
The prompt now guarantees improved_code is complete and ready-to-apply, but the tool can truncate
improved_code and append a truncation marker, producing an incomplete/non-applyable suggestion.
This directly contradicts the strengthened prompt contract and can reintroduce “not committable”
suggestions for long edits.
Code

pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[100]

+    improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion. Must be a complete, ready-to-apply replacement for 'existing_code': never shorten it with ellipsis (...) or use placeholders for omitted code.")
Evidence
The truncation helper can cut improved_code and append an arbitrary marker line. Since the
publishing path embeds improved_code directly as the suggested replacement, truncation can yield
broken, non-applyable code despite the prompt’s new “ready-to-apply” requirement.

pr_agent/tools/pr_code_suggestions.py[499-508]
pr_agent/tools/pr_code_suggestions.py[572-590]
pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[109-112]

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 requires `improved_code` be a complete, ready-to-apply replacement. However, runtime logic may truncate `improved_code` and append a message, which makes the code snippet incomplete and not directly applicable.

### Issue Context
Inline code suggestions render the truncated `improved_code` verbatim inside a ```suggestion``` block.

### Fix Focus Areas
- pr_agent/tools/pr_code_suggestions.py[499-508]
- pr_agent/tools/pr_code_suggestions.py[572-590]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts.toml[109-112]
- pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml[98-101]

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


Context used
Qodo Logo

…comment

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@IsmaelMartinez

Copy link
Copy Markdown
Collaborator Author

Addressed the review:

  1. Non-YAML example footnote — applied in d6c208d5: the note now lives inside the fenced example as a YAML comment, so it stays parse-safe even if echoed.
  2. Ellipsis replacement mismatch — not applied: keeping ellipsis allowed in existing_code is the intentional scope here (see the issue thread); the runtime guard already skips committable publishing when existing_code is shortened, and forbidding it there would change suggestion localization behavior beyond this fix.
  3. Truncation breaks applyability — not applied: the truncation helper is a pre-existing publisher safeguard independent of the prompt contract; worth its own issue if it bites in practice.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit d6c208d

…ML comment

Keeps the parse-safety fix consistent when duplicate_prompt_examples=true.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit 3a85481

@yefuyou yefuyou left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for addressing the duplicated prompt examples.

@IsmaelMartinez

Copy link
Copy Markdown
Collaborator Author

Hi @naorpeled , this should be ready for review. Thanks in advance!

@IsmaelMartinez

Copy link
Copy Markdown
Collaborator Author

Closing in favour of a community pick-up: main needs an approving review from a second maintainer and I cannot approve my own PR, so this has sat green since 11 August. The change stays on fix/2086-improved-code-ellipsis as a reference implementation, and #3409 is open as help wanted for anyone who wants to land it.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

system instructions to shorten 'existing_code' is polluting generated 'improved_code'

3 participants