Cloud: a retry of one start reuses its first key, so no second machine (#33493)
Issue #33493:
If the answer to a create is lost and the person retries, the retry makes a new idempotency key. That can leave an orphan VM, make a duplicate, or trip the cap refusal.
Expected: the retry reuses the first attempt's key.
What changed
The page made a fresh cloud.startChat key with crypto.randomUUID() on every send. The host's start ledger (cmux-tui link/start_chat_cli.rs) derives the machine's create key, the chat tab key and the pin from that key, and already dedupes a retry that brings the same key back. A new key per Return defeated that.
cloudRun.ts:cloudStartKeyskeeps one key per start the person asked for, named by a hash of the start (prompt, chips by id/name/size, folder, agent, model, environment). It is kept inlocalStorage, so a relaunch mid-create still sends the same key, with a one-day expiry. It is forgotten once the start opened its chat, or the cap card's Run on This Mac sent the prompt here. A failure keeps it, since the start may have made its machine. A changed prompt, folder, agent, model or environment is a new start with a new key. The stored entry holds only the hash and the key, never the prompt.App.tsx:sendToCloudtakes its key fromcloudStartKeysinstead ofcrypto.randomUUID(), and tells it how the start ended.cloudRun.test.ts: three sends after a lost answer carry the same key; the key survives a new page (relaunch) and is new after success; the cap card, an edited prompt, folder or agent each give a new key; expiry; a store that refuses writes still dedupes the page's own retries; the stored entry has no prompt text.
Client side only. The server's error mapping is out of scope here.
Risk: low. One web file plus its helper; no host change. If the person sends the exact same prompt from the same folder, agent and model in two tabs while the first is still starting, the second now joins the first start, as the host's same-key rule says, instead of making a second machine.
Fixes #33493
Agent session: agent session
🤖 Generated with Claude Code
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Fixes the Cloud create retry making a second machine when the first answer was lost or failed. The page now keeps one start key per start and reuses it on retry, named by a hash of the start (prompt, chips, folder, agent, model, environment), and drops it once the start opens its chat or runs on this Mac. The key survives a page reload while the answer is still out, but not an app relaunch.
Notes
- Sending the exact same start from two tabs while one is still starting now joins that start instead of making a second machine.
- Client-side only; no host change.