Skip to content

[0.38] feat(install): recognise earlier writes after a branch round trip (multi-hash receipt history) (#4428) - #4730

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-p2-4428-receipt-history
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-p2-4428-receipt-history

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

After a branch round trip without a reinstall (install on main, install on
branch B, check out main again), a source edit to a local skill refused with
"no trustworthy local deployment baseline" and asked the user to move the
deployed skill aside. The deployed bytes were ones this installation had
written earlier, but each deployment receipt kept only the latest hash
(branch B's).

Each receipt key now keeps a short, bounded history of the hashes this
installation wrote there (core/receipt_history.py, up to HISTORY_LIMIT = 8 earlier hashes,
oldest dropped first). DeploymentMaterializationSession records it on every flushed
write and consults it only where it already decides a trusted baseline: when
the lock no longer claims the receipt's latest hash and the file does not hold
it, bytes equal to an earlier write here are a trusted baseline. Binding rules
are unchanged (same installation identity, owner and claim signature; the lock
can only withdraw trust). The history is local state next to the receipts,
never in apm.lock.yaml, never shared across checkouts, and never deletion
evidence. A malformed history fails closed like a malformed receipt.

Issue and approved scope

Issue: Fixes #4428

Human scope-approval comment: #4428 (apm-scope:v1 record by Daniel Meppiel (@danielmeppiel); moved back to 0.38.0)

Does this PR complete the issue, or what remains? It completes the issue.

Done-when mapping:

  • test_source_edit_after_branch_round_trip_installs_without_recovery loses its
    #4428 strict-xfail marker and passes (strict xfail on main = fails there).
  • test_user_edit_after_branch_round_trip_is_still_refused: a user edit to the
    deployed skill after the same round trip is still refused with the scoped
    recovery and nothing is deleted.
  • test_removal_after_branch_round_trip_needs_todays_deletion_evidence[member|skill]:
    removing a member, or the whole local skill (the uninstall of local
    content; apm uninstall takes dependencies only), keeps the deployed bytes
    because history is not deletion evidence.
  • test_branch_switch_then_source_edit_never_deletes_skill_members keeps every
    never-delete assertion; its refusal assertions now expect the install to
    succeed where history proves the bytes, and the genuine edit in the other
    skill is kept and named.
  • Controls unchanged: test_user_edit_variants_never_lose_bytes,
    test_member_skipped_as_modified_is_never_stale,
    tests/integration/test_receiptless_overwrite_lifecycle.py.

Type of change

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

Testing

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

Validation evidence (host under a test cap: targeted files only, heavy suites on CI):

  • pytest tests/integration/test_checkout_switch_skill_lifecycle.py -n 2 (real binary): 26 passed.
  • Unit cells in tests/unit/test_deployment_materialization_receipts.py: earlier write is a baseline but not deletion evidence, history is bounded, an invalid history is refused.
  • ruff check / ruff format --check (0.15.12, CI paths): clean.
  • scripts/lint_architecture_boundaries.py --root .: exit 0.
  • pylint R0801: 10.00/10. lint-auth-signals.sh: clean.
  • check_complexity_ratchet.py --base-ref main: clean.
  • check_test_assertions.py: assertion-quality ratchet clean.
  • tests.quality.taxonomy --changed: clean.

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 (local receipt state under .apm-local/, not the lockfile).

…h round trip (#4428)

Deployment receipts keep up to 8 earlier hashes per key (receipt_history.py),
and DeploymentMaterializationSession trusts a file that holds one of them
after the existing binding checks pass. Cleanup's receipt_hashes stays
latest-only, so history is never deletion evidence.

Co-authored-by: Copilot App <[email protected]>
…eipt-history

# Conflicts:
#	tests/unit/test_deployment_materialization_receipts.py
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 22, 2026
Copilot AI balanced review requested due to automatic review settings November 22, 2026 10:17

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 ownership-handoff flaw can cause older hashes to be trusted under a new owner’s binding, and the deletion-safety regression can pass without exercising cleanup.

2 open issues
What changed in this PR

This PR addresses #4428 by adding local receipt history so install can recognize earlier deployed bytes after switching branches and back, avoiding unnecessary manual recovery.

Changes:

  • Retains up to eight earlier hashes per receipt and consults them for trusted overwrite baselines, not deletion evidence.
  • Updates branch-switch regressions and adds coverage for history limits, malformed history, user edits, and removal safety.
  • Documents the behavior and registers the history module with the deployment-state owner.
File Description
tests/​unit/​test_deployment_materialization_receipts.py Tests historical baselines, bounded history, and invalid history rejection.
tests/​integration/​test_checkout_switch_skill_lifecycle.py Tests branch round trips, user-edit protection, and removal safety.
src/​apm_cli/​core/​receipt_history.py Implements bounded receipt history and historical hash matching.
src/​apm_cli/​core/​deployment_ledger.py Integrates history with receipt recording, persistence, and baseline decisions.
docs/​src/​content/​docs/​reference/​cli/​install.md Explains branch-round-trip recovery and deletion limits.
changelog.d/​4730.fixed.md Adds the user-facing fix entry.
.apm/​architecture/​owners/​install-deployment.json Registers history under deployment provenance ownership.

Review effort: Balanced

Comment thread src/apm_cli/core/deployment_ledger.py Resolved
…claim binding (#4428)

A rewrite keeps the replaced hash only for the same key, owner and claim
signature; bind_committed_claims forgets the history when it rebinds.
The removal cells assert a successful install so they reach cleanup.

Co-authored-by: Copilot App <[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

No active review issues are reported for the branch-round-trip receipt-history change.

No open issues 🎉

2 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 are recorded for the receipt-history change.

No open issues 🎉

Review effort: Balanced

…eipt-history

# Conflicts:
#	src/apm_cli/core/deployment_ledger.py

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 block approval of the receipt-history change.

No open issues 🎉

Review effort: Balanced

…eipt-history

# Conflicts:
#	src/apm_cli/core/deployment_ledger.py

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 CLI documentation incorrectly excludes receipts written under another branch’s lock, although _trusted_hash() accepts earlier writes with matching installation, owner, and claim bindings.

1 open issue

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit a65f859 into main Nov 22, 2026
74 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p2-4428-receipt-history branch November 22, 2026 21:42
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Merge main f4efa6b and fold #4730 and #4769 (bundle allow-list policy from #4677) into the [0.38.0] block.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Main (#4730) moved is_canonical_bundle_hash into core/receipt_history; this
branch had moved it into core/deployment_state. Keep receipt_history as the
single owner (deployment_state imports it) and drop the duplicate ledger
helper.

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.

Round-trip a source edit after a branch switch without a manual recovery step (multi-hash receipt history)

2 participants