fix(sessions): mark worktree sessions as live-connected #329
No reviewers
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman!329
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/worktree-liveconnection"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
Directoryis the worktree path (.../.worktrees/<repo>/<slug>).Adapter.Sessions()set theLiveConnectionflag by exact directory match against themap[dir]portport map (keyed by each process's cwd). The worktree path is never a key, so every worktree session reportedLiveConnection=false.The frontend mirrors
session.liveConnectionintoportAvailable(useSessionCapabilities.ts), andportAvailablegates:SessionDetail.tsx)The earlier fix
393367bonly removed theportAvailablegate 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 purefoldWorktreeToProjectRoothelper (mirrorsserver.projectRootForDirectory/git.WorktreePathFor; kept local to avoid an import cycle).adapter.go: newdirectoryHasLivePort(exact match, then fold fallback);Sessions()uses it for theLiveConnectionflag.Tests
Table-driven tests for both helpers, incl. a regression guard for the worktree case. Verified red→green: the old exact-match returns
falsefor a worktree directory (the bug); the fold fallback returnstrue.go test ./internal/platforms/opencode/and./internal/server/pass;go vetclean;go build ./...clean.Coverage ratchet: ✅ pass
Tolerance: -0.1%. Baseline stored on
gh-pages.