Skip to content

Commit f7be284

Browse files
only21milclaude
andcommitted
fix(server): give project CLI requests longer than the live-server probe
The 1 s probe timeout also bounded the snapshot read and the mutation sent to a server that already answered. A busy server that took over a second to apply a change made the CLI report failure for a change that went through. Keep the 1 s probe and give the live requests 10 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent afb7eb5 commit f7be284

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

‎apps/server/src/cli/project.ts‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ const layerProjectCliRuntime = RuntimeLayer.layerProjectService.pipe(
214214
Layer.provideMerge(SqlitePersistence.layerConfig),
215215
);
216216

217-
const PROJECT_CLI_LIVE_SERVER_TIMEOUT = Duration.seconds(1);
217+
// The probe only picks live or offline mode. A server that answered it is
218+
// live, so the requests after it get longer to reply.
219+
const PROJECT_CLI_LIVE_SERVER_PROBE_TIMEOUT = Duration.seconds(1);
220+
const PROJECT_CLI_LIVE_SERVER_REQUEST_TIMEOUT = Duration.seconds(10);
218221
const withProjectCliSessionToken = <A, E, R>(
219222
environmentAuth: EnvironmentAuth.EnvironmentAuth["Service"],
220223
run: (token: string) => Effect.Effect<A, E, R>,
@@ -228,9 +231,6 @@ const withProjectCliSessionToken = <A, E, R>(
228231
(issued) => environmentAuth.revokeSession(issued.sessionId).pipe(Effect.ignore({ log: true })),
229232
);
230233

231-
const withProjectCliLiveServerTimeout = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
232-
effect.pipe(Effect.timeout(PROJECT_CLI_LIVE_SERVER_TIMEOUT));
233-
234234
const makeLiveServerClient = (origin: string) =>
235235
HttpApiClient.make(EnvironmentHttpApi, {
236236
baseUrl: origin,
@@ -317,17 +317,14 @@ const findActiveProjectTarget = Effect.fn("findActiveProjectTarget")(function* (
317317
});
318318

319319
const fetchLiveOrchestrationSnapshot = Effect.fn("project.fetchLiveOrchestrationSnapshot")(
320-
function* (origin: string, bearerToken: string) {
320+
function* (origin: string, bearerToken: string, _timeout: Duration.Duration) {
321321
const client = yield* makeLiveServerClient(origin);
322322
return yield* client.projects.snapshot({
323323
headers: { authorization: `Bearer ${bearerToken}` },
324324
});
325325
},
326-
(effect, _origin, _bearerToken) =>
327-
effect.pipe(
328-
withProjectCliLiveServerTimeout,
329-
Effect.mapError(projectCommandErrorFromLiveServerRequest),
330-
),
326+
(effect, _origin, _bearerToken, timeout) =>
327+
effect.pipe(Effect.timeout(timeout), Effect.mapError(projectCommandErrorFromLiveServerRequest)),
331328
);
332329

333330
const dispatchLiveOrchestrationCommand = Effect.fn("project.dispatchLiveOrchestrationCommand")(
@@ -340,7 +337,7 @@ const dispatchLiveOrchestrationCommand = Effect.fn("project.dispatchLiveOrchestr
340337
},
341338
(effect, _origin, _bearerToken, _command) =>
342339
effect.pipe(
343-
withProjectCliLiveServerTimeout,
340+
Effect.timeout(PROJECT_CLI_LIVE_SERVER_REQUEST_TIMEOUT),
344341
Effect.mapError(projectCommandErrorFromLiveServerRequest),
345342
),
346343
);
@@ -361,7 +358,11 @@ const tryResolveLiveProjectExecutionMode = Effect.fn("tryResolveLiveProjectExecu
361358
}
362359

363360
const attempt = withProjectCliSessionToken(environmentAuth, (token) =>
364-
fetchLiveOrchestrationSnapshot(runtimeState.value.origin, token).pipe(
361+
fetchLiveOrchestrationSnapshot(
362+
runtimeState.value.origin,
363+
token,
364+
PROJECT_CLI_LIVE_SERVER_PROBE_TIMEOUT,
365+
).pipe(
365366
Effect.as({
366367
origin: runtimeState.value.origin,
367368
}),
@@ -410,7 +411,11 @@ const runProjectMutation = Effect.fn("runProjectMutation")(function* (
410411
if (Option.isSome(liveMode)) {
411412
return yield* withProjectCliSessionToken(environmentAuth, (token) =>
412413
Effect.gen(function* () {
413-
const snapshot = yield* fetchLiveOrchestrationSnapshot(liveMode.value.origin, token);
414+
const snapshot = yield* fetchLiveOrchestrationSnapshot(
415+
liveMode.value.origin,
416+
token,
417+
PROJECT_CLI_LIVE_SERVER_REQUEST_TIMEOUT,
418+
);
414419
const output = yield* run({
415420
snapshot,
416421
dispatch: (command) =>

0 commit comments

Comments
 (0)