Fix Mac discovery consent, live terminal resizing, and blank hibernated agents
Summary
Opening another Mac as a device workspace now works only when that exact Mac has opted into Mac-to-Mac hosting. The Mac directory is the only source that can authorize it; saved pairings, the device registry, and presence can enrich a directory record but never stand in for one. A Mac that is signed in but not discoverable gets its own localized error with the Settings path to enable it, instead of the generic "unavailable" failure.
Once linked, the remote terminals and splits stay in sync:
- Grids. The source Mac publishes terminal grid snapshots (
DeviceTerminalGridPublisher) with the latest dimensions for each surface. The connection's event queue coalesces them per surface, bounds both event count and bytes, and closes the connection when a grid can't be admitted. A newer grid replaces the queued one only once it fits; if it's rejected, the older grid stays queued. Per-lane arrival orders are compacted as they drain, so a lane that stays backlogged doesn't grow its order storage without bound. Closing a connection cancels its event drains, including one parked in a stalled write. The connection actor owns those drains: every drain starts through one actor method that checks for close in the same turn, so a drain claimed after close is released instead of started. - Mirrors. A mirrored pane shows a scrollbar when the source grid is taller than the local pane. Scrolling that pane stays local and is never sent back as a viewport change that would reflow the source terminal.
- Layouts. Divider moves on the source Mac update the local split geometry. A pending or failed pane reservation no longer blocks layout sync, and stranded reserved panes keep their local order. If a split's create finishes after the source layout already mirrored its terminal (a lost receipt that was replayed, or a layout event that beat the create response), the create finishes on the mirrored pane and closes the reserved one. It no longer projects the terminal a second time and leaves every later layout failing. If the user was in the reserved pane, focus moves to the mirrored pane instead of a neighbor. Removing reserved panes from the source layout and restoring them around their local neighbors is pure tree logic on
DeviceWorkspaceLayoutNodeinCmuxCore. It visits each panel of both layouts once and finds every restored split's anchor in one union-find pass, so it runs in near-linear time. - New splits. Cmd-D / Cmd-Shift-D reserve the pane, then bind it to the exact terminal-create receipt before adopting it. The new remote terminal can't paint into the focused pane first, and input can't reach a different terminal.
Input typed into a reserved pane before its first attach sticks is held and sent once that attach succeeds, including when a replay fails while the link is still up. Losing the link drops that held input, because a restarted Mac can restore a terminal under the same surface ID with a new shell. Stopping the session also drops it, so a replacement pane never inherits it. After a pane has attached, input typed while it's detached is dropped.
A remote view of an idle agent no longer stays blank. Agent Hibernation tears down an agent terminal that has sat idle and unseen, and selecting its tab on the host brings it back. A viewer on another Mac or the phone attaches through mobile.terminal.replay, which found no runtime, returned an empty replay, and never received output: the pane stayed white with no disconnect overlay. The replay now resumes the hibernated agent, the same as selecting its tab, and the restarted terminal's output streams to the viewer. The resume runs only after the request's viewport report validates, and only when the resolved surface is still that panel's own, the same rule explicit input follows.
Trade-offs of that fix:
- A remote viewer that reconnects wakes the agents it shows. Reattach after a dropped link, and iOS replay triggers, count as visits, so an agent watched from another device hibernates again only after the next idle timeout. Hibernation's planner still protects only panels visible on the host.
- An attach that lands while the agent's process is still exiting still shows blank until the next replay.
- The cause is inferred from the symptom, not confirmed on the host Mac in the report: its mirrored agent panes were blank with no disconnect overlay.
MobileTerminalReplayHibernationTestsreproduces the empty replay of a hibernated agent and shows the resume fixes it. - No new capability:
mobile.terminal.inputon the same socket already resumes a hibernated agent, andRemoteRelayCommandPolicydoesn't allow either method.
This changes the macOS app, its CmuxCore, CmuxMobileHost, and CmuxTerminalCore packages, and the shared CmuxIrxTransport authorization error. It doesn't change the Cloudflare worker, the backend contract, or the remote relay allowlist, and it adds no v2 socket method or parameter; mobile.terminal.replay now also resumes a hibernated agent. Dogfood needs a new tagged Mac build on both Macs; the blank-pane fix needs only the host Mac updated.
Testing
Each behavior fix landed after a commit with its failing test, and the same focused command passed on the fix.
| Behavior | Failing test | Fix | Red evidence |
|---|---|---|---|
| Closing a connection ends a drain parked in a write | 8b593349d4 | e92692b601 | e2e run 36217330290 |
| A backlogged lane keeps its order storage bounded | 3e66bd1d21 | 62eb621a7f | swift test in CmuxMobileHost: 10,045 stored IDs against a bound of 336 |
| A rejected grid replacement keeps the queued grid | 9df6caef0f | 9438c94328 | swift test in CmuxMobileHost: the queue emptied instead of keeping the older grid |
| A reserved pane drops held input when its Mac link drops | b8a67064c8 | c1fb92a366 | e2e run 36218161734: 2 of 18 tests failed |
| A reserved pane keeps input typed before its first attach sticks | 0f67f0930b | be20b0a570 | e2e run 36218299160: 2 of 16 tests failed |
| A retried device create reuses the pane the layout already mirrored | 9f38806fc5 | 4b034f70ec | e2e run 36224223096: 1 of 15 tests failed with 4 issues |
| Focus moves to the mirrored pane when the reserved pane it was in closes | 34765e26bf | 21bf56f6ce | e2e run 36225021730: 1 of 15 tests failed, focus stayed on a neighbor |
| A remote attach resumes a hibernated agent | d7165a75e5 | 1c04ccd0bc | e2e run 36363680822: the agent stayed hibernated and its resume state stayed .manualResume |
The refactors that answer the review's pre-merge checks and rule findings don't change behavior, so they carry coverage instead of a red commit:
- Actor-owned drains (3c2955fdd1).
testCloseCancelsFanOutEventDrainParkedInWritestarts a drain through the service's event fan-out, parks it in a stalled write, and checks that closing the connection cancels it. - Grid publisher isolation (292ffe2abd).
DeviceTerminalGridPublisheris a plainSendablevalue. The render observer that samples Ghostty stays on the main actor. - One reservation index per layout pass (16294759ab).
reconcile()looks up each terminal's bound reservation in a dictionary built once per pass, instead of scanning every reservation for every terminal. - Event order bookkeeping (5d304279ca). The test target reads the queue's order storage through
@testable import; production code no longer carries a count accessor for it. - Layout graft in
CmuxCore(c460dae3fb). A differential test compares the new graft with the previous per-panel insertion over 3,000 random layouts; reversing the order of restored tabs or loosening the common-ancestor bound makes it fail. - Split anchors in one pass (2a7f9db592). The graft found each restored split's anchor by walking up from its panes, which is quadratic when restored splits nest deeply. It now answers every anchor in one pass over the tree (Tarjan's offline lowest common ancestor, with union-find). On a layout with n nested restored splits, 8,000 took 1.7 s before and 0.06 s after, and 32,000 took 27.5 s before and 0.25 s after. A new test restores three splits nested around the same terminals.
swift testinPackages/macOS/CmuxCorepassed 91 tests in 14 suites, and a 40,000-panel layout grafts in about 0.1 s. Answering every query at the tree root, or skipping the ancestor update after a node's first child, makes the differential test fail. - Grid delivery through the link (261730511372, 98326ad993).
DeviceLink.handlepasses every topic it doesn't own toDeviceLinkTerminalEvents.receive(_:). A test builds aDeviceLink, checks that it subscribes toterminal.updatedanddevice.terminal.grid, handshandlean envelope for each, and reads the resize from that surface's mirror stream. Focused app-host e2e at 98326ad993, run 36227583756, passed 34 tests in 2 suites (CloudNativeLayoutProjectionTests,DeviceTerminalMirrorTests). - Replay resume guards (88506ea39e). The replay wakes the agent only after its viewport report validates, and only for the panel's own surface.
rejectedReplayLeavesHibernatedAgentAsleepsends a replay with a partial viewport report and checks the agent stays hibernated. Focused e2e run 36364493370 passed both tests in the suite.
Checks at the head, a032df802c, which includes main at 446581e109:
- PR CI run 36374604203 passed. The app-host changed-suite batch ran 481 XCTest tests (4 skipped, 0 failures) and 1,140 Swift Testing tests in 73 suites. It includes this PR's suites:
MobileHostAuthorizationTests(with the event lane and connection lifecycle extensions and the fan-out drain test),MobileHostSurfaceEventLaneTests, the layout projection, terminal mirror, grid queue, pane reservation, device presence and link failure suites, and the hibernated-agent replay suite. - The iOS simulator lanes run because the shared
CmuxIrxTransportpackage changed; this PR changes no iOS file. Run 36374604006 at this head: attempt 1 never ran tests because the runner was out of capacity. In attempt 2, iPad passed and iPhone failed one test,TerminalSurfaceMountOwnershipTests.terminalPrimesViewportBeforeClaimingOutputOnEachMount(), which this PR doesn't touch. I reran the iPhone lane unchanged as attempt 3, and it passed along withios-tests. - All 55 required and conditional checks pass at this head. The 18 skipped jobs are lanes this change doesn't trigger without
full-ci: web, remote daemon, browser, UI tests, the release build, and deploy jobs. At the previous head, 88506ea39e, which has the same shared-package change, run 36364377043 passed the iPhone and iPad simulator lanes. ./scripts/sync-test-wiring --checkpassed for 1,127 test files. The string catalog differs from main only by the new key, andpython3 tests/test_localizable_xcstrings_structure.pypassed. The project file differs from main only by this PR's own entries: the two new test files, and the event queue's move intoCmuxMobileHost.- Focused app-host e2e at c460dae3fb, run 36219417132: 170 tests in 7 suites passed (
MobileHostAuthorizationTests,MobileHostSurfaceEventLaneTests,MobileHostOrderedInputTests,CloudNativeLayoutProjectionTests,DeviceGridQueueTests,DeviceTerminalMirrorTests,CloudTerminalPaneReservationTests), including the new fan-out drain test.
Not run: the iOS connectivity soak. The per-connection event queue in CmuxMobileHost also carries iOS connections, so the soak's terminal I/O and event workload applies. It needs prebuilt tagged Mac and Simulator builds on one fleet Mac. The leased-Mac path is retired, cmux-ci has no soak recipe, and the Iroh release gate workflow can't pass --soak-profile. I also didn't dispatch that workflow's standard gate: another branch is running it repeatedly against the same shared staging account, and the workflow has no concurrency group.
Changelog
Changed: Opening another Mac from Devices requires “Make this Mac discoverable” on that Mac, and the error says where to turn it on
Fixed: A hibernated agent's terminal no longer shows blank when viewed from another Mac or the iOS app
Demo Video
Not captured. Dogfood needs the tagged build on both Macs.
Checklist
- Behavior changes have added or updated tests, with a failing-test commit before each fix.
- Localization audited: the one new string,
devices.link.error.notDiscoverable, has all 20 catalog locales, which include the nine required ones. No existing keys changed. - No new v2 socket method, parameter, or relay allowlist change.
mobile.terminal.replaynow resumes a hibernated agent; the relay policy denies it as before. - No production or backend deployment needed; the blank-pane fix ships in the host Mac's app. The Mac directory and the
cmux.mac-host.v1opt-in this relies on are already live: production iroh-v2/v2/healthreportscmux.mac-peer-inbound.v1at e0263f46a6, whoseworkers/iroh-v2/srcmatches main.device.terminal.gridtravels only between the two Macs. - iOS connectivity soak: not run, for the reasons under Testing. The unit and app-host tests above cover the queue's bounds, coalescing, and close behavior; no soak result is recorded.
- No user-facing docs change needed.
- Reviewed with a subagent before merge, and all bot and human review comments resolved. The latest main merge (a032df802c) resolved only generated files, the string catalog and the project file. CodeRabbit's docstring-coverage warning is answered in its thread.
🤖 Generated with Claude Code