With the manifest outside .socket/, repair, scan --prune, rollback and remove delete the project's own files in packages/, diffs/ and blobs/
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 54/100
Rechercherichtung
Start with crates/socket-patch-core/src/manifest/cleanup_blobs.rs, where ArtifactReferences::sweep and cleanup_dir handle artifact cleanup, then inspect its callers in repair.rs, remove.rs, rollback.rs and scan/gc.rs. Run the described sweep_spares_user_files_beside_a_manifest_outside_dot_socket test and add CLI coverage for the listed commands. Done means cleanup preserves ordinary user files beside a relocated manifest while retaining existing .socket/ cleanup behavior.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
[agent] Found by the architecture refactor routine (ledger discussion #2244, lead L43), on main at cfc870f.
Problem
With --manifest-path (or SOCKET_MANIFEST_PATH) naming a manifest that is not inside a .socket/ directory, the directory the manifest sits in becomes the artifact directory. For a bare file name that is the project root. The cleanup that repair, scan --prune, scan --sync, rollback and remove run then treats <that directory>/blobs, <that directory>/diffs and <that directory>/packages as socket-patch's own stores and deletes the files in them:
- every regular, non-hidden file directly in
packages/and indiffs/; - every regular, non-hidden file directly in
blobs/that is not a blob the manifest references; - the directory itself, when that leaves it empty.
The run exits 0 and reports the files as "unused package archives", "unused diff archives" or "orphan files". Subdirectories are left alone.
A manifest outside .socket/ is a layout the contract documents: "a manifest file elsewhere (state/patches.json, /etc/socket/manifest.json) relocates only the manifest and its lock/artifact directory, not the project" (crates/socket-patch-cli/CLI_CONTRACT.md, line 96), and docs/migrating-to-v5.md (line 50) gives --manifest-path state/patches.json as the example.
Who it hurts
- A monorepo that keeps its manifest at the repository root, next to the lockfile, and has a
packages/directory. The firstscan --mode agent --prunedeletespackages/README.md,packages/tsconfig.base.json, a sharedjest.config.js: whatever sits directly inpackages/. The next build fails, in CI too. - Anyone whose manifest directory has a
diffs/orblobs/directory of their own. - Files that are not committed are gone for good. Only
repair --dry-runnames the files; every other run gives a count.
Evidence on main
The binary is built from cfc870f. No network or patch API is needed.
$ mkdir -p app/packages/web && cd app && git init -q
$ echo '{"compilerOptions":{"strict":true}}' > packages/tsconfig.base.json
$ echo '# Packages' > packages/README.md
$ echo '{"patches":{}}' > socket-patches.json
$ ls packages
README.md tsconfig.base.json web
$ socket-patch repair --offline --dry-run --manifest-path socket-patches.json
No patches in manifest; nothing to download.
Would remove 2 unused package archives (47 B freed)
Unused package archives:
- README.md
- tsconfig.base.json
Dry run: no changes made. (exit 0)
$ socket-patch repair --offline --manifest-path socket-patches.json
No patches in manifest; nothing to download.
Removed 2 unused package archives (47 B freed)
Repair complete. (exit 0)
$ ls packages
web
rollback says there is nothing to roll back and deletes the file anyway:
$ echo '# Packages' > packages/README.md
$ SOCKET_MANIFEST_PATH=socket-patches.json socket-patch rollback --offline
No patches in this project; nothing to roll back (no manifest at ./socket-patches.json).
Freed 11 B of unused blobs and archives (exit 0)
$ ls packages
web
The contract's own example path loses its files the same way, and the emptied directory goes with them:
$ mkdir -p app2/state/packages && cd app2 && git init -q
$ echo keep > state/packages/index.json
$ echo '{"patches":{}}' > state/patches.json
$ socket-patch repair --offline --manifest-path state/patches.json
No patches in manifest; nothing to download.
Removed 1 unused package archive (5 B freed)
Repair complete. (exit 0)
$ ls state
patches.json
With a patch API (an npm tree with six patched packages and a stand-in API; the scripts are in the routine's ledger entry of 2026-11-26 22:56Z), the first agent-mode run of a project that has no manifest yet does it:
$ socket-patch scan --mode agent --prune --manifest-path socket-patches.json
Applied 6 patches.
GC: pruned 0 manifest entries and removed 2 orphan files (47 B). (exit 0)
$ ls packages
web
$ socket-patch remove lodash --yes --manifest-path socket-patches.json
Removed 1 unused blob (41 B freed)
Removed 1 unused package archive (11 B freed) (exit 0)
| Command, with a manifest at the project root | packages/*, diffs/*, stray blobs/* files |
|---|---|
repair |
deleted |
scan --prune (hosted, the default mode, with the manifest file present; agent) |
deleted |
scan --sync |
deleted, on a run that exits 1 too |
rollback |
deleted, with an empty manifest too |
remove <target> |
deleted |
repair --dry-run, scan --prune --dry-run |
kept; repair names them, scan counts them |
scan, apply, list, vex |
kept |
The default layout is not affected: with the manifest at .socket/manifest.json the swept directories are .socket/blobs, .socket/diffs and .socket/packages.
A unit test for core manifest/cleanup_blobs.rs that hands the sweep a project root, as socket_dir_of does for a bare file name, fails on main:
#[tokio::test]
async fn sweep_spares_user_files_beside_a_manifest_outside_dot_socket() {
let tmp = tempfile::tempdir().unwrap();
let project = tmp.path().join("app");
for (dir, file) in [
("packages", "tsconfig.base.json"),
("packages", "README.md"),
("diffs", "review.diff"),
("blobs", "logo.png"),
] {
std::fs::create_dir_all(project.join(dir)).unwrap();
std::fs::write(project.join(dir).join(file), "the user's own file").unwrap();
}
std::fs::create_dir_all(project.join("packages/web")).unwrap();
// What `socket_dir_of("socket-patches.json", cwd)` hands the sweep.
let sweep = ArtifactReferences::active(&PatchManifest::new())
.sweep(&project, false)
.await;
let removed: Vec<String> = [sweep.blobs, sweep.diffs, sweep.packages]
.into_iter()
.flat_map(|pass| pass.map(|r| r.removed_blobs).unwrap_or_default())
.collect();
assert!(
removed.is_empty(),
"the sweep deleted files socket-patch never wrote: {removed:?}"
);
assert!(project.join("packages/tsconfig.base.json").exists());
}
$ cargo test -p socket-patch-core --lib sweep_spares_user_files
---- manifest::cleanup_blobs::tests::sweep_spares_user_files_beside_a_manifest_outside_dot_socket stdout ----
the sweep deleted files socket-patch never wrote: ["logo.png", "review.diff", "README.md", "tsconfig.base.json"]
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 8642 filtered out
Cause
Two rules that are each right for .socket/ meet in a directory that is not socket-patch's:
socket_dir_of(CLIargs.rs, line 767) returns the manifest's parent directory, and--cwdfor a bare file name. That is whereapply.lockandblobs/go.ArtifactReferences::sweep(coremanifest/cleanup_blobs.rs, line 86) sweepsblobs,diffsandpackagesunder that directory, andcleanup_dir(line 134) "treats it as authoritative socket-patch state (so any regular non-hidden file is considered for removal)". Thediffsandpackagespasses keep nothing: "every file in either directory is an orphan" (line 99), since v5 writes neither store. The pre-v5 stores named their archives<patch uuid>.tar.gz.
The four callers are repair.rs line 814, remove.rs line 1392, rollback.rs line 2798 and scan/gc.rs line 258.
The contract states the premise the sweep relies on: "socket-patch creates .socket/ and everything under it itself" (line 1576). That holds for a .socket/ directory. It does not hold for state/ or for the project root.
The same class was fixed twice already, each time for one site:
- The lock guard removes an emptied
.socket/and is "gated to a directory literally named.socket:--manifest-pathcan point the lock at an arbitrary user directory, and the lock must never delete one of those just because it happened to be empty" (prune_empty_socket_dir, corepatch/apply_lock.rs, line 315, since #247). The sweep runs under that same lock, in that same directory, with no such gate. - The sweep refuses an artifact directory that is a link: "socket-patch never creates a link there, so its target is someone else's tree, and every file in it would read as an orphan" (the comment above
sweep, pinned bysweep_refuses_a_linked_artifact_dir_and_spares_its_target). A directory that is someone else's by its location was not covered.
Planned fix
One rule in ArtifactReferences::sweep: a pass deletes only what socket-patch can have written there.
- When the artifact directory is not a directory named
.socket, a pass removes only files that carry socket-patch's own artifact names: a 64-character lowercase hex name inblobs/, and<uuid>.tar.gzindiffs/andpackages/(the names the pre-v5 stores used). Every other file is left and not counted. The directory is removed afterwards only when the pass itself emptied it. - A
.socket/directory keeps today's behavior, which its tests pin.
That changes no flag, default, exit code or JSON shape. The counts in gc and the Removed … lines get smaller for a relocated manifest, because the user's files are no longer in them. Tests: the unit test above, and a CLI test over repair, scan --prune, rollback and remove with a manifest at the project root beside a packages/ directory.
Not planned, because each changes a layout or refuses a documented one: refusing a manifest outside .socket/, or moving the artifact directory of such a manifest to a .socket/ beside it.
Seen beside this, and not part of it: rollback over an empty manifest at a non-default path says "no manifest at ./socket-patches.json" for a file that exists.
Generated by Claude Code
- Vorherrschende Sprache
- Rust
- Sterne
- 9
- Forks
- 2
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 313
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus SocketDev/socket-patch
-
agent:triaged arch-audit bug priority:p2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
SocketDev/socket-patch#2306 ·
Maintainer antworten meist innerhalb von 1 Tag
-
agent:triaged arch-audit bug priority:p3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
SocketDev/socket-patch#2296 ·
Maintainer antworten meist innerhalb von 1 Tag
-
agent:needs-human agent:triaged ci-janitor priority:p1
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
SocketDev/socket-patch#2270 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
agent:triaged arch-audit bug priority:p1
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
SocketDev/socket-patch#2259 ·
Maintainer antworten meist innerhalb von 1 Tag
-
agent:triaged arch-audit priority:p3 refactor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
SocketDev/socket-patch#1860 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in SocketDev/socket-patch
Ähnliche Issues
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Evtl. vergeben @iliqiliev hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
ajeetdsouza/zoxide#1381 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
triage
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
kornia/kornia-rs#1416 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
paritytech/revive#749 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
swc-project/swc-next-issues#1043 ·