Fix agent new-chat placement during top-page transition
What changed
The same agent new-chat command now consistently follows the documented top-page placement path. When Home or another top page has published its page state but has not finished parking the previous content, the command creates and focuses a chat workspace instead of opening in the stale pane left mounted during the transition.
Defect
“The same agent new-chat command opened as a split beside Home in one run and inside the workspace in another.”
“The first New Agent Chat from the CLI opened as a split beside Home in one run and inside the target workspace in another (same build, same command).”
“agent new-chat from Home opened beside Home in no workspace. The sidebar still said "No workspaces" while Home listed "Your agents: Agent · Idle". The code says Start an agent over a top page opens a new workspace (AgentHandlers+Pane.swift:10-23).”
Root cause and fix
withAgentPane looked up the scoped focused pane before checking activeWindow.state.page. During a top-page transition, the page state was already set while the old content and focused pane were still mounted, so the same invocation could take either branch depending on timing. The handler now checks the top-page route first, then falls through to the existing pane route only when no top page is active. The documented placement rule and explicit-target refusal behavior are unchanged.
Validation
- Regression:
AgentChatFromHomeTests/duringTopPageTransitionTheChatOpensANewWorkspace. - Red base evidence: scratch commit
507c8fa6734e7cddc1c4725f9c5d3bb417cfca62(basee5ea466cd04aae52e4681aa42179fe71ea3df077plus the test); fleet step4a845e38b702e8e9170395f8. The test fails while waiting for a new workspace because the stale pane path wins. - Green fixed-head evidence: commit
fcb5c66610745cb5e404791b4401755d801a7c4d; fleet stepdd71b170(AgentChatFromHomeTests, all tests passed). The final PR head4d247a1265b286062eb087af1166ae9e1b844b10only changes the capture state after that same passing code, so the test implementation is unchanged. - Static check:
git diff --checkandscripts/cmux-next/prepush-gate.pypass.
Fleet capture
The capture state is committed at scripts/cmux-next/media/states/agent-new-chat-placement.json. It launches fresh, reaches a top page, runs agent new-chat three times, and records debug.windows and debug.pane_chrome after each invocation.
The fleet capture is inconclusive for this timing-only race: base and head take the same settled placement on the fleet, so no Before/After image is attached. The capture does not contradict the red/green transition regression above.
No capture: timing-only race; the fleet capture was inconclusive because base and head settle the same way, and the red/green regression test covers the transition.
Risk: the branch ordering changes only the race window between a top page publishing and content parking. Normal workspace placement, explicit targets, and the existing top-page workspace creation path are unchanged.
Agent session: agent session