fix: address review findings on the reconnect flow
Three defects found by Macroscope and Cursor Bugbot: - The restart window was armed only at click time, but an npm install can consume most of the 10-minute request window, so a slow-but-successful update restarted after the window had lapsed and was presented as an outage. Re-arm from the acknowledgement and from the interrupt path, matching what keepPendingForRestart already does for the button expiry. - Effect.catch on the detached restart fiber only sees typed failures, so an unexpected defect skipped the inFlight reset and left a live process refusing every further update until restarted by other means. Release the guard from Effect.onExit, outside the typed handler. Success still deliberately keeps it set: systemd is about to stop the process and a second update would race the handoff. - "A server update is already in progress" is a typed failure, so it cleared a restart overlay that the earlier still-pending update needed, restoring the harsh reconnect UI mid-restart. That reason now lives in contracts as SERVER_SELF_UPDATE_ALREADY_RUNNING_REASON with an isAlreadyRunning helper, so the client can distinguish it structurally instead of matching prose. Each fix has a regression test; the defect-path test was confirmed to fail without the onExit change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
b462ae5f2f
commit
7aecc5d47a
5 files changed
+181
-9
No files matched your search
@@ -3,6 +3,7 @@
|
||||
// detached fire-and-forget child that outlives this process, while Effect's
|
||||
// ChildProcessSpawner ties every child to a scope that kills it.
|
||||
import {
|
||||
SERVER_SELF_UPDATE_ALREADY_RUNNING_REASON,
|
||||
ServerSelfUpdateError,
|
||||
type ServerSelfUpdateCapability,
|
||||
type ServerSelfUpdateInput,
|
||||
@@ -18,6 +19,7 @@ import * as NodeChildProcess from "node:child_process";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
@@ -246,7 +248,7 @@ export const make = Effect.fn("cloud.server_self_update.make")(function* (option
|
||||
|
||||
const alreadyRunning = yield* Ref.getAndSet(inFlight, true);
|
||||
if (alreadyRunning) {
|
||||
return yield* failWith("A server update is already in progress.");
|
||||
return yield* failWith(SERVER_SELF_UPDATE_ALREADY_RUNNING_REASON);
|
||||
}
|
||||
|
||||
return yield* Effect.gen(function* () {
|
||||
@@ -387,9 +389,24 @@ export const make = Effect.fn("cloud.server_self_update.make")(function* (option
|
||||
"Server self-update could not restore the previous systemd unit after a rejected restart.",
|
||||
).pipe(Effect.annotateLogs({ targetVersion, error: String(rollbackError) })),
|
||||
),
|
||||
// The process survived a rejected restart, so it must stay
|
||||
// updatable — leaving the guard set would reject every retry
|
||||
// until the server was restarted by other means.
|
||||
Effect.ensuring(Ref.set(inFlight, false)),
|
||||
),
|
||||
),
|
||||
// The typed catch above cannot see defects or interrupts, which
|
||||
// would otherwise strand the guard on a live process. A success
|
||||
// deliberately leaves it set: systemd is about to stop this
|
||||
// process and a second update would race the handoff.
|
||||
Effect.onExit((exit) =>
|
||||
Exit.isSuccess(exit)
|
||||
? Effect.void
|
||||
: Effect.logError("Server self-update restart fiber ended unexpectedly.").pipe(
|
||||
Effect.annotateLogs({ targetVersion, exit: String(exit) }),
|
||||
Effect.ensuring(Ref.set(inFlight, false)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user