Repository navigation
fix(server): scheduled tasks start from the default branch, not always main #27983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f8081a4
7ca575f
130b62a
342a845
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,14 +252,6 @@ function errorMessage(error: unknown): string { | |
| return error instanceof Error ? error.message : String(error); | ||
| } | ||
|
|
||
| function scheduledTaskWorkspaceStrategy( | ||
| boundToThread: boolean, | ||
| ): ScheduledTask["workspaceStrategy"] { | ||
| return boundToThread | ||
| ? { type: "root" } | ||
| : { type: "worktree", baseRef: "main", startFromOrigin: true }; | ||
| } | ||
|
|
||
| function scheduledTaskSummary(task: ScheduledTask, mayRun: boolean): OrchestratorMcpScheduledTask { | ||
| return { | ||
| scheduledTaskId: task.id, | ||
|
|
@@ -1793,6 +1785,50 @@ const make = Effect.gen(function* () { | |
| effect.pipe(Effect.timeoutOption(Duration.millis(timeoutMs)), Effect.map(Option.flatten)), | ||
| ); | ||
|
|
||
| const refExists = (cwd: string, revision: string) => | ||
| gitDriver.resolveCommit({ cwd, revision }).pipe( | ||
| Effect.as(true), | ||
| Effect.orElseSucceed(() => false), | ||
| ); | ||
|
|
||
| const resolveScheduledTaskBaseRef = Effect.fn( | ||
| "OrchestratorMcpService.resolveScheduledTaskBaseRef", | ||
| )(function* (cwd: string) { | ||
| const remoteName = yield* gitDriver | ||
| .resolvePrimaryRemoteName(cwd) | ||
| .pipe(Effect.orElseSucceed(() => null)); | ||
| // Launch fetches a bare name from `origin` only, so any other remote must be named. | ||
| const onRemote = (branch: string) => | ||
| remoteName === "origin" ? branch : `${remoteName}/${branch}`; | ||
|
tuanvumaihuynh marked this conversation as resolved.
Resolved
|
||
| const remoteDefault = | ||
| remoteName === null | ||
| ? null | ||
| : yield* gitDriver | ||
| .resolveDefaultBranchName(cwd, remoteName) | ||
| .pipe(Effect.orElseSucceed(() => null)); | ||
| if (remoteDefault !== null) return onRemote(remoteDefault); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not accept a stale remote HEAD as the default branch. After a remote default changes from Based on learnings, “
|
||
| // Local-only repositories and remotes without a recorded HEAD report no default. | ||
| for (const branch of ["main", "master"]) { | ||
| if (remoteName !== null && (yield* refExists(cwd, `refs/remotes/${remoteName}/${branch}`))) { | ||
| return onRemote(branch); | ||
| } | ||
| if (yield* refExists(cwd, `refs/heads/${branch}`)) return branch; | ||
|
tuanvumaihuynh marked this conversation as resolved.
Resolved
|
||
| } | ||
| return "main"; | ||
| }); | ||
|
|
||
| const scheduledTaskWorkspaceStrategy = Effect.fn( | ||
| "OrchestratorMcpService.scheduledTaskWorkspaceStrategy", | ||
| )(function* (boundToThread: boolean, projectId: ProjectId) { | ||
| if (boundToThread) return { type: "root" as const }; | ||
| const { workspaceRoot } = yield* requireProject(projectId); | ||
| return { | ||
| type: "worktree" as const, | ||
| baseRef: yield* resolveScheduledTaskBaseRef(workspaceRoot), | ||
| startFromOrigin: true, | ||
| }; | ||
| }); | ||
|
|
||
| const scheduledTaskRunModes = Effect.fn("OrchestratorMcpService.scheduledTaskRunModes")( | ||
| function* (task: ScheduledTask) { | ||
| const modes = [{ runtimeMode: task.runtimeMode, interactionMode: task.interactionMode }]; | ||
|
|
@@ -1904,7 +1940,7 @@ const make = Effect.gen(function* () { | |
| schedule: input.schedule, | ||
| projectId, | ||
| threadId: bindToCurrentThread && parent !== undefined ? parent.thread.id : null, | ||
| workspaceStrategy: scheduledTaskWorkspaceStrategy(bindToCurrentThread), | ||
| workspaceStrategy: yield* scheduledTaskWorkspaceStrategy(bindToCurrentThread, projectId), | ||
| modelSelection, | ||
| runtimeMode: limits.runtimeMode, | ||
| interactionMode: limits.interactionMode, | ||
|
|
@@ -1976,7 +2012,7 @@ const make = Effect.gen(function* () { | |
| const workspaceStrategy = | ||
| input.bindToCurrentThread === undefined | ||
| ? existing.workspaceStrategy | ||
| : scheduledTaskWorkspaceStrategy(input.bindToCurrentThread); | ||
| : yield* scheduledTaskWorkspaceStrategy(input.bindToCurrentThread, existing.projectId); | ||
| const upsertInput: ScheduledTaskUpsertInput = { | ||
| id: existing.id, | ||
| title: input.title ?? existing.title, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.