Skip to content

fix(install): keep a drift edit of the project's own local outputs (#4873) - #4892

Merged
Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
cloud-4873-local-owner-drift-keep
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
cloud-4873-local-owner-drift-keep

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Description

OverwriteGate.keep rejected the project's own outputs (receipt owner .), so a receipt-proven drift edit of a deployed local instruction or agent fell through to the error branch: install reported the edit, rolled back, and exited 1. Dependency-owned outputs already keep such an edit and exit 0 (RA-012).

The fix routes owner . through the same shared kept-overwrite path:

  • src/apm_cli/core/deployment_ledger.py: OverwriteGate.keep no longer rejects owner ..
  • src/apm_cli/install/phases/integrate.py: _keep_prior_entries reads a local keep's prior hash from local_deployed_file_hashes.
  • src/apm_cli/install/phases/post_deps_local.py: the local reconcile excludes kept paths from current hashing and passes the retained map as cleanup_retained_hashes, as LockfileBuilder does for dependencies, so a kept file keeps its prior lock hash and never records the edit's. A kept path the project did not already claim (a dependency output the project starts rendering locally after it was edited) gains no local claim, so its receipt still proves the edit on the next install.
  • src/apm_cli/integration/base_integrator.py: comment only.
  • tests/integration/test_required_lifecycle_state_machine.py (_run_refused) and tests/integration/test_project_self_audit_lifecycle.py: drop the local=True branch that pinned the old exit 1. A local keep now asserts the same exit 0 and warning as a dependency keep.

Finalize then reports the keep (Kept <file>: it was modified since APM deployed it.) as a warning with exit 0 for drift, and still fails for unproven or blocking keeps, exactly as for dependencies. No parallel path.

Issue and approved scope

Issue: Fixes #4873

Human scope-approval comment: #4873 (comment)

Does this PR complete the issue, or what remains? It completes it on main for every local file primitive. Local hooks and canvases join the shared gate in #4678; once that lands they inherit this keep with no further change.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

New cell test_an_edited_local_output_is_kept_with_exit_zero in tests/integration/test_file_primitive_receipt_lifecycle.py: edits a deployed local instruction and changes a local agent's source, then installs. It asserts exit 0, the keep named in output, the edited bytes unchanged, the prior local_deployed_file_hashes entry unchanged, the unedited local agent refreshed (control), and a repeat install that is a no-op. A second cell, test_a_kept_edit_newly_claimed_locally_never_hashes_the_edit, covers a dependency output the project starts rendering locally after it was edited: the edited hash never enters the lock, the path gains no local claim, and both installs exit 0. It fails without the change. On main it fails with exit 1 (. -- Kept .github/instructions/style.instructions.md ..., rollback).

Validation evidence:

  • APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest tests/integration/test_file_primitive_receipt_lifecycle.py: 13 passed. Both new cells fail without the fix.
  • 18 related integration modules (receiptless overwrite, local edit advice, self audit, drift, legacy lock, ownership, state machine and more): 189 passed, 1 env failure (host git commit signing), which passes with signing disabled.
  • uv run --extra dev pytest -n auto tests/unit: 29300 passed, 259 failed. The same failures reproduce on unmodified main: Unix install ownership, network guard, git env and transport, auth report. All are host-environment failures.
  • uv run --extra dev pytest -n auto tests/quality: 665 passed.
  • Windows Compatibility Gate 3/3 hits an inherited run_replay mock-leak guard that test: pre-load install.audit_replay so run_replay patches cannot leak (MAIN-RED FIX, #4876) #4884 fixes. It is not caused by this diff.
  • APM_E2E_TESTS=1 ... pytest tests/integration/test_project_self_audit_lifecycle.py tests/integration/test_file_primitive_receipt_lifecycle.py: 17 passed.
  • The full lint-chain mirror passed: ruff check and format, complexity ratchet, taxonomy and obligation ratchets, YAML guard, file length, relative_to, pylint R0801, auth signals and architecture boundaries. The Mode B detector passed with 8 added lines, and CONFORMANCE regeneration produced no diff.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…4873)

OverwriteGate.keep rejected the project's own outputs (owner '.'), so a
receipt-proven drift edit of a local instruction or agent errored and
exited 1. Local outputs now take the shared kept-overwrite path, and the
local reconcile keeps their prior local_deployed_file_hashes.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 23, 2026
Copilot AI balanced review requested due to automatic review settings November 23, 2026 01:47
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

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 kept local output without a prior local hash can incorrectly adopt edited bytes as its baseline during dependency-to-local overlap, requiring a hashing fix and regression coverage.

1 open issue
What changed in this PR

This PR addresses #4873 by routing the project's own local outputs through APM's shared overwrite-keep path, allowing receipt-proven drift edits to remain without failing installation.

Changes:

  • Allows owner . to use the shared keep mechanism.
  • Carries prior local hashes into reconciliation for kept outputs.
  • Adds lifecycle coverage for preserved edits, unrelated output refreshes, and repeat-install stability.
File Description
tests/​integration/​test_file_primitive_receipt_lifecycle.py Adds a local-edit keep lifecycle regression.
src/​apm_cli/​integration/​base_integrator.py Updates a fallback comment; no functional change.
src/​apm_cli/​install/​phases/​post_deps_local.py Passes retained local hashes into reconciliation.
src/​apm_cli/​install/​phases/​integrate.py Retrieves prior hashes for local-owner keeps.
src/​apm_cli/​core/​deployment_ledger.py Allows local owners through the shared keep gate.
changelog.d/​4892.fixed.md Documents the user-visible install fix.

Review effort: Balanced

…ecycle helper

Exclude kept local outputs from current hashing in the local reconcile, as
LockfileBuilder does for dependencies, so a kept path with no prior local
hash never records the edited bytes. Update the shared _run_refused helper:
the project's own edited content now keeps with exit 0 (#4873). Trim the
keep docstring to hold deployment_ledger.py at the 2100-line cap.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

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

Kept dependency/local overlap paths acquire an unrebound ownership claim, causing the next install to reject the receipt and exit 1; the inventory handling and repeat-install regression need correction.

1 open issue
1 resolved since last review

Review effort: Balanced

A dependency output the project starts rendering locally after it was
edited stays out of the local inventory, so its receipt's claim signature
is unchanged and the next install still proves the edit (exit 0). Also
pre-import apm_cli.install.audit_replay in the mock-leak guard.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

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.

🟢 Approval recommended

There are no active review issues blocking approval of the local-output drift preservation change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues remain for the local-output preservation changes.

No open issues 🎉

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues are blocking approval of the local-output keep changes.

No open issues 🎉

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues remain for the changes that preserve locally edited outputs through the shared keep path.

No open issues 🎉

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 9fc8c82 into main Nov 23, 2026
72 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the cloud-4873-local-owner-drift-keep branch November 23, 2026 07:44
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Move the #4678, #4890, #4892, #4912 and #4934 lines into [0.38.1]: they merged before the v0.38.1 tag and shipped in it. [0.38.2] keeps #4920.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overwrite gate: keep a drift edit of the project's own local outputs (owner '.') with exit 0

2 participants