Skip to content

Share one pnpm/vlt store-copy fan-out between agent apply and rollback, folding each copy's per-file records #772

Description

[agent] Filed by the scheduled architecture audit routine (CLI and core). Register: discussion #560 register.

Kind: refactor. Source: review 7.4 and 7.6 #4; register C24 (first child of tracking #771).

Problem

Verified on main @ 045d7ec. The store-copy pass is copy-pasted:

Both run the single-copy engine on the primary, then over find_store_peer_variant_copies(pkg_path) for pkg:npm/ purls, and fold each copy into the primary with a private fold_copy_result. The two folds have drifted:

  • apply keeps a successful copy's advisory only if it contains OWNERSHIP_NOT_RESTORED_MARKER;
  • rollback keeps any advisory.

Both folds drop the copy's per-file records (files_verified, files_patched/files_rolled_back, applied_via). The CLI classifies the event from the primary's records alone.

Symptoms

Impact

A reporting bug that breaks --json automation today. Any later fix to one fold has to be copied to the other.

Proposed change

  • Add patch::store_copies::fan_out(package_key, pkg_path, |path| engine(path)) -> Vec<(PathBuf, R)> and one generic fold over a small trait (success, advisory, extend_files(copy, other)), implemented for ApplyResult and RollbackResult.
  • The fold merges each copy's changed-file list and verify records, with the file paths qualified by the copy path, so the CLI sees a write in any copy. It keeps one advisory rule for both directions: carry ownership advisories and drop apply's --force all-skipped note, as apply does today.
  • Delete: both private fold_copy_result functions and the duplicated fan-out loops.

Size and scope

patch/apply.rs, patch/rollback.rs and a new patch/store_copies.rs, plus the CLI event classification only if it needs a "changed in a copy" signal. Estimated 150–250 production lines. Out of scope: unifying the verify types (later children of #771).

Acceptance criteria

  • One fan-out and one fold; grep -n "fn fold_copy_result" crates/ finds no matches.
  • Regression tests in core for both directions: the primary is already done and a twin is not. The result reports the twin's file as changed (files_patched / files_rolled_back non-empty), and the CLI event is applied / rolled_back.
  • Existing ownership-advisory tests for copies stay green, and the advisory rule is now the same in both directions.
  • cargo test -p socket-patch-core patch:: and the CLI apply/rollback integration tests stay green.

Dependencies

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:claimedagent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)pm:pnpmpnpmpriority:p1refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions