remove <target> reports success over a vendored package whose ledger entry is lost: the lockfile keeps installing the patched artifact and the patch record is deleted

未關閉
#2,290 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
rust
領域
cli

研究方向

Start with crates/socket-patch-cli/src/commands/rollback.rs and remove.rs, then inspect the failing cases in tests/in_process_vendor.rs and the relevant state discovery rules in CLI_CONTRACT.md. Trace how each command identifies unowned vendor directories and checks them before writing. Done means scoped remove and rollback refuse affected targets with the missing-ledger guidance, preserve the manifest record, and keep unrelated targets working.

由索引模型根據 Issue 內容生成。

描述

agent:triaged arch-audit bug priority:p1

[agent] Found by the architecture refactor routine (ledger discussion #2244, lead L37), on main at cfc870f.

Problem

A lockfile still installs a package from .socket/vendor/<eco>/<uuid>/, and the vendor ledger has no entry for it. The contract names how a project gets there: a git merge that kept one side of .socket/vendor/state.json (#991), or a state.json that was deleted or never committed.

An unscoped rollback refuses that state with vendor_ledger_missing, exit 1, and writes nothing (#1739 for #991). remove <target> and rollback <target> do not ask the same question, and give four other answers. The worst one is a success:

$ socket-patch remove pkg:npm/[email protected] --yes
1 package already in original state

Removed 1 patch from manifest:
  - pkg:npm/[email protected]

Manifest updated at <project>/.socket/manifest.json

Removed 2 unused blobs (65 B freed)                                                 (exit 0)

$ grep -A2 '"node_modules/left-pad"' package-lock.json
    "node_modules/left-pad": {
      "version": "1.3.0",
      "resolved": "file:.socket/vendor/npm/9f6b2c4e-1d3a-4f6b-8c2d-7e5a9b1c3d5f/left-pad-1.3.0.tgz",

The patch is reported removed and the package original. The lockfile still installs the patched tarball, and the record that described it is gone.

Who it hurts

  • Someone removes a patch, perhaps because it broke the build, and is told it is gone. npm ci keeps installing the patched package.
  • After that list no longer shows the patch, a second remove says "No patch found", and vex can no longer attest the package without the patch API (record_unavailable). Only vendor --check and repair still see the wiring.
  • In a project with no manifest (every scan --mode vendored project) the same commands exit 1 and write nothing, but say there is no patch, where rollback names the lost ledger and the way out.

Evidence on main

The binary is built from cfc870f. The projects are files only: a lockfile, the installed copies and, where stated, a manifest. vendor or scan --mode vendored ran first against the repository's prebuilt-artifact fixture (tests/prebuilt_common), and then one ledger entry or the whole state.json was removed. In every row the lockfile still names the artifact afterwards.

A project with a manifest (agent mode, then socket-patch vendor), two vendored npm packages:

Ledger Command Result
entry lost, or file deleted rollback exit 1, vendor_ledger_missing, nothing written
entry lost, or file deleted vendor --check exit 1, vendor_ledger_missing
entry lost, or file deleted rollback pkg:npm/[email protected] exit 0: "Rolled back 1 package: pkg:npm/[email protected] (already original)", "Removed 1 patch from manifest.", and the vendor_orphan_still_wired warning
entry lost, or file deleted remove pkg:npm/[email protected] --yes exit 0, the output above, no warning

Under --json the remove is "status": "success" with a removed event for the purl and no warnings. A requirements.txt project and a Cargo project give the same remove result (exit 0, the wiring kept, plus a rollback_not_installed skip).

What the other commands say after that remove:

$ socket-patch list                         # the patch is no longer listed
Found 1 patch:
Package: pkg:npm/[email protected]

$ socket-patch remove pkg:npm/[email protected] --yes
Error: No patch found matching identifier: pkg:npm/[email protected]                   (exit 1)

$ socket-patch vendor --check
vendor_ledger_missing: a lockfile references a vendored npm artifact under .socket/vendor/npm/ but the vendor ledger (.socket/vendor/state.json) has no entry for it; restore state.json from version control   (exit 1)

$ socket-patch vex --output - --product pkg:generic/[email protected]
Warning: omitting pkg:npm/[email protected] from VEX: a lockfile wires the patch, but no local record exists and the patch API could not supply one (…) (record_unavailable)

A project with no manifest (scan --mode vendored):

Ledger Command Result
entry lost rollback exit 1: "Lockfiles reference .socket/vendor/npm/9f6b2c4e-…/, which the vendor ledger (.socket/vendor/state.json) has no entry for, so rollback cannot unwind them; restore the missing entries …"
entry lost rollback pkg:npm/[email protected] exit 1: "No patch found matching identifier: pkg:npm/[email protected]"
entry lost remove pkg:npm/[email protected] --yes exit 1: "No patch found matching identifier: pkg:npm/[email protected]"
file deleted rollback, rollback pkg:npm/[email protected] exit 1: "Lockfiles still reference .socket/vendor/ artifacts but the vendor ledger is missing — restore .socket/vendor/state.json from version control, then roll back (…)"
file deleted remove pkg:npm/[email protected] --yes exit 1: "No patches in this project; nothing to remove."

Cause

One rule, "a lockfile reference into .socket/vendor/<eco>/<uuid>/ that no ledger entry owns cannot be unwound", is asked in two places of crates/socket-patch-cli/src/commands/rollback.rs and nowhere in remove.rs:

  • the missing-ledger early exit (line 2040), which rollback reaches only when the project has no manifest;
  • unledgered_vendor_wiring (line 1080), guarded by !scoped (line 2220).

The guard is right for a target that names another package: that run does not own the wiring. It also lets through a target that names the very package the unowned directory holds. With a manifest record for it the agent leg then finds the installed copy original and reports the patch rolled back. remove has neither check: its no-state exit (remove.rs line 614) and its unmatched-target error (line 793) never read the lockfiles.

Earlier fixes of the same class, each for one command or one cause: #1739 for #991 (unscoped rollback), #2250 for #2249 (remove and rollback <target> over a ledger that cannot be read, where the contract now says such a target "is never 'not found' while the ledger cannot be read, since the ledger may hold it").

What settles the expected behavior

  • CLI_CONTRACT.md, rollback's state discovery: "A project whose lockfiles still reference .socket/vendor/ artifacts but whose vendor ledger is missing errors asking for .socket/vendor/state.json to be restored from version control first", and the error table: "vendor_ledger_missing | rollback | Lockfiles reference .socket/vendor/ artifacts but the vendor ledger is missing, or (unscoped run) has no entry for a referenced uuid dir (#991)". With a manifest present and the ledger file deleted, rollback <target> exits 0 today.
  • The same section, on why the unscoped run refuses: "reverting the rest would exit 0, leave that package wired and delete the ledger". The scoped remove does that to the manifest record.
  • The charter's rule that success is never reported for work that did not happen.

Planned fix

One function answers "which unowned vendor directories does this run's target reach", and rollback and remove both call it before any write:

  1. A target that selects a manifest record whose uuid an unowned lockfile reference carries: refuse with vendor_ledger_missing, naming the directory and the remedy rollback already prints. Nothing is restored and no record is dropped.
  2. A target that selects nothing while an unowned reference exists: vendor_ledger_missing in place of "No patch found", as #2250 did for the unreadable ledger.
  3. remove in a project whose only state is that wiring: the message rollback gives, in place of "No patches in this project; nothing to remove."
  4. A target that names another package keeps working, as the contract says.

Tests, failing on main: the first table's remove and rollback <target> rows over the npm fixture of tests/in_process_vendor.rs, and the second table's three bold rows.

One open point: the contract's error table lists vendor_ledger_missing for rollback only. Giving remove the same code is the sibling's rule and adds a row to that table.

Not checked

  • Hosted pins beside the unowned wiring.
  • --ecosystems narrowing and --global.
  • JVM artifacts, which keep their own tree layout.

Generated by Claude Code

主要語言
Rust
星號
9
分支
2
平均合併
1 天 8 小時
30 天內合併 PR
313

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

SocketDev/socket-patch 的其他 Issue

查看 SocketDev/socket-patch 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。