Repository navigation
Keep the replace of the version in use when a stale Go patch record is undone - #2428
Conversation
Assisted-by: Claude Code
Go keys a replace by module and version, and so does a patch record, but a module has one socket-owned replace. After a version bump of a patched module the manifest holds two records of it and the replace serves the newer. The undo of an agent-mode Go patch dropped the module's replace whatever it pointed at, so `remove` or `rollback` of the stale record exited 0 and took the directive of the version in use: the next build linked the unpatched module while the manifest still recorded its patch. The vendored revert did the same by owner. drop_replace_entry now takes the directory its caller is removing (the record's copy under .socket/go-patches, or a vendored patch's uuid dir) and drops the socket-owned directives of the module that point into it: the ones that would dangle, and no other. The go.sum lines saved for another record's directive are neither put back nor forgotten. The reconcile passes the directive's own target, which is what its path check already asked for. The cleanup of a failed apply keeps dropping every directive the owner holds for the module, as the upsert it undoes rewrites the module's one directive whatever it pointed at. Refs #2414. Assisted-by: Claude Code
Runs `rollback <purl>` and `remove <purl>` of the record a version bump left behind, beside the record of the version in use. Each exits 0, removes the stale record's copy and leaves go.mod, the other copy and the other record as they were. On main both commands delete the replace of the version in use. Refs #2414. Assisted-by: Claude Code
Three more places took or left something by module where the record decides, found in review of the previous commit. The cleanup of a failed apply dropped every directive the owner held for the module. With a second record of the module wired, a failed apply of the first took the second's directive although its copy was intact. It now drops only a directive that points at the copy the failure removed, like the undo, so drop_replace_entry_for_cleanup takes the directory too. The go.sum lines saved for a record stayed in .upstream-go.sum once a bump had moved the directive to another version: the undo forgot only the lines of a directive it found. The undo, and the reconcile when it prunes an orphan copy, now forget the record's own lines, so nothing of an undone record keeps .socket/go-patches/ alive. Reverting a vendored record of a module that another vendored record still redirects no longer reports a takeover that was not restored: the module is still vendored, and `socket-patch apply` is not the remedy. Refs #2414. Assisted-by: Claude Code
Review of the previous commit found two things it got wrong and one probe that disagreed with the drop it guards. The undo forgot the go.sum lines saved under the record's module and version even when a directive had pointed at the copy. For a directive the restore cannot key (one with no version on its left) that deleted lines nothing had put back. The undo and the reconcile now forget the lines of the directives they dropped, as before, and the record's own only when no directive pointed at its copy. The vendored revert went back to reporting a takeover it does not restore whatever else redirects the module. The fact lives on the reverted ledger entry alone, so staying silent beside another record lost the only hint that `socket-patch apply` puts the redirect back. The reconcile looked for a directive at an orphan copy by its exact text and then dropped by the directory. It now asks the same question both times, so a directive spelled with a trailing separator goes with the copy it points at. Refs #2414. Assisted-by: Claude Code
The undo and the reconcile forgot the go.sum lines saved under a record's own module and version when no directive pointed at its copy. Two more cases in review showed that reading as "nothing was dropped" when something was: a directive the reconcile's first pass had already dropped, and one in a go.work the reader skips. In both the lines were deleted without having been put back. Those lines are left as they are on main: an undo forgets the lines of the directives it dropped and no others. What a version bump leaves in .upstream-go.sum for the version it moved off stays there, as before. Two comments now describe the drop by directory they sit beside. Refs #2414. Assisted-by: Claude Code
The undo dropped only a directive that pointed at the record's own copy. A directive keyed at the record's version but pointing at another copy (the wrong-path drift `apply --check` names) is the record's as well: Go redirects that version through it. Left in place it kept the version redirected with no record behind it, where main dropped it. drop_record_replace takes what belongs to one record: the directives its owner holds for its version of the module, wherever they point, and any socket-owned one into the directory the undo removes. The agent-mode undo and the vendored revert call it and forget the saved go.sum lines of exactly the directives it returns. A directive keyed at another version and pointing at another copy is another record's and still stays. drop_replace_entry keeps the by-directory rule for the reconcile and the cleanup of a failed apply, which remove a directory and have no record to go by. Refs #2414. Assisted-by: Claude Code
The cleanup of a failed apply dropped only a directive that pointed at the copy the failure removed. A directive keyed at the record's version but pointing at another copy, which the apply was healing, survived the failure; with that other copy gone every `go build` failed on it, where main dropped it and fell back to the unpatched module. The cleanup now takes the record's directives, as the undo does: the ones the owner holds for this version, and any into this copy. The directive of another record of the module still stays. Refs #2414. Assisted-by: Claude Code
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Go
New CLI and core tests cover stale-record undo, failed apply, vendored multi-record revert, and path-exact directive matching (including drifted wrong-target cases). Reviewed by Cursor Bugbot for commit 658f738. Configure here. |
Assisted-by: Claude Code
|
[agent] PR shepherd: review brief for the approver What it does Risk Look here
Verified
Changes I made Open questions Generated by Claude Code |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed the full diff at 658f738: undoing a stale Go record now takes only the directive keyed at the record's version or pointing into its copy, every removal path still drops directives into the directory it deletes, and the go.sum backups follow the dropped directives. No defects found.
Non-blocking note
Reverting a stale vendored record of the same version under a different uuid still takes the live directive, as on main; no test covers it.
|
[agent] On the non-blocking note in the approval: agreed, and left as it is on The revert takes the vendor-owned directive keyed at its record's version, so a second vendored record of the same module and version under another uuid would lose its directive to it. The vendor ledger is a map keyed by purl ( Keying that arm by the entry's uuid dir alone would close it, but it would also stop the revert from dropping a same-version directive that drifted to another path, which Generated by Claude Code |
LLM Description written by Claude Code
Fixes #2414.
Problem
Go keys a
replaceby module and version, and so does a patch record, but a module has one socket-ownedreplace. After a version bump of a patched module the manifest holds two records of it (the scan that patches the new version leaves the old record failing), and thereplaceserves the new version.The undo of a Go patch dropped the module's
replacewhatever it was keyed at. Soremoveorrollbackof the stale record exits 0, reports "Rolled back 1 package", and deletes the directive of the version in use. The next build links the unpatched module while the manifest still records its patch. A scan's summary asks the user to commit.socket/andgo.mod, and a Go project patched that way runs noapplyin CI, so the unpatched state ships.The same class was fixed before in two neighbours and not here: the reconcile's stale-copy prune was keyed by the copy in a2f07e0 (#223), and the vendored failure cleanup got its path condition in 08ea9ba (#150).
Evidence on
main(9f2bc04)Real Go 1.24.7, a module served from a file proxy, the binary built from
main. The project is on v0.9.1 with its patch applied; the manifest also holds the v0.8.1 record:rollback <purl>gives the same. It also deletes the go.sum lines saved for v0.9.1 from.socket/go-patches/.upstream-go.sum.The test added to the CLI's
rollbacksuite, onmain:Fix
One rule for what a removal may take from
go.mod/go.work, in corevendor/go_mod_edit.rs:drop_record_replaceis new; the undo forgets the saved go.sum lines of exactly the directives it returns.drop_replace_entrynow takes that directory in place of an owner.A directive keyed at another version and pointing at another copy is another record's, and stays.
With this branch the transcript above ends:
Deleted
The owner-wide drop on disk.
remove_replace_entryby owner stays as the pure function the hosted undo calls after it has matched the directive by its patch uuid.Behavior change
remove/rollbackof a Go record, and a failedapplyof one, leave thereplaceof another record of the module. That is the fix.replaceof another version that no record claims (the manifest moved to a new version and noapplyhas run since).maindropped it in passing. It cannot be told from the case above without the manifest, which the core undo does not see.apply --checknames it ("orphan go.modreplace", exit 1) and the nextapplyremoves it ("Removed 1 stale Go patch redirect"); both run here.CLI_CONTRACT.mddescribes none of this, and already says Go keysreplaceby version.Risk
Low for the common shape: one record per module behaves as before, and every existing Go test passes unchanged except for the new argument. The care is in drifted
go.modfiles, which the tests cover: a directive keyed at the record's version but pointing at another copy is still dropped by the undo and by a failed heal, as onmain; a directive with no version, or with a trailing separator, is matched by the copy it points at.Tests
undoing_a_stale_go_record_keeps_the_replace_of_the_version_in_use(rollbackandremove)maintest_remove_keeps_the_directive_of_another_version(also: the saved go.sum lines of the version in use stay)test_failed_apply_keeps_the_directive_of_another_versiontest_revert_keeps_the_directive_of_another_vendored_recordtest_drop_takes_only_the_directives_into_the_directorytest_remove_drops_its_versions_directive_at_another_copy,test_failed_heal_drops_its_versions_directive_at_another_copy,test_drop_record_replace_takes_the_records_directivesmainalready did for a drifted directive"Red" for the core tests is a build with the selection switched back to "every socket-owned directive of the module"; the switch was never committed.
Run on the final head: CI's clippy, core's 8,700 unit tests, and 15 CLI suites, among them the three real-toolchain Go suites (
e2e_golang_build,e2e_golang_workspace_build,e2e_vendor_golang_build),rollback,remove,apply,vendor,vexandscan.Review
Five passes of
/code-review high. Fixed: the failed-apply cleanup took another record's directive; the undo and the failed heal must still drop a directive keyed at their own version; the reconcile's probe and its drop asked different questions; three stale comments. The last pass's finding was fixed and tested but not reviewed again.Left, with the reason:
.upstream-go.sumkeeps the saved lines of the version a bump moved off after every Go patch is undone, so.socket/go-patches/is not pruned. Pre-existing, the same onmain. I tried to forget them in the undo and took it out: two review passes found cases where that deleted lines nothing had put back.mainprints it too.go.modmirror pointing into a removed uuid dir when thego.workwrite fails after the mirror's. Pre-existing, read and not reproduced.remove_go_redirectkeeps itsownerparameter, whichbase_relimplies. Its one caller is in a file an open PR changes.Not run
go.work, beyond the existing suites; Windows and macOS; Go releases other than 1.24.7.Diff
git diff --stat: 5 files, +752 −136. Production: +210 −92 in three core files. Tests: +542 −44.Generated by Claude Code