fix: eliminate duplicate system_reminder prompt injection in format_chat_chunks - #5630
Closed
AaronGoodrum wants to merge 1 commit into
Closed
fix: eliminate duplicate system_reminder prompt injection in format_chat_chunks#5630AaronGoodrum wants to merge 1 commit into
AaronGoodrum wants to merge 1 commit into
Conversation
|
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Upstream Pull Request Proposal for
Aider-AI/aiderPR Title
fix: eliminate duplicate system_reminder prompt injection in format_chat_chunksPR Description
Summary
Fixes a prompt duplication issue in
format_chat_chunks()wheresystem_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.pywhereshell_cmd_reminderwas an exact duplicate ofshell_cmd_prompt.Root Cause
In
aider/coders/base_coder.py(format_chat_chunks()):main_sys += "\n" + self.fmt_system_prompt(self.gpt_prompts.system_reminder)unconditionally appendedsystem_reminderinto the primary system prompt.reminder_messagecontaining the samesystem_reminderand sent it as a trailingchunks.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
aider/coders/base_coder.py:Only append
system_remindertomain_syswhen trailing reminders are not active (self.main_model.reminder == "none").aider/coders/shell.py:Set
shell_cmd_reminder = ""to avoid repeating the identical 6-bullet examples list that is already present inshell_cmd_prompt.tests/basic/test_coder.py:Added regression test asserting that
system_reminderis only present once in the formatted message chunks whenmodel.reminder == "sys".Measured Token Savings (Default
editblockformat)main_sys)Verification