You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
agent.spawn / spawn_batch with no --pane or --workspace still target the focused workspace, not the caller's (follow-up to #242) #246
Follow-up to #242 (fixed in 2.13.0). That fix made an explicit --pane authoritative, but the case with no--pane and no--workspace still resolves to the focused workspace instead of the caller's. Seen on 2.13.
Symptom
An orchestrator is started in workspace A. While it runs, the user switches to workspace B. Some of the time the agents show up in B (where the user is looking) instead of A (where the orchestrator lives).
What I checked (static reading of v2.13.1, not yet reproduced live)
The CLI attaches caller: $WMUX_SURFACE_ID to every sendV2 call (src/cli/wmux.ts, sendV2).
agent.spawn / agent.spawn_batch are not in that table. They go through resolveSpawnTarget (src/main/agent-spawn-target.ts), whose params type is { paneId?, workspaceId? } — caller is never read.
With neither given, resolveSpawnWorkspace falls back to lookups.activeWorkspaceId(), i.e. the first window's active workspace, and paneLoads(workspaceId) then picks a pane in it.
So a bare wmux agent spawn --cmd … (or spawn-batch without --workspace) issued from a pane in a background workspace, or in a second window, files the agent under whatever workspace is focused.
Why the bundled plugin can still hit it
wmux-orchestrator's spawn-agents.sh passes --pane from layout grid, so after #242 that path is pane-authoritative. But:
Any orchestration recipe that spawns without --pane (hand-written wmux agent spawn, spawn-batch) is unprotected.
layout grid is only as good as the caller resolution. If $WMUX_SURFACE_ID no longer resolves (stale id after a session restore mints new pane ids, or claude --resume in a different pane), resolveCallerTarget falls back to the focused window/workspace and the grid itself is created where the user is. I have not verified that this happens in practice — it is a suspect, not a finding.
Suggested fix
Give resolveSpawnWorkspace a middle step: explicit --workspace → the caller's workspace (via resolveCallerTarget / __wmux_locateSurface, looking at every window) → active workspace. Same for the pane-load lookup in spawn_batch, which today reads the first window only. A caller that does not resolve should probably fall through to the current behaviour rather than error, matching resolveCallerTarget.
Test: two workspaces, caller surface in the non-active one, agent.spawn with no pane/workspace → agent lands in the caller's workspace.
Workaround
Pass both explicitly: --workspace <id from wmux current-workspace> and --pane <id>.
The agent is filed under, and its pane taken from, the focused workspace, not the caller's. wmux current-workspace answers Personal-1 from the same shell in the same breath, so caller resolution is live and working — agent.spawn just never asks.
Control: the same spawn with an explicit --workspace ws-c2ca9a68 lands correctly in Personal-1 (pane-596c6570). So the flag is honoured; only the default is wrong.
It happens in practice
agent list from a six-agent spec run earlier the same day, all spawned from one session whose pane lives in Personal-1, all with & $wmux agent spawn --cmd $cmd --label $labels[$n] — no --pane, no --workspace:
label
spawned
workspaceId
spec-01-style-library
10:37:13
ws-c2ca9a68 Personal-1
spec-02-visual-dna
10:38:09
ws-e6d34f5b Work - Code
spec-03-swipe-discovery
10:38:09
ws-e6d34f5b Work - Code
spec-04-moodboard-export
10:38:10
ws-e6d34f5b Work - Code
spec-05-art-direction
10:38:10
ws-e6d34f5b Work - Code
spec-06-project-persistence
10:38:11
ws-e6d34f5b Work - Code
spec-01-…-retry
11:08:56
ws-c2ca9a68 Personal-1
Agent 1 went to the caller's workspace, agents 2-6 went wherever the user had clicked in the intervening 56 seconds, and the retry half an hour later went back. 02/04/06 → one pane, 03/05 → another: distributeAgents round-robin over the active workspace's panes, which is the no---pane signature.
Correction to my report
The bundled wmux-orchestrator's spawn-agents.sh does pass --pane (from wmux layout grid, which is caller-scoped), so on 2.13.0 that path is already correct thanks to #242. The breakage is in hand-rolled spawn loops, which is what an agent writes when it drives the CLI directly. That makes the wrong default a footgun for exactly the caller this API is for.
I also could not reproduce the second suspect in my report (stale WMUX_SURFACE_ID misplacing layout grid) — in every check here caller resolution was correct. Treat that part as unsubstantiated.
Separate finding
While testing the --workspace workaround I found it silently fails whenever the --cmd value contains double quotes, which also corrupts the command itself. Different root cause (PowerShell 5.1 native argument passing + the CLI's pairwise flag parser), filed separately as a follow-up to #154.
Fixed in v2.14.0. With neither --pane nor --workspace, agent spawn / spawn-batch now resolve the caller's workspace ($WMUX_SURFACE_ID → __wmux_locateSurface, asked of every window) before falling back to the focused one; an unresolvable caller falls through to the old behaviour silently. Thanks for the live repro and the agent list table — that made the round-robin signature obvious.
Activity
mkh63d commentedon Sep 19, 2026
Reproduced live on 2.13.0, plus evidence from a real orchestration run. The static reading in the report holds.
Controlled repro
Caller pane in a background workspace, a different workspace focused:
The agent is filed under, and its pane taken from, the focused workspace, not the caller's.
wmux current-workspaceanswersPersonal-1from the same shell in the same breath, so caller resolution is live and working —agent.spawnjust never asks.Control: the same spawn with an explicit
--workspace ws-c2ca9a68lands correctly inPersonal-1(pane-596c6570). So the flag is honoured; only the default is wrong.It happens in practice
agent listfrom a six-agent spec run earlier the same day, all spawned from one session whose pane lives inPersonal-1, all with& $wmux agent spawn --cmd $cmd --label $labels[$n]— no--pane, no--workspace:Agent 1 went to the caller's workspace, agents 2-6 went wherever the user had clicked in the intervening 56 seconds, and the retry half an hour later went back. 02/04/06 → one pane, 03/05 → another:
distributeAgentsround-robin over the active workspace's panes, which is the no---panesignature.Correction to my report
The bundled
wmux-orchestrator'sspawn-agents.shdoes pass--pane(fromwmux layout grid, which is caller-scoped), so on 2.13.0 that path is already correct thanks to #242. The breakage is in hand-rolled spawn loops, which is what an agent writes when it drives the CLI directly. That makes the wrong default a footgun for exactly the caller this API is for.I also could not reproduce the second suspect in my report (stale
WMUX_SURFACE_IDmisplacinglayout grid) — in every check here caller resolution was correct. Treat that part as unsubstantiated.Separate finding
While testing the
--workspaceworkaround I found it silently fails whenever the--cmdvalue contains double quotes, which also corrupts the command itself. Different root cause (PowerShell 5.1 native argument passing + the CLI's pairwise flag parser), filed separately as a follow-up to #154.fix(agent): spawn defaults to the caller's workspace, and the CLI ref…
amirlehmam commentedon Sep 29, 2026
Fixed in v2.14.0. With neither
--panenor--workspace,agent spawn/spawn-batchnow resolve the caller's workspace ($WMUX_SURFACE_ID→__wmux_locateSurface, asked of every window) before falling back to the focused one; an unresolvable caller falls through to the old behaviour silently. Thanks for the live repro and theagent listtable — that made the round-robin signature obvious.fix(worktree): branch from the caller's repository and validate refs