Skip to content

fix(extensions): restore native outputs after a failed install - #5625

Open
aarjang wants to merge 13 commits into
github:mainfrom
aarjang:fix/5379-native-skill-rollback
Open

aarjang wants to merge 13 commits into
github:mainfrom
aarjang:fix/5379-native-skill-rollback

Conversation

@aarjang

@aarjang aarjang commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #5379.

Use the existing file journal during native extension registration. If registration fails, the journal restores the files the attempt replaced and removes the outputs it created. It also removes newly created output directories when they are empty.

Related work is open in #5384.

Testing

  • Ran .venv/bin/specify --help.
  • Ran .venv/bin/python -m pytest tests/test_extension_skills.py tests/test_extensions.py tests/specify_cli/extensions/test_skill_resources.py tests/specify_cli/extensions/test_command_add.py tests/specify_cli/integrations/test_command_switch.py tests/integrations/test_file_changes.py -q on macOS with Python 3.13. All 942 tests passed.
  • Confirmed the registry-failure regression fails before the journal is applied and passes afterward. Existing coverage also checks a hook registration failure and survival of unrelated user files.

AI Disclosure

  • I used AI assistance for this contribution.

Claude Code (Claude Fable 5, supervised, as recorded in the original commit trailer) helped develop the initial fix and regression tests. Codex (GPT-6, autonomous agent mode) integrated the journal, added rollback coverage, ran verification, and drafted this PR on behalf of @aarjang.

… add

When install_from_directory failed after command registration (hook
registration or the final registry write), the rollback removed the
installed package and registry entry but left the native skill outputs
(<skills dir>/speckit-<ext>-<cmd>/SKILL.md) and command files written
by the attempt behind. They were recorded nowhere, so no later
lifecycle operation owned them. The generic route's
rollback_generic_registration already retires its outputs; the failure
path now does the same for non-generic agents by unregistering the
commands and skills this attempt registered. Both unregister paths
only remove outputs they can verify as spec-kit's own, so user skills
are untouched.

Fixes github#5379

Assisted-by: Claude Code (model: Claude Fable 5, supervised)
Restore the exact output files touched by a failed native installation, including prior contents, without broad unregistration.

Assisted-by: Codex (model: GPT-6, autonomous)
@aarjang
aarjang requested a review from mnriem as a code owner November 29, 2026 18:52
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 18:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical failure path during native force reinstalls replaces recovered user configuration with packaged defaults if registry registration fails, and a plain retry does not restore the backup.

1 open issue
What changed in this PR

Addresses #5379 by applying the existing file journal to native extension registration, restoring replaced outputs and removing newly created outputs when installation fails.

Changes:

  • Wrap native registration in a rollback journal while respecting existing lifecycle transactions.
  • Track output-directory creation so rollback can remove newly created empty directories.
  • Add regressions for hook and registry failures, output restoration, and preservation of unrelated user skills.

AI-generated review for the requester by GitHub Copilot (model: unknown; autonomous).

File Description
tests/​test_extension_skills.py Adds native-output rollback regression tests.
src/​specify_cli/​integrations/​_lifecycle.py Adds the extension-registration journal context manager.
src/​specify_cli/​extensions/​__init__.py Applies journaling to native registration and tracks skill directories.
src/​specify_cli/​agents.py Uses journal-aware directory creation for command outputs and caches.

Review effort: Balanced (adaptive)

Comment thread src/specify_cli/extensions/__init__.py Resolved
…guard

Use FileHelper for trusted root identities and keep the output publication step separate from journal setup.

Assisted-by: Codex (model: GPT-6, autonomous)
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 19:01
Reuse the durable kept-config recovery path for native force reinstalls so a registration failure can be retried without replacing user settings.

Assisted-by: Codex (model: GPT-6, autonomous)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The rollback logic can lose user configuration after a failed forced reinstall, while symlinked command directories can cause installation to succeed without publishing commands.

3 open issues

Review effort: Balanced (adaptive)

Comment thread src/specify_cli/extensions/__init__.py Resolved
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 19:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A forced native reinstall can remove the existing installation before rejecting a symlinked config, and the output journal starts too late to restore it.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Unused nonexistent HOME blocks project-local installs

src/​specify_cli/​integrations/​_lifecycle.py:531

Project-local native installs now fail when HOME points to a nonexistent directory: the caller includes Hermes's home scope even when another integration is active, and FileHelper(home) requires an existing root. This happens after the extension package has been copied, despite registration not needing any home output. Derive home scopes from the actual registration targets so unused home directories do not block installation.

