Skip to content

fix: wake cmux surfaces in hidden workspaces before sending launch commands#48

Draft
elucid wants to merge 2 commits into
HazAT:mainfrom
elucid:fix/cmux-hidden-surface-wake
Draft

fix: wake cmux surfaces in hidden workspaces before sending launch commands#48
elucid wants to merge 2 commits into
HazAT:mainfrom
elucid:fix/cmux-hidden-surface-wake

Conversation

@elucid
Copy link
Copy Markdown
Contributor

@elucid elucid commented May 5, 2026

Problem

When a subagent is spawned while the user is viewing a different cmux workspace the launch command isn't evaluated.

Example, if you prompt the main agent, Cmd+2 to another workspace before the subagent pane is created, the new split pane opens, the shell-ready delay passes, and the bash <script> command is sent but not evaluated. You'll see it there when you switch back to the initial workspace.

Root Cause

Creating a fresh cmux surface in a hidden workspace creates the surface but defers terminal/PTY initialization until the surface receives activity or the workspace becomes visible. The first cmux send to the surface triggers initialization, but its payload is consumed as display text rather than shell input — the shell hasn't started yet when the text arrives.

Confirmed via a red/green cmux integration test that uses the same low-level launch shape as subagents (sendLongCommand()bash <script>), without any LLM call:

  • Pre-fix: the hidden split renders bash <script> before the login banner, but the script never executes (TEXT_ONLY)
  • Post-fix: the marker emitted by the script appears on screen, proving the command executed

Fix

Layered the wake behavior into the cmux surface creation paths introduced by #36.

After creating and renaming a fresh cmux surface, cmux.ts checks the pre-create cmux identify --json snapshot. If the caller workspace differs from the focused workspace, the caller workspace is hidden, so Pi sends a harmless \n to the newly-created target surface. This forces cmux to initialize the hidden terminal before the existing shell-ready delay sends the real launch command.

The wake is applied in both fresh cmux creation paths:

  • createCmuxSplitSurface()
  • createSurfaceInPane()

This preserves #36’s focus-neutral behaviour: no focus-pane, no select-workspace, and no replacement of the CMUX_SURFACE_ID anchored creation flow.

@elucid elucid force-pushed the fix/cmux-hidden-surface-wake branch from de23b62 to 39ed6a2 Compare May 5, 2026 19:28
@elucid elucid force-pushed the fix/cmux-hidden-surface-wake branch from 39ed6a2 to fc23b98 Compare May 5, 2026 20:30
@elucid elucid marked this pull request as ready for review May 5, 2026 20:37
@elucid elucid marked this pull request as draft May 6, 2026 15:48
@elucid
Copy link
Copy Markdown
Contributor Author

elucid commented May 6, 2026

Ugh, this is actually no longer working after my rebase onto the changes #36 introduced. I need to go back to the drawing board...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant