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 22, 12:00 UTC
fix(orchestration): gate prepared provider starts (#23669)
Co-authored-by: Tejas Parmar <parmartejas@vanojay.in> Co-authored-by: maria-rcks <maria@kuuro.net>
parmartejas committed
Oct 31, 2026 at 02:26 UTC
28c7d3e76780d5adca9103546962db6c66a7780d
2 files changed
+110
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+94
@@ -1159,6 +1159,100 @@ it.effect("shows the fetch diagnosis when preparing a worktree from origin fails
1159
}).pipe(Effect.provide(harness.layer));
1160
});
1161
1162
+it.effect("rejects a preparation retry after the project disables its provider", () => {
1163
+ let fetchAttempts = 0;
1164
+ const harness = makeHarness({
1165
+ fetchWorktreeBaseCommit: () =>
1166
+ fetchAttempts++ === 0
1167
+ ? Effect.fail(
1168
+ new GitCommandError({
1169
+ operation: "GitVcsDriver.fetchRemote",
1170
+ command: "git",
1171
+ cwd: project.workspaceRoot,
1172
+ detail: "Git could not reach the remote.",
1173
+ exitCode: 128,
1174
+ }),
1175
+ )
1176
+ : Effect.succeed({ commitSha: "remote-main-sha", remoteRefName: "origin/main" }),
1177
+ });
1178
+ return Effect.gen(function* () {
1179
+ const launches = yield* ThreadLaunch.ThreadLaunchService;
1180
+ const settings = yield* ServerSettings.ServerSettingsService;
1181
+ const threads = yield* ThreadManagement.ThreadManagementService;
1182
+ const launched = yield* launches.launch(
1183
+ launchInput({
1184
+ command: "command:launch:disabled-preparation-retry",
1185
+ thread: "thread:launch:disabled-preparation-retry",
1186
+ message: "Start from origin",
1187
+ workspace: { type: "worktree", baseRef: "main", startFromOrigin: true },
1188
+ }),
1189
+ );
1190
+ yield* preparationSettled(launched.threadId);
1191
+ yield* settings.updateSettings({
1192
+ projectSettingsOverrides: {
1193
+ [projectId]: { providerInstances: { [modelSelection.instanceId]: { enabled: false } } },
1194
+ },
1195
+ });
1196
+
1197
+ const error = yield* launches
1198
+ .retryPreparation({
1199
+ commandId: CommandId.make("command:launch:disabled-preparation-retry:retry"),
1200
+ threadId: launched.threadId,
1201
+ runId: launched.projection.runs[0]!.id,
1202
+ })
1203
+ .pipe(Effect.flip);
1204
+
1205
+ assert.equal(error._tag, "ThreadManagementProviderInstanceDisabledError");
1206
+ assert.equal((yield* threads.getThreadProjection(launched.threadId)).runs[0]?.status, "failed");
1207
+ assert.equal(fetchAttempts, 1);
1208
+ }).pipe(Effect.provide(harness.layer));
1209
+});
1210
+
1211
+it.effect("does not release a prepared run after the project disables its provider", () => {
1212
+ return Effect.gen(function* () {
1213
+ const setupEntered = yield* Deferred.make<void>();
1214
+ const allowSetup = yield* Deferred.make<void>();
1215
+ const harness = makeHarness({
1216
+ runSetup: () =>
1217
+ Deferred.succeed(setupEntered, undefined).pipe(
1218
+ Effect.andThen(Deferred.await(allowSetup)),
1219
+ Effect.as({ status: "no-script" as const }),
1220
+ ),
1221
+ });
1222
+ yield* Effect.gen(function* () {
1223
+ const launches = yield* ThreadLaunch.ThreadLaunchService;
1224
+ const settings = yield* ServerSettings.ServerSettingsService;
1225
+ const launched = yield* launches.launch(
1226
+ launchInput({
1227
+ command: "command:launch:disable-during-preparation",
1228
+ thread: "thread:launch:disable-during-preparation",
1229
+ message: "Prepare a worktree",
1230
+ workspace: { type: "worktree", baseRef: "main" },
1231
+ }),
1232
+ );
1233
+ yield* Deferred.await(setupEntered);
1234
+ yield* settings.updateSettings({
1235
+ projectSettingsOverrides: {
1236
+ [projectId]: { providerInstances: { [modelSelection.instanceId]: { enabled: false } } },
1237
+ },
1238
+ });
1239
+ yield* Deferred.succeed(allowSetup, undefined);
1240
+ const projection = yield* preparationSettled(launched.threadId);
1241
+ assert.equal(projection.runs[0]?.status, "failed");
1242
+ const effects = yield* (yield* EffectOutbox.EffectOutboxV2).listByCommandId(
1243
+ CommandId.make("command:launch:disable-during-preparation:release"),
1244
+ );
1245
+ assert.isFalse(
1246
+ effects.some(
1247
+ (effect) =>
1248
+ effect.request.type === "provider-turn.start" &&
1249
+ effect.request.runId === launched.projection.runs[0]?.id,
1250
+ ),
1251
+ );
1252
+ }).pipe(Effect.provide(harness.layer));
1253
+ });
1254
+});
1255
+
1256
it.effect.each(["fails", "is interrupted"] as const)(
1257
"holds a message queued during setup when the workspace preparation %s",
1258
(ending) =>
apps/server/src/orchestration-v2/ThreadManagementService.ts
+16
@@ -724,6 +724,22 @@ const make = Effect.gen(function* () {
724
}),
725
),
726
);
727
+ case "prepared-run.release":
728
+ case "prepared-run.retry":
729
+ return orchestrator
730
+ .getThreadRecords(command.threadId, ["runs"], { runIds: [command.runId] })
731
+ .pipe(
732
+ Effect.flatMap((projection) => {
733
+ const run = projection.runs.find((candidate) => candidate.id === command.runId);
734
+ return run === undefined
735
+ ? Effect.void
736
+ : assertProviderInstanceEnabled({
737
+ projectId: projection.thread.projectId,
738
+ commandId: command.commandId,
739
+ instanceId: run.providerInstanceId,
740
+ });
741
+ }),
742
+ );
743
default:
744
return Effect.void;
745
}