Repository navigation
fix(ssh): corroborate an empty lsof answer before calling an endpoint free - #20585
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe POSIX lsof probe now checks Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The Linux corroboration retains bound sockets as unavailable without introducing a supported cleanup or endpoint-detection regression. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Corroborating an empty lsof answer —
pathStillBoundinposix-lsof-probe.tsreads the world-readable/proc/net/unixand, when a cleanlsofanswer reported no pids for a path the kernel still lists as bound, moves the marker tounavailable. That propagates toHOLDERS_SOURCE=unavailable→holdersEnumerable=false→ verdictunverifiable, so the superseded-relay sweep no longerrm -fs an inode a live relay (owned by another uid, or hidden byhidepid=2) still holds. - Gate shape — the check runs only for an otherwise-clean empty answer (
!unconfirmed && !unavailable && !stderrSeen && !pids.length); a reported pid still stands alone, and the marker can only move fromlsoftowardunavailable, never toward authorising an unlink the prior fix refuses. - Linux-gated coverage —
runProbegainslsof/sockPathoverrides, and a new suite binds a real unix socket while stubbing a blindlsof. It pins blind-and-bound →unavailable, blind-and-unbound →lsof(the anti-accumulation control), reported-pid precedence, and exact-path rather than substring matching on both prefix and suffix neighbours, plus an assertion that/proc/net/unixexists so the block cannot pass vacuously.
I verified the line-and-inode regex against real /proc/net/unix output for a bound socket (exact capture), ran posix-lsof-probe.test.ts (19 passed), the incumbent and shell-integration suites with real lsof present (42 passed), oxlint on both changed files (clean), and the changed-code quality gate against 0c81284 (all four scans passed). The residual macOS gap is deliberate and documented in the source; it does not regress the prior behavior.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
… free #18304 decided enumerability after `lsof` runs, keying on stderr, non-numeric output, and an abnormal exit. One failure carries none of those signals: probing as a uid that does not own the socket's holder, `lsof -t -a -U <path>` exits 1 with no stdout and no stderr. Measured on Debian 12 against #18304's own probe, a live relay owned by root probed as `nobody`: probe uid path marker pids merged nobody held.sock lsof [] <- live relay holds it merged nobody stale.sock lsof [] <- genuinely nobody merged root held.sock lsof [10] merged root stale.sock lsof [] The first two rows are byte-identical, so nothing about lsof's answer can separate them. The first reaches `verdict: exited / evidence: no-holder`, which `classifySupersededRelay` maps to `stale-endpoint-removed` and `rm -f` on an inode a live relay is still holding. `hidepid=2` produces the same shape. A positive control does not solve this. Controlling on something the probe itself holds passes precisely when we are blind: as `nobody`, `lsof -t -p $$` returns a pid while the socket query returns nothing. Blindness is to *other* uids, and another uid's process is not ours to manufacture. /proc/net/unix is. It is world-readable and lists every bound unix socket regardless of owner, so an entry for the path alongside no reported pid proves lsof was blind rather than that the path is free. Only an otherwise-clean empty answer is corroborated; a reported pid still stands on its own, and the check is skipped when the answer was already unavailable. Same run, with this change: fixed nobody held.sock unavailable [] <- no longer reapable fixed nobody stale.sock lsof [] <- still reapable fixed root held.sock lsof [10] <- unchanged fixed root stale.sock lsof [] <- unchanged The marker can only ever move from `lsof` toward `unavailable`, so this never authorises an unlink that #18304 refuses. Off Linux there is no /proc/net/unix, the check returns false, and behaviour is exactly as before -- deliberately, because defaulting to `unavailable` there would stop every macOS host from reaping a stale endpoint and trade a rare destructive bug for a universal accumulation one. The tests are Linux-gated for the same reason, with an assertion that the evidence they depend on is actually present so the block cannot pass vacuously.
10bbcc2 to
f29baa6
Compare
… free (stablyai#20585) stablyai#18304 decided enumerability after `lsof` runs, keying on stderr, non-numeric output, and an abnormal exit. One failure carries none of those signals: probing as a uid that does not own the socket's holder, `lsof -t -a -U <path>` exits 1 with no stdout and no stderr. Measured on Debian 12 against stablyai#18304's own probe, a live relay owned by root probed as `nobody`: probe uid path marker pids merged nobody held.sock lsof [] <- live relay holds it merged nobody stale.sock lsof [] <- genuinely nobody merged root held.sock lsof [10] merged root stale.sock lsof [] The first two rows are byte-identical, so nothing about lsof's answer can separate them. The first reaches `verdict: exited / evidence: no-holder`, which `classifySupersededRelay` maps to `stale-endpoint-removed` and `rm -f` on an inode a live relay is still holding. `hidepid=2` produces the same shape. A positive control does not solve this. Controlling on something the probe itself holds passes precisely when we are blind: as `nobody`, `lsof -t -p $$` returns a pid while the socket query returns nothing. Blindness is to *other* uids, and another uid's process is not ours to manufacture. /proc/net/unix is. It is world-readable and lists every bound unix socket regardless of owner, so an entry for the path alongside no reported pid proves lsof was blind rather than that the path is free. Only an otherwise-clean empty answer is corroborated; a reported pid still stands on its own, and the check is skipped when the answer was already unavailable. Same run, with this change: fixed nobody held.sock unavailable [] <- no longer reapable fixed nobody stale.sock lsof [] <- still reapable fixed root held.sock lsof [10] <- unchanged fixed root stale.sock lsof [] <- unchanged The marker can only ever move from `lsof` toward `unavailable`, so this never authorises an unlink that stablyai#18304 refuses. Off Linux there is no /proc/net/unix, the check returns false, and behaviour is exactly as before -- deliberately, because defaulting to `unavailable` there would stop every macOS host from reaping a stale endpoint and trade a rare destructive bug for a universal accumulation one. The tests are Linux-gated for the same reason, with an assertion that the evidence they depend on is actually present so the block cannot pass vacuously.

Follow-up to #18304, which fixed the general case: enumerability decided after
lsofruns, keying on stderr, non-numeric output, and an abnormal exit. One failure carries none of those signals.The gap
Probing as a uid that does not own the socket's holder,
lsof -t -a -U <path>exits 1 with no stdout and no stderr. Measured on Debian 12 against #18304's own probe — a live relay owned by root, socket mode 666, probed asnobody:held.socklsof[]stale.socklsof[]held.socklsof[10]stale.socklsof[]The first two rows are byte-identical. Nothing about lsof's answer separates them, so this is not reachable by inspecting the answer harder.
The first row reaches
verdict: exited / evidence: no-holder, whichclassifySupersededRelaymaps tostale-endpoint-removed→rm -fon an inode a live relay still holds.hidepid=2produces the same shape.Why a positive control doesn't work
The obvious shape — ask
lsofabout something that must have a holder, and treat a blank control as blindness — fails here. A control on something the probe itself holds passes precisely when we are blind:Blindness is to other uids, and another uid's process is not ours to manufacture. So the control has to come from outside lsof.
What does work
/proc/net/unixis world-readable and lists every bound unix socket regardless of owner. Measured identically as root and asnobody:An entry for the path alongside no reported pid proves
lsofwas blind, rather than that the path is free. Same run as the table above, with this change:held.sockunavailable[]stale.socklsof[]held.socklsof[10]stale.socklsof[]Only an otherwise-clean empty answer is corroborated: a reported pid still stands on its own, and the check is skipped when the answer was already
unavailableorcleanup-unconfirmed. The marker can only ever move fromlsoftowardunavailable, so this never authorises an unlink #18304 refuses.Non-Linux, and why it is not conservative there
There is no
/proc/net/unixoff Linux; the check returns false and behaviour is exactly as before. That is deliberate. Defaulting tounavailablethere would stop every macOS host from reaping a genuinely stale endpoint — trading a rare destructive bug for a universal accumulation one. The gap remains on macOS hosts and is called out in the source.The tests are Linux-gated for the same reason, with an assertion that
/proc/net/unixactually exists so the block cannot pass vacuously on a runner that lacks it.Mutation table
Every row was re-introduced and run; each maps to a distinct assertion.
origin/mainunmodifiedreports unavailable when nothing was reported for a socket that is still boundkeeps a reported pid even while the path is still bounddoes not treat a prefix of the bound path as bounddoes not treat a path the bound one prefixes as boundstill reports lsof for an empty answer about a path nothing has boundThe last row is the control that matters: it is the one that fails if this change ever makes a healthy host stop reaping.
Verified on Linux (node 22 container, repo config): 19 passed, 0 skipped, and confirmed able to fail there by breaking the cross-uid assertion (
1 failed | 17 passed).oxlintclean;tscclean for these files.Two caveats on the local run, for the record: four
src/main/ai-vault/*test files fail to import and onetscerror is reported insession-document-stream.ts, both from a missing@streamparser/jsonin thenode_modulessnapshot this scratch checkout borrowed. Neither touches this change, and both reproduce without it.Rebased onto
main@caa465d1da886b2697c85c18bf36f79f2d3b9e68(2026-09-15).10bbcc2cd4c781bbc4bff995b9ae230a43e5d372f29baa6c547a6b304d38c09f1ea4cdaf9d3303beRebase only; the commit is byte-identical under
git range-diff. Rebased so CI re-evaluates against currentmain. The branch already cleared every tightened gate locally at the new base.