Skip to content

Commit 6d84a1e

Browse files
zainmitchellclaude
andcommitted
Merge the amended launch-request-key target into #22446
The target's launch commit now skips new-launch checks when a retry finds its thread. Keep that for the worktree base ref and project defaults, and also skip the base ref for an accepted receipt as before. Keep checking existing-worktree membership on every launch: a retry may bind a workspace to an idle accepted launch, and this branch's tests require the refusal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents cdb82b0 + 071e661 commit 6d84a1e

2 files changed

Lines changed: 57 additions & 10 deletions

File tree

‎apps/server/src/mcp/toolkits/project/handlers.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,46 @@ it.effect("a launch into a new worktree creates nothing when its base ref has no
385385
expect(launched).toHaveLength(1);
386386
}),
387387
);
388+
389+
it.effect("a retried worktree launch replays after its base ref is gone", () =>
390+
Effect.gen(function* () {
391+
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
392+
const base = { exists: true };
393+
const { projectId, dependencies } = clientLaunchHarness({
394+
runtimeModeCeiling: "auto",
395+
launched,
396+
checkWorktreeBase: ({ projectId, workspaceStrategy }) =>
397+
base.exists || workspaceStrategy.type !== "worktree"
398+
? Effect.void
399+
: Effect.fail(
400+
new ThreadLaunch.ThreadLaunchBaseRefError({
401+
projectId,
402+
projectTitle: "Client target",
403+
workspaceRoot: "/projects/client-target",
404+
baseRef: workspaceStrategy.baseRef,
405+
}),
406+
),
407+
});
408+
const toolkit = yield* ProjectToolkit.pipe(
409+
Effect.provide(
410+
McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)),
411+
),
412+
);
413+
const launch = toolkit
414+
.handle("t3_thread_launch", {
415+
title: "Fix",
416+
projectId,
417+
clientRequestId: "fix-worktree",
418+
workspaceStrategy: { type: "worktree", baseRef: "feature", startFromOrigin: false },
419+
})
420+
.pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies));
421+
422+
yield* launch;
423+
base.exists = false;
424+
expect((yield* launch).at(-1)?.result).toMatchObject({ projectId });
425+
expect(launched.map((input) => input.threadId)).toEqual([
426+
launched[0]?.threadId,
427+
launched[0]?.threadId,
428+
]);
429+
}),
430+
);

‎apps/server/src/mcp/toolkits/project/handlers.ts‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
123123
Effect.mapError(unavailable),
124124
Effect.map(Option.getOrUndefined),
125125
);
126+
// A retry of an accepted launch replays it: it keeps the model it started
127+
// with and skips the checks only a new launch needs, which the project
128+
// may no longer pass, such as a base branch deleted since.
129+
const launched =
130+
input.clientRequestId === undefined
131+
? null
132+
: yield* context.threads.getThreadShell(threadId).pipe(Effect.mapError(unavailable));
133+
const launchedModel =
134+
launched === null || launched.deletedAt !== null ? undefined : launched.modelSelection;
135+
const replaying = launchedModel !== undefined;
136+
// A retry may bind a workspace to an idle accepted launch, so membership
137+
// is checked on every launch, unlike the checks below.
126138
if (input.workspaceStrategy?.type === "existing_worktree") {
127139
const project = yield* readProject;
128140
if (project === undefined)
@@ -135,7 +147,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
135147
// A launch is accepted before its worktree is provisioned, so a base
136148
// ref that cannot resolve is refused while the agent can still act on it.
137149
const strategy = input.workspaceStrategy;
138-
if (acceptedLaunch === undefined && strategy?.type === "worktree")
150+
if (acceptedLaunch === undefined && !replaying && strategy?.type === "worktree")
139151
yield* ThreadLaunch.ThreadLaunchService.pipe(
140152
Effect.flatMap((launches) =>
141153
launches.checkWorktreeBase({ projectId, workspaceStrategy: strategy }),
@@ -152,19 +164,11 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
152164
}),
153165
),
154166
);
155-
// A retry of an accepted launch keeps the model it started with, even if
156-
// the project's defaults changed since, and the launch service replays it.
157-
const launched =
158-
input.clientRequestId === undefined
159-
? null
160-
: yield* context.threads.getThreadShell(threadId).pipe(Effect.mapError(unavailable));
161-
const launchedModel =
162-
launched === null || launched.deletedAt !== null ? undefined : launched.modelSelection;
163167
// A caller outside a thread has nothing to inherit, so it starts with the
164168
// project's effective defaults, as the composer does. Its mode stays
165169
// within the ceiling it was approved with.
166170
const projectDefaults =
167-
caller === undefined && launchedModel === undefined
171+
caller === undefined && !replaying
168172
? yield* ServerSettings.ServerSettingsService.pipe(
169173
Effect.flatMap((settings) => settings.getSettings),
170174
Effect.mapError(unavailable),

0 commit comments

Comments
 (0)