With the manifest outside .socket/, repair, scan --prune, rollback and remove delete the project's own files in packages/, diffs/ and blobs/
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
[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
- 主要語言
- Rust
- 星號
- 9
- 分支
- 2
- 平均合併
- 1 天 8 小時
- 30 天內合併 PR
- 313
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
SocketDev/socket-patch 的其他 Issue
-
agent:triaged arch-audit bug priority:p2
難度 2/5 1-3 小時 新手友好度 84/100
SocketDev/socket-patch#2306 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit bug priority:p3
難度 2/5 1-3 小時 新手友好度 88/100
SocketDev/socket-patch#2296 ·
維護者通常 1 天內回覆
-
agent:needs-human agent:triaged ci-janitor priority:p1
難度 2/5 1-3 小時 新手友好度 72/100
SocketDev/socket-patch#2270 · 3 則留言 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit bug priority:p1
難度 2/5 1-3 小時 新手友好度 82/100
SocketDev/socket-patch#2259 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit priority:p3 refactor
難度 2/5 1-3 小時 新手友好度 83/100
SocketDev/socket-patch#1860 ·
維護者通常 1 天內回覆
查看 SocketDev/socket-patch 的全部 Issue
相似的 Issue
-
Find/Replace panel: "Previous/Next occurrence" labels overlap and overflow their buttons (French)未關閉
難度 2/5 1-3 小時 新手友好度 63/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
obi1kenobi/cargo-semver-checks#1839 · 3 則留言 ·
維護者通常 1 天內回覆
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`可能已有人在做 @iliqiliev 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
ajeetdsouza/zoxide#1381 ·
維護者通常 5 天內回覆
-
triage
難度 1/5 1-3 小時 新手友好度 88/100
kornia/kornia-rs#1416 · 1 則留言 ·
維護者通常 2 天內回覆