cmux NEXT: resume every workspace's agent chats at launch, not on first show

Draft
AU
1mo ago
+163-0

Summary

Fixes https://github.com/manaflow-ai/cmux/issues/22292.

After a relaunch, the agent chats of a workspace only started again once that workspace was selected. The cause is that a chat tab's page (AgentTabStore.view(for:)) is built the first time its tab shows. The page's handshake is what makes acpmux load the session and start its agent, so a chat in a workspace you hadn't opened yet stayed stopped.

Now, when this Mac's tree first loads, the agent tab store asks acpmux to warm (_acpmux/warm) the session of every chat tab of this Mac, in every workspace:

  • No page is built, and warming a session whose agent already runs does nothing.
  • The store sends one call per session, because the daemon warms only one session per folder in a single call. At most four calls run at once.
  • AcpmuxChiefSessionRouter warms each session in the acpmux that owns it: the Chief's for a subagent, this Mac's for any other.
  • acpmux starts each agent the way the page would, with the mode the session was started in (a --yolo Codex chat comes back in that mode). A folder with no Trust answer still starts nothing.
  • Chats of other machines are skipped.

Terminal tabs already restarted at launch, whichever workspace is shown, so this PR does not change them:

  • the daemon's startup respawn sweep, respawn_lost_terminals_at_start;
  • the keep-layout relaunch at first connect, relaunchKeptTabs.

The respawn pre-fill (an agent's resume command typed at the new prompt, without Enter) also stays as it is. terminal.resumeCommands is a classic setting; NEXT does not read it, and this PR does not touch it.

Testing

AgentChatsLaunchResumeTests (new) checks:

  • every chat of this Mac is warmed once, across workspaces, with one session per call;
  • a duplicate tab on the same chat is warmed once;
  • New Tab pages and other machines' chats are skipped;
  • the session the page reported wins over the stored one;
  • the Chief router sends each session to the acpmux that owns it.

The test is committed before the fix (c60132a4f9e23). On that commit it does not compile, because warm(sessionIds:), sessionsToResume() and resumeChatsAtLaunch() do not exist yet.

Observed / Not run

  • Observed: python3 scripts/verify-local.py --affected origin/feat-cmux-next --swift-changed origin/feat-cmux-next passed (Swift syntax, localization defaults, package groups, feature flags). scripts/lint-ios-package-conventions.sh passed.
  • Not run locally: swift test. The build host cmux-lawrence-2 does not resolve from this machine (REPAIR.md row on nx-remote), so the Swift tests run in a dispatched cmux-next.yml run on this branch, linked in a comment below.
  • Not run: a tagged-build relaunch with chats in several workspaces.

Changelog

Fixed: After a relaunch, agent chats in every workspace start again at once, not only when their workspace is first opened

Proof

Not UI: nothing on screen changes; the chats' agents start at launch instead of when their tab first shows.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

After a relaunch, only the agent chats of the workspace you first opened resumed; chats in other workspaces stayed stopped because a chat tab's page—and with it its acpmux session—is built only when its tab first shows. Now, when this Mac's tree first loads, the agent tab store warms (_acpmux/warm) every chat tab's session of this Mac, across all workspaces, so all chat agents resume at launch.

  • Sends one call per session because the daemon warms one session per folder per call, up to four calls at once; duplicate tabs on the same chat and tabs without a session are skipped.
  • Warms each session in the acpmux that owns it via AcpmuxChiefSessionRouter; chats of other machines and folders without a Trust answer are left as they are.
  • Terminal tabs already resumed at launch, so their behavior is unchanged.
  • Adds AgentChatsLaunchResumeTests covering resume selection, deduplication, routing, and the page-reported session winning over the stored one.