The best way to control Claude Code, Codex and more from any computer or phone
fix(server): scheduled tasks in a non-Git project run in its folder instead of failing (#36821)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Bryan Clark committed
Nov 14, 2026 at 09:03 UTC
3ceed620cfcfe6bd34acf2cbcea77d9671b21b84
4 files changed
+72
-21
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+43
-19
@@ -3,6 +3,7 @@ import * as Scheduler from "../scheduling/Scheduler.ts";
3
import * as WorktreeSetupTracker from "../project/WorktreeSetupTracker.ts";
4
import * as ProjectCloneTracker from "../project/ProjectCloneTracker.ts";
5
import * as TerminalManager from "../terminal/Manager.ts";
6
+import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
7
import * as NodeServices from "@effect/platform-node/NodeServices";
8
import * as FileSystem from "effect/FileSystem";
9
import * as ServerConfig from "../config.ts";
@@ -27,6 +28,7 @@ import {
28
ThreadId,
29
TextGenerationError,
30
ServerSettingsError,
31
+ VcsProcessExitError,
32
} from "@t3tools/contracts";
33
import * as Cause from "effect/Cause";
34
import * as Deferred from "effect/Deferred";
@@ -135,6 +137,7 @@ interface HarnessOptions {
137
readonly getLaunchSettings?: ServerSettings.ServerSettingsService["Service"]["getSettings"];
138
readonly providers?: ReadonlyArray<ServerProvider>;
139
readonly git?: Partial<GitWorkflow.GitWorkflowService["Service"]>;
140
+ readonly isGitRepository?: CheckpointStore.CheckpointStore["Service"]["isGitRepository"];
141
}
142
143
function makeHarness(options: HarnessOptions = {}) {
@@ -185,6 +188,9 @@ function makeHarness(options: HarnessOptions = {}) {
188
WorktreeSetupTracker.layer,
189
Layer.mock(ProjectCloneTracker.ProjectCloneTracker)({ get: () => Effect.succeed(null) }),
190
Layer.mock(TerminalManager.TerminalManager)({ close: closeTerminal }),
191
+ Layer.mock(CheckpointStore.CheckpointStore)({
192
+ isGitRepository: options.isGitRepository ?? (() => Effect.succeed(true)),
193
+ }),
194
Layer.succeed(ProjectService.ProjectService, {
195
create: () => Effect.die("unused"),
196
bootstrap: () => Effect.die("unused"),
@@ -919,9 +925,10 @@ it.effect("a rejected initial message leaves no title change and no new thread",
925
}),
926
);
927
922
-// Stands `projectId` in for the Scratch project: a plain folder, not a Git
923
-// repository, so Git fails there with the error a real one raises.
924
-function scratchHarness() {
928
+// Stands `projectId` in for a plain folder, not a Git repository, so Git fails
929
+// there with the error a real one raises. It is the Scratch project unless
930
+// `scratch` is false.
931
+function scratchHarness({ scratch = true }: { readonly scratch?: boolean } = {}) {
932
const claimed: Array<ThreadId> = [];
933
const scratchRoot = project.workspaceRoot;
934
const notARepository = (operation: string, cwd: string) =>
@@ -934,15 +941,28 @@ function scratchHarness() {
941
const harness = makeHarness({
942
managedFolders: Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({
943
namedProjectsRoot: "/projects",
937
- isScratchProject: (id) => Effect.succeed(id === projectId),
944
+ isScratchProject: (id) => Effect.succeed(scratch && id === projectId),
945
folderForThread: (input) =>
946
Effect.sync(() => {
940
- if (input.projectId !== projectId) return Option.none();
947
+ if (!scratch || input.projectId !== projectId) return Option.none();
948
claimed.push(input.threadId);
949
return Option.some(`/scratch/folder-${claimed.length}`);
950
}),
951
}),
952
git: { repositoryRoot: (cwd) => Effect.succeed(cwd === scratchRoot ? null : cwd) },
953
+ // The other project is a repository Git cannot read, which must not count as none.
954
+ isGitRepository: (cwd) =>
955
+ cwd === scratchRoot
956
+ ? Effect.succeed(false)
957
+ : Effect.fail(
958
+ new VcsProcessExitError({
959
+ operation: "GitVcsDriver.probeWorkTree",
960
+ command: "git rev-parse",
961
+ cwd,
962
+ exitCode: 128,
963
+ detail: "fatal: bad config line 1",
964
+ }),
965
+ ),
966
remoteExists: (input) =>
967
input.cwd === scratchRoot
968
? Effect.fail(notARepository("GitWorkflowService.remoteExists", input.cwd))
@@ -1171,20 +1191,23 @@ it.effect("launches a worktree request for Scratch at the root, in its own folde
1191
}).pipe(Effect.provide(harness.layer));
1192
});
1193
1174
-it.effect("stores a Scratch scheduled task at the root and keeps worktrees elsewhere", () => {
1175
- const harness = scratchHarness();
1176
- return Effect.gen(function* () {
1177
- const tasks = yield* ScheduledTasks.ScheduledTaskService;
1178
- const scratch = yield* tasks.upsert(
1179
- scheduledTaskInput("scheduled-task:scratch-upsert", projectId),
1180
- );
1181
- assert.deepEqual(scratch.task.workspaceStrategy, { type: "root" });
1182
- const git = yield* tasks.upsert(
1183
- scheduledTaskInput("scheduled-task:git-upsert", otherProjectId),
1184
- );
1185
- assert.deepEqual(git.task.workspaceStrategy, worktreeStrategy);
1186
- }).pipe(Effect.provide(harness.layer));
1187
-});
1194
+it.effect.each([true, false])(
1195
+ "stores a non-Git scheduled task at the root and keeps worktrees elsewhere (Scratch: %s)",
1196
+ (scratch) => {
1197
+ const harness = scratchHarness({ scratch });
1198
+ return Effect.gen(function* () {
1199
+ const tasks = yield* ScheduledTasks.ScheduledTaskService;
1200
+ const plain = yield* tasks.upsert(
1201
+ scheduledTaskInput("scheduled-task:plain-upsert", projectId),
1202
+ );
1203
+ assert.deepEqual(plain.task.workspaceStrategy, { type: "root" });
1204
+ const git = yield* tasks.upsert(
1205
+ scheduledTaskInput("scheduled-task:git-upsert", otherProjectId),
1206
+ );
1207
+ assert.deepEqual(git.task.workspaceStrategy, worktreeStrategy);
1208
+ }).pipe(Effect.provide(harness.layer));
1209
+ },
1210
+);
1211
1212
it.effect("runs a Scratch scheduled task saved with a worktree in its own folder", () => {
1213
const harness = scratchHarness();
@@ -2227,6 +2250,7 @@ it.effect("shared intake preserves durable attachment bytes after a lost launch
2250
),
2251
),
2252
checkWorktreeBase: launches.checkWorktreeBase,
2253
+ isNonGitProject: launches.isNonGitProject,
2254
retryPreparation: launches.retryPreparation,
2255
prepareRun: launches.prepareRun,
2256
}),
apps/server/src/orchestration-v2/ThreadLaunchService.ts
+25
-1
@@ -41,6 +41,7 @@ import {
41
isTemporaryWorktreeBranch,
42
} from "@t3tools/shared/git";
43
44
+import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
45
import * as GitWorkflow from "../git/GitWorkflowService.ts";
46
import { parseGitCloneProgressLine } from "../project/gitCloneProgress.ts";
47
import * as ProjectService from "../project/ProjectService.ts";
@@ -216,6 +217,8 @@ export class ThreadLaunchService extends Context.Service<
217
void,
218
ThreadLaunchBaseRefError | ThreadLaunchBranchConflictError | ThreadLaunchNotRepositoryError
219
>;
220
+ /** True only when the project's folder is known not to be a Git repository. */
221
+ readonly isNonGitProject: (projectId: ProjectId) => Effect.Effect<boolean>;
222
readonly retryPreparation: (
223
input: ThreadLaunchPreparationInput,
224
) => Effect.Effect<
@@ -244,6 +247,7 @@ const make = Effect.gen(function* () {
247
const cloneTracker = yield* ProjectCloneTracker.ProjectCloneTracker;
248
const terminals = yield* TerminalManager.TerminalManager;
249
const git = yield* GitWorkflow.GitWorkflowService;
250
+ const checkpointStore = yield* CheckpointStore.CheckpointStore;
251
const setupScripts = yield* ProjectSetupScriptRunner.ProjectSetupScriptRunner;
252
const providerRegistry = yield* ProviderRegistry.ProviderRegistry;
253
const serverSettings = yield* ServerSettings.ServerSettingsService;
@@ -428,6 +432,20 @@ const make = Effect.gen(function* () {
432
});
433
});
434
435
+ const isNonGitProject: ThreadLaunchService["Service"]["isNonGitProject"] = Effect.fn(
436
+ "ThreadLaunchService.isNonGitProject",
437
+ )(function* (projectId) {
438
+ const project = yield* projects
439
+ .getById(projectId)
440
+ .pipe(Effect.orElseSucceed(() => Option.none()));
441
+ if (Option.isNone(project)) return false;
442
+ // Unlike `git.repositoryRoot`, this fails on a repository Git cannot read, which is not "no repository".
443
+ return yield* checkpointStore.isGitRepository(project.value.workspaceRoot).pipe(
444
+ Effect.map((isRepository) => !isRepository),
445
+ Effect.orElseSucceed(() => false),
446
+ );
447
+ });
448
+
449
const prepareInBackground = Effect.fn("ThreadLaunchService.prepareInBackground")(function* (
450
input: PreparationInput,
451
threadId: ThreadId,
@@ -1382,7 +1400,13 @@ const make = Effect.gen(function* () {
1400
);
1401
});
1402
1385
- return ThreadLaunchService.of({ launch, checkWorktreeBase, retryPreparation, prepareRun });
1403
+ return ThreadLaunchService.of({
1404
+ launch,
1405
+ checkWorktreeBase,
1406
+ isNonGitProject,
1407
+ retryPreparation,
1408
+ prepareRun,
1409
+ });
1410
});
1411
1412
export const layer = Layer.effect(ThreadLaunchService, make);
apps/server/src/scheduledTasks/ScheduledTaskService.interval.test.ts
+1
@@ -26,6 +26,7 @@ const dependencies = Layer.mergeAll(
26
ManagedPolicy.layerTest(),
27
Layer.mock(ThreadLaunchService.ThreadLaunchService)({
28
launch: () => Effect.die("synthetic dispatch failure"),
29
+ isNonGitProject: () => Effect.succeed(false),
30
}),
31
Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({
32
namedProjectsRoot: "/projects",
apps/server/src/scheduledTasks/ScheduledTaskService.ts
+3
-1
@@ -1511,9 +1511,11 @@ export const layer = Layer.effect(
1511
return { token, secret, secretChanged };
1512
})
1513
: { token: null, secret: null, secretChanged: true };
1514
+ // A folder that is not a Git repository, Scratch included, cannot hold a worktree.
1515
const workspaceStrategy: ScheduledTask["workspaceStrategy"] =
1516
input.workspaceStrategy.type === "worktree" &&
1516
- (yield* managedFolders.isScratchProject(input.projectId))
1517
+ ((yield* managedFolders.isScratchProject(input.projectId)) ||
1518
+ (yield* threadLaunch.isNonGitProject(input.projectId)))
1519
? { type: "root" }
1520
: input.workspaceStrategy;
1521
const scheduleUnchanged =