AI-generated review: GitHub Copilot, model unknown, autonomous; entirely AI-authored for the requesting user (identity unavailable).

Medium severity Add rollback tests for symlinked and home-scoped paths

src/​specify_cli/​integrations/​_lifecycle.py:542

The new path remapping lacks rollback coverage for symlinked project roots and home-scoped outputs; the added failure tests use ordinary project-local Claude paths. Add failure-path tests for lexical/canonical project aliases and a home-scoped Hermes destination, checking restoration of existing bytes, removal of new outputs, and preservation of existing directories. These tests are needed because the remapping determines which paths rollback overwrites or deletes.

AI-generated by GitHub Copilot (model: unknown; autonomous), entirely AI-authored for the requesting reviewer.

2 resolved since last review

Review effort: Balanced (adaptive)

Comment thread src/specify_cli/extensions/__init__.py Resolved
@aarjang

aarjang commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

The native install rollback and config recovery follow-ups are pushed in 3fd4a3ba. All 943 focused tests passed locally on macOS, including the retry regression for preserving user config. Ruff and the FileHelper migration check also passed.

Could a maintainer approve the pending GitHub Actions workflows for this fork PR so Test Python, Lint & Security, and CodeQL can run?

AI disclosure — Codex (GPT-6, autonomous agent mode) implemented the follow-ups, ran the local tests, and drafted this comment on behalf of aarjang.

Report journal refusals as install errors and validate kept configuration before removing an installed native extension.

Assisted-by: Codex (model: GPT-6, autonomous)
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A symlinked skills destination can leave newly created directories behind because validation happens after directory creation and rollback rejects the same path.

1 open issue
2 resolved since last review

Review effort: Balanced (adaptive)

Comment thread src/specify_cli/agents.py
if not self._generic_owned_output(dest_file, source_id, project_root):
continue
dest_file.parent.mkdir(parents=True, exist_ok=True)
make_directories(dest_file.parent)
@aarjang

aarjang commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

I pushed both earlier follow-ups in ae7faa6c. A refused output write now stops the install before the registry is committed, and force reinstall checks kept configuration before removing the existing extension. All 1,052 focused tests passed locally, along with Ruff and the FileHelper migration check.

Could a maintainer re-review the PR and mark conversations resolved once their fixes are verified? GitHub already marks the two earlier threads resolved. The new directory-creation thread remains open for review.

AI disclosure — Codex (GPT-6, autonomous agent mode) implemented the follow-ups, reran verification, and drafted this comment on behalf of aarjang.

Apply the extension journal’s existing destination checks before creating registration directories. Cover both command and native Skill layouts in the blocked-destination regression.

Assisted-by: Codex (model: GPT-6, autonomous)
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 19:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because force-reinstall cleanup can fail on directory symlinks, leaving commands and skills unregistered while the extension remains marked as installed.

1 open issue

Review effort: Balanced (adaptive)

@aarjang

aarjang commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

The directory-creation fix is pushed in d3235b61. Extension registration now validates the output directory before creating it. The regression test covers both Claude skills and Gemini commands, and all 1,053 focused tests passed locally.

Could a maintainer re-review this change and resolve the directory-creation thread if the fix addresses the concern?

AI disclosure — Codex (GPT-6, autonomous agent mode) implemented the fix, ran the tests, and drafted this comment on behalf of aarjang.

Remove links in the old extension package without traversing their targets. Cover forced reinstall and preservation of user configuration and registered skills.

Assisted-by: Codex (model: GPT-6, autonomous)
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 20:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Helper calls double-apply relative project roots, breaking kept-config removal and native force reinstalls while silently skipping config preflight validation.

2 open issues

Review effort: Balanced (adaptive)

Comment thread src/specify_cli/extensions/__init__.py Resolved
@aarjang

aarjang commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

The forced-reinstall cleanup fix is pushed in 8dfff347. Cleanup now removes a directory link while preserving its target and the user's configuration. The new regression failed before the fix, and all 1,054 focused tests passed locally afterward.

Could a maintainer re-review the fix and resolve the conversation if it addresses the cleanup concern?

The separate follow-up about relative project roots remains open.

AI disclosure — Codex (GPT-6, autonomous agent mode) implemented the fix, ran the tests, and drafted this comment on behalf of aarjang.

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 30, 2026
@mnriem

mnriem commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

Assert that a failed force reinstall preserves the original link and identifies the same settings file even when Windows reports an extended-length target.

Assisted-by: Codex (model: GPT-6, autonomous)
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 05:54
@aarjang

