Use stored worktree path when creating task terminals#3074
Merged
Conversation
ShellService.getTaskEnv recomputed the worktree path from the managed worktree layout, which fails for tasks that reuse an existing worktree living outside the managed directory. The derived path doesn't exist, so simple-git threw and the terminal never opened. Use the authoritative path stored on the worktree row when it exists on disk, deriving only as a fallback for stale rows. Also degrade gracefully: if workspace env construction fails, start the shell without the POSTHOG_CODE_* vars instead of failing shell creation. Generated-By: PostHog Code Task-Id: 7dc599d8-3621-4c77-b988-4dbb412c2618
…ries Narrow the try/catch in getTaskEnv to the buildWorkspaceEnv call so the repo lookups keep their early-return style. Replace hand-rolled repo stubs in the shell tests with the shared mock repository factories and scope the temp directory to the one test that needs a real path. Generated-By: PostHog Code Task-Id: 7dc599d8-3621-4c77-b988-4dbb412c2618
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
charlesvien
approved these changes
Jul 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes task terminal creation when a task reuses an existing worktree located outside the managed worktree directory by treating the stored worktree path as authoritative and making workspace env setup non-fatal.
Changes:
- Prefer the stored
worktree.path(when it exists on disk) over re-deriving the managed-layout path. - Gracefully degrade when workspace env construction fails by logging and spawning the shell without
POSTHOG_CODE_*variables. - Add unit tests covering stored-path usage, derived-path fallback, and env-construction failure behavior (using shared repository mock factories).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/workspace-server/src/services/shell/shell.ts | Uses stored worktree path when valid and wraps workspace env construction in a try/catch so terminal creation doesn’t fail. |
| packages/workspace-server/src/services/shell/shell.test.ts | Adds test coverage for stored vs derived worktree paths and verifies shell creation continues when env building throws. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Reviews (1): Last reviewed commit: "test(shell): improve type accuracy and b..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Task terminals fail to open when a task reuses an existing worktree that lives outside the managed worktree directory.
ShellService.getTaskEnvalways recomputed the worktree path from the managed layout, and that derived path doesn't exist on disk for reused worktrees, sosimple-gitthrows and the terminal never opens.Changes
getTaskEnvnow uses the worktree's stored path when it exists on disk, and only falls back to deriving the path from the managed layout for stale rows.POSTHOG_CODE_*vars) instead of failing terminal creation entirely.How did you test this?
Manually tested opening a task terminal for a task with an external worktree. Also ran the updated unit test suite (
vitest run shell.test.ts, 5/5 passing),tsc --noEmit, andbiome checkon the changed files.Automatic notifications