[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
Dependencies
[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:apply.rs#L732-L788rollback.rs#L344-L392Both run the single-copy engine on the primary, then over
find_store_peer_variant_copies(pkg_path)forpkg:npm/purls, and fold each copy into the primary with a privatefold_copy_result. The two folds have drifted:OWNERSHIP_NOT_RESTORED_MARKER;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
already_patched/applied: 0when it actually patched an unpatched pnpm peer-variant copy (the store-copy pass's writes are never reported) #756 (p1,bughunt): apply reportsalready_patched/applied: 0after writing an unpatched twin, and the comment there confirms rollback reportsalready_originalthe same way. The fix belongs in the shared fold, not twice.Impact
A reporting bug that breaks
--jsonautomation today. Any later fix to one fold has to be copied to the other.Proposed change
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 forApplyResultandRollbackResult.--forceall-skipped note, as apply does today.fold_copy_resultfunctions and the duplicated fan-out loops.Size and scope
patch/apply.rs,patch/rollback.rsand a newpatch/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
grep -n "fn fold_copy_result" crates/finds no matches.files_patched/files_rolled_backnon-empty), and the CLI event isapplied/rolled_back.cargo test -p socket-patch-core patch::and the CLIapply/rollbackintegration tests stay green.Dependencies
already_patched/applied: 0when it actually patched an unpatched pnpm peer-variant copy (the store-copy pass's writes are never reported) #756 lands first, this becomes the mechanical merge of the two folds and keeps that PR's tests.patch/apply.rs, which open PRs Fix agent mode patching linked first-party source (#626) #634 and Full Gradle support in agent, hosted and vendored modes #646 also change.