-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: prevent duplicate updates when multiple agents share the same file #1259
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
Conversation
Add processed_files tracking in update_all_existing_agents() to ensure files referenced by multiple agent variables (e.g., AGENTS.md used by opencode, codex, amp, shai, q, and bob) are only updated once when updating all existing agents.
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.
Pull request overview
This PR adds duplicate prevention logic to the update_all_existing_agents() function to prevent multiple updates when different agent variables point to the same physical file. The implementation uses a bash associative array to track which files have already been processed.
Key changes:
- Introduced
processed_filesassociative array to track updated files - Added duplicate check conditions to all agent file update blocks
- Marked each processed file in the tracking array after update
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| processed_files["$CODEBUDDY_FILE"]=1 | ||
| found_agent=true | ||
| fi | ||
|
|
Copilot
AI
Nov 27, 2025
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.
The update_all_existing_agents() function is missing a check for AMP_FILE. According to the update_specific_agent() function (line 620-621), "amp" is a valid agent type that uses $AMP_FILE which points to $REPO_ROOT/AGENTS.md (same as AGENTS_FILE, Q_FILE, and BOB_FILE).
While the duplicate prevention logic will handle the case where multiple variables point to the same file, the function should still include a check for AMP_FILE for completeness and consistency with the update_specific_agent() function. The check should be added after the CODEBUDDY_FILE check and before the SHAI_FILE check to maintain alphabetical ordering:
if [[ -f "$AMP_FILE" ]] && [[ -z "${processed_files[$AMP_FILE]}" ]]; then
update_agent_file "$AMP_FILE" "Amp"
processed_files["$AMP_FILE"]=1
found_agent=true
fi| if [[ -f "$AMP_FILE" ]] && [[ -z "${processed_files[$AMP_FILE]}" ]]; then | |
| update_agent_file "$AMP_FILE" "Amp" | |
| processed_files["$AMP_FILE"]=1 | |
| found_agent=true | |
| fi |
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.
I didn't introduce the issue of the missing check for AMP_FILE - it was already missing in the existing code (and I wouldn't know whether that omission was intentional or not)
|
Thanks for the recommendation here, @carlo42 - we're going to take a different approach here, consolidating the AGENTS.md file as just one variable. |
This PR was created with the help of Cursor
Problem Summary
The
update_all_existing_agents()function in.specify/scripts/bash/update-agent-context.shprocesses the same file multiple times when multiple variables point to the same file path. This can cause the "Recent Changes" section in agent context files to be incorrect.Root Cause
Multiple Variables Point to Same File
The following variables all point to the same file (
$REPO_ROOT/AGENTS.md):Function Processes File Multiple Times
In
update_all_existing_agents()(lines 640-719), the function checks each variable independently:Since all three variables point to the same file, when
AGENTS.mdexists, it gets processed three times in a single function call.Impact
Data Loss
AGENTS.md fileFunctional Impact
grepchecksAGENTS.mdfile may lead to misleading context about what each feature addedAffected Files
AGENTS.md- processed 3 timesAGENTS.md)How the Fix Works
Testing
Tested by setting up a minimum test environment with dummy
AGENTS.mdandplan.mdfiles and ran theupdate_all_existing_agents()function to verify the contents of theAGENTS.mdupdate