Repository navigation
fix: kill every helper a serve-mode git fetch leaves behind (sc+git::) - #374
Merged
Merged
Conversation
In serve mode on unix the fetch watchdog now spawns /bin/sh as the leader of git's process group instead of git itself. The shell runs git in a subshell, writes git's exit code to <cache>/.fetch-status-<n>, closes its own stdout and stderr, and blocks reading a stdin pipe only sc holds. When sc closes that pipe (or dies) the shell kills its whole group with the builtin kill. sc never waits for the leader before its group is dead: git's exit comes from the status file (strict parse), so the leader's pid keeps pinning the group id. Every end of a fetch, normal or breach, drops the pipe, signals the group once through the system kill as a backup while the leader is unreaped, reaps the leader within a bound, then settles and measures. A helper that stays in git's group, including one that outlives git, can no longer write after the discard. A helper that leaves the group (setsid) still escapes. Exit status 126 or 127 maps to the "cannot run git" error; a signalled git reads as 128 + n. The CLI and non-unix builds are unchanged. Tests rewrite the old "no group signal after git exits" cases for the new rule and add: a quiet writer that outlives git is dead and stops growing the pack directory, a mid-run breach kills the group with no kill program, exit codes propagate, 126/127, a leader that dies early, and the strict status parse.
…tchdog ADR-0060, THREAT-MODEL, ARCHITECTURE, CLAUDE.md, the sc-cli-reference skill and ROADMAP now say that serve mode on unix kills every helper that stays in git's process group, including after git exits, and when sc serve dies. A helper that leaves the group (setsid: an ssh ControlPersist master, a credential-cache daemon) escapes; the status file trusts local executables; SC_GIT is resolved by /bin/sh through command. Follow-on (10) moves to built, and the claims that a helper outliving git is never killed, that serve mode needs a kill program, and that a fetch outlives a killed sc serve are removed for serve mode.
… leg The escaped helper now writes its pid after setsid succeeds and the shim waits for it, instead of sleeping, which raced the group kill. The late writer test regains its serve-mode leg (a writer that left the group and holds the pipes). describe_code words the 128 + n case as a hint, and the THREAT-MODEL no longer says a v0/v1 helper chain may survive in serve mode.
…nbounded waits The leader's environment loses SHELLOPTS, BASHOPTS, BASH_ENV, ENV and every BASH_FUNC_* variable (bash is /bin/sh on macOS: monitor moves the job out of the group, errexit skips the status line and the final kill, exported functions override command, echo, read and kill). The script itself now tolerates errexit and uses `command --`. The backup kill program is spawned and waited for at most 2 s. A missing /bin/sh is reported as that, not as a missing git. The 128 + n hint appears only in the text of fetches the leader ran, and a 126/127 from the shell includes git's own stderr. Tests: a hostile shell environment (set through a test seam on the leader command), a hanging kill program, the leader must still exist when the group is signalled, the quiet-writer test waits for the helper's first write and has a variant without the backup kill, and the perl setsid probe needs a positive session id. Docs soften the claims about sc serve dying, say the shell functions are stripped, and note the per-fetch cost.
…kill is the only group kill An external kill program waited on by sc kills only that program's own process, and signalling a group id after the leader is reaped could hit a reused id. The leader's `kill -s KILL 0`, run when its stdin closes, is now the one group kill. stop() closes the pipe, gives the leader 5 s to exit, then kills it alone; terminate() reaps it, settles and measures. Removed: kill_group, may_signal_group, KILL_WARNED, warn_once, Tuning.kill, the `reaped` parameters, and the tests that existed only for the backup (hanging kill, signalled-once ordering, missing kill, runaway-without-kill). The quiet-writer test now also asserts the leader is reaped when the call returns. A leader killed from outside first leaves its group's helpers running: documented in ADR-0060, THREAT-MODEL and CLAUDE.md, with every claim about a backup kill or a needed kill program removed.
…d its reap The status line can say 0 after the leader was killed from outside, with a helper that closed its pipes still writing. stop() now checks that the leader is still running right before closing its stdin, and then requires it to end by SIGKILL, its own `kill -s KILL 0`. A leader that had already exited, exits any other way, or is still there after the 5 s grace makes the fetch an error even when git succeeded, and the download is discarded. The slow leader is killed alone and waited for at most 2 s more, then left unreaped instead of blocking. Tests: a leader killed from outside after a successful fetch with a quiet writer, and a leader (through a new Tuning.leader seam) that exits normally or ignores the end of input. Two timing-fragile watchdog tests now put the pid file first and make the budget crossing deterministic. Docs describe the seen-to-end-by-its-own-kill rule instead of the reaping order.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
tonibergholm
approved these changes
Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sc serve --store sc+git::runs every fetch from the Git host under a download watchdog (#371). The watchdog had a documented hole: a helper that outlived git's exit was never killed, because after git was reaped its process-group id could be reused and signalling it was unsafe. Examples are a smart-HTTP v0/v1 helper chain and a hostile process that git started. Such a helper could keep writing into the cache after the download was discarded.Now, in serve mode on unix, git runs under a
/bin/shgroup leader that kills its own group:kill.killprogram. A reused group id therefore cannot be hit, andkillno longer has to be on the PATH.kill_group,may_signal_groupand the missing-killwarning are gone.SHELLOPTS,BASHOPTS,BASH_ENV,ENVand everyBASH_FUNC_*are removed. On macOS/bin/shis bash, andSHELLOPTS=monitoror an exportedkillfunction could otherwise move git out of the group or replace the group kill.Limits, documented in ADR-0060 and THREAT-MODEL:
setsid, such as an sshControlPersistmaster or a credential-cache daemon, is not killed.shand about 20 ms.ROADMAP records (10) as built.
Proof:
/bin/sh(bash), dash, bash and zsh. Each propagated git's exit code and killed a helper that closed its pipes and kept writing, both after git exited and partway through.kill -s KILL 0or never closing stdin fails five tests.-D warnings,cargo test --workspace(1959 passed), the objio tests repeated anddemo/run_git_carrier_demo.shpass.The plan was reviewed by Mythos (security), Astra and code-reviewer. The diff was reviewed by Mythos twice, by code-reviewer and with sol-loop.
Reviewed with sol-loop: 5 rounds with gpt-6.2-sol on high. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code (T3 Code), with a Claude Sonnet 5.5 subagent writing most of the implementation.