Repository navigation
fix(server): retire inherited device daemons before reuse #38595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1b37750
25b4606
f0e3edf
baee643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,8 @@ import { | |
| const HUB_READY_TIMEOUT_MS = 30_000; | ||
| const DAEMON_READY_TIMEOUT_MS = 30_000; | ||
| const DAEMON_POLL_MS = 100; | ||
| // `daemon stop` waits 10s after SIGTERM and 2s after SIGKILL before it retires the registration. | ||
| const DAEMON_STOP_TIMEOUT_MS = 15_000; | ||
| const HUB_RESTART_STABLE_UPTIME_MS = 60_000; | ||
| const HUB_RESTART_MAX_DELAY_MS = 30_000; | ||
|
|
||
|
|
@@ -530,6 +532,7 @@ export const make = Effect.fn("LocalDeviceHost.make")(function* () { | |
| const startAgentDeviceDaemon = Effect.fn("LocalDeviceHost.startAgentDeviceDaemon")(function* ( | ||
| agentTool: Pick<DeviceToolPaths, "entryPath">, | ||
| nodePath: string, | ||
| currentEndpoint?: DeviceHost.AgentDaemonEndpoint, | ||
| ): Effect.fn.Return< | ||
| DeviceHost.AgentDeviceEndpoint, | ||
| | DeviceHost.DeviceHostError | ||
|
|
@@ -567,8 +570,28 @@ export const make = Effect.fn("LocalDeviceHost.make")(function* () { | |
| Effect.scoped, | ||
| Effect.orElseSucceed(() => false), | ||
| ); | ||
| if (alive) return toEndpoint(existing.value); | ||
| yield* fs.remove(daemonFilePath(), { force: true }).pipe(Effect.ignore); | ||
| if (alive) { | ||
| const endpoint = toEndpoint(existing.value); | ||
| if ( | ||
| currentEndpoint?.baseUrl === endpoint.baseUrl && | ||
| currentEndpoint.token === endpoint.token | ||
| ) { | ||
| return endpoint; | ||
| } | ||
| // A previous server's in-memory device sessions cannot be recovered by this host. | ||
| yield* stopAgentDeviceDaemon; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bind retirement to the daemon that failed the endpoint comparison. If another client replaces daemon A with daemon B in the same state directory after the health probe, the comparison still uses A's endpoint. The stop helper and the CLI then read the current registration. The CLI verifies and stops B, which can already have work of its own. Bind retirement to A's process lifetime. If the registration changes, reread it and make a new retirement decision. A separate file check before launching the CLI does not close the race. (raw.githubusercontent.com)
|
||
| if (yield* fs.exists(daemonFilePath()).pipe(Effect.orElseSucceed(() => true))) { | ||
| return yield* new DeviceHost.AgentDeviceStartError({ | ||
| hostId, | ||
| stateDir, | ||
| exitCode: null, | ||
| reason: "daemon_retirement_unconfirmed", | ||
| cause: new Error("The previous agent-device daemon retained its registration."), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the stop failure in If the stop CLI cannot spawn, the helper discards the process error. This branch then substitutes a registration error, so diagnostics cannot distinguish a failed launch from a daemon that refused to stop. Return the stop outcome to startup and attach the immediate failure as
|
||
| }); | ||
| } | ||
| } else { | ||
| yield* fs.remove(daemonFilePath(), { force: true }).pipe(Effect.ignore); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve the registration while the daemon drains. If the first retirement sends
|
||
| } | ||
| } | ||
| // No `daemon start` exists; `devices` is the cheapest command that starts and awaits it. | ||
| const runResult = yield* runner | ||
|
|
@@ -661,7 +684,7 @@ export const make = Effect.fn("LocalDeviceHost.make")(function* () { | |
| agentDeviceStateDir(path, config.stateDir), | ||
| ], | ||
| env: { ...hostEnvironment, AGENT_DEVICE_NO_UPDATE_NOTIFIER: "1" }, | ||
| timeout: Duration.seconds(10), | ||
| timeout: Duration.millis(DAEMON_STOP_TIMEOUT_MS), | ||
| timeoutBehavior: "timedOutResult", | ||
| }); | ||
| }).pipe( | ||
|
|
@@ -758,6 +781,7 @@ export const make = Effect.fn("LocalDeviceHost.make")(function* () { | |
| const agentDevice = yield* startAgentDeviceDaemon( | ||
| running.agentDevice, | ||
| running.hub.nodePath, | ||
| running.agentDevice, | ||
| ); | ||
| yield* Ref.set(runningRef, { ...running, agentDevice }); | ||
| return { ...toReady(running), agentDevice }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert that startup attempted retirement.
This test also passes if startup returns
daemon_retirement_unconfirmedwithout callingdaemon stop. The registration stays unchanged, and the replacement stub never runs. Before scope cleanup, assert that the runner receiveddaemon stop --state-dirfor this fixture. Use the existing command log so a missing stop fails the assertion instead of leaving the test waiting. As per path instructions, “test behavior that can break, including the logic changed by a bug fix.”Source: Path instructions