Skip to content

fix: eliminate duplicate system_reminder prompt injection in format_chat_chunks - #5630

Closed
AaronGoodrum wants to merge 1 commit into
Aider-AI:mainfrom
AaronGoodrum:fix-duplicate-system-reminder
Closed

fix: eliminate duplicate system_reminder prompt injection in format_chat_chunks#5630
AaronGoodrum wants to merge 1 commit into
Aider-AI:mainfrom
AaronGoodrum:fix-duplicate-system-reminder

Conversation

@AaronGoodrum

Copy link
Copy Markdown

Upstream Pull Request Proposal for Aider-AI/aider

PR Title

fix: eliminate duplicate system_reminder prompt injection in format_chat_chunks


PR Description

Summary

Fixes a prompt duplication issue in format_chat_chunks() where system_reminder (typically 2,500–3,000 characters / ~600–750 tokens) was being injected twice on every request for all models configured with trailing reminders (reminder in ("sys", "user")).

Additionally, removes a duplicate 6-bullet examples list in aider/coders/shell.py where shell_cmd_reminder was an exact duplicate of shell_cmd_prompt.


Root Cause

In aider/coders/base_coder.py (format_chat_chunks()):

  1. First injection (top of context): main_sys += "\n" + self.fmt_system_prompt(self.gpt_prompts.system_reminder) unconditionally appended system_reminder into the primary system prompt.
  2. Second injection (bottom of context): Lines ~1330–1341 created reminder_message containing the same system_reminder and sent it as a trailing chunks.reminder (or appended it to the final user message).

As a result, for modern LLMs (GPT-4o, Claude 3.5/3.7, Sonnet, Gemini, DeepSeek, Qwen), the entire ~750-token rules block was duplicated in both the system message and the trailing reminder chunk on every single turn.


Key Changes

  1. aider/coders/base_coder.py:
    Only append system_reminder to main_sys when trailing reminders are not active (self.main_model.reminder == "none").
    if self.main_model.reminder == "none" and self.gpt_prompts.system_reminder:
        main_sys += "\n" + self.fmt_system_prompt(self.gpt_prompts.system_reminder)
  2. aider/coders/shell.py:
    Set shell_cmd_reminder = "" to avoid repeating the identical 6-bullet examples list that is already present in shell_cmd_prompt.
  3. tests/basic/test_coder.py:
    Added regression test asserting that system_reminder is only present once in the formatted message chunks when model.reminder == "sys".

Measured Token Savings (Default editblock format)

Component Before Fix After Fix Net Reduction
System Prompt (main_sys) ~5,117 chars (~1,279 tok) ~2,078 chars (~519 tok) -760 tokens
Trailing Reminder ~3,039 chars (~760 tok) ~2,486 chars (~621 tok) -139 tokens
Total Injected Prompt Overhead ~9,456 chars (~2,364 tok) ~5,864 chars (~1,466 tok) ~900 tokens saved / request

Verification

  • Ran full basic test suite: 478 passed, 0 failed.
  • Confirmed with OpenAI, Anthropic, and local OpenAI-compatible endpoints.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@AaronGoodrum AaronGoodrum closed this by deleting the head repository Aug 25, 2026
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.

3 participants