@devries-cameron20 / t3code-1 / commits / b7c7a7819a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): t3 project commands wait for a busy server's reply (#24090)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 29, 2026 at 12:58 UTC b7c7a7819a9bd144072cb8ea11b4896cf435473d
2 files changed +78 -12
apps/server/src/cli/project.test.ts
+67
@@ -18,11 +18,14 @@ import {
18 import * as NetService from "@t3tools/shared/Net";
19 import * as DateTime from "effect/DateTime";
20 import * as Effect from "effect/Effect";
21 +import * as Fiber from "effect/Fiber";
22 import * as FileSystem from "effect/FileSystem";
23 import * as Layer from "effect/Layer";
24 import * as References from "effect/References";
25 import * as Stream from "effect/Stream";
26 import { Command } from "effect/cli";
27 +import { FetchHttpClient } from "effect/http";
28 +import * as TestClock from "effect/testing/TestClock";
29
30 import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
31 import { cli } from "../binCli.ts";
@@ -37,6 +40,10 @@ import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts";
40 import * as ProjectService from "../project/ProjectService.ts";
41 import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
42 import * as T3ProjectFileLoader from "../project/T3ProjectFileLoader.ts";
43 +import {
44 + makePersistedServerRuntimeState,
45 + persistServerRuntimeState,
46 +} from "../serverRuntimeState.ts";
47 import * as ServerSettings from "../serverSettings.ts";
48 import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
49
@@ -121,6 +128,66 @@ it.effect("adds, renames, and removes projects through the V2 project CLI domain
128 }).pipe(Effect.provide(NodeServices.layer)),
129 );
130
131 +it.effect.each(["snapshot", "mutation"] as const)(
132 + "waits for a busy live server's %s response",
133 + (slowRequest) =>
134 + Effect.gen(function* () {
135 + const fs = yield* FileSystem.FileSystem;
136 + const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-live-project-cli-" });
137 + const baseDir = NodePath.join(root, "state");
138 + const workspaceRoot = NodePath.join(root, "workspace");
139 + yield* fs.makeDirectory(workspaceRoot);
140 + yield* persistServerRuntimeState({
141 + path: NodePath.join(baseDir, "userdata", "server-runtime.json"),
142 + state: yield* makePersistedServerRuntimeState({
143 + config: { host: "127.0.0.1", devUrl: undefined },
144 + port: 3_773,
145 + }),
146 + });
147 + const now = "2026-01-01T00:00:00.000Z";
148 + const requestReceived = Promise.withResolvers<void>();
149 + const releaseResponse = Promise.withResolvers<void>();
150 + let snapshotRequests = 0;
151 + let mutations = 0;
152 + const fetch: typeof globalThis.fetch = async (_input, init) => {
153 + const isMutation = init?.method === "POST";
154 + if (isMutation) mutations++;
155 + else snapshotRequests++;
156 + if (slowRequest === "mutation" ? isMutation : !isMutation && snapshotRequests === 2) {
157 + requestReceived.resolve();
158 + await releaseResponse.promise;
159 + }
160 + return Response.json(
161 + isMutation
162 + ? {
163 + id: "live-project",
164 + title: NodePath.basename(workspaceRoot),
165 + workspaceRoot,
166 + defaultModelSelection: null,
167 + scripts: [],
168 + createdAt: now,
169 + updatedAt: now,
170 + deletedAt: null,
171 + }
172 + : { projects: [], updatedAt: now },
173 + );
174 + };
175 +
176 + const add = yield* runCli(["project", "add", workspaceRoot, "--base-dir", baseDir]).pipe(
177 + Effect.provideService(FetchHttpClient.Fetch, fetch),
178 + Effect.forkChild,
179 + );
180 + yield* Effect.promise(() => requestReceived.promise);
181 + yield* TestClock.adjust("2 seconds");
182 + releaseResponse.resolve();
183 + yield* Fiber.join(add);
184 +
185 + assert.equal(snapshotRequests, 2);
186 + assert.equal(mutations, 1);
187 + assert.deepEqual((yield* readProjects(baseDir)).projects, []);
188 + }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
189 +);
190 +
191 const makeProjectLookupFixture = Effect.fn("ProjectCliTest.makeProjectLookupFixture")(function* () {
192 const fs = yield* FileSystem.FileSystem;
193 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-v2-project-lookup-" });
apps/server/src/cli/project.ts
+11 -12
@@ -214,7 +214,8 @@ const layerProjectCliRuntime = RuntimeLayer.layerProjectService.pipe(
214 Layer.provideMerge(SqlitePersistence.layerConfig),
215 );
216
217 -const PROJECT_CLI_LIVE_SERVER_TIMEOUT = Duration.seconds(1);
217 +const PROJECT_CLI_LIVE_SERVER_PROBE_TIMEOUT = Duration.seconds(1);
218 +const PROJECT_CLI_LIVE_SERVER_REQUEST_TIMEOUT = Duration.seconds(10);
219 const withProjectCliSessionToken = <A, E, R>(
220 environmentAuth: EnvironmentAuth.EnvironmentAuth["Service"],
221 run: (token: string) => Effect.Effect<A, E, R>,
@@ -228,9 +229,6 @@ const withProjectCliSessionToken = <A, E, R>(
229 (issued) => environmentAuth.revokeSession(issued.sessionId).pipe(Effect.ignore({ log: true })),
230 );
231
231 -const withProjectCliLiveServerTimeout = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
232 - effect.pipe(Effect.timeout(PROJECT_CLI_LIVE_SERVER_TIMEOUT));
233 -
232 const makeLiveServerClient = (origin: string) =>
233 HttpApiClient.make(EnvironmentHttpApi, {
234 baseUrl: origin,
@@ -317,17 +315,14 @@ const findActiveProjectTarget = Effect.fn("findActiveProjectTarget")(function* (
315 });
316
317 const fetchLiveOrchestrationSnapshot = Effect.fn("project.fetchLiveOrchestrationSnapshot")(
320 - function* (origin: string, bearerToken: string) {
318 + function* (origin: string, bearerToken: string, _timeout?: Duration.Duration) {
319 const client = yield* makeLiveServerClient(origin);
320 return yield* client.projects.snapshot({
321 headers: { authorization: `Bearer ${bearerToken}` },
322 });
323 },
326 - (effect, _origin, _bearerToken) =>
327 - effect.pipe(
328 - withProjectCliLiveServerTimeout,
329 - Effect.mapError(projectCommandErrorFromLiveServerRequest),
330 - ),
324 + (effect, _origin, _bearerToken, timeout = PROJECT_CLI_LIVE_SERVER_REQUEST_TIMEOUT) =>
325 + effect.pipe(Effect.timeout(timeout), Effect.mapError(projectCommandErrorFromLiveServerRequest)),
326 );
327
328 const dispatchLiveOrchestrationCommand = Effect.fn("project.dispatchLiveOrchestrationCommand")(
@@ -340,7 +335,7 @@ const dispatchLiveOrchestrationCommand = Effect.fn("project.dispatchLiveOrchestr
335 },
336 (effect, _origin, _bearerToken, _command) =>
337 effect.pipe(
343 - withProjectCliLiveServerTimeout,
338 + Effect.timeout(PROJECT_CLI_LIVE_SERVER_REQUEST_TIMEOUT),
339 Effect.mapError(projectCommandErrorFromLiveServerRequest),
340 ),
341 );
@@ -361,7 +356,11 @@ const tryResolveLiveProjectExecutionMode = Effect.fn("tryResolveLiveProjectExecu
356 }
357
358 const attempt = withProjectCliSessionToken(environmentAuth, (token) =>
364 - fetchLiveOrchestrationSnapshot(runtimeState.value.origin, token).pipe(
359 + fetchLiveOrchestrationSnapshot(
360 + runtimeState.value.origin,
361 + token,
362 + PROJECT_CLI_LIVE_SERVER_PROBE_TIMEOUT,
363 + ).pipe(
364 Effect.as({
365 origin: runtimeState.value.origin,
366 }),