Repository navigation
[0.38] fix(install): restore every deployed file after a failed or interrupted install (#4282) - #4612
Merged
Daniel Meppiel (danielmeppiel) merged 14 commits intoNov 21, 2026
Conversation
) Every install now records, at integration/write_seam.py, the prior bytes (or absence) of each path the first time an integrator writes it. InstallTransaction owns record, rollback and release: a rollback restores the journaled paths and discards the staged lockfile; after the audit the journal settles once the staged lockfile reaches disk. The next install reaps a journal a killed install left. A registered architecture guard (install-deployment-deploy-write-seam) rejects integrator writes that bypass the seam. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…4282) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…l-p2-4282-lazy-snapshot
… guard (#4282) The cleanup-target-roots guard landed on main after this branch forked. Callers of write_seam.rmdir are still judged at their own call sites. Co-authored-by: Copilot App <[email protected]>
…4282) apm-spec-waiver: restores pre-command bytes under the existing req-pl-002 failing-check contract; no new OpenAPM-observable surface. Co-authored-by: Copilot App <[email protected]>
Keeps deployment_ledger.py under the 2100-line cap after merging main. Co-authored-by: Copilot App <[email protected]>
…l-p2-4282-lazy-snapshot
…ine and failure-phase cells (#4282) The lockfile-write fault row drops its #4164 expectations, the required state-machine cell asserts the restored state, and the ledger retires the late-lock-write-atomicity known gap. Co-authored-by: Copilot App <[email protected]>
… its receipt (#4282) Co-authored-by: Copilot App <[email protected]>
…4282) R4 exits 1 before its lockfile commits, so references/a.md keeps its prior bytes instead of an unrecorded v2. Co-authored-by: Copilot App <[email protected]>
…sset (#4282) Co-authored-by: Copilot App <[email protected]>
Ports the 4282 bug row and the retired late-lock-write-atomicity gap to the per-row ledger layout (#4583). Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 21, 2026 17:08
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 21, 2026 17:08
6 of 14 tasks
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical transaction-ordering and recovery-retention flaws can leave lockfiles inconsistent with deployed files, eliminate rollback protection, or destroy the only recovery backup.
6 open issues
Preserve recovery backups when renaming the store fails · New Keep rollback available until the lockfile commits · New Settle the journal when the lockfile commits · New Discard staged lockfile writes on empty-journal rollback · New Detect writable Path.open and Path.replace calls · New Journal symlink referents for writers that follow links · New
What changed in this PR
This PR addresses #4282 by replacing audit-only deployment snapshots with lazy journaling for every install. It aims to restore pre-command deployment state on failures or interrupts before the lockfile commits, while preserving existing post-commit behavior.
Changes:
- Routes deployment writes through a shared seam that records each touched path before modification.
- Connects journal restoration, cleanup, and staged-lockfile disposal to the install transaction.
- Adds architecture enforcement and updates regression tests, lifecycle evidence, and documentation.
| File | Description |
|---|---|
tests/unit/scripts/test_architecture_runner.py |
Registers the new guard in the expected inventory. |
tests/unit/install/test_pipeline_ownership_snapshot.py |
Updates failure expectations for deployment restoration. |
tests/unit/install/test_failed_install_residue.py |
Checks restored files and absence of residue. |
tests/unit/install/test_deploy_snapshot.py |
Tests lazy recording, rollback, settlement, and reaping. |
tests/lifecycle/scenarios/test_failure_phase.py |
Removes the known lock-write failure exception. |
tests/integration/test_shared_skill_preservation_lifecycle.py |
Expects failed shared-skill writes to roll back. |
tests/integration/test_required_lifecycle_state_machine.py |
Requires unchanged state after lock-write failure. |
tests/integration/test_lockfile_commit_point_lifecycle.py |
Expands failure, interrupt, and recovery coverage. |
tests/integration/test_checkout_switch_skill_lifecycle.py |
Updates failed checkout-switch restoration expectations. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds journal ownership and write-seam mutations. |
tests/fixtures/lifecycle_bug_ledger/known_gaps/late-lock-write-atomicity.json |
Removes the retired known-gap record. |
tests/fixtures/lifecycle_bug_ledger/bugs/4282.json |
Records the bug and linked regression tests. |
src/apm_cli/integration/write_seam.py |
Introduces shared pre-write recording wrappers. |
src/apm_cli/integration/targets.py |
Routes target-directory creation through the seam. |
src/apm_cli/integration/skill_transformer.py |
Routes transformed-agent writes through the seam. |
src/apm_cli/integration/skill_integrator.py |
Routes skill directory creation and copies through the seam. |
src/apm_cli/integration/skill_adoption.py |
Marks private scratch cleanup as exempt. |
src/apm_cli/integration/prompt_integrator.py |
Routes prompt deployment through the seam. |
src/apm_cli/integration/mcp_integrator.py |
Imports configuration writers from the seam. |
src/apm_cli/integration/lsp_integrator.py |
Routes configuration writes and cleanup through the seam. |
src/apm_cli/integration/kiro_hook_integrator.py |
Routes Kiro hook deployment through the seam. |
src/apm_cli/integration/instruction_integrator.py |
Routes instruction deployment through the seam. |
src/apm_cli/integration/hook_ownership.py |
Journals hook ownership sidecar changes. |
src/apm_cli/integration/hook_integrator.py |
Routes hook writes and removals through the seam. |
src/apm_cli/integration/hook_bundle.py |
Journals deployed hook bundle files. |
src/apm_cli/integration/command_integrator.py |
Routes command-directory creation through the seam. |
src/apm_cli/integration/cleanup.py |
Journals stale-file removals and renames. |
src/apm_cli/integration/canvas_integrator.py |
Journals canvas bundle copies. |
src/apm_cli/integration/base_integrator.py |
Connects shared deployment and cleanup operations to journaling. |
src/apm_cli/integration/agent_integrator.py |
Routes agent deployment through the seam. |
src/apm_cli/integration/_hook_dropped_targets.py |
Journals orphaned hook sidecar removal. |
src/apm_cli/install/transaction.py |
Owns journal activation, settlement, and rollback. |
src/apm_cli/install/skill_path_migration.py |
Records migration removals before modification. |
src/apm_cli/install/pipeline.py |
Starts journaling before integration. |
src/apm_cli/install/phases/audit.py |
Updates comments to describe journal-backed restoration. |
src/apm_cli/install/helpers/gitignore.py |
Routes gitignore appends through the seam. |
src/apm_cli/install/failure_residue.py |
Updates documentation of rollback boundaries. |
src/apm_cli/install/deploy_snapshot.py |
Replaces eager snapshots with lazy deployment journals. |
src/apm_cli/install/commit_gate.py |
Documents the pre-lockfile restoration boundary. |
src/apm_cli/deps/lockfile_write_authority.py |
Adds explicit disposal of staged lockfile writes. |
src/apm_cli/core/deployment_ledger.py |
Journals deployment evidence persistence. |
scripts/architecture_linter/checks/install_entry_and_commit.py |
Updates transaction ownership checks for journaling. |
scripts/architecture_linter/checks/install_deployment_analyzers.py |
Registers the deployment write-seam guard. |
scripts/architecture_linter/checks/install_deploy_write_seam.py |
Adds checks for writes that bypass journaling. |
scripts/architecture_linter/checks/install_cleanup_target_roots.py |
Allows the seam’s directory-removal wrapper. |
docs/src/content/docs/reference/cli/install.md |
Documents restoration and post-commit behavior. |
CHANGELOG.md |
Adds a release note for install restoration. |
.apm/architecture/owners/install-deployment.json |
Updates journal ownership and guard references. |
Review effort: Balanced
- A store kept after a failed restore carries a RETAINED marker the reaper honors, so its copies survive a failed rename. - Writers that write through a symlink (append, in-place write, copy) also journal the link's destination. - The journal settles first at the lockfile commit, before receipt binding or any other fallible post-commit action. - A rollback with nothing deployed still discards the staged lockfile. - The write-seam guard rejects Path.open in a writing mode and one-argument Path.replace, with mutation cells. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
This was referenced Nov 21, 2026
Merged
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-p2-4282-lazy-snapshot
branch
November 21, 2026 20:40
This was referenced Nov 21, 2026
Merged
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
A failed or interrupted (SIGINT, SIGTERM)
apm installwith the install-time audit off left deployed files thatapm.lock.yamldid not record. Only an audit-gated install took a deploy snapshot, and it copied every path integration could write.Every install now journals lazily at one integrator write seam:
src/apm_cli/integration/write_seam.pyis the only way an integrator writes, replaces or removes a deploy path. Each writer records the path first. Ledger, gitignore and skill-path migration writes call it too.install/deploy_snapshot.pyis a lazyDeployJournalunder~/.apm/install-snapshots/deploy-*. It keeps the prior bytes, or notes the absence, of a path the first time it is written. Paths the install never touches cost nothing.InstallTransaction(ownerinstall-commit-order) ownsjournal_deploy_writes,release_deploy_targetsandrollback. Rollback restores every journaled path, removes target roots the attempt created and left empty, and discards the staged lockfile (lockfile_write_authority.discard_staged_lockfile_writes). After release, the journal settles when the staged lockfile commits.retained-*.install-deployment-deploy-write-seamrejects a raw file write insrc/apm_cli/integration/that bypasses the seam, with a sortedMutationCaseand parametrized mutation cells.install-deployment-cleanup-target-roots(landed onmainafter this branch forked) allowlists only the seam's ownrmdirwrapper; every caller is still judged at its call site.Failures after the lockfile commits (for example an MCP connection collision) keep the 0.37 behavior: record what reached disk.
apm-spec-waiver: restores pre-command bytes under the existing req-pl-002 failing-check contract; no new OpenAPM-observable surface.
Issue and approved scope
Issue: Fixes #4282
Human scope-approval comment: #4282 (comment)
Does this PR complete the issue, or what remains? It completes the approved scope. Refs #4594: this also flips the
lockfile-writerow oftests/lifecycle/scenarios/test_failure_phase.py(its_UNTRACKED_SKILL/_DEPLOY_CHANGED#4164 cells are removed) and retires the ledger'slate-lock-write-atomicityknown gap; themcp-config-writerow (failure after the lock commits) stays with #4594, sequenced after this PR. Out of scope, as approved: refusal ordering, SIGKILL or power-loss recovery, uninstall/prune/update rollback, snapshotting paths the install does not write.Type of change
Testing
Done-when cells in
tests/integration/test_lockfile_commit_point_lifecycle.py:test_sigterm_without_a_deploy_snapshot_keeps_the_lock_equal_to_diskandtest_the_next_install_reaps_a_killed_installs_deploy_snapshot: install: lazy pre-write snapshot at the integrator write chokepoint #4282 strict-xfail markers removed, now pass.test_a_failure_after_deploy_leaves_every_byte_as_it_wasinjectsAPM_TEST_FAIL_LOCK_REPLACEafter deploy and asserts deployed files,apm.yml, receipts andapm.lock.yamlare byte-identical to pre-command, with no journal left behind.test_a_failed_lockfile_write_restores_deploys_and_the_lock(was..._is_reported_by_audit_and_converged) andtest_sigterm_without_an_audit_restores_deploys_and_the_lock(wastest_sigterm_without_a_deploy_snapshot_is_reported_by_audit_and_converged).test_interrupt_at_the_commit_point_restores_deploys_and_discards_the_lock(SIGINT, SIGTERM) andtest_a_killed_install_is_reported_by_audit_and_converged_by_the_next_install(SIGKILL backstop).Validation evidence (local, macOS, merge of
main0f9b391):pytest tests/integration/test_lockfile_commit_point_lifecycle.py(installed CLI,APM_BINARY_PATH=.venv/bin/apm)src/frommain5337f2fpytest tests/integration/test_architecture_owner_rule_mutations.py tests/unit/scripts/test_architecture_runner.py tests/unit/install/test_deploy_snapshot.py tests/unit/install/test_failed_install_residue.py tests/unit/install/test_pipeline_ownership_snapshot.pypython scripts/lint_architecture_boundaries.py --root .pytest tests/integration/test_required_lifecycle_state_machine.py::test_required_failed_lock_write_restores_state_and_recovers tests/lifecycle/scenarios/test_failure_phase.pypytest tests/quality/test_lifecycle_bug_ledger.py tests/unit/scripts/test_lifecycle_evidence.pyci-integration.ymldispatch at 1dca1d2uvx [email protected] check/format --check(CI paths)pylint --enable=R0801 --min-similarity-lines=10bash scripts/lint-auth-signals.shpython scripts/check_complexity_ratchet.py --base-ref <main>python -m tests.quality.taxonomy --changedChangelog
## [Unreleased]inCHANGELOG.md:user-visible effect first, 25 words or fewer, ending with
(#PR);breaking changes only under upgrade notes; no Highlights; see
.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.