fix(automations): survive deleted pinned workspaces end to end
Summary
An automation pinned to a workspace that later gets deleted fails every run with an opaque `relay 500` JSON blob ("Workspace not found"), while the workspace picker renders the dead pin as "New workspace" — so the config looks healthy and there is no way to see what's wrong (root-caused from a real failure: automation `Daily Email`, whose pinned workspace was deleted ~1.5h after creation).
Three layers, one failure mode — all host-authoritative (no schema change; cloud `v2_workspaces` is a best-effort mirror slated for removal in R3, so a cloud-side FK was considered and deliberately dropped):
- Dispatch (`packages/trpc`): if `agents.run` on a pinned workspace comes back NOT_FOUND for that workspace id, clear the stale pin (compare-and-set, so a concurrent repin is never erased) and retry once in a fresh workspace. The guard matches the workspace uuid in the error message, so other NOT_FOUNDs (agent config, attachments) can never wipe a valid pin.
- Error reporting: `relay-client` parses the tRPC error envelope out of relay failure bodies (run rows now store `agents.run: Workspace … not found on this host — it may have been deleted.` instead of raw JSON), and host-side `agents.run` pre-checks workspace existence to return a proper NOT_FOUND instead of a generic 500.
- UI: WorkspacePicker shows an amber "Workspace not found" warning (trigger + dropdown row) when a pinned id no longer resolves, instead of falling through to the "New workspace" label.
Deploy notes: cloud changes are safe to ship first; the dispatch fallback starts firing once hosts run the new NOT_FOUND response (old hosts keep current behavior, just with readable errors).
Test Plan
- `bun run lint` exits 0; typecheck passes
- `packages/trpc` automation router tests (7) and `host-service` agents tests (6) pass
- Reproduced the original failure and verified the fresh-create path dispatches end-to-end via `superset automations run`
- With a host on this build: delete a pinned workspace, run the automation → run succeeds in a fresh workspace and the pin is cleared
Summary by CodeRabbit
- Bug Fixes
- Workspace pickers now clearly identify pinned workspaces that are deleted or unavailable.
- Agent runs now report a clear “workspace not found” error instead of an internal failure.
- Automations can recover from stale workspace references by creating a replacement workspace and retrying once.
- Relay errors now display more helpful messages when available.