Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): scheduled tasks in a non-Git project run in its folder instead of failing #36821

Mergedmoenzuel(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/36821/headmerged by juliusmarminge View on GitHub

A 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

DelegateRound 1Round 2
Claude Opus 5.57/108.5/10
GPT-6.1 Sol7/109/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

    2. tanstack-source added labelsbug

    3. @@ -409,3 +411,11 @@
      409411 });
      410412 });
      411413
      414+ const isNonGitProject: ThreadLaunchService["Service"]["isNonGitProject"] = Effect.fn(
      415+ "ThreadLaunchService.isNonGitProject",
      416+ )(function* (projectId) {
      417+ const project = yield* projects
      418+ .getById(projectId)
      419+ .pipe(Effect.orElseSucceed(() => Option.none()));
      420+ if (Option.isNone(project)) return false;
      421+ const root = yield* git
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High orchestration-v2/ThreadLaunchService.ts: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.

      🤖 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.
    4. 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
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. juliusmarminge added labelstakeover:in-progress

    6. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      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.ts
      ThreadLaunchService adds isNonGitProject. It returns false when project lookup fails or finds no project. It also returns false when 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.ts
      ScheduledTaskService 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 to 78ab4

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe 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 checkPassedThe 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 checkPassed[#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 checkPassedChanged 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

      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.ts
      • apps/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.

    7. 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.

      EvidenceBeforeAfter
      Commitb779d4007778ab430085
      ResultWorkspace preparation fails; next occurrence remains queued; zero repliesBoth occurrences produce replies one minute apart
      ConfigurationBefore: default worktree configurationAfter: identical default worktree configuration
      First occurrenceBefore: failed workspace preparationAfter: successful first occurrence
      Next occurrenceBefore: error and queued occurrenceAfter: another reply from the interval occurrence
      RecordingBefore recordingAfter recording

      Scenario source

      Not shown:

      • Unreadable Git repositories and existing failed task queues were not exercised; this comparison covers newly created tasks in ordinary non-Git folders.
    8. juliusmarminge added labelstakeover:ready

    9. juliusmarminge removed labelstakeover:in-progress

    10. juliusmarminge merged this3ceed62

    11. juliusmarminge closed this

    12. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.