fix(workspaces): start immediately with safe background naming

Merged
KI
1mo ago
+2513-742

What & why

Creating a session or worktree used to wait for an agent CLI to name it (5–20s). Creation now returns in about a second, named "New workspace" (or "New session") until a title is generated; the folder and branch get a unique slug (friendly name plus an 8-character id suffix). Naming happens in the background.

How naming works now

  • The first attempt starts at creation, alongside agent launch. Names typically land ~4s after create with Claude, ~9s with Codex.
  • Naming state (prompt, attempt count, the branch still safe to rename, naming agent) lives in memory per host database, not on the workspaces table; there is no migration. Any user rename clears it, so a manual name always wins.
  • A failed attempt keeps a prompt-derived title and retries on the agent's next Stop, with the agent's reply as context (max 3 attempts). A Stop that lands mid-attempt queues behind it. If naming gives up, the desktop shows one toast.
  • The model reports vague for prompts like "hi"; that guess is applied now and refined with the agent's reply on the next turn.
  • Linked GitHub issues and pull requests (URLs, or #123 against the project repo) are fetched as naming context, 3s budget, skipped on failure.
  • The automatic branch is renamed only while still checked out, unpushed and without a matching remote; checked before and after generation, prefix and suffix kept, echoed prefix stripped, deduplicated. A failed probe counts as a failed attempt.
  • Naming instructions now accept questions and greetings. Before, Haiku returned no name for most question-style prompts (0/3 for "What does git rebase --onto do?"); now 16/16 across the probe set.
  • Claude names with --strict-mcp-config, which skips MCP startup (~9.8s → 5.1s per call).

Also fixed

  • Same-ID retries of a local workspace create no longer fail with CONFLICT.
  • git.renameBranch renames the branch the row holds after waiting for an in-flight background rename, instead of the stale name the UI sent.

Known tradeoffs: naming still owed when the host restarts is dropped; the workspace keeps its placeholder or prompt title. Separately, a branch can be renamed after the agent has started, so the agent may still refer to the old name (seen once: Claude's first push used it, then recovered). T3 Code and Orca have the same behavior. Accepted for this PR.

Recovery patterns follow T3 Code (vague-title refinement, link context, title sanitizing) and Orca (retry on the next agent event, upstream re-check, prefix strip). The naming policy is a pure decideNaming in workspace-naming-job.ts, separate from its I/O.

How I tested it

  • Unit and integration: the full host-service suite passes in CI, including the retry cap, a rename between attempts, a Stop during the first attempt, vague refinement, link lookup timeouts, the local same-ID retry, and renameBranch after a background rename. New behavior tests were checked to fail without their fix.
  • End to end in the dev desktop app over CDP, against a throwaway repo with a local bare remote:
    • Worktree named 4.2s after create; branch renamed with suffix.
    • Agent pushes first: title updates, pushed branch kept, row and checkout stay consistent.
    • Manual rename right after create is kept.
    • Delete during naming: row archived, branch removed, nothing renamed afterwards.
    • Three concurrent creates, including a Japanese prompt, all named.
    • Question-style session named on the first try; "hi" gets a guess, then a refinement.
    • No agent: prompt-derived title. Codex: named in 9.1s.
    • PR link prompt: title comes from the linked PR.
    • Stack killed mid-naming: no orphaned naming processes.
  • Typecheck is clean apart from existing errors on main in runtime/filesystem (#7865), DaemonClient and test helpers. Lint clean on all changed files; all 17 locales translated.

Summary by CodeRabbit

  • New Features
    • Workspace names and branches can now be generated in the background using your prompt, linked GitHub issues or pull requests, and agent replies. If automatic naming fails, the workspace keeps a title based on your prompt and you’ll see a notification.
  • Improvements
    • Workspace creation now shows clearer “Preparing” and “Starting” steps with elapsed time. If preparation takes too long, a “Reload window” action is available.
    • Workspace creation retries are handled more reliably, and manual name or branch edits are preserved.