MCP ensure path does not fold a worktree dir to the project root #532

Closed
opened 2026-08-20 02:55:14 +02:00 by dries · 0 comments
Owner

Found during review of PR #523 (fix: relaunch a killed opencode on local create). Pre-existing; same bug class the PR fixed on the create-session path, but on the MCP/scheduled-prompt path.

internal/server/host.go:133 — ensureProjectOpencodePort passes the raw directory to EnsureProjectOpencode without the projectRootForDirectory folding that the create handler now does. If the parent session lives in a git worktree, ensure resolves the worktree's toplevel (git.ResolveRepoRoot returns the worktree root, internal/git/worktree.go:62) instead of the main checkout — violating the "one opencode instance per project" invariant and potentially launching a second instance per worktree for MCP splits and scheduled prompts.

Open design question first (flagged during review): is per-worktree ensure on this path intentional? If not, apply the same folding as the create path and add a table-driven test mirroring the create-path one.

Found during review of PR #523 (fix: relaunch a killed opencode on local create). **Pre-existing**; same bug class the PR fixed on the create-session path, but on the MCP/scheduled-prompt path. `internal/server/host.go:133` — `ensureProjectOpencodePort` passes the raw directory to `EnsureProjectOpencode` without the `projectRootForDirectory` folding that the create handler now does. If the parent session lives in a git worktree, ensure resolves the **worktree's** toplevel (`git.ResolveRepoRoot` returns the worktree root, `internal/git/worktree.go:62`) instead of the main checkout — violating the "one opencode instance per project" invariant and potentially launching a second instance per worktree for MCP splits and scheduled prompts. Open design question first (flagged during review): is per-worktree ensure on this path *intentional*? If not, apply the same folding as the create path and add a table-driven test mirroring the create-path one.
dries closed this issue 2026-08-20 23:12:38 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#532
No description provided.