You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The "copy may still hold the patch" rule is written twice and drifted: cargo GC keeps a missing-blob modified copy, rollback's other-scope check drops it #1926
agent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)priority:p3refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code
let still = match v.status{VerifyRollbackStatus::Ready | VerifyRollbackStatus::MissingBlob => true,VerifyRollbackStatus::NotFound => !v.is_absent(),VerifyRollbackStatus::AlreadyOriginal | VerifyRollbackStatus::HashMismatch => false,};
The drift. Core verify_file_rollback L229-L320 returns MissingBlob after the AlreadyOriginal check but before the current == after check. A MissingBlob result therefore says nothing about whether the copy is patched, and the two copies read it differently:
A file whose hash is neither before nor after, with the before-blob gone:
copy A says still patched (keep);
copy B says not patched.
npm's LF-shebang form of a patched bin (where source_hash == after_hash but current_hash != after_hash), with the blob gone:
copy B misses it;
copy A never sees npm.
I verified this by reading both copies and the core function. The rule is deterministic, so the two answers follow from the code. I did not run it end to end.
Proposed change
Add VerifyRollbackResult::may_hold_patch(&self, info: &PatchFileInfo) -> bool in core patch/rollback.rs, next to the function whose status order it depends on. Pick one meaning for MissingBlob. Keeping the copy (copy A) is the fail-safe choice, because dropping the record strands patched bytes.
Use it from both sites.
Optionally, carry the npm-bin source_hash match in the result, so the predicate needs no CLI knowledge.
Size
3 files, roughly -25/+20 lines.
Acceptance criteria
Tests that guard the change:
the cargo_copies_still_patched callers (scan --prune, rollback);
rollback's other-scope tests.
Add one core unit test of may_hold_patch over every VerifyRollbackStatus, including MissingBlob with a third hash.
[agent] Triaged: priority:p3 (cross-cutting rollback/GC refactor; latent drift in the MissingBlob reading between ecosystem_dispatch.rs and rollback.rs). No duplicate or open fix PR found.
[agent] A third copy of this rule, run end to end on main at cfc870f. It gives a wrong outcome with every blob present.
The copy.holds_patched_bytes (CLI commands/rollback.rs, lines 4286 to 4313) answers "does this copy hold any of the record's patched bytes" by hashing each file and comparing the result with the afterHash. It does not go through core's verify_file_rollback, so it does not know npm's LF-shebang form of a patched bin. patched_in_other_scope, in the same file, was taught that form by #1757 (lines 377 to 381: "Ready also covers npm's LF-shebang form of a patched bin"). #2119 then put holds_patched_bytes in front of every ecosystem: when a newer patch replaces a recorded one and drops one of its files, rollback_pass (CLI commands/agent_download.rs, line 1018) uses it to choose between "refuse the replacement" and "the old patch is not on this copy".
What a user sees. A package lists a bin file that was published with a CRLF shebang. npm 10.9.9, pnpm 10.28.0 and Bun 1.4.4 install it with the first \r\n turned into \n (Yarn 1.22.22 keeps it), and apply writes that form for a linked bin under all four. The recorded patch aaaaaaaa…0001 changes that bin (cli.js) and index.js. A developer adds a line to index.js. A newer patch …0002 that lists neither file arrives, and scan runs:
$ socket-patch scan --mode agent --yes
Found 1 package (1 npm)
1 package has a newer patch available.
[update] pkg:npm/crlfbin@1.0.0 (replacing aaaaaaaa)
Warning: pkg:npm/crlfbin@1.0.0: the replaced patch aaaaaaaa was not rolled back in ./node_modules/crlfbin: no file there holds its patched bytes (Cannot roll back: package/index.js - File holds neither the patched nor the original content. Cannot safely roll back). A file edited after that patch was applied stays as it is. Reinstall the package to get the original files back.
Applied 1 patch.
HIGH crlfbin@1.0.0 CVE-2026-0001
$ echo $?
0
"No file there holds its patched bytes" is false: cli.js holds the first patch. The record is replaced, so nothing lists cli.js any more:
manifest before: {'pkg:npm/crlfbin@1.0.0': ('0001', ['cli.js', 'index.js'])}
manifest after: {'pkg:npm/crlfbin@1.0.0': ('0002', ['lf.js'])}
$ ./node_modules/.bin/crlfbin
crlfbin AFTER # the first patch's content
$ socket-patch rollback --yes # exit 0, the manifest is now empty
$ ./node_modules/.bin/crlfbin
crlfbin AFTER # still patched, and no record to roll it back with
Under --json the same run has status: success, the events updated and applied, and the warning replaced_patch_not_on_copy.
The control is the same package, edit and pair of patches, with the patched bin published with an LF shebang (lf.js). The check sees the patched bytes and the replacement is refused, as #2119 intended:
$ socket-patch scan --mode agent --yes
[update] pkg:npm/crlfbin@1.0.0 (replacing aaaaaaaa)
[fail] pkg:npm/crlfbin@1.0.0 (the recorded patch aaaaaaaa could not be rolled back first: Cannot roll back: package/index.js - File holds neither the patched nor the original content. Cannot safely roll back. That patch stays recorded and applied. Reinstall the package to get the original files back, then run this command again.)
No changes to ./.socket/manifest.json (1 failed).
$ echo $?
1
With no edit to index.js, both shapes are fine: the dry rollback passes, the first patch's two files are restored and the new patch is applied.
For the fix. The may_hold_patch predicate proposed above should serve this site too, so that the LF-shebang form is answered in one place. copy_carries_record (lines 4330 to 4363 of the same file) makes the same raw comparison. Its one caller asks about release variants of one purl, which npm packages do not have, so I read it and did not run it.
It takes three things at once (a bin with a CRLF shebang, a local edit to another patched file, and a newer patch that drops the bin), so the harm is rare: one file left at the old patch's content with no record.
How to run it
A package crlfbin@1.0.0 with "bin": {"crlfbin": "cli.js", "lfbin": "lf.js"}; cli.js starts #!/usr/bin/env node\r\n, lf.js starts #!/usr/bin/env node\n. Serve its packument and tarball from a directory on loopback and install with npm install --registry http://127.0.0.1:<port>/. A stand-in for the public patch proxy (SOCKET_PROXY_URL) answers the batch, by-package, view and blob routes from a catalog.
Catalog with the first patch alone (package/cli.js and package/index.js): socket-patch scan --mode agent --yes.
Catalog with the first patch and a second one for the same purl, a later publishedAt, listing package/lf.js alone: socket-patch scan --mode agent --yes.
For the control, the first patch lists package/lf.js and package/index.js, and the second package/cli.js.
agent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)priority:p3refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code
Activity
mikolalysenko commentedon Nov 1, 2026
[agent] Triaged: priority:p3 (cross-cutting rollback/GC refactor; latent drift in the
MissingBlobreading betweenecosystem_dispatch.rsandrollback.rs). No duplicate or open fix PR found.Generated by Claude Code
refactor: #1917, #1926, #1860 ran; L17 rejected
mikolalysenko commentedon Nov 29, 2026
[agent] A third copy of this rule, run end to end on
mainat cfc870f. It gives a wrong outcome with every blob present.The copy.
holds_patched_bytes(CLIcommands/rollback.rs, lines 4286 to 4313) answers "does this copy hold any of the record's patched bytes" by hashing each file and comparing the result with theafterHash. It does not go through core'sverify_file_rollback, so it does not know npm's LF-shebang form of a patched bin.patched_in_other_scope, in the same file, was taught that form by #1757 (lines 377 to 381: "Readyalso covers npm's LF-shebang form of a patched bin"). #2119 then putholds_patched_bytesin front of every ecosystem: when a newer patch replaces a recorded one and drops one of its files,rollback_pass(CLIcommands/agent_download.rs, line 1018) uses it to choose between "refuse the replacement" and "the old patch is not on this copy".What a user sees. A package lists a
binfile that was published with a CRLF shebang. npm 10.9.9, pnpm 10.28.0 and Bun 1.4.4 install it with the first\r\nturned into\n(Yarn 1.22.22 keeps it), andapplywrites that form for a linked bin under all four. The recorded patchaaaaaaaa…0001changes that bin (cli.js) andindex.js. A developer adds a line toindex.js. A newer patch…0002that lists neither file arrives, andscanruns:"No file there holds its patched bytes" is false:
cli.jsholds the first patch. The record is replaced, so nothing listscli.jsany more:Under
--jsonthe same run hasstatus: success, the eventsupdatedandapplied, and the warningreplaced_patch_not_on_copy.The control is the same package, edit and pair of patches, with the patched bin published with an LF shebang (
lf.js). The check sees the patched bytes and the replacement is refused, as #2119 intended:With no edit to
index.js, both shapes are fine: the dry rollback passes, the first patch's two files are restored and the new patch is applied.For the fix. The
may_hold_patchpredicate proposed above should serve this site too, so that the LF-shebang form is answered in one place.copy_carries_record(lines 4330 to 4363 of the same file) makes the same raw comparison. Its one caller asks about release variants of one purl, which npm packages do not have, so I read it and did not run it.It takes three things at once (a bin with a CRLF shebang, a local edit to another patched file, and a newer patch that drops the bin), so the harm is rare: one file left at the old patch's content with no record.
How to run it
A package
crlfbin@1.0.0with"bin": {"crlfbin": "cli.js", "lfbin": "lf.js"};cli.jsstarts#!/usr/bin/env node\r\n,lf.jsstarts#!/usr/bin/env node\n. Serve its packument and tarball from a directory on loopback and install withnpm install --registry http://127.0.0.1:<port>/. A stand-in for the public patch proxy (SOCKET_PROXY_URL) answers the batch, by-package, view and blob routes from a catalog.package/cli.jsandpackage/index.js):socket-patch scan --mode agent --yes.echo "console.log('debugging')" >> node_modules/crlfbin/index.jspublishedAt, listingpackage/lf.jsalone:socket-patch scan --mode agent --yes.For the control, the first patch lists
package/lf.jsandpackage/index.js, and the secondpackage/cli.js.Generated by Claude Code
refactor: #1926 third copy; five areas ran