fix(sessions): mark worktree sessions as live-connected #329

Merged
dries merged 1 commit from fix/worktree-liveconnection into main 2026-07-13 23:01:14 +02:00
Owner

Problem

When a worktree session prompts for a permission or question, the UI does not show it in that session. The composer is also disabled for worktree sessions.

Root cause

Worktree sessions run on the project's single shared OpenCode instance, whose process cwd is the main checkout. But each worktree session's Directory is the worktree path (.../.worktrees/<repo>/<slug>).

Adapter.Sessions() set the LiveConnection flag by exact directory match against the map[dir]port port map (keyed by each process's cwd). The worktree path is never a key, so every worktree session reported LiveConnection=false.

The frontend mirrors session.liveConnection into portAvailable (useSessionCapabilities.ts), and portAvailable gates:

  • question prompt render + resurrection effects (SessionDetail.tsx)
  • the composer

The earlier fix 393367b only removed the portAvailable gate from the permission render path — a targeted patch that left the underlying liveness signal wrong, so questions and the composer stayed broken.

Fix

Fold a worktree directory back to its project root (<prefix>/.worktrees/<repo>/<slug><prefix>/<repo>) before the liveness lookup, so the hosting instance is found. One backend change fixes permissions, questions, and the composer — no frontend edit needed.

  • portdiscovery.go: new pure foldWorktreeToProjectRoot helper (mirrors server.projectRootForDirectory / git.WorktreePathFor; kept local to avoid an import cycle).
  • adapter.go: new directoryHasLivePort (exact match, then fold fallback); Sessions() uses it for the LiveConnection flag.

Tests

Table-driven tests for both helpers, incl. a regression guard for the worktree case. Verified red→green: the old exact-match returns false for a worktree directory (the bug); the fold fallback returns true.

go test ./internal/platforms/opencode/ and ./internal/server/ pass; go vet clean; go build ./... clean.

## Problem When a worktree session prompts for a permission or question, the UI does not show it in that session. The composer is also disabled for worktree sessions. ## Root cause Worktree sessions run on the project's **single shared** OpenCode instance, whose process cwd is the **main checkout**. But each worktree session's `Directory` is the worktree path (`.../.worktrees/<repo>/<slug>`). `Adapter.Sessions()` set the `LiveConnection` flag by exact directory match against the `map[dir]port` port map (keyed by each process's cwd). The worktree path is never a key, so **every worktree session reported `LiveConnection=false`**. The frontend mirrors `session.liveConnection` into `portAvailable` (`useSessionCapabilities.ts`), and `portAvailable` gates: - question prompt render + resurrection effects (`SessionDetail.tsx`) - the composer The earlier fix `393367b` only removed the `portAvailable` gate from the *permission* render path — a targeted patch that left the underlying liveness signal wrong, so questions and the composer stayed broken. ## Fix Fold a worktree directory back to its project root (`<prefix>/.worktrees/<repo>/<slug>` → `<prefix>/<repo>`) before the liveness lookup, so the hosting instance is found. One backend change fixes permissions, questions, and the composer — no frontend edit needed. - `portdiscovery.go`: new pure `foldWorktreeToProjectRoot` helper (mirrors `server.projectRootForDirectory` / `git.WorktreePathFor`; kept local to avoid an import cycle). - `adapter.go`: new `directoryHasLivePort` (exact match, then fold fallback); `Sessions()` uses it for the `LiveConnection` flag. ## Tests Table-driven tests for both helpers, incl. a regression guard for the worktree case. Verified red→green: the old exact-match returns `false` for a worktree directory (the bug); the fold fallback returns `true`. `go test ./internal/platforms/opencode/` and `./internal/server/` pass; `go vet` clean; `go build ./...` clean.
fix(sessions): mark worktree sessions as live-connected
All checks were successful
CI / Build Desktop (macOS arm64) (pull_request) Successful in 2m26s
CI / Backend (pull_request) Successful in 4m54s
CI / Frontend (pull_request) Successful in 5m3s
CI / Coverage Ratchet (pull_request) Successful in 5m26s
CI / Build (pull_request) Successful in 5m43s
CI / Playwright E2E (pull_request) Successful in 8m44s
CI / Semantic Tag (pull_request) Successful in 7s
2070086fd7
Worktree sessions run on the project's shared OpenCode instance (rooted
at the main checkout), but their directory is the worktree path. The
LiveConnection flag was set by exact directory match against the port
map, so worktree sessions always reported LiveConnection=false. On the
frontend this mirrors to portAvailable=false, which disabled the
composer and the question-prompt UI for them.

Fold a worktree directory back to its project root before the liveness
lookup so the hosting instance is found.

Coverage ratchet: pass

Suite Baseline This PR Δ
go 72.50% 72.60% +0.10

Tolerance: -0.1%. Baseline stored on gh-pages.

<!-- coverage-ratchet --> ### Coverage ratchet: ✅ pass | Suite | Baseline | This PR | Δ | | |---|---|---|---|---| | go | 72.50% | 72.60% | +0.10 | ✅ | _Tolerance: -0.1%. Baseline stored on `gh-pages`._
dries merged commit d2a4552657 into main 2026-07-13 23:01:14 +02:00
Sign in to join this conversation.
No description provided.