fix(desktop): stop the new-workspace screen from switching the launch target on its own

Merged
SA
24d ago
+652-563

Links

Summary

  • The new-workspace screen no longer changes the Device target by itself. Only a pick from the chip saves it; a link can pin a host for one open through the URL.
  • The project is derived per host (same project → same repository → that host's last choice → the only project → none) instead of being corrected by effects.
  • New Workspace from inside a cloud workspace hands off that workspace's repository instead of the sandbox's own project id.

Why / Context

A customer (Fiveable, Team plan, cloud enabled) reported having to pick Cloud over "This device" on every launch. In PostHog, every New Workspace from inside a cloud workspace opened /new-workspace?projectId=<sandbox-only id>&host=<their Mac>.

Several paths wrote the device into the target behind the user's back:

  • handoffs forwarded draft.hostId, which survives resetDraft, so any one write stuck for the session;
  • a handed-off project that wasn't a cloud project switched the draft to the device;
  • DevicePicker reset to the device, and saved it, whenever cloud-workspaces read false, including the window before plan_tier reaches PostHog on a first session;
  • File menu / add-repo / issue and PR launches wrote their host into the draft.

The sidebar also handed off the open cloud workspace's project id, which exists only inside that sandbox (sandbox-self-seed mints a random one), so it never matched a project list.

I couldn't tell from the data which of these hit this customer. This change removes all of them.

How It Works

  • resolveLaunchHost: the URL's host for that open, else the saved lastHostId, else this device. Computed on each render; hostId is gone from the draft store. A chip pick saves it and drops the URL's host.
  • resolveLaunchProject replaces useProjectPreselection and the switch effect. A pick carries its repository (owner/name), so it follows to another host. A pick no list knows and that has no repository is held as pending, which covers a just-added repo; one with a repository missing from the host falls back.
  • Problems block instead of switching. Cloud without the flag shows the existing "Cloud workspaces need the Team or Ultra plan…" string; an offline host shows "Host is offline".
  • useWorkspaceHandoffProject: from a cloud workspace, hand off its primary repository and stand-in project id (via cloudWorkspace.repositories). It hands off nothing while that lookup is loading.
  • Issue/PR launches, add-repo and the Cloud "+" pin their host through the URL only.
  • DevicePicker gains offersCloud. The issues "Run in Workspace" popover, which has no cloud path, sets it to false; it used to offer Cloud and then say "Host is offline". The tasks popover gets the plan blocker.

Manual QA Checklist

Not done yet; see Testing. Case numbers refer to the scenario page.

  • (01) Inside a cloud workspace, New Workspace (sidebar) and ⌘N stay on Cloud with that workspace's repo selected
  • (02) Restart the app → New Workspace is still on Cloud
  • (03/04) Switch This device ↔ Cloud on a repo checked out locally; the project follows. On a cloud-only repo it falls back, and returns when switching back
  • (05) Opened from Add repository, pick Cloud → host leaves the URL, Cloud is saved
  • (06) Add a local repo (opens on the device), then ⌘N → back on Cloud
  • (07) Start a workspace from a GitHub issue → opens on the issue's host; the next plain launch uses the saved host
  • (09) With cloud-workspaces off and Cloud saved → Cloud stays selected, Start is blocked with the plan message
  • (12/14) Several projects and nothing remembered → "Select a project"; just after adding a repo, the new repo is selected once the list catches up, with no flash of another project
  • (17) Issues "Run in Workspace" with Cloud saved → opens on this device, no Cloud entry
  • No console errors on the new-workspace route

Testing

  • bun test src/renderer in apps/desktop: 7506 pass. New table tests for resolveLaunchHost, resolveLaunchProject and resolveWorkspaceHandoffProject; useOpenNewWorkspace.test.ts rewritten for the new contract; useProjectPreselection tests removed (their cases are in the resolver tests).
  • bun run typecheck (desktop), biome check, bun run check:i18n (no catalog changes; the plan message reuses an existing string).
  • The app was not run end to end. The cloud workspace it was written in (4 vCPU / 8 GB) is too small for the dev stack plus Electron (see docs/cloud-sandbox-mismatches.md). A canary from this commit failed before building: the Production environment allows only main and desktop-v*, so scripts/release-canary.sh <commit> and its canary-release-* branch are rejected. The checklist above is unverified.

Design Decisions

  • Block instead of correct. An offline host or an unavailable Cloud stays selected with a reason on the launch button. A silent switch was the bug, and saving it made it permanent.
  • No more defaulting to the first project. With several projects and nothing remembered, no project is selected; a quick ⌘↵ could otherwise launch on the wrong repo. A single project is still selected.
  • Pins are one-shot. Only a pick from the chip saves the target, so launching from add-repo or an issue doesn't change what the next plain launch uses.

Known Limitations

  • Project memory is per target type (Cloud vs any device), as before, not per machine.
  • Automation triggers set to Cloud with the flag off now show Cloud (what's saved) rather than being rewritten to the device; the run is refused by billing with its own message.

Risks / Rollout

  • Risk: this changes how every new-workspace entry point picks its host and project. The most likely regression is a launch opening on an unexpected project or host.
  • Rollout: canary main after merge, then run the checklist on the canary build.
  • Rollback: revert this PR. Nothing persisted changes shape. selectedProjectRepository is in-memory draft state, and lastHostId keeps its key and meaning.

Summary by cubic

Stops the new-workspace screen from switching the launch target on its own, fixing cloud users being dropped back to "This device" on every launch.

The screen now computes its host and project from the URL's host for that open, the saved pick, or this device — nothing writes to the target except a chip pick. Projects are resolved per host: same repository follows across hosts, then the host's last choice, then the only project, then none. Invalid choices block launch with a reason instead of silently switching; New Workspace from inside a cloud workspace now hands off that workspace's repository instead of its sandbox-local project id.

Behavior changes

  • hostId is removed from the draft store; links pin a host through the URL for that open only.
  • A handed-off project that can't launch on the selected host now blocks with a message (or falls back) rather than switching hosts.
  • Cloud without the plan flag shows the plan message on the launch button; the issues "Run in Workspace" popover no longer offers Cloud, and the tasks popover gets the same blocker.
  • With several projects and nothing remembered, no project is selected instead of defaulting to the first one.

Migration

  • Rollout via canary main; rollback is a revert, nothing persisted changes shape.

Summary by CodeRabbit

  • New Features
    • Starting a workspace from a viewed cloud workspace now carries over its primary repository when available.
    • Workspace launch selections can reflect the requested host, project, repository, or session.
    • Cloud workspace creation now displays a plan requirement and blocks submission when unavailable.
  • Bug Fixes
    • Workspace launches from pull requests and issues now retain their associated project and host.
    • Running issues in a workspace no longer offers Cloud as a device option.