Skip to content

Read patch files committed to .socket/blob/ when .socket/blobs/ lacks them - #2514

Open
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
fix/legacy-blob-dir
Open

Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
fix/legacy-blob-dir

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A project whose patch files were committed under .socket/blob/ (an older commit layout, as written by an integration) has every byte of its patch in the repository, in a folder the CLI never read. So:

  • every apply downloaded the patch files again;
  • apply --offline failed with "no local source";
  • once the patch service stopped serving a superseded patch, apply failed with "Blob not found on server" and exit 1, although the files were in the checkout.

Change

One fallback, in the apply source stager (commands/fetch_stage.rs, the place that decides "missing, so download"). A blob .socket/blobs/ lacks is looked for in .socket/blob/ before it counts as missing. apply, the nested apply of get and scan, and --offline all go through it.

  • A legacy file is used only when it is a regular file reached through no link (same rules as .socket/blobs/) and its bytes hash (git-sha256) to its name. Any other file is ignored and the blob is downloaded as before.

  • The verified bytes are handed to the pipeline as in-memory sources. apply still writes nothing under .socket/, and builds no API client when the folder covers the run.

  • The run says so once, on stderr (muted by --silent), and as run warning legacy_blob_dir in --json:

    Warning: read 6 patch files from `.socket/blob/`; socket-patch keeps patch files in `.socket/blobs/`. Run `socket-patch scan` to update the patches and store their files there (or `socket-patch repair` to copy them as they are), then commit `.socket/`
    

    scan is named first on purpose. A project in this layout was set up long ago and often holds a patch that has since been replaced. Now that its apply runs offline, this notice is the only one it gets. scan moves the manifest to the current patches and stores their files in .socket/blobs/; repair only copies the old files as they are.

repair copies them. Before any download, repair copies the blobs the manifest references that .socket/blobs/ lacks (or holds corrupt) from .socket/blob/, through the existing verified blob writer. It works with --offline; --dry-run reports the copy and makes none. It goes by the whole manifest (vendored records included, as apply stages them), so the apply notice clears after one repair. It prints

Copied 6 blobs from `.socket/blob/` to `.socket/blobs/`. Commit `.socket/blobs/`; `.socket/blob/` can then be deleted.

and reports the same legacy_blob_dir warning in --json. The legacy folder is never modified or removed: it is the user's committed data.

Readers left alone

  • rollback: needs before-hash blobs, which the older layout never held; it fetches them on demand as before.
  • remove, vendor, vex, get / agent download: they read or fill .socket/blobs/ and work after repair has copied the files. Giving each its own fallback would spread the legacy name over every reader.
  • The orphan sweeps (repair, remove, rollback, scan --prune) only read .socket/blobs/, diffs/ and packages/. Checked on a real project: a scan --prune and a repair leave .socket/blob/ and every file in it untouched. This PR does not widen them.

Tests

  • Core unit tests: a legacy blob is read only when it hashes to its name; a linked entry or a linked folder is refused; the repair copy restores what verifies and nothing else.
  • Stager unit tests: a legacy hit is Ready offline and online with no overlay and no API client; a corrupt legacy file is no source; with partial coverage only the uncovered blob is asked of the server.
  • End to end (tests/apply/legacy_blob_dir.rs): offline apply from the legacy folder alone, with .socket/ unchanged; online apply against an endpoint that refuses every request; a partly covered run downloads only the uncovered blob; the --json warning and --silent; a corrupt legacy file is ignored; linked entries are not followed; repair --offline copies and the next apply is quiet.
  • get's nested apply (tests/get/get_nested_apply_api_flags_e2e.rs): reads the legacy folder, makes no blob request, and get carries the warning in both output modes.
  • Checked by hand against a real project with a superseded patch: the 5.2.0 release exits 1 offline, this build applies.

Review (/code-review high)

Fixed:

  • The download step asked for what .socket/blobs/ lacked instead of what the overlay lacked, so an entry the overlay does not mirror (a link, a directory) was no longer downloaded. It is the old rule again, less the legacy blobs.
  • repair copied by the manifest scoped to non-vendored records while apply stages vendored records too, so the notice could name files repair never copied. repair now copies by the whole manifest. Not covered by a test of its own (a vendored fixture needs a full vendor run).
  • repair in human mode did not say to commit .socket/blobs/; a dry run said to commit and that every blob was present. Both fixed.
  • The "no download" test could not fail against a dead endpoint; it now counts requests on a listening server.

Declined:

  • apply does not use an intact legacy copy when .socket/blobs/ holds a corrupt entry of the same name. Finding that out means hashing the whole cache on every apply, which apply has never done; repair restores such an entry from the legacy folder. The contract row says so.
  • apply reads every legacy blob the cache lacks on every run, a no-op run included. The offline gate and the download plan need to know up front which hashes have a usable source, only a read can tell, and holding the verified bytes is what makes the bytes checked the bytes written. It replaces a download of the same blobs on every run, and one repair ends it. Said in a comment.
  • A file left by an earlier patch whose blob is only in .socket/blob/ and no longer in the manifest is not recognised as Socket content. It was not recognised before this change either; the fallback covers the blobs the manifest references.

Windows

A Windows test run was dispatched by hand (PR runs have no Windows job) on the commit before the last two, which change a contract sentence and the notice text. All tests this PR adds passed there. One test failed, quoted_url_credentials::a_hosted_warning_quotes_a_lock_entry_without_its_token in the scan suite; it fails on main on Windows too and is in code this PR does not touch.


Generated by Claude Code

…acks them

