@devries-cameron20 / t3code-1 / commits / 8678a80c2f
Fork 0

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

fix(server): a disabled bootstrap provider no longer stops startup (#20035)

Scott Norteman committed Oct 18, 2026 at 15:51 UTC 8678a80c2fbb3416426486ed28c891b5f1109a38
2 files changed +253 -15
apps/server/src/serverRuntimeStartup.test.ts
+222
@@ -1,20 +1,50 @@
1 import { assert, it } from "@effect/vitest";
2 +import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
3 import {
4 DEFAULT_SERVER_SETTINGS,
5 DEFAULT_MODEL,
6 ProjectId,
7 ProviderInstanceId,
8 + ProviderDriverKind,
9 + CommandId,
10 + EnvironmentId,
11 + type ServerLifecycleStreamEvent,
12 } from "@t3tools/contracts";
13 +import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
14 +import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
15 +import { HttpServer } from "effect/http";
16 +import * as NetAddress from "effect/net/NetAddress";
17 import * as Deferred from "effect/Deferred";
18 import * as Effect from "effect/Effect";
19 import * as Exit from "effect/Exit";
20 import * as Fiber from "effect/Fiber";
21 import * as Ref from "effect/Ref";
22 +import * as Layer from "effect/Layer";
23 +import * as Path from "effect/Path";
24
25 import * as GitVcsDriver from "./vcs/GitVcsDriver.ts";
26
27 import * as ServerConfig from "./config.ts";
28 import * as ServerRuntimeStartup from "./serverRuntimeStartup.ts";
29 +import * as EnvironmentAuth from "./auth/EnvironmentAuth.ts";
30 +import * as ServiceLauncherClient from "./cloud/serviceLauncherClient.ts";
31 +import * as ServerEnvironment from "./environment/ServerEnvironment.ts";
32 +import * as Keybindings from "./keybindings.ts";
33 +import * as EffectWorker from "./orchestration-v2/EffectWorker.ts";
34 +import * as LegacyV1ThreadImporter from "./orchestration-v2/legacy/LegacyV1ThreadImporter.ts";
35 +import * as Orchestrator from "./orchestration-v2/Orchestrator.ts";
36 +import * as ProjectStore from "./orchestration-v2/ProjectStore.ts";
37 +import * as ProviderRuntimeRecovery from "./orchestration-v2/ProviderRuntimeRecoveryService.ts";
38 +import * as ProviderSessionManager from "./orchestration-v2/ProviderSessionManager.ts";
39 +import * as ThreadLaunch from "./orchestration-v2/ThreadLaunchService.ts";
40 +import * as ThreadManagement from "./orchestration-v2/ThreadManagementService.ts";
41 +import * as ExternalLauncher from "./process/externalLauncher.ts";
42 +import * as ProjectService from "./project/ProjectService.ts";
43 +import * as AgentAwarenessRelay from "./relay/AgentAwarenessRelay.ts";
44 +import { ServerActivation } from "./serverActivation.ts";
45 +import * as ServerLifecycleEvents from "./serverLifecycleEvents.ts";
46 +import * as ServerSettings from "./serverSettings.ts";
47 +import * as AnalyticsService from "./telemetry/AnalyticsService.ts";
48
49 it("uses the canonical Codex model for auto-bootstrap", () => {
50 assert.deepEqual(ServerRuntimeStartup.getAutoBootstrapThreadModelSelection(), {
@@ -23,6 +53,198 @@ it("uses the canonical Codex model for auto-bootstrap", () => {
53 });
54 });
55
56 +it.effect.each([
57 + "disabled-codex",
58 + "disabled-default",
59 + "launch-failure",
60 + "project-failure",
61 +] as const)("keeps bootstrap launch failures separate from project failures: %s", (scenario) =>
62 + Effect.scoped(
63 + Effect.gen(function* () {
64 + const projectId = ProjectId.make("bootstrap-project");
65 + const instanceId = ProviderInstanceId.make(
66 + scenario === "disabled-default" ? "custom" : "codex",
67 + );
68 + const events: ServerLifecycleStreamEvent[] = [];
69 + const recovery = {
70 + terminalizedRuns: 0,
71 + stoppedSessions: 0,
72 + closedRequests: 0,
73 + retiredEffects: 0,
74 + requeuedEffects: 0,
75 + };
76 + const imports = { importedThreadCount: 0, importedMessageCount: 0 };
77 + const dependencies = Layer.mergeAll(
78 + NodeCrypto.layer,
79 + Path.layer,
80 + Layer.mock(ServerConfig.ServerConfig)({
81 + ...(yield* ServerConfig.deriveServerPaths("/bootstrap-project", undefined).pipe(
82 + Effect.provide(Path.layer),
83 + )),
84 + baseDir: "/bootstrap-project",
85 + logLevel: "Error",
86 + traceMinLevel: "Info",
87 + traceTimingEnabled: false,
88 + traceBatchWindowMs: 200,
89 + traceMaxBytes: 1024,
90 + traceMaxFiles: 1,
91 + otlpTracesUrl: undefined,
92 + otlpMetricsUrl: undefined,
93 + otlpLogsUrl: undefined,
94 + otlpTracesExport: DEFAULT_SIGNAL_EXPORT,
95 + otlpMetricsExport: DEFAULT_SIGNAL_EXPORT,
96 + otlpLogsExport: DEFAULT_SIGNAL_EXPORT,
97 + otelEnvironment: OtelEnvironment.none,
98 + staticDir: undefined,
99 + devAllowedOrigins: [],
100 + desktopBootstrapToken: undefined,
101 + logWebSocketEvents: false,
102 + tailscaleServeEnabled: false,
103 + tailscaleServePort: 443,
104 + mode: "web",
105 + cwd: "/bootstrap-project",
106 + host: "localhost",
107 + port: 3773,
108 + devUrl: undefined,
109 + noBrowser: true,
110 + startupPresentation: "browser",
111 + autoBootstrapProjectFromCwd: true,
112 + }),
113 + Layer.mock(Keybindings.Keybindings)({ start: Effect.void }),
114 + Layer.mock(LegacyV1ThreadImporter.LegacyV1ThreadImporter)({
115 + pendingThreadCount: Effect.succeed(0),
116 + reconcileShells: Effect.succeed(imports),
117 + importPendingTranscripts: Effect.succeed(imports),
118 + }),
119 + Layer.mock(ProviderRuntimeRecovery.ProviderRuntimeRecoveryService)({
120 + recover: Effect.succeed(recovery),
121 + prepareForShutdown: Effect.void,
122 + reconcile: () => Effect.succeed(recovery),
123 + }),
124 + Layer.mock(Orchestrator.OrchestratorV2)({ recoverDelegatedTasks: Effect.void }),
125 + Layer.mock(ProviderSessionManager.ProviderSessionManagerV2)({ shutdown: Effect.void }),
126 + Layer.mock(AgentAwarenessRelay.AgentAwarenessRelay)({ start: () => Effect.void }),
127 + Layer.mock(EffectWorker.OrchestrationEffectWorkerV2)({ runOnce: Effect.never }),
128 + Layer.mock(ServerLifecycleEvents.ServerLifecycleEvents)({
129 + publish: (event) =>
130 + Effect.sync(() => {
131 + const published = { ...event, sequence: events.length + 1 };
132 + events.push(published);
133 + return published;
134 + }),
135 + }),
136 + Layer.mock(ServerSettings.ServerSettingsService)({
137 + start: Effect.void,
138 + getSettings: Effect.succeed({
139 + ...DEFAULT_SERVER_SETTINGS,
140 + defaultModelSelection:
141 + scenario === "disabled-default" ? { instanceId, model: "custom-model" } : null,
142 + providerInstances: {
143 + [instanceId]: {
144 + driver: ProviderDriverKind.make("codex"),
145 + enabled: false,
146 + config: {},
147 + },
148 + },
149 + }),
150 + }),
151 + Layer.mock(ServerEnvironment.ServerEnvironment)({
152 + getDescriptor: Effect.succeed({
153 + environmentId: EnvironmentId.make("bootstrap-environment"),
154 + label: "Test environment",
155 + platform: { os: "linux", arch: "x64" },
156 + serverVersion: "0.0.0-test",
157 + capabilities: { repositoryIdentity: true },
158 + }),
159 + }),
160 + Layer.mock(ProjectStore.ProjectStoreV2)({}),
161 + Layer.mock(ProjectService.ProjectService)({
162 + bootstrap: () =>
163 + scenario === "project-failure"
164 + ? Effect.die("project bootstrap failed")
165 + : Effect.succeed({
166 + created: true,
167 + project: {
168 + id: projectId,
169 + title: "Project",
170 + workspaceRoot: "/bootstrap-project",
171 + repositoryIdentity: null,
172 + faviconPath: null,
173 + scripts: [],
174 + createdAt: "2026-01-01T00:00:00Z",
175 + updatedAt: "2026-01-01T00:00:00Z",
176 + deletedAt: null,
177 + defaultModelSelection:
178 + scenario === "disabled-default"
179 + ? { instanceId, model: "custom-model" }
180 + : null,
181 + },
182 + }),
183 + }),
184 + Layer.mock(ThreadManagement.ThreadManagementService)({
185 + getShellSnapshot: () =>
186 + Effect.succeed({
187 + threads: [],
188 + archivedThreads: [],
189 + schemaVersion: 1,
190 + snapshotSequence: 0,
191 + }),
192 + }),
193 + Layer.mock(ThreadLaunch.ThreadLaunchService)({
194 + launch: (input) => {
195 + assert.equal(input.modelSelection.instanceId, instanceId);
196 + return scenario === "launch-failure"
197 + ? Effect.fail(
198 + new ThreadLaunch.ThreadLaunchError({
199 + operation: "create-thread",
200 + commandId: CommandId.make("bootstrap-command"),
201 + projectId,
202 + cause: "test launch failure",
203 + }),
204 + )
205 + : Effect.fail(
206 + new ThreadManagement.ThreadManagementProviderInstanceDisabledError({
207 + projectId,
208 + instanceId,
209 + }),
210 + );
211 + },
212 + }),
213 + Layer.mock(ServiceLauncherClient.ServiceLauncherClient)({
214 + managed: false,
215 + prepareTrial: Effect.succeed(undefined),
216 + }),
217 + Layer.mock(GitVcsDriver.GitVcsDriver)({}),
218 + Layer.mock(AnalyticsService.AnalyticsService)({}),
219 + Layer.mock(EnvironmentAuth.EnvironmentAuth)({}),
220 + Layer.mock(ExternalLauncher.ExternalLauncher)({}),
221 + Layer.mock(HttpServer.HttpServer)({
222 + address: NetAddress.inetAddressFromIpStringUnsafe("127.0.0.1", 3773),
223 + }),
224 + );
225 + yield* Effect.gen(function* () {
226 + const startup = yield* ServerRuntimeStartup.ServerRuntimeStartup;
227 + yield* startup.markHttpListening;
228 + const ready = yield* Effect.exit(startup.awaitCommandReady);
229 + assert.equal(Exit.isSuccess(ready), scenario !== "project-failure");
230 + const welcome = events.find((event) => event.type === "welcome");
231 + if (scenario === "project-failure") {
232 + assert.isUndefined(welcome);
233 + } else {
234 + assert.isDefined(welcome);
235 + if (welcome?.type === "welcome") {
236 + assert.equal(welcome.payload.bootstrapProjectId, projectId);
237 + assert.isUndefined(welcome.payload.bootstrapThreadId);
238 + }
239 + }
240 + }).pipe(
241 + Effect.provide(ServerRuntimeStartup.layerWithOptions().pipe(Layer.provide(dependencies))),
242 + Effect.provideService(ServerActivation, Effect.never),
243 + );
244 + }),
245 + ),
246 +);
247 +
248 it.effect("starts without scanning or rebuilding projection history", () =>
249 Effect.gen(function* () {
250 const calls = yield* Ref.make<ReadonlyArray<string>>([]);
apps/server/src/serverRuntimeStartup.ts
+31 -15
@@ -283,22 +283,38 @@ const resolveAutoBootstrapWelcomeTargets = Effect.gen(function* () {
283 if (existingThread === undefined) {
284 const serverSettings = yield* ServerSettings.ServerSettingsService;
285 const settings = yield* serverSettings.getSettings;
286 - const launched = yield* threadLaunch.launch({
287 - commandId: CommandId.make(yield* randomUUID),
288 - projectId: project.id,
289 - title: "New thread",
290 - modelSelection:
291 - resolveProjectSettings(settings, project.id, project).settings.defaultModelSelection ??
292 - threadModelSelection,
293 - interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
294 - runtimeMode: resolveProjectSettings(settings, project.id, project).settings
295 - .defaultRuntimeMode,
296 - workspaceStrategy: { type: "root" },
297 - createdBy: "system",
298 - creationSource: "server",
299 - });
286 + const launched = yield* threadLaunch
287 + .launch({
288 + commandId: CommandId.make(yield* randomUUID),
289 + projectId: project.id,
290 + title: "New thread",
291 + modelSelection:
292 + resolveProjectSettings(settings, project.id, project).settings.defaultModelSelection ??
293 + threadModelSelection,
294 + interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
295 + runtimeMode: resolveProjectSettings(settings, project.id, project).settings
296 + .defaultRuntimeMode,
297 + workspaceStrategy: { type: "root" },
298 + createdBy: "system",
299 + creationSource: "server",
300 + })
301 + .pipe(
302 + // The bootstrap thread is optional; its launch must not prevent opening the app.
303 + Effect.catchTags({
304 + ThreadManagementProviderInstanceDisabledError: (error) =>
305 + Effect.logInfo("Skipped bootstrap thread because its provider instance is disabled", {
306 + projectId: project.id,
307 + instanceId: error.instanceId,
308 + }).pipe(Effect.as(undefined)),
309 + ThreadLaunchError: (error) =>
310 + Effect.logWarning("Failed to launch bootstrap thread", {
311 + projectId: project.id,
312 + operation: error.operation,
313 + }).pipe(Effect.as(undefined)),
314 + }),
315 + );
316 bootstrapProjectId = project.id;
301 - bootstrapThreadId = launched.threadId;
317 + bootstrapThreadId = launched?.threadId;
318 } else {
319 bootstrapProjectId = project.id;
320 bootstrapThreadId = existingThread.id;