fix: unify MCP and settings pipelines in cache build#8
Merged
wpfleger96 merged 2 commits intomainfrom Apr 30, 2026
Merged
Conversation
Two independent pipelines (build_merged_settings and install_mcps) wrote to the same agent config files without coordination, causing status to show false-positive diffs for amp, codex, and gemini. The cache now represents the complete expected file state by merging managed MCPs during build_merged_settings via a _merge_managed_mcps hook. Also fixes: MCP install output missing per-agent labels, amp settings.json formatting mismatch, tool install output appearing before profile header, Claude Code UI settings (skipAutoPermissionPrompt) lost on cache rebuild, and work profile model variant (opus vs opus[1m]).
Codex's mcp_settings_key ("mcp_servers") and mcp_tracking_key
("_ai_agent_rules_managed") weren't in preserved_fields, so
get_cache_diff still produced false-positive diffs after the MCP/cache
unification — the same class of bug fixed for Amp and Gemini.
Rather than manually adding MCP keys to each agent's preserved_fields
(which is fragile and caused the Codex omission), adds an
_effective_preserved_fields property that dynamically extends the
static list with MCP keys from the agent's MCPManager. Also guards
_merge_managed_mcps against non-dict MCP entries, and restores dim
ALREADY_INSTALLED output with per-agent labels.
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.
ai-agent-rules installandinstall_mcpswrote to the same agent config files through independent pipelines with no coordination. This causedstatusto show false-positive diffs for amp, codex, and gemini after every install — the cache had settings but not MCPs, so the live files (which had MCPs added byinstall_mcps) always looked out of sync.The fix makes the settings cache the single source of truth for what each agent config file should contain. A
_merge_managed_mcps()hook now runs at the end ofbuild_merged_settings()to reconcile managed MCPs into the cache — adding, updating, and removing stale entries — so the cache and the live file are always consistent. A Codex-specific subtlety (tracking section vs. inline markers) required reading managed-entry identity from[_ai_agent_rules_managed].namesrather than per-entry_managedByfields.MCP keys that need to be preserved across cache rebuilds (
mcp_settings_key,mcp_tracking_key) are now derived dynamically from each agent'sMCPManagervia_effective_preserved_fields, rather than manually added to each agent'spreserved_fields. This prevents the class of bugs where a new agent's MCP key is missed (which happened with Codex'smcp_serversand_ai_agent_rules_managedduring initial implementation).Several related UX issues resolved in the same pass:
statusdiffs for non-symlink JSON files (amp, gemini) now normalize formatting before comparing, eliminating false diffs from whitespace differencesinstall_mcpsreturnsALREADY_INSTALLEDand skips file writes when nothing changed_merge_managed_mcpsguards against non-dict MCP entries to avoidAttributeErroron malformed user configsinstalloutputskipAutoPermissionPromptadded to Claude's base settings alongsideskipDangerousModePermissionPromptwork.yamlprofile model corrected toopus[1m]to stop cache rebuilds overwriting the 1M context variant