A project whose patch files were committed under `.socket/blob/` (an
older commit layout, as written by an integration) has every byte of its
patch in the repository, in a folder the CLI never read. Each `apply`
downloaded the files again, `apply --offline` failed with "no local
source", and once the patch service stopped serving a superseded patch
the run failed with "Blob not found on server" and exit 1.

The apply source stager now looks for a blob `.socket/blobs/` lacks in
`.socket/blob/` before it counts it as missing. A file found there is
read into memory and used only when it is a regular file reached through
no link and its bytes hash (git-sha256) to its name; any other file is
ignored and the blob is downloaded as before. The verified bytes are
handed to the pipeline as in-memory sources, so `apply` still writes
nothing under `.socket/`, needs no API client when the folder covers the
run, and `get` / `scan`'s nested apply get the same behaviour.

A run that read such files says so once (`Warning:` on stderr, muted by
`--silent`; run warning `legacy_blob_dir` in `--json`) and points at
`socket-patch repair`, which now copies the blobs the manifest references
from `.socket/blob/` into `.socket/blobs/` before any download (with
`--offline` too; `--dry-run` reports the copy). The legacy folder is
never modified, and no sweep reads it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ed cases

The stager asked the server by hash for what `.socket/blobs/` lacked,
which skips an entry the overlay holds in any form. It now asks, as
before this branch, for what the overlay lacks by the cache's own rule,
less the blobs read from `.socket/blob/`.

Tests: a run with one patch's file in the legacy folder and another's
nowhere downloads only the second and applies both; `get`'s nested apply
reads the legacy folder, makes no blob request and carries the
`legacy_blob_dir` warning in both output modes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- `repair` copies from the legacy folder by the whole manifest, not the
  one scoped to non-vendored records: `apply` stages for vendored
  records too, so its advisory named files `repair` never copied and
  never cleared.
- `repair` tells a person what is left to do (commit `.socket/blobs/`),
  which only the `--json` warning said. A dry run, which copied nothing,
  no longer says to commit, nor that every blob is present.
- The "no download" test counts requests on a listening server: against
  a dead endpoint it could not fail.
- Say why the stager reads the legacy blobs up front.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A project in the older layout was set up long ago and often holds a
patch that has since been replaced. Now that its `apply` runs offline,
this notice is the only one it gets, and `repair` only copies the old
files as they are. `scan` moves the manifest to the current patches and
stores their files in `.socket/blobs/`, so the notice names it first and
`repair` second, and says to commit `.socket/`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 4, 2026 20:24
@cursor

cursor Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes patch artifact resolution for every apply/repair/get path, but reads are hash-verified and fail closed on links; corrupt entries in .socket/blobs/ still fail apply as before.

Overview
Adds a fallback for projects that committed patch file blobs under the older .socket/blob/ layout instead of .socket/blobs/. During staging, any manifest-referenced hash missing from the cache is loaded from the legacy folder (if present) before offline failure or network download.

Legacy files are accepted only as regular, non-symlink entries whose bytes match their git-sha256 filename; verified content is passed through mem_blobs so apply stays read-only under .socket/ and can succeed --offline without hitting a dead patch service. Runs that use legacy files emit run warning legacy_blob_dir (human stderr or JSON warnings[], including nested get apply).

repair copies missing or corrupt cache entries from .socket/blob/ into .socket/blobs/ before downloads (works --offline; --dry-run reports only). The legacy directory is never deleted or swept.

CLI_CONTRACT.md documents the new warning; unit and e2e tests cover staging, partial legacy coverage, corruption, symlink refusal, and repair migration.

Reviewed by Cursor Bugbot for commit c359dbb. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c359dbb. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief

What it does. Projects that committed their patch files under the older .socket/blob/ folder had every byte locally but the CLI never read it, so apply re-downloaded each run, failed under --offline, and failed outright once the patch service stopped serving a superseded patch. apply (and the nested apply of get/scan) now uses a .socket/blob/ file when .socket/blobs/ lacks it, after checking it is a plain non-linked file whose git-sha256 matches its name, and says so in a legacy_blob_dir warning. repair copies those files into .socket/blobs/ (offline too) and never touches the legacy folder.

Risk: low. It only acts when a .socket/blob/ directory exists (one lstat otherwise), and a file that fails verification falls back to the old download path. apply still writes nothing under .socket/. On Windows, a checkout that converts line endings in that folder fails the hash check and falls back to downloading, so it is no worse than today.

Look here

  • fetch_stage.rs:229: legacy lookup feeding both the offline gate and the download plan
  • [fetch_stage.rs:293-298](https://github.com/SocketDev/socket-patch/blob/c359dbb54b116bb735801aa64f21a6072182a933/crates/socket-patch-cli/src/commands/fetch_stage.rs#L293-L298): the overlay download still asks for what the overlay lacks, minus legacy hits
  • blob_fetcher.rs:124: read_legacy_blob, with link refusal and hash check
  • repair.rs:773: repair copies by the whole manifest, so the apply notice clears after one run

Verified. Read the whole diff. ci-ok and clippy pass on c359dbb. Ran cargo test -p socket-patch-cli --test apply legacy_blob_dir locally: 7 passed. CHANGELOG.md is untouched.

Changes I made. No code changes. I answered Bugbot's "legacy hit skips bad cache entries" thread and resolved it: the no-overlay path it describes is the one main already takes whenever nothing is absent, so this PR adds no regression. I also removed a duplicated sentence from the description's Windows section.

Open questions. None. The description's "Declined" list covers the remaining trade-offs: no fallback when a .socket/blobs/ entry is corrupt, and legacy blobs are read on every run until repair is run.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant