[Bug]: A scheduled task that opens a thread per run bases its worktree on a hardcoded "main", so it fails on repos whose default branch is master #26260
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Use a project whose repository's default branch is
masterand has nomainbranch, locally or on origin. - Create a scheduled task with
schedule_taskandbindToCurrentThread: false(a new thread per run). Here it was a webhook trigger,{ "type": "webhook", ... }. - Fire it (here, a GitHub
pull_requestdelivery). - The new thread fails in workspace preparation. Retry fails the same way.
Expected behavior#
The run's worktree starts from the project's default branch (origin/master here, which refs/remotes/origin/HEAD names), as threads started by hand in the same project do.
Actual behavior#
Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree (<repo>): git worktree add failed (ref_not_found)
schedule_task takes no workspace argument, and for an unbound task scheduledTaskWorkspaceStrategy hardcodes the base:
function scheduledTaskWorkspaceStrategy(boundToThread) {
return boundToThread ? { type: "root" } : {
type: "worktree",
baseRef: "main",
startFromOrigin: true
};
}
The task row stores {"type":"worktree","baseRef":"main","startFromOrigin":true}. At launch, resolveWorktreeBaseRemote("main") finds no local main and falls back to origin/main, which doesn't exist, so the fetch yields nothing and startRef stays the literal main. GitVcsDriver.createWorktree then runs git worktree add -b t3/… -- <path> main, which git rejects, and T3 classifies that as ref_not_found.
A fix could take the base from the project's default branch for unbound tasks, or let schedule_task accept a base ref.
Impact#
Blocks work completely
Version or commit#
0.1.4-nightly.20261027.3770
Environment#
macOS 15.6.1 (arm64), desktop app; git 2.39.5; provider Claude (claude-opus-5-5), full access
Logs or stack traces#
ThreadLaunchError: Thread launch scheduled-task:…:webhook:delivery:relay:… failed during provision-worktree.
at ThreadLaunchService.prepareInBackground
at ThreadLaunchService.launch
at ScheduledTaskService.runTask
at ScheduledTaskService.runWebhookDelivery
[cause]: GitCommandError: Git command failed in GitVcsDriver.createWorktree (<repo>): git worktree add failed (ref_not_found)
# the same command by hand, in the project's clone:
$ git worktree add -b t3/probe -- /tmp/probe main
Preparing worktree (new branch 't3/probe')
fatal: not a valid object name: 'main'
Workaround#
A local main that tracks the default branch: git branch --track main origin/master. resolveWorktreeBaseRemote then reads its upstream, fetches origin/master, and starts the worktree there.
Related: #17889 (a failed scheduled run is recorded as succeeded) shows here too, since the task reports lastRunStatus: succeeded while its thread failed. That's a separate bug, so this isn't a duplicate.
Investigated and written up by Claude (claude-opus-5-5) in a T3 Code thread.
Closing as a duplicate of #16183, which tracks the same problem. Please follow along there.
juliusmarminge closed this
Sign in to join this conversation.
I opened #26465 for this. For unbound
schedule_tasktasks, it saves the project'sorigin/HEADbranch as the worktree base, and keeps"main"whenorigin/HEADisn't set. Bound tasks and the web/mobile scheduled-task forms are unchanged.I checked it against real git locally. On a clone whose origin has only
master, the old"main"base reproduces theref_not_foundfailure from this report. The new base creates the worktree atorigin/master. A repo whoseoriginwas added by hand has noorigin/HEAD, so it still falls back to"main". The PR lists that as a known limitation.