aarjang commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 9385c889. The force-reinstall regression now checks that the original symlink and its target file are preserved, including when Windows reports an extended-length path. The local run also covered the Claude and Gemini cases for the directory-creation thread, with and without an outer transaction. The 1,236 focused tests and 698 adapter tests passed locally on macOS, along with Ruff and the FileHelper migration check.

Could a maintainer approve the GitHub Actions workflows for this commit and re-review the PR?

AI disclosure: OpenAI Codex (GPT-6, Default mode, autonomous) implemented and tested the fixes and drafted and posted this update on behalf of @aarjang at their request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Interacting rollback contracts across nested journals, native extension publishing, and forced-reinstall configuration rescue warrant maintainer review.

1 open issue

Review effort: Balanced (adaptive)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A registry save failure leaves the cache marking a rolled-back extension as installed, blocking retries because the cached registry snapshot is not restored.

2 open issues

Review effort: Balanced

Comment thread src/specify_cli/extensions/__init__.py Resolved
Scope the working-directory change to each relative-project test so it is restored before the temp_dir fixture runs. Windows cannot remove the process working directory and raised WinError 32 for four cases during teardown.

Assisted-by: Codex (model: GPT-6, autonomous)
Copilot AI balanced review requested due to automatic review settings December 2, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because a failed registry save can leave an extension marked installed in memory, blocking retries or republishing the failed entry later.

2 open issues

Review effort: Balanced

@mnriem

mnriem commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

…stall

Restore the native registry snapshot when publishing fails so the same manager can retry. Cover failures before and after the registry file is written.

Assisted-by: Codex (model: GPT-6, autonomous)
Copilot AI balanced review requested due to automatic review settings December 2, 2026 13:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Interacting rollback contracts across nested lifecycle journals, shared registry state, home-scoped outputs, and force-reinstall config rescue require broader review.

1 open issue
1 resolved since last review

Review effort: Balanced

@aarjang

aarjang commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 3df50a07. A failed native registry save now restores the in-memory registry so a retry can succeed with the same manager. The regression covers failure both before and after the registry write. This revision also includes 9e4ee613, which restores the working directory before temporary-directory cleanup in the Windows regression tests. All 1,237 focused tests passed locally on macOS, including the destination-directory cases.

Could a maintainer approve the GitHub Actions workflows for the new commit and re-review the PR?

AI disclosure: OpenAI Codex (GPT-6, Default mode, autonomous) implemented and tested the changes and drafted and posted this update on behalf of @aarjang at their request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Failed-install regression coverage is missing for home-scoped outputs, including restoration of existing files, cleanup of new outputs and project markers, and preservation of unrelated files.

2 open issues

Review effort: Balanced

Comment on lines +561 to +562
scopes = [home_path(scope) for scope in home_scopes]
transaction = _journalled(canonical, [], scopes, {"retained": False}, initial={})
@mnriem

mnriem commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

Verify failed registry publication restores existing home output, removes new skills and the project marker, preserves unrelated home files, and permits retry.

Assisted-by: Codex (model: GPT-6, autonomous)
Copilot AI balanced review requested due to automatic review settings December 2, 2026 14:46
@aarjang

aarjang commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 600f8911. The Hermes regression verifies that a failed registry write restores existing home-scoped skills, removes new skills and the project marker, preserves unrelated files, and allows a retry. The Claude and Gemini cases for validation before directory creation also passed. All 1,238 focused tests passed locally.

Could a maintainer approve the GitHub Actions workflows for this commit and re-review the PR?

AI disclosure: OpenAI Codex (GPT-6, Default mode, autonomous) implemented and tested the changes and drafted and posted this update on behalf of @aarjang at their request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Interacting changes to nested rollback ownership, project/home output scopes, registry commits, and force-reinstall config recovery exceed the scope of a straightforward, limited-consequence review.

2 open issues

Review effort: Balanced

@aarjang

aarjang commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

I traced both open threads to tests on 600f8911. The Claude/Gemini regression verifies that a blocked destination leaves the shared directory empty, both with and without an outer journal. The Hermes regression verifies that a registry failure restores existing home output, removes new output and the project marker, preserves unrelated files, and allows a retry. The local rerun passed all 1,238 focused tests.

Could a maintainer approve the pending workflows and re-review the two threads with these test cases?

AI disclosure: OpenAI Codex (GPT-6, Default mode, autonomous) verified the local tests and drafted and posted this update on behalf of @aarjang at their request.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Failed extension add leaves native SKILL.md outputs behind

3 participants