Repository navigation
Conversation
ExtensionRegistry._save() opened .specify/extensions/.registry with "w", truncating it, and then streamed the JSON. When the write failed part-way (disk full, interrupted process, a value json.dump cannot encode) the registry was left truncated. _load() treats that as a corrupt registry and starts from an empty one, so every installed extension dropped out of it and the next successful save made the loss permanent. Write the JSON to a temporary file in the same directory and os.replace it over the registry, keeping the existing file mode, as the workflow package registry already does. Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The registry writer forces mode 0644 on first save despite a restrictive umask, exposing installed-extension metadata to other local users in traversable project directories.
1 open issue
What changed in this PR
This PR makes Specify CLI’s extension registry writes atomic so failed writes preserve previously saved extension records.
Changes:
- Write JSON to a temporary file, then replace the registry atomically.
- Preserve existing file permissions and clean up temporary files.
- Add tests for interrupted writes and successful saves with permission preservation.
Review authored by GitHub Copilot (model: unknown; autonomous) for the requesting reviewer; analysis and wording are AI-generated. Project tests were not run during this review.
| File | Description |
|---|---|
tests/test_extensions.py |
Adds interrupted-write regression and successful-save coverage. |
src/specify_cli/extensions/__init__.py |
Replaces direct registry writes with temporary-file creation and atomic replacement. |
Review effort: Balanced (adaptive)
Comment on lines
+851
to
+853
| except OSError: | ||
| mode = 0o644 | ||
| temp_path.chmod(mode) |
| except OSError: | ||
| mode = 0o644 | ||
| temp_path.chmod(mode) | ||
| os.replace(temp_path, self.registry_path) |
Collaborator
|
Please address Copilot feedback and fix test & lint errors |
This branch has not been deployed
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
When a write of the extension registry (
.specify/extensions/.registry) fails part-way, all installed extensions drop out of the registry.Where:
ExtensionRegistry._save()insrc/specify_cli/extensions/__init__.py.Root cause:
_save()opened the registry withopen(path, "w"), which truncates it immediately, and then streamedjson.dumpinto it. If the write stopped part-way, the file was left holding a JSON prefix. That can come from a disk-fullOSError, an interrupted process, or a metadata valuejson.dumpcannot encode._load()treats an unparseable registry as corrupt and starts from{"extensions": {}}, so every installed extension disappears fromextension list. The extension directories and hooks stay on disk. The next successful save (anyextension add/enable/disable/remove) then writes that empty registry for good.Reproduction (
tests/test_extensions.py::test_interrupted_save_keeps_previous_registry):first-ext.json.dumpwrite the first 20 characters and raiseOSError(28, "No space left on device")while addingsecond-ext.On
main(59d61c5) the registry file is left as{\n "schema_version", and a freshExtensionRegistryreportsfirst-extas not installed. A realTypeErrormid-dump does the same: onmain,registry.add("b", {"v": object()})afteradd("a", …)leaves a registry that reloads withouta.The disk-full case is simulated in the test, not captured from a real full disk. The non-serializable case is a real, unmocked trigger, but I have no caller that passes such a value today. The concrete risk is a write that is interrupted or out of space.
Fix: write the JSON to a temp file in the same directory (
tempfile.mkstemp), copy the existing registry's mode onto it (0o644for a new file), andos.replaceit over the registry. Thefinallyblock removes the temp file if anything fails. A failed save now leaves the previous registry byte-for-byte intact. This is the same temp-file +os.replacepattern the workflow package registry andshared_infra._write_shared_bytesalready use.before_file_change/after_file_changeare called as before.Behavior differences I checked (main vs. this branch, Python 3.14, macOS):
mainjson.dump+OSError)TypeError)064006440644.registryis a directoryIsADirectoryErrorIsADirectoryError.registryis a symlink to a fileThe last row is the one intentional change.
os.replacedoes not follow a symlink at the destination, so the registry stays inside the project. The workflow package registry's atomic writer behaves the same way.PresetRegistry._save()(src/specify_cli/presets/_registry.py) has the same truncate-then-write pattern. I left it out to keep this PR to one concern and can send it separately if wanted.Testing
test_interrupted_save_keeps_previous_registry(regression) fails onmain(registry text truncated to{\n "schema_version") and passes with the fix.test_save_replaces_registry_and_keeps_its_mode(POSIX) checks that a successful save writes both entries, keeps a0640mode and leaves no temp file. It passes onmaintoo; it guards the new write path.Commands run on macOS, Python 3.14 (CI matrix version):
.venv/bin/python -m pytest tests/test_extensions.py tests/specify_cli/extensions tests/test_presets.py -q -n 6: 827 passedfull suite
LC_ALL=en_US.UTF-8 .venv/bin/python -m pytest tests -q -n 6: 16796 passed, 620 skipped, 1 failed. The failure istest_version_execution.py::…::test_non_windows_uv_tool_dry_run_still_previews_installer, which fails the same way on unmodifiedmainin my environment (Rich wraps the long temp path).ruff check src tests(ruff 0.15.0, as inlint.yml): cleanReal CLI on a sample project, run against this branch:
specify extension add --dev extensions/selftest, thenextension list,disable,enable,remove --force. All exited 0. The registry contents were correct after each step, and no temp files were left in.specify/extensions/.Tested locally with
.venv/bin/specify --helpRan relevant existing tests with
.venv/bin/python -m pytest tests -q(withLC_ALL=en_US.UTF-8on macOS)Tested with a sample project (extension lifecycle above)
Slash commands: only the way the registry file is written changes, not its contents, so no
/speckit.*command behavior is affected, and I did not run one through an agent.AI Disclosure
AI disclosure: Found, reproduced, fixed and tested by Claude Code (model: Claude Opus 5.5) running autonomously on behalf of GitHub user divya0795. AI wrote the code, the tests and this description. The commit carries an
Assisted-by:trailer. No human reviewed this change line by line before submission. Any later replies on this PR made by the agent will say so.🤖 Generated with Claude Code