@devries-cameron20 / t3code Mirror · read-only / commits / 9c96180aa3
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 21:00 UTC

fix(server): t3_thread_launch says when its project does not exist (#29109)

Julius Marminge committed Nov 11, 2026 at 16:38 UTC 9c96180aa3e0d216abf7b4eaa5e6e03f4cc18541
5 files changed +90 -22
apps/server/src/mcp/linkOrigin.test.ts
+16 -1
@@ -16,6 +16,7 @@ import {
16 } from "@t3tools/contracts";
17 import * as Effect from "effect/Effect";
18 import * as Layer from "effect/Layer";
19 +import * as Option from "effect/Option";
20 import { McpSchema, McpServer } from "effect/ai";
21
22 import * as ServerConfig from "../config.ts";
@@ -133,7 +134,21 @@ const layerTools = Layer.mergeAll(
134 Layer.provide(Layer.mock(ScheduledTaskService.ScheduledTaskService)({})),
135 Layer.provide(
136 Layer.mock(ProjectService.ProjectService)({
136 - getById: () => Effect.succeedNone,
137 + getById: (id) =>
138 + Effect.succeed(
139 + id === projectId
140 + ? Option.some({
141 + id,
142 + title: "t3code",
143 + workspaceRoot: "/p/t3code",
144 + defaultModelSelection: null,
145 + scripts: [],
146 + createdAt: "2026-10-18T00:00:00.000Z",
147 + updatedAt: "2026-10-18T00:00:00.000Z",
148 + deletedAt: null,
149 + })
150 + : Option.none(),
151 + ),
152 create: (input) =>
153 Effect.succeed({
154 id: input.projectId,
apps/server/src/mcp/toolkits/project/handlers.test.ts
+34
@@ -642,6 +642,40 @@ it.effect("a launch into a new worktree creates nothing when its branch collides
642 }),
643 );
644
645 +it.effect("a launch into an unknown project says the project was not found", () =>
646 + Effect.gen(function* () {
647 + const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
648 + const { modelSelection, dependencies } = clientLaunchHarness({
649 + runtimeModeCeiling: "auto",
650 + launched,
651 + });
652 + const toolkit = yield* ProjectToolkit.pipe(
653 + Effect.provide(
654 + McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)),
655 + ),
656 + );
657 + for (const workspaceStrategy of [
658 + undefined,
659 + { type: "worktree", baseRef: "main", startFromOrigin: false } as const,
660 + ]) {
661 + const result = yield* toolkit
662 + .handle("t3_thread_launch", {
663 + title: "Fix",
664 + message: "Fix the bug",
665 + projectId: ProjectId.make("current"),
666 + modelSelection,
667 + ...(workspaceStrategy === undefined ? {} : { workspaceStrategy }),
668 + })
669 + .pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies));
670 + expect(result.at(-1)?.result).toMatchObject({
671 + code: "invalid_request",
672 + message: "The project was not found.",
673 + });
674 + }
675 + expect(launched).toHaveLength(0);
676 + }),
677 +);
678 +
679 it.effect("a retried worktree launch replays after its base ref is gone", () =>
680 Effect.gen(function* () {
681 const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
apps/server/src/mcp/toolkits/project/handlers.ts
+22 -19
@@ -151,11 +151,6 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
151 ),
152 )).projectId
153 : yield* resolveProjectId(context, input.projectId);
154 - const readProject = Project.ProjectService.pipe(
155 - Effect.flatMap((projects) => projects.getById(projectId)),
156 - Effect.mapError(unavailable),
157 - Effect.map(Option.getOrUndefined),
158 - );
154 // A retry of an accepted launch replays it: it keeps the model it started
155 // with and skips the checks only a new launch needs, which the project
156 // may no longer pass, such as a base branch deleted since.
@@ -166,15 +161,26 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
161 const launchedModel =
162 launched === null || launched.deletedAt !== null ? undefined : launched.modelSelection;
163 const replaying = launchedModel !== undefined;
169 - if (!replaying && input.workspaceStrategy?.type === "existing_worktree") {
170 - const project = yield* readProject;
171 - if (project === undefined)
172 - return yield* new OrchestratorMcpFailure({
173 - code: "invalid_request",
174 - message: "The project was not found.",
175 - });
164 + const project = replaying
165 + ? undefined
166 + : yield* Project.ProjectService.pipe(
167 + Effect.flatMap((projects) => projects.getById(projectId)),
168 + Effect.mapError(unavailable),
169 + Effect.flatMap(
170 + Option.match({
171 + onNone: () =>
172 + Effect.fail(
173 + new OrchestratorMcpFailure({
174 + code: "invalid_request",
175 + message: "The project was not found.",
176 + }),
177 + ),
178 + onSome: Effect.succeed,
179 + }),
180 + ),
181 + );
182 + if (project !== undefined && input.workspaceStrategy?.type === "existing_worktree")
183 yield* assertProjectWorktree(project.workspaceRoot, input.workspaceStrategy.worktreePath);
177 - }
184 if (!replaying && input.modelSelection !== undefined) {
185 const { instanceId, model } = input.modelSelection;
186 const providers = yield* (yield* ProviderRegistry.ProviderRegistry).getProviders;
@@ -201,15 +207,12 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
207 // project's effective defaults, as the composer does. Its mode stays
208 // within the ceiling it was approved with.
209 const projectDefaults =
204 - caller === undefined && !replaying
210 + caller === undefined && project !== undefined
211 ? yield* ServerSettings.ServerSettingsService.pipe(
212 Effect.flatMap((settings) => settings.getSettings),
213 Effect.mapError(unavailable),
208 - Effect.flatMap((settings) =>
209 - Effect.map(
210 - readProject,
211 - (project) => resolveProjectSettings(settings, projectId, project).settings,
212 - ),
214 + Effect.map(
215 + (settings) => resolveProjectSettings(settings, projectId, project).settings,
216 ),
217 )
218 : undefined;
apps/server/src/peer/PeerForwarding.test.ts
+16 -1
@@ -16,6 +16,7 @@ import { expect, it } from "@effect/vitest";
16 import * as Context from "effect/Context";
17 import * as Effect from "effect/Effect";
18 import * as Layer from "effect/Layer";
19 +import * as Option from "effect/Option";
20 import * as Ref from "effect/Ref";
21 import { McpSchema, McpServer } from "effect/ai";
22
@@ -166,7 +167,21 @@ const boxLaunches = (seen: Ref.Ref<Seen>) =>
167 const boxProjects = (seen: Ref.Ref<Seen>) =>
168 Layer.merge(
169 Layer.mock(ProjectService.ProjectService)({
169 - getById: () => Effect.succeedNone,
170 + getById: (id) =>
171 + Effect.succeed(
172 + id === boxProject
173 + ? Option.some({
174 + id,
175 + title: "t3code",
176 + workspaceRoot: "/box/t3code",
177 + defaultModelSelection: null,
178 + scripts: [],
179 + createdAt: "2026-10-18T00:00:00.000Z",
180 + updatedAt: "2026-10-18T00:00:00.000Z",
181 + deletedAt: null,
182 + })
183 + : Option.none(),
184 + ),
185 create: (input) =>
186 Ref.update(seen, (current) => ({
187 ...current,
apps/server/src/peer/RemoteDelegation.test.ts
+2 -1
@@ -567,7 +567,8 @@ const boxToolkitLayer = (thread: BoxThread) => {
567 Layer.provide(Layer.mock(ScheduledTaskService.ScheduledTaskService)({})),
568 Layer.provide(
569 Layer.mock(ProjectService.ProjectService)({
570 - getById: () => Effect.succeedNone,
570 + getById: (id) =>
571 + Effect.succeed(Option.fromNullishOr(boxProjects.find((project) => project.id === id))),
572 // More than a page, so finding the project with this repository pages.
573 listPage: ({ cursor, limit }) =>
574 Effect.succeed({