fix(team-mode): surface port-0 fallback and silent layout skip (#3963)

When ctx.serverUrl had a port string of "0", TmuxSessionManager
silently replaced it with the localhost:4096 fallback and
createTeamLayout subsequently skipped pane creation without any
user-visible signal. The two-step silent failure made team_mode
tmux_visualization look broken in default TUI mode.

Surface the failure path:

- TmuxSessionManager now retains ctx.serverUrl on the instance and
  exposes it via getCtxServerUrl(), and emits a structured warning
  log on the port-0 fallback branch naming both the discarded URL
  and the fallback it landed on.
- createTeamLayout's "opencode server not reachable" log is
  upgraded to a structured warning including ctxServerUrl and a
  hint to launch with --port N + OPENCODE_PORT=N.

No behavior change to the fallback resolution itself - only the
silence. Existing port-0 fallback tests still pass; two new tests
assert the warning fires on port 0 and is absent for real ports.
This commit is contained in:
ZeyuFu
2026-05-16 01:23:25 -04:00
parent 1723a8b74c
commit ced95c4bfa
3 changed files with 91 additions and 2 deletions
@@ -121,7 +121,17 @@ export async function createTeamLayout(teamRunId: string, members: Array<TeamLay
try {
const serverUrl = tmuxMgr.getServerUrl()
if (!(await deps.isServerRunning(serverUrl))) {
log("opencode server not reachable, skipping team layout", { serverUrl })
const ctxServerUrl = tmuxMgr.getCtxServerUrl?.()
log("opencode server not reachable, skipping team layout (see issue #3963)", {
kind: "warning",
teamRunId,
serverUrl,
ctxServerUrl: ctxServerUrl && ctxServerUrl !== serverUrl ? ctxServerUrl : undefined,
hint:
ctxServerUrl && ctxServerUrl !== serverUrl
? "ctx.serverUrl was discarded (likely port 0); launch opencode with --port N and OPENCODE_PORT=N to bind a real port"
: "no opencode server is listening on the fallback URL",
})
return null
}