fix(server): scheduled tasks in a non-Git project run in its folder instead of failing #36821
main fromrefs/pull/36821/head·merged by juliusmarminge View on GitHubA scheduled task in a project whose folder isn't a Git repository (a Perforce workspace, say) failed every run, because it was saved with "Create a new worktree" and a worktree needs Git. When the runs share a bound thread, the failed setup also holds that thread's queue, so later runs sit queued forever. Now such a task is saved to run in the project folder, the same way Scratch tasks already are.
Fixes #36813
Fix#
ScheduledTaskService.upsert already saved Scratch worktree tasks at the root. It now does the same when the project folder isn't a Git repository, checked by a new ThreadLaunchService.isNonGitProject (a repositoryRoot lookup, so saving never touches a remote). It's true only when Git reports no repository; an unknown project or a Git error keeps the saved strategy. A missing git executable counts as no repository (probeWorkTree treats it that way).
Every save goes through upsert: Settings on web and mobile, and the MCP schedule_task / update_scheduled_task tools. So this covers the path #34995 fixes for #16183 as well as the Settings path it doesn't reach.
Not in this PR:
- Tasks saved before this change keep their worktree strategy until they're saved again.
- A task that already failed stays stuck on its held thread even after a re-save, since later runs still go to that thread. Delete and recreate it. Getting a thread out of a held queue when setup can never succeed is a separate problem.
Evidence#
The existing "stores a Scratch scheduled task at the root" case now runs for Scratch and for an ordinary non-Git project. The non-Git row fails without the change:
× stores a non-Git scheduled task at the root and keeps worktrees elsewhere (Scratch: false)
AssertionError: expected { type: 'worktree', …(2) } to deeply equal { type: 'root' }
and passes with it. vp test run on ThreadLaunchService.test.ts, scheduledTasks/, ws.test.ts, OrchestratorMcpService.test.ts and runtimeLayer.test.ts passes (438 tests). Server typecheck is clean, and vp run check:changed passed against latest upstream main (fcf50ffe3).
Council review#
Rounds: 2
| Delegate | Round 1 | Round 2 |
|---|---|---|
| Claude Opus 5.5 | 7/10 | 8.5/10 |
| GPT-6.1 Sol | 7/10 | 9/10 |
Round 1 moved the check off checkWorktreeBase, which could fetch the base ref from a remote on save, and folded the test into the existing case.
Created with Claude Opus 5.5 in Claude Code (running in T3 Code).
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
moenzuel(GitHub profile, opens in a new tab) linked this to fix #36813
tanstack-source added labelsbug
- @@ -409,3 +411,11 @@409411 });410412 });411413414+ const isNonGitProject: ThreadLaunchService["Service"]["isNonGitProject"] = Effect.fn(415+ "ThreadLaunchService.isNonGitProject",416+ )(function* (projectId) {417+ const project = yield* projects418+ .getById(projectId)419+ .pipe(Effect.orElseSucceed(() => Option.none()));420+ if (Option.isNone(project)) return false;421+ const root = yield* git
🟠 High
orchestration-v2/ThreadLaunchService.ts:421For an existing Git repository with a malformed
.git/config,isNonGitProjectreturnstrue, so scheduled-task upsert replaces the requestedworktreestrategy withroot; after the config is repaired, the task runs in the original checkout instead of an isolated worktree.repositoryRootmapsVcsProcessExitErrorfromWORK_TREE_PROBE_OPERATIONtonull, so use detection here that preserves operational probe errors and distinguishes them from a missing repository.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/orchestration-v2/ThreadLaunchService.ts around line 421: For an existing Git repository with a malformed `.git/config`, `isNonGitProject` returns `true`, so scheduled-task upsert replaces the requested `worktree` strategy with `root`; after the config is repaired, the task runs in the original checkout instead of an isolated worktree. `repositoryRoot` maps `VcsProcessExitError` from `WORK_TREE_PROBE_OPERATION` to `null`, so use detection here that preserves operational probe errors and distinguishes them from a missing repository. Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — Scheduled tasks in non-Git projects now save and use root-folder execution instead of failing worktree preparation. Human review is needed for this automatic fallback because scheduled runs can modify the original project files rather than an isolated workspace.
Needs human approval because:
- 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
juliusmarminge added labelstakeover:in-progress
No actionable comments were generated in the recent review.
Walkthrough
-
ThreadLaunchService now identifies non-Git projects. ScheduledTaskService selects the root workspace strategy for worktree requests in Scratch and non-Git projects. Tests cover both project types and retain worktree behavior for Git projects.
Changes: Scheduled task workspace selection
Layer / File(s) Summary Expose non-Git project detection
apps/server/src/orchestration-v2/ThreadLaunchService.ts,apps/server/src/orchestration-v2/ThreadLaunchService.test.tsThreadLaunchService adds isNonGitProject. It returnsfalsewhen project lookup fails or finds no project. It also returnsfalsewhen the Git repository check fails. The test harness can configure repository checks and simulate Git probe failures.Select root strategy for non-Git tasks
apps/server/src/scheduledTasks/ScheduledTaskService.ts,apps/server/src/orchestration-v2/ThreadLaunchService.test.ts,apps/server/src/scheduledTasks/ScheduledTaskService.interval.test.tsScheduledTaskService uses the root strategy for worktree requests when a project is Scratch or non-Git. Tests cover Scratch and non-Git projects, retain worktree strategy for Git projects, and update service mocks. Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge
Merge Risk:
Minimal · up to78ab4-
Scheduled tasks saved in non-Git projects now use the project folder instead of a Git worktree, and Git projects keep worktrees. Tasks saved before this change keep their worktree strategy until they are saved again. No concrete merge-blocking risk was found in the reviewed change.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: scheduled tasks in a non-Git project now run in the project folder instead of failing. It follows the conventional commit form and matches the code change in Scheduled… Description check The description covers the problem, the fix, scope and exclusions, and verification. It names the linked issue ( #36813) and reports the failing-then-passing test, the test commands run, and the counci…Linked Issues check [ #36813] requires that a scheduled task saved from Settings, or by another caller of ScheduledTaskService.upsert, in a non-Git project run in the project folder, as Scratch tasks already do. At the re…Out of Scope Changes check Changed areas at the reviewed head: ScheduledTaskService.ts (root-strategy condition in upsert, with a comment), ThreadLaunchService.ts (new isNonGitProject method, interface entry, and a CheckpointSt… Full details: Title check
-
Explanation
The title names the main change: scheduled tasks in a non-Git project now run in the project folder instead of failing. It follows the conventional commit form and matches the code change in ScheduledTaskService.upsert and the new ThreadLaunchService.isNonGitProject check.
Full details: Description check
-
Explanation
The description covers the problem, the fix, scope and exclusions, and verification. It names the linked issue (
#36813) and reports the failing-then-passing test, the test commands run, and the council review. The template's Problem, Change, Scope, and Verification sections are all present and substantive.
Full details: Linked Issues check
-
Explanation
[
#36813] requires that a scheduled task saved from Settings, or by another caller of ScheduledTaskService.upsert, in a non-Git project run in the project folder, as Scratch tasks already do. At the reviewed head, ScheduledTaskService.upsert converts a worktree request to { type: "root" } when managedFolders.isScratchProject or threadLaunch.isNonGitProject returns true. ThreadLaunchService.isNonGitProject returns false for an unknown project or a failed check. Otherwise it returns !checkpointStore.isGitRepository(workspaceRoot), so only a confirmed non-repository becomes root. The lookup does not contact a remote. The Git-probe error case is covered by a test that expects the worktree strategy to be kept. The non-Git test case in ThreadLaunchService.test.ts runs for Scratch true and false. The PR description names a repositoryRoot lookup, but the code calls CheckpointStore.isGitRepository. This wording mismatch does not change the verdict, because the code behavior matches the issue. The held-thread recovery from already-failed tasks is outside the objectives, so it is not assessed. Non-coding items are excluded.
Full details: Out of Scope Changes check
-
Explanation
Changed areas at the reviewed head: ScheduledTaskService.ts (root-strategy condition in upsert, with a comment), ThreadLaunchService.ts (new isNonGitProject method, interface entry, and a CheckpointStore dependency that the method needs), ThreadLaunchService.test.ts (non-Git harness and a parameterized Scratch and non-Git test, plus a mock for CheckpointStore and the intake mock forwarding isNonGitProject), and ScheduledTaskService.interval.test.ts (mock for ManagedProjectFolders.isNonGitProject). Each change supports the upsert root-strategy behavior required by
#36813, or keeps the test mocks compilable. No unrelated change was found. Unresolved uncertainty: the Git-executable-missing behavior depends on CheckpointStore.isGitRepository and git.detectRepository, which were not fully read. This does not change the verdict, because such a change still falls within the same scope.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: b779d40
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c9ea68ef-1235-494e-b846-01eae6a0baac
Commits-
Reviewing files that changed from the base of the PR and between 164209699acb4b97d2a0aff576c3fb363a284407 and 78ab430085a3ac993719d017a4f9e8c535f2ce6e.
Files selected for processing: 2-
apps/server/src/orchestration-v2/ThreadLaunchService.test.tsapps/server/src/orchestration-v2/ThreadLaunchService.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
-
-
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Evidence#
Create a fresh task on each commit in a plain folder outside Git: leave Workspace at Create a new worktree, select One thread, fresh session each run, enable a one-minute interval, save, run now, and observe the next occurrence in the bound thread.
Environment for all captures: Chromium web client, 1280 × 800, light theme, real local server, fresh isolated database per commit, synthetic project, Replay (dev) Showcase provider.
Evidence Before After Commit b779d40077 78ab430085 Result Workspace preparation fails; next occurrence remains queued; zero replies Both occurrences produce replies one minute apart Configuration 

First occurrence 

Next occurrence 

Recording Before recording After recording Not shown:
- Unreadable Git repositories and existing failed task queues were not exercised; this comparison covers newly created tasks in ordinary non-Git folders.
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged this3ceed62
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed