fix(next): prepare Cloud remote approvals before first chat

Merged
TE
2d ago
+113-4

A fresh Cloud machine now prepares the app's person key before the first chat starts, so a tool permission Allow can be relayed immediately instead of being refused until the user finds Restart with approvals.

Leo asked for Cloud to work this way: "I want us to be able to do this too." Before this change, a fresh Cloud chat's first start had no prepare callback. The keyed agent-session handshake therefore fell through to an unkeyed start, and the daemon rejected the first relayed Allow.

The Cloud path now mirrors SSH: the remote daemon's safe-to-restart decision triggers one serialized keyed restart per machine, while older daemons use a bounded status read and restart only when idle. Busy machines, shared/team machines, and keyed-start failures quietly fall back to the existing unkeyed start and its normal restart notice.

The person key still travels only through the existing keyed-start request body stream to the provider's stdin. It is never placed in the image, cloud-init, environment, argv, or a file. Team machines are not retried and do not surface a new error card.

Tests cover an idle keyed start, a busy machine with no restart, and a not-single-owner failure that returns the unkeyed fallback. The app compile is green at the merged head. The Swift test compile also exposed a missing Foundation import in the new test fixture; follow-up PR #31976 carries that one-line fix.

agent-identity footer --repo manaflow-ai/cmux