Skip to content

Commit 058b06a

Browse files
committed
fix(daemon): gate the probe retry on liveness, not the ps identity read
Under the load that stalls the probe, ps misses its deadline too and the identity read fails closed, ending the retries. The takeover still proves identity before it signals.
1 parent 7b49dd3 commit 058b06a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎src/daemon-client/daemon-client-lifecycle.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import type { DaemonRequest, DaemonResponse } from '../daemon/daemon-request.ts'
88
import { runCmdDetachedMonitored, type ExecDetachedExit } from '@agent-device/host-kit/command';
99
import { shellQuoteIfNeeded } from '@agent-device/kernel/device-shell';
1010
import { emitDiagnostic } from '@agent-device/host-kit/diagnostics';
11+
import { isProcessAlive } from '@agent-device/host-kit/process';
1112
import { sleep } from '@agent-device/host-kit/retry';
1213

13-
import { isAgentDeviceDaemonProcess } from '../daemon-process.ts';
1414
import { findUnrecoveredRepairCommitFailure } from '../session-repair-tombstone.ts';
1515
import {
1616
resolveDaemonPaths,
@@ -206,18 +206,20 @@ async function readReusableLocalDaemon(settings: DaemonClientSettings): Promise<
206206
}
207207

208208
/**
209-
* A daemon whose process is still the one its metadata recorded is probed again before it can be
210-
* judged unreachable. A probe's budget is wall-clock time on this client's event loop, so a client
211-
* that stalls past it (a large synchronous parse, a GC pause on a loaded host) reads a listening
212-
* daemon as unreachable, and replacing it ends every session the daemon holds.
209+
* A daemon whose pid is still alive is probed again before it can be judged unreachable. A probe's
210+
* budget is wall-clock time on this client's event loop, so a client that stalls past it (a large
211+
* synchronous parse, a GC pause on a loaded host) reads a listening daemon as unreachable, and
212+
* replacing it ends every session the daemon holds. Liveness is the signal-0 check, not the `ps`
213+
* identity read: under the load that stalls the probe, `ps` misses its deadline too, and the
214+
* takeover still proves identity before it signals anything.
213215
*/
214216
async function canReachReusableDaemon(
215217
info: DaemonInfo,
216218
preference: DaemonTransportPreference,
217219
): Promise<boolean> {
218220
if (await canConnectReusableDaemon(info, preference)) return true;
219221
for (let retry = 1; retry <= LIVE_DAEMON_PROBE_RETRIES; retry += 1) {
220-
if (!isAgentDeviceDaemonProcess(info.pid, info.processStartTime)) return false;
222+
if (!isProcessAlive(info.pid)) return false;
221223
await sleep(LIVE_DAEMON_PROBE_RETRY_DELAY_MS);
222224
if (await canConnectReusableDaemon(info, preference)) {
223225
emitDiagnostic({

0 commit comments

Comments
 (0)