Skip to content

An interrupted run leaves stage files nothing removes: a partial download in .socket/blobs/, and a copy of a rewritten project file (.npmrc with its token) that git add -A stages #2337

Backlog

Description

[agent] Found by the architecture refactor routine while interrupting and killing runs at random moments. Run on main at cfc870f with the binary built from it: agent mode over a real npm install (npm 10.9) with a stand-in patch API, hosted mode over the npm project of the repository's benchmark harness.

Problem

Every file socket-patch writes is staged under a second name and renamed into place. A run that is interrupted (Ctrl-C, SIGTERM) or killed between the two leaves the stage behind. Two kinds of stage are cleaned up later, and two are never removed by any command:

Stage Where Removed later?
.socket-stage-<file>-<uuid>, .socket-orig-<file>-<uuid> beside a patched file of an installed package yes: the next apply or rollback of the package, once ten minutes old
.socket-stage-* directly under .socket/ yes: the next command that takes the lock, once an hour old
.socket-dl-<hash>-<uuid> .socket/blobs/, a blob download that did not finish never
.socket-stage-<file>-<uuid> beside a project file a hosted run rewrites (package-lock.json, .npmrc, gradle.lockfile, …) never

Who it hurts:

  • A project whose .npmrc holds a registry token. A hosted scan appends allow-remote=all to .npmrc, so its stage is a full copy of the file, token included. The project ignores .npmrc in git; no ignore rule names .socket-stage-.npmrc-<uuid>. After a Ctrl-C at the wrong moment, git status shows the copy as untracked and git add -A stages the token.
  • Anyone who interrupts a download. The partial blob sits in .socket/blobs/, the directory the scan tells the user to commit ("Commit .socket/ to keep the patches"). repair reports "all in use" beside it, scan --prune keeps it, and after a full rollback it is what keeps .socket/blobs/ in the project. Each interrupted run adds another.

Evidence

1. A token-bearing .npmrc, hosted mode. The project is the benchmark harness's npm project with .npmrc (mode 0600, one _authToken line) and a .gitignore naming .npmrc, committed. A hosted scan was sent SIGINT at a random moment until a stage was left; it took 63 interrupts of a run that takes about 70 ms.

$ git status --short                      # before any scan: clean
$ socket-patch scan --yes                 # Ctrl-C
$ git status --short
?? .socket-stage-.npmrc-b5e43b73-4a87-49ec-b1ff-9fdab649e005
$ ls -l .npmrc .socket-stage-.npmrc-*
-rw------- .npmrc
-rw------- .socket-stage-.npmrc-b5e43b73-4a87-49ec-b1ff-9fdab649e005
$ grep -c _authToken .socket-stage-.npmrc-*
1
$ git check-ignore .npmrc .socket-stage-.npmrc-*
.npmrc
$ socket-patch scan --yes; echo "exit $?"
Switched 1 package to hosted patches; rewrote 2 files.
exit 0
$ touch -d '2 hours ago' .socket-stage-.npmrc-*; socket-patch scan --yes; echo "exit $?"
exit 0
$ git status --short
 M package-lock.json
?? .socket-stage-.npmrc-b5e43b73-4a87-49ec-b1ff-9fdab649e005
$ git add -A; git diff --cached --name-only
.socket-stage-.npmrc-b5e43b73-4a87-49ec-b1ff-9fdab649e005
package-lock.json

How often a signal lands in the window, over the same project without the token, 200 signals each at a random moment of the run:

Signal Left a stage of .npmrc or package-lock.json in the project root
SIGINT 8
SIGTERM 8
SIGKILL 7

A rollback leaves them the same way: a kill inside a Gradle hosted rollback's writes left .socket-stage-gradle.lockfile-<uuid> in the project root, and a later scan and rollback kept it.

2. A partial download, agent mode. lodash, ms, kleur and left-pad installed by npm, one patch each (44 files). 150 signals each at a random moment of scan --mode agent --yes:

Signal Left .socket/blobs/.socket-dl-* Left stages beside patched files Left .socket/.socket-stage-manifest.json-*
SIGINT 8 24 0
SIGTERM 24 20 1

The API here is local, so the download is a small part of the run; against a real network it is most of it. Then, over one of those trees:

$ ls -A .socket/blobs | grep -v -E '^[0-9a-f]{64}$'
.socket-dl-54a481a52cca5cbe80e498ed5e41632a9b317f61cce5edaa29746948b06bba53-45d40953-1fb3-4413-b1d4-20312a8a66db
$ socket-patch scan --mode agent --yes | sed -n 2p
Applied 4 patches.
$ socket-patch repair --yes
All blobs are present locally.

