Repository navigation
fix(daemon-client): name a sandbox-denied connect and leave that daemon alone - #5095
Conversation
…on alone A reachability probe answered a boolean, so a loopback connect the host refused (EPERM or EACCES under a sandbox around the client) read exactly like a daemon that answers nothing. The client then judged a healthy daemon dead and tried to replace it, and reported "Daemon replacement could not be confirmed." The replacement attempt could also kill the daemon it could not reach. Probes now answer a verdict, and a refusal carried by EPERM or EACCES is a denial, not an answer about the daemon. The takeover ladder answers a new connectDenied decision for it, and every client that hears it throws details.reason daemon-connect-denied with the errno, transport, port, and daemon identity, plus the host-access hint the denied listen already used. Nothing is spawned, retired, or signaled on that answer. The probe layer moves to daemon-client-loopback-probe.ts, which owns the denial set, so the transport module stays under the lint file-size limit.
Size Report
Startup median (7 runs, lower is better):
|
There was a problem hiding this comment.
All reported issues were addressed across 16 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
This comment has been minimized.
This comment has been minimized.
|
At 19fccac, some routes can still retire a daemon whose connect the host refused, or can lose the Older-version, missing-version and code-mismatch decisions return replace without a reachability probe. Managed SDK and proxy calls can then signal a live daemon and end its sessions, including a startup-race winner after a denial was already observed. A managed client pinned to an unadvertised transport also gets replace without a usable connect attempt. CLI/MCP ensure and attach can report incompatibility, a transport failure or For a daemon the client launched itself, The fresh HTTP and socket liveness checks turn Can the local HTTP reachability probe reuse a pooled keep-alive socket and miss a refusal of new connects? A reused or stale socket never exposes the connect error, and the later RPC then reports an ordinary transport failure. The local probe should force a fresh connection, as the liveness check does, with remote health and RPC behavior unchanged. A test should prime the pool, deny new connects and show the denial. When the first leg is denied and the fallback succeeds after the outer deadline, this return drops the denial and can end in a startup failure. Only an in-budget fallback success should replace the first denial. Every other outcome should keep a denial from either leg, covered by a late-fallback test. The rule that a client never treats an Would it be simpler for Not blocking: these can be taken or left: add an These high-priority threads still apply: launched daemon denial, help errno condition and CLI replace route. Five lower-priority threads also still apply. The pooled socket thread can be resolved for a process refused from the start, since reuse needs an earlier successful connect; a later policy change is the pooled socket question above. The Repo Guards & Compatibility check fails because of this PR: the test naming guard finds no module for Not verified here: the sandbox reproduction and the test suite were not rerun, and the regression tests were judged by reading their mocks and assertions. The managed SDK kill assumes the sandbox allows signaling a daemon outside it, as the base run in the PR description shows; that was not rerun on this route. |
A host-denied loopback connect (EPERM or EACCES) reached `daemon-connect-denied` only on the one ladder branch that probed. Every other path to a replacement judged the daemon from the record alone, so a client that cannot see a daemon still retired it, and a launch whose own readiness probe was refused fell into the startup cleanup that signals the launched process. The ladder now probes the advertised endpoints before ANY `replace` answer, for a version mismatch and a code mismatch alike, so `connectDenied` is the verdict wherever a replacement was about to be decided. A launch-time refusal is terminal and names the typed reason before the stalled and ceiling cleanup paths. The liveness probe classifies its legs' errnos too: a refused leg settles as a denial, so neither the drain wait, a timed-out quiesce, nor a reset-eligible timeout can retire on a connect this client was refused. The HTTP reachability leg asks on a fresh connection, and the first leg's refusal survives a late answer on the second. The probe implementation moves behind the function-scoped `await import` its one caller already uses, and `readDaemonHttpHealth` returns to the shape the wire ledger records: a probe now proves a refused connect with its own connect rather than by carrying an errno in a health payload, so no wire declaration changes. Docs name the two errnos the reason covers, and the connect-denied test is named for the module it pins.
|
Everything below is on 1. Probe an advertised endpoint with denial detection before ANY replace. Fixed at the decision owner, 2. A denial at launch time is terminal. 3. Fresh connection on the HTTP reachability leg. The probe no longer borrows the health reader: 4. The two failing checks. The connect-denied test is renamed to |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 2b30ec4. The verdict and the full list are in the summary comment.
The guard every replacement now takes out was run through the reachability probe, and that probe is built for a different question: it sends a health request and retries with waits, so a mismatched daemon cost a takeover one request and one extra wait step it had never paid. What a retirement has to check is narrower — whether the HOST lets this client reach the registered ports at all — so it asks that directly: `readAdvertisedConnectDenial` makes one bare loopback connect per advertised port, at once, with no health request and no retries. A sandbox that blocks local ports refuses the connect itself, which is the evidence the guard needs; a busy daemon's silence stays no evidence at all. A reset-eligible timeout whose liveness probe the host refused also stops reporting a timeout. That hint promised a session the caller could not have reached, when the client's real finding is that the host refused the connect: the refusal now answers with `daemon-connect-denied` and the shared host-access hint. `handleRequestTimeout` is split at its own owners — the probe, the recovery decision, the diagnostic, and the failure — so the decision reads as one step per function and the file is back under the complexity threshold. The reason table now carries the EPERM/EACCES wording where the generated reasons page reads it, which is what made `website/docs/docs/error-reasons.md` stale.
…imitive The HTTP reachability leg loaded `node:http` under a hand-rolled `Promise.race` against an abort listener, which is the third such race in this package (R88 counts two at the merge-base) and the one shape the rule exists for: a timer racing work, cleared only where the author remembered. It now waits on `settleWithin`, which clears its own timer on every settle path, and the loader's spend is taken out of the request's window so the probe's budget stays absolute across both steps.
This comment has been minimized.
This comment has been minimized.
|
This PR is ready at f4793a2. Every point from the earlier review that could retire a daemon because of a refused connect is now fixed. Three smaller points remain and can go to a follow-up issue. Not blocking: these can be taken or left: when a pinned transport is not advertised, the unreachable branch could ask These threads no longer apply and can be resolved: launched daemon survives denial; HTTP probe uses its own connection; help names the errno codes; mismatch branches check refusal first; attach case is tested; configuration and error docs aligned; fixture doc corrected; transport, errno and port tested; probe doc corrected; denied timeout reports host access, with the All 21 checks pass, including Repo Guards, which the test rename fixed. The sandbox reproduction in the PR description ran on the earlier commit, was not rerun on this one, and did not cover a mismatched or newly launched daemon. Not verified here: tests were not run locally, and their regression value was judged by reading the mocks and assertions. Not verified here: whether any real setup allows a request to connect and then refuses the later probe in the same process, which the timeout point depends on. No further change is required before merge. |
…spatch visible Three follow-ups from the ready review: - The takeover's unreachable branch now asks `refusedByHost` before it answers `replace`, so a managed client pinned to a leg the daemon does not serve no longer retires a daemon it was never allowed to reach. - A denial that replaces a timed-out request's reason carries `daemonRequestSent`, and the transport's failure classifier discloses dispatch from it, so a request written before the host refused the probe is still reported as one that may have run. - Route coverage for each route that can act on a refusal: the launch-time readiness probe, the reachability probe's late fallback leg and its pooled-socket case, the quiesce-timeout route, and the drain-escalation route. Each asserts the reason and that nothing is signaled or spawned.
|
Took all three notes, plus the thread cleanup, at fdbb7fb.
Locally I ran only the six suites this touches (107 tests), |
This comment has been minimized.
This comment has been minimized.
The Coverage lane runs the file's cases in a shuffled order, and two cases added for the denial shapes patched process globals: Date.now frozen to a counter, and every net.Socket connect refused. Anything still in flight from an earlier case was refused too, and a keep-alive socket left in the global agent was handed to a later case whose server the OS had just given the same port. The late-leg case now spends a real budget, the refusal is scoped to the probed port, and the primed socket is destroyed.
|
Coverage failure root cause: the two reachability-shape cases added in Fixed in d93f600: the late-leg case spends a real budget instead of faking one, the refusal is scoped to the probed port (comparing numbers, since Node hands |
This comment has been minimized.
This comment has been minimized.
…hrough the fixture plan Two Coverage failures on this head: The repo guard reads the launch seam as a daemon-fixture family member: its launcher mock must be a bare vi.fn() with the launch plan installed on it, and its fixture teardown must run through the shared family cleanup. The mock was built in a hoisted block instead. The pooled-socket case hung and then reported an error thrown after it completed. Two shared-state faults made that possible: it primed the process-wide agent and emptied it in teardown, so every socket another case was still using went with it, and it issued the prime without clearing the entry this endpoint already had, so a keep-alive socket a previous file had left for a port the OS just reused answered the write with nothing and the request had no bound to end the wait. The case now clears only this endpoint's pooled sockets, before and after, and the prime has its own deadline.
This comment has been minimized.
This comment has been minimized.
The case refused every connect made while its patch was installed, and a worker runs the cases of one file in one process: a connect another case was still waiting on was refused too, and the errno surfaced as an unhandled error once that case had finished. Vitest gives every file a worker, so the patch now reaches only this case. The refusal also lands later. Destroying a socket synchronously inside its connect reports a closed socket rather than the errno, and it fires before the requester has a listener on the socket. The real connect runs, so the socket has its handle, and the errno arrives on the next turn, when the request owns it. The case pins that the prime really did leave an idle socket in the pool, so the verdict cannot come from an empty pool, and it drops only this endpoint's pooled sockets.
2071fc7 to
411ad6e
Compare
|
Coverage fix (round 3), head 411ad6e: the pooled-socket probe case now has its own file, Two adjustments made it stable in the isolated file: the refusal is emitted asynchronously on the next turn (a synchronous |
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
|
The code at 411ad6e has no findings, which matches the earlier review of f4793a2. Nothing remains to fix, and the required evidence is in place. This earlier thread no longer applies: at this commit, a denied connect returns CI is green, with all 22 checks passing at this commit. Not verified here: tests were not run locally, and the test isolation claim for the pooled-socket test file rests on the green CI run. Nothing else needs to happen before merge. |
Summary
A reachability probe answered a boolean, so a loopback connect the host refused (
EPERMorEACCESunder a Codexworkspace-writesandbox around the client) read exactly like a daemon that answers nothing. The client judged a healthy daemon dead, tried to replace it, and failed with "Daemon replacement could not be confirmed." That attempt killed the daemon this client could not reach.Probes now answer a verdict, and a refusal by
EPERMorEACCESis a denial rather than evidence about the daemon. The takeover ladder answers a newconnectDenieddecision; each client hearing it fails withdetails.reason: daemon-connect-denied, the errno, transport, port, daemon identity, and the host-access hint the denied listen already used. Nothing is spawned, retired, or signaled on that answer. The probe layer moves todaemon-client-loopback-probe.ts, which owns the denial set.Before / after
Validation
Head
19fccace43.typecheck,lint,format,gate fallow,check:layering,check:doc-prose,check:command-docsclean.packages/daemon-client385 tests pass, pluspackages/daemon4779 andtest/repo-guards181. Suppressing the classifier or the ladder branch fails the new cases. Reproduced with the Codex sandbox CLI, no device. CI owes the full lane. Risk: a denial errno besidesEPERM/EACCESstill reads as unreachable.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.