Repository navigation
Report an unreadable vendor ledger instead of "No patch found" in remove and rollback - #2250
Conversation
Refs #2249. Assisted-by: Claude Code
A vendored project records its patches only in the vendor ledger. When that file could not be parsed, remove <target> and rollback <target> answered "No patch found matching identifier" for every target the manifest and the hosted pins did not hold. The ledger may hold it, and the lockfiles still install its artifact. report and a bare rollback already named the ledger. A target that selects nothing in the stores that could be read now fails with vendor_state_unreadable in both commands, for an identifier and for a rollback path target, in place of not_found, patch_not_found and path_glob_no_match. The exit code stays 1. remove takes the error it already raised before a vendored revert; the two share one mapping. With every store readable the "not found" codes are unchanged, and so is a target that the manifest or a hosted pin does hold. Fixes #2249. Assisted-by: Claude Code
Review of the previous commit found the same input mishandled in three more places. remove <target> for a manifest record restored the installed files in place and only then failed with vendor_state_unreadable, reporting no event and rolledBack 0. The contract says the refusal comes before any mutation. It now comes before the in-place rollback, so nothing is restored; the ledger no longer reaches that rollback as "nothing vendored". With no manifest, remove and rollback probed for the ledger with a stat and took any error for absence, so a ledger that could not be stat'd (a symlink loop, an unsearchable directory) was "No patches in this project". Only a missing file is absence now, as for the manifest. The error of an unmatched target names that target, so a run given several can tell which one stopped it, and rollback keeps the note that names the project directories below holding it. Refs #2249. Assisted-by: Claude Code
A second review of the branch. repair probed for the vendor ledger with the same stat as remove and rollback did: with no manifest, a ledger it could not stat was manifest_not_found. Only a missing file is absence there too now, and the run reports the ledger. The contract said a ledger under an unsearchable .socket/vendor/ fails as vendor_state_unreadable. It does not: the apply lock's journal check reads that directory first and fails as lock_io, as it already did with a manifest present. The contract and the comments say that now. rollback <name> keeps its "to target a directory instead" hint when the ledger is what failed. The contract's patched_projects_below row covers an identifier, not a path target, which never carried the note. Refs #2249. Assisted-by: Claude Code
PR SummaryLow Risk Overview
Shared messaging lives in Reviewed by Cursor Bugbot for commit 8579eb6. Configure here. |
|
bugbot run Generated by Claude Code |
|
[agent] PR shepherd: review brief for the approver What it does Risk: low. Only error paths change, and every exit code stays 1. One visible change: a Look here
Verified
Changes I made: none. Open questions: none. Generated by Claude Code |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed the refusal order in remove, the missing-file probe and both rollback early returns; nothing is changed on disk before the refusal. One nit inline, not blocking.
A review comment on the branch: with the vendor ledger unreadable, rollback <name> appended "(to target a directory instead, use ./x or x/**)" after the ledger's own error, so the hint read as part of the parse error: ... key must be a string at line 4 column 1 (to target a directory instead, use ./x or x/**) The hint now ends the clause about the target, ahead of that error: cannot read .socket/vendor/state.json to look up x, which matches nothing else in the project (to target a directory instead, use ./x or x/**): corrupt ./.socket/vendor/state.json: key must be ... patch_not_found reads as before, and a PURL or UUID target still carries no hint. A test pins where the hint lands. Refs #2249. Assisted-by: Claude Code
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 8579eb6. Configure here.
The fourth run answered the one open review thread on #2250, which was holding an approved PR out of the merge queue: rollback's directory hint now comes before the ledger's error. The PR is in the queue. Leads run on main at 9a2a946: L06 is filed as #2259 (the Hatch uv-installer check reads environments hatch.toml replaces), L21 is confirmed on #1910 (scan --prune drops the still-wired orphans), L16 and L20 are rejected, #1014 is closed, and #1950, L09 and L15 are out of charter. The next-PR list is ordered by harm. Assisted-by: Claude Code
LLM Description written by Claude Code
Fixes #2249.
Problem
A vendored project records its patches only in
.socket/vendor/state.json: vendored mode keeps no manifest. When that file cannot be read,remove <target>androllback <target>say the patch does not exist. A merge that leaves conflict markers in the ledger is enough:The lockfiles still install the vendored artifact, and the user has been told there is nothing to take off.
reportand a barerollbackalready name the ledger, andCLI_CONTRACT.mddefinesnot_found/patch_not_foundas "no manifest entry, vendor-ledger entry or hosted pin matches", which cannot be said of a ledger that was never read.Evidence on
main(0a391c1)a_target_is_never_not_found_while_the_vendor_ledger_is_unreadableintests/manifest_load_error_matrix.rsgives one project to each command that takes a target: 9 commands over 3 projects (ledger only; beside an empty manifest; beside a manifest holding another package's patch). Onmain,reportpasses its 6 runs andremove/rollbackfail their 21:Review of the first commit found the same input mishandled in three more places. Each has a test that fails before its fix:
removechanged the install before refusing. With the target in the manifest,removerestored the patched file and then failed withvendor_state_unreadable,events: []androlledBack: 0. The contract says "a hard top-level error before any mutation".remove_corrupt_vendor_ledger_restores_no_installed_filefailed withleft: "original bytes\n",right: "patched bytes\n".state.jsona symlink to itself,remove xandrollback xreturnedmanifest_not_foundwhilereport xreturnedvendor_state_unreadable(a_target_is_never_not_found_while_the_vendor_ledger_cannot_be_stat). The manifest's own probe was fixed the same way earlier (apply, apply --check and vendor report noManifest (exit 0) when .socket/manifest.json exists but can't be stat'd #998).repairhad the same probe and returnedmanifest_not_found(repair_reports_a_vendor_ledger_it_cannot_stat).Fix
remove <target>androllback <target>(an identifier or a path target) fail withvendor_state_unreadablewhen the target selects nothing in the stores that could be read and the ledger could not be. The message names the file and the target:Error: Cannot read .socket/vendor/state.json to look up pkg:pypi/six@1.16.0, which matches nothing else in the project: corrupt ./.socket/vendor/state.json: key must be a string at line 4 column 1removerefuses an unreadable ledger before its in-place rollback, so nothing is restored first.remove,rollbackandrepairtreat only a missing ledger file as "no ledger".json_envelope::vendor_ledger_load_error, gives the code and message forremoveandrollback, next tomanifest_load_error.Deleted
remove's "unreadable ledger degrades to nothing vendored" path: theResultno longer reaches the in-place rollback, the prompt count or the vendored leg.not_foundwhatever the ledger holds");removejoins that file's ledger-root matrix instead.Behavior change
All exit codes stay 1. With an unreadable vendor ledger:
remove <target>, target in no readable storenot_found,status: "notFound"vendor_state_unreadable,status: "error"rollback <identifier>, samepatch_not_foundvendor_state_unreadable(thepatched_projects_belownote is kept, and so is the directory hint of a bare name, placed ahead of the ledger's own error)rollback <path>, samepath_glob_no_matchvendor_state_unreadableremove <target>, target in the manifestvendor_state_unreadablevendor_state_unreadable, nothing restoredremove,rollback,repairmanifest_not_found.socket/vendor/itself cannot be entered, the apply lock's journal check fails first withlock_io, as it already does when a manifest is presentUnchanged: every "not found" code with a readable ledger (the control test pins them), a target the manifest or a hosted pin holds in
rollback, aremovethat only restores hosted pins, a barerollback, andreport.CLI_CONTRACT.md: 7 rows updated to say the above.Not fixed here
scan --prune'shas_ledgeruses the same stat probe (scan/gc.rs). Report a kept or failed vendored revert of scan --prune truthfully #2246 changes that file, so it is left for a later run.reportkeeps its own wording and its broader rule (it refuses a name the manifest holds too). It was the copy that was right.Risk
Low. The change is on error paths that already exit 1. The one run that now does less is
removewith a corrupt ledger and a manifest match: it used to restore files before failing, and now restores nothing, which is what the contract promised. Nocfg(windows)orcfg(unix)production code changed; the two stat tests arecfg(unix).Verification
cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings: clean.remove,rollback,report_e2e,cli_parse_remove,cli_parse_rollback,cli_parse_repair,cli_remove_silent,in_process_remove_repair_lifecycle,in_process_rollback_vendored,in_process_rollback_hosted,remove_rollback_api_overrides,manifest_load_error_matrix,manifest_path_ledger_root, andrepairexcept the two below.chmod, which root ignores; unrelated to this change):repair_invariants::repair_cleanup_failure_is_reported_in_json_and_silent_modes,repair_render::repair_exits_zero_and_stays_quiet_when_lock_file_unremovable, and inin_process_redirect:partial_lockfile_write_failure_exits_1_and_writes_no_ledger,redirect_json_mode_write_failures_emit_error_envelope,vlt::scan_redirect_vlt_heal_invalidation_failure_warns.26a0f4a: all 83 checks pass. Bugbot found no issues./code-review highran twice. Its 8 findings are fixed in the second and third commits, except thescan --pruneprobe above.rollback.rsasked for the directory hint to come before the ledger's error instead of after it, where it read as part of the parse error.8579eb6does that:... to look up x, which matches nothing else in the project (to target a directory instead, use ./x or x/**): corrupt ./.socket/vendor/state.json: ....rollback_puts_the_directory_hint_ahead_of_the_ledger_errorfailed on26a0f4aand passes now. An independent review of that commit found nothing to fix; the CLI unit tests and the 10 suites that coverremove,rollbackandreportpass (1,451 tests), and clippy is clean. CI on8579eb6: all 51 checks pass, and Bugbot found no issues.git diff --stat origin/main: production +150 −80 (4 files), tests +342 −3 (3 files), contract +7 −7.Generated by Claude Code