Checked 88 blobs: all in use.
$ socket-patch scan --mode agent --yes --prune | sed -n 2p
Applied 0 of 4 patches: 4 already patched.
$ socket-patch rollback --yes | sed -n 2p
Rolled back 4 packages:
$ find .socket
.socket
.socket/manifest.json
.socket/blobs
.socket/blobs/.socket-dl-54a481a52cca5cbe80e498ed5e41632a9b317f61cce5edaa29746948b06bba53-45d40953-1fb3-4413-b1d4-20312a8a66db

The stage was still there after each of them, and after an apply. The same rollback of a project no run was interrupted in leaves .socket/manifest.json alone.

3. The two sweeps that exist, as controls. Both kinds of stage, two hours old, in one .socket/:

$ find .socket -name '.socket-*'
.socket/blobs/.socket-dl-c77d51fc…-1c259529-12a7-44e5-bf58-d7215a59afad
.socket/.socket-stage-manifest.json-121437bf-9fc7-4249-a068-ccf574b7b774
$ socket-patch scan --mode agent --yes >/dev/null; find .socket -name '.socket-*'
.socket/blobs/.socket-dl-c77d51fc…-1c259529-12a7-44e5-bf58-d7215a59afad

And the stages beside patched files, 16 minutes after the kill that left them: apply took 30 to 0, rollback 25 to 0, rollback --preserve-state 24 to 0.

Why

  • A blob is staged as .socket-dl-<hash>-<uuid> beside its final name (core api/blob_fetcher.rs, lines 369 and 433), and the stage is removed only when the write returns an error (lines 376 and 459). A signal ends the process before that.
  • The hour sweep reads the direct children of .socket/ and takes names that start with .socket-stage- (core utils/socket_dir.rs, lines 129 to 164). It never opens blobs/.
  • The blob cleanup of repair, scan --prune and rollback skips every name that starts with a dot, and says a hidden file keeps the directory (core manifest/cleanup_blobs.rs, lines 126 and 158).
  • The ten-minute sweep reads only the directories of an installed package's patch files (core patch/apply.rs, lines 778 to 815).
  • A project file is staged beside itself with the destination's mode (core utils/fs.rs, stage_path at line 776 and stage_open_options at line 793), which is why the copy of .npmrc is 0600. No sweep reads the project root or a rewritten file's directory.
  • On a catchable signal the handler unlinks the lock and nothing else (core patch/apply_lock.rs, cleanup_held_lock_on_interrupt at line 350).

Both sweeps came in with #2052 (git log -S"fn sweep_stale_stage_entries" and -S"fn sweep_stale_stages" both name it), for this same class: the comment on the first says that without it a half-written stage "would stay under .socket/ for good". The download stage and the project-file stage are the two places that fix did not reach. CLI_CONTRACT.md describes the two sweeps (line 37, and the sentence "A killed run also leaves …" in the apply section) and says nothing of the other two.

Planned fix

  1. One rule for "a stage this tool named, older than its floor", in place of the three that exist (sweep_stale_stage_entries, is_stale_stage, and the gem build's), run over every directory a run stages into:
    • .socket/ and .socket/blobs/, when the lock is taken;
    • the directory of each project file a hosted or vendored run is about to rewrite, for stages of that file's name (the <prefix><file name>-<uuid> shape is_stale_stage already checks).
  2. On a catchable signal, unlink the stages the run holds, beside the lock, so Ctrl-C and SIGTERM leave nothing to sweep. This is the part that closes the .npmrc case without waiting an hour.
  3. The blob cleanup takes a .socket-dl- name as an orphan, so repair and scan --prune report and remove it and an emptied blobs/ goes with it.
  4. CLI_CONTRACT.md line 37 names the two new places.

Tests: a unit test per directory that plants an old stage and runs the sweep; a CLI test that parks a hosted scan between stage and rename (the ~pause failpoint the interrupt tests use), signals it, and asserts the project holds no .socket-stage-*.

This is not a decision issue: the rule is the one the two existing sweeps state. The first slice is the project-file stage (1 and 2), since that is where the token is.

The routine has three PRs open and awaiting review, so no PR is opened for this yet.

Not checked: Windows; a vendored run's downloads into .socket/vendor/ (no vendor service here); get and repair, which download through the same writer; whether the hour sweep's age floor is right for a project file's directory.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 28, 2026
  2. added a commit that references this issue on Nov 28, 2026
  3. added a commit that references this issue on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditbugpriority:p3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions