Repository navigation
Add an experimental hot-patch subcommand - #2068
Conversation
The kernel shields a container's main process from every signal it does not handle. The handler cleaned up and re-raised the signal with the default disposition, which as PID 1 is dropped: the run carried on, and `docker stop` waited out its grace period before a SIGKILL. The handler now ends the process itself when it is PID 1, with the status a signal death would report (128 + the signal's number). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ENTRYPOINT ["socket-patch", "hot-patch", "--"] CMD ["node", "server.js"] Hot patch mode patches everything installed on the machine in place, saves nothing, and then replaces itself with the command after `--`, which keeps the PID, the environment and the exit status it would have had. As a container's entrypoint it makes a restart the way a patch is deployed or withdrawn. The hidden `hot-patch` subcommand takes scan's options plus --timeout: - it always starts the command: a flag that does not parse, an unreachable API, packages that cannot be written and a panic are each one line on stderr; - it runs two agent-mode scans, the project under --cwd and then the globally installed packages (--global runs only the second). The project pass leaves Go to the global one, because a project run redirects Go modules through go.mod instead of patching them in place, and the global pass reads the working directory's socket.yml too, so a package the repository excludes stays unpatched wherever it is; - it saves nothing: the manifests and patch data live in a temporary directory that is removed before the command starts, and --manifest-path, --prune, --sync, --vex and --max-new-patches are refused; - it applies every patch a scan would select. --min-severity, SOCKET_MIN_SEVERITY and socket.yml narrow that as they do for scan; - it drops a pass that has not started writing patches within --timeout seconds of the start (default 10), and never interrupts a write; - it prints one `socket-patch: ...` line on stderr and nothing on stdout. SOCKET_OFFLINE=1 is the off switch. Without a command after `--` it patches nothing and exits 2. The subcommand is hidden and experimental: nothing about it is stable. Scan and every other subcommand behave as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview Hot-patch behavior is wired through scan/apply: refused flags include save-oriented options ( All subcommands: interrupt handling now exits PID 1 with Docs ( Reviewed by Cursor Bugbot for commit 0fe56a8. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, 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 0fe56a8. Configure here.
On a restart, a package both passes reach (a Python image's system site-packages) is found patched by each, and the summary line said so twice. The in-place count is now of packages, like the failed and dry-run counts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] PR shepherd: review brief for the approver What it does. Adds a hidden, experimental Risk: medium. The new mode is hidden and opt-in, but Look here
Verified
Changes I made: none. Open questions
Generated by Claude Code |

Adds hot patch mode as a hidden, experimental subcommand.
socket-patch hot-patch -- <command>patches everything installed on the machine in place, saves nothing, and then becomes the command. As a container's entrypoint it makes a restart the way a patch is deployed or withdrawn, with no image rebuild.scanand every other subcommand behave as before. The one change outside the new subcommand is the stop-signal fix below.What hot patch mode does
execs the command, which keeps the PID, the signals, the environment it was given and its exit status.--cwd, then the system's globally installed packages (--globalruns only the second).--manifest-path,--prune,--syncand--vexare refused.--min-severity,SOCKET_MIN_SEVERITYand socket.yml narrow it as they do forscan, and they are where a policy or a target list would plug in later.--timeoutseconds of the start (default 10) is dropped, and it has touched nothing. A pass that has started writing is never interrupted.socket-patch: ...line on stderr, nothing on stdout.SOCKET_OFFLINE=1is the off switch.The subcommand takes scan's options plus
--timeout. Without a command after--it patches nothing and exits 2.Two things differ from running the two scans by hand:
go.modto a copy under.socket/, and drops the redirects its manifest does not list. This mode's manifest starts empty and it writes nothing but installed packages.--globalscan does not. The two passes can reach the same installed copy (a Python image's system site-packages), and a package the repository excludes has to stay unpatched in both.The stop-signal fix (every subcommand)
The kernel drops a signal that PID 1 re-raises with the default disposition, so when socket-patch was a container's main process
docker stopdid nothing until the grace period ran out. The handler now ends the process itself when it is PID 1, with exit status 128 + the signal's number. Measured withdocker stopduring a check that was waiting on a dead API: 0.2 s, exit 143.Start-up cost
Time added before the command starts, measured inside the container on a laptop (Docker Desktop, linux/arm64) against the public patch API with no token, median of 5 fresh containers:
Nearly all of it is round trips to the patch API.
SOCKET_OFFLINE=1adds 2 to 3 ms, and an API that never answers costs the time limit. The default limit is 10 s because these starts were too close to 5 s.Size
src/hot_patch.rsis new (about 510 lines plus its unit tests). The rest of the non-test change is about 130 lines in six files:main.rscuts the command off the command line before parsing and makes every way out start it,lib.rsdeclares the hidden subcommand,ui/mod.rshands scan's JSON document to hot patch mode instead of printing it,agent_download.rsmarks the start of the apply step,scan/policy.rslets the global pass read socket.yml in this mode, andinterrupt.rsholds the PID 1 fix.ScanArgs, the patch engine, the crawlers and the API client are untouched.Testing
tests/hot_patch_e2e.rs: 19 end-to-end tests that spawn the real binary against a mock patch API. They cover both passes patching and the command's exit status,--global, the same PID, the command's own flags, an unreachable API, the time limit (the whole run, and the global pass alone), a severity floor, a dry run, socket.yml covering the global pass, a rollout cap, a withdrawn patch, a restart, usage errors and refused flags, the off switch, a missing command, the unchanged environment, a panic, and a stop signal.hot_patch.rsfor the command-line split, the passes, the time parser and the summary line.docker stopduring the check.e2e_vendor_cargo_buildtests that need old x86 cargo toolchains this Mac cannot run ('cargo': Bad CPU type in executable); they fail the same way onmain. The hot-patch end-to-end tests also pass on Linux (in therust:1.93-bookwormimage), including the one that needs/dev/full.Known gaps
Review findings I chose not to fix in this PR, and why:
.socket/directory behind.yarn global diris still running when the limit is reached, it is left as a child of the command. Closing this needs a registry of live children in core.ui::print_json, the agent engine and the policy loader consult. Passing them throughScanArgsinstead would have touched everyScanArgsliteral in the tests.enabled, but a root excluded byignorePathsdoes not exclude global packages.Also out of scope here: containers that cannot write to their packages (non-root with root-owned packages, read-only root) get nothing patched, and a patch withdrawn after a container was patched is not rolled back when that container restarts in place.
/code-review highwas run on this diff; its confirmed findings are fixed or listed above.🤖 Generated with Claude Code