fix(server): scheduled tasks start fresh threads from the repository's default branch #16215
ClosedMnigos(GitHub profile, opens in a new tab)wants to merge 9 commits into
main fromrefs/pull/16215/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/server/src/mcp/OrchestratorMcpService.ts line 838OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -829 +818,21 @@829818819+ /**820+ * Workspace strategy for a scheduled task created/updated over MCP: bound runs821+ * post into the existing thread (the strategy is unused, keep root); unbound822+ * runs launch a fresh worktree per run from the base a manual worktree thread823+ * defaults to: origin's default branch, else the project's checked-out branch,824+ * else (detached HEAD or not a git repository) the previous default, main.825+ */826+ const scheduledTaskWorkspaceStrategy = (827+ boundToThread: boolean,828+ projectId: ProjectId,829+ ): Effect.Effect<ScheduledTask["workspaceStrategy"], OrchestratorMcpFailure> =>830+ Effect.gen(function* () {831+ if (boundToThread) return { type: "root" };832+ const { workspaceRoot } = yield* requireProject(projectId);833+ const checkedOutBranch = git.statusDetailsLocal(workspaceRoot).pipe(834+ Effect.map((status) => status.branch),835+ Effect.mapError((error) =>836+ failure(837+ "orchestration_error",838+ `Could not read the project's checked-out branch to pick a base branch; try again. ${error.message}`,coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/server/src/mcp/OrchestratorMcpService.ts line 930OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -921 +910,21 @@921910911+ /**912+ * Workspace strategy for a scheduled task created/updated over MCP: bound runs913+ * post into the existing thread (the strategy is unused, keep root); unbound914+ * runs launch a fresh worktree per run from main. Only when the project has no915+ * main (neither `origin/main` nor a local branch, the refs a run's launch916+ * falls back across) does it branch from origin's default branch, else the917+ * checked-out branch, else (detached HEAD or not a git repository) main. Every918+ * check reads local refs; nothing is fetched.919+ */920+ const scheduledTaskWorkspaceStrategy = (921+ boundToThread: boolean,922+ projectId: ProjectId,923+ ): Effect.Effect<ScheduledTask["workspaceStrategy"], OrchestratorMcpFailure> =>924+ Effect.gen(function* () {925+ if (boundToThread) return { type: "root" };926+ const { workspaceRoot } = yield* requireProject(projectId);927+ const hasMain =928+ (yield* git929+ .remoteBranchExists({ cwd: workspaceRoot, remoteName: "origin", refName: "main" })930+ .pipe(Effect.orElseSucceed(() => false))) ||apps/server/src/mcp/OrchestratorMcpService.ts lines 945 to 950OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -921,0 +930,21 @@930+ .pipe(Effect.orElseSucceed(() => false))) ||931+ (yield* git.listLocalBranchNames(workspaceRoot).pipe(932+ Effect.map((branches) => branches.includes("main")),933+ Effect.orElseSucceed(() => false),934+ ));935+ if (hasMain) return { type: "worktree", baseRef: "main", startFromOrigin: true };936+ const checkedOutBranch = git.statusDetailsLocal(workspaceRoot).pipe(937+ Effect.map((status) => status.branch),938+ Effect.mapError(() =>939+ failure(940+ "orchestration_error",941+ "Could not read the project's checked-out branch to pick a base branch; try again.",942+ ),943+ ),944+ );945+ const baseRef =946+ (yield* git947+ .resolveDefaultBranchName(workspaceRoot, "origin")948+ .pipe(Effect.orElseSucceed(() => null))) ??949+ (yield* checkedOutBranch) ??950+ "main";coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/server/src/mcp/OrchestratorMcpService.ts lines 953 to 958Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -923,0 +932,21 @@932+ ({ type: "worktree", baseRef, startFromOrigin: true }) as const;933+ const unreadable = failure(934+ "orchestration_error",935+ "Could not read the project's branches to pick a base branch; try again.",936+ );937+ const readGit = <A>(read: Effect.Effect<A, GitCommandError>) =>938+ read.pipe(Effect.mapError(() => unreadable));939+ const probe = yield* readGit(940+ git.execute({941+ operation: "OrchestratorMcpService.scheduledTaskBase",942+ cwd,943+ args: ["rev-parse", "--git-dir"],944+ allowNonZeroExit: true,945+ }),946+ );947+ if (probe.exitCode !== 0) {948+ if (probe.stderr.toLowerCase().includes("not a git repository")) {949+ return worktreeFrom("main");950+ }951+ return yield* unreadable;952+ }coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
Mnigos(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — The production behavior for unbound scheduled tasks changes from always using
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).mainto selecting and persisting a repository-derived base branch, which affects future worktree creation and scheduled execution. The change is focused and well tested, but its impact on the product default warrants deliberate review.