fix(extensions): preserve keep-config leftover on reinstall (data loss)#3380
Open
jawwad-ali wants to merge 1 commit into
Open
fix(extensions): preserve keep-config leftover on reinstall (data loss)#3380jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
remove(keep_config=True) intentionally leaves the top-level *-config.yml / *-config.local.yml in place and drops the registry entry. A subsequent install_from_directory is not a --force removal (did_remove is False), so the unconditional 'if dest_dir.exists(): shutil.rmtree(dest_dir)' wiped the preserved config and the backup-restore path never ran — silently destroying user configuration the feature promised to keep. Capture the top-level *-config.yml/*-config.local.yml from an existing dest_dir before the rmtree and write them back after the fresh copytree, mirroring the *-config filter the --force restore path already uses. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Description
extension remove --keep-configdeliberately preserves the top-level*-config.yml/*-config.local.ymlin the extension dir and drops the registry entry, so the user can reinstall and keep their configuration. But a subsequentinstall_from_directorysilently destroys it:After a keep-config remove the registry reports not installed, so the reinstall is not a
--forceremoval →did_removeisFalse→ the restore block never runs → the config is gone. Reproduced on main @92b7cf7: a user config (api_key: MY-CUSTOMIZED-VALUE) survivesremove(keep_config=True)but is wiped by the next reinstall — the file doesn't even exist afterward. This is data loss that directly contradicts the feature's promise.Fix
Before the
rmtree, capture any top-level*-config.yml/*-config.local.ymlfrom the existing dest_dir (in-memory), and write them back after the freshcopytree— using the same*-configfilter and symlink guard the--forcerestore path already applies. The--force.backuprestore still takes precedence for that path; this only covers the in-place keep-config leftover.Testing
New
test_reinstall_preserves_keep_config_leftover: install → write custom config →remove(keep_config=True)→ reinstall (no force) → assert the custom config survives. Fails before (config file gone after reinstall — verified by source-stash), passes after. Fulltests/test_extensions.py: 327 passed, 3 skipped (no regressions;keep_config=False/.backup path unaffected).uvx ruff checkclean.AI Disclosure
Found and fixed with Claude Code (Claude Fable 5) under my direction. AI traced the keep-config leftover through the reinstall path and found the restore only fires on
--force; I reproduced the data loss, verified fail-before/pass-after and the full suite, and reviewed the diff.