fix(deploy): use the cloud workspace id for cloud API calls
Problem
After agentworkforce login, deployments list, destroy and deploy fail with
403 {"error":"Forbidden","code":"forbidden"} from
/api/v1/workspaces/<id>/deployments.
resolveWorkspaceToken (packages/deploy/src/login.ts) returned
workspace: descriptor.relaycastWorkspaceId. Cloud APIs are scoped by the
cloud workspace id (UUID). Using descriptor.cloudWorkspaceId returns 200.
On top of that, the resolve normalizer fell back to the relaycast id
(cloudWorkspaceId: ⦠?? relaycastWorkspaceId), and so does @agent-relay/cloud's
active-workspace normalizer (it falls back to workspaceId, the relay id). Cloud's
/resolve returns cloudWorkspaceId: null for a relay workspace with no cloud binding,
so a missing id was silently replaced with an id that cloud rejects.
Audit
Every /api/v1/workspaces/<id>/⦠call in the CLI takes its id from
resolveWorkspaceToken().workspace:
| Command / module | Endpoint(s) | Needs |
|---|---|---|
deploy (deploy.ts, modes/cloud, connect.ts, modes/sandbox-client.ts) | deployments, integrations, runtime-credentials, provider-credentials, sandboxes | cloud id |
deployments list, runs, trigger (list-command.ts) | deployments, runs, triggers | cloud id |
destroy | deployments/:id | cloud id |
env | env (already had its own workaround; still works) | cloud id |
integrations (integrations-list.ts) | integrations | cloud id |
local-surface | deployments, local-surface API, node config | cloud id |
local-surface fleet enrollment lookup | local fleet store keyed by relayWorkspaceId | relaycast id |
So the fix goes at the source, plus one targeted change in local-surface.
Changes
resolveWorkspaceTokenreturns the cloud workspace id asworkspaceand exposes
relaycastWorkspaceIdseparately for relaycast/fleet consumers.- The relaycast fallback is gone. If the cloud id is missing, or equals a relay
id (the SDK fallback case), the CLI stops with an actionable error. The error
names the relaycast id and tells the user to re-runagentworkforce loginor
pass--workspace <cloud-workspace-id>. local-surfacelooks up fleet enrollments with the relaycast id and uses the
cloud id everywhere else.- Token source: the cloud-session path always uses the cloud access token.
WORKFORCE_WORKSPACE_TOKENset to a relaycast workspace key (rk_ā¦, thekey
inworkspaces.json) is now rejected up front with guidance. Cloud request
auth never accepts those keys, so it could only ever 401. The token value is
never echoed. agentworkforce loginprints the cloud workspace id, and warns when the
workspace has no linked cloud workspace.- Docs: new "Login and workspace ids" section in
packages/cli/README.md(cloud
vs relaycast ids, correct token source for the CI override). Also fixed the
customer onboarding doc, the weekly-digest example and the mcp-workforce README.
CHANGELOG[Unreleased]entry.
Tests
These fail on main and pass with the fix:
login.test.ts: explicit--workspacereturns the cloud id; the active
workspace (viaworkspaces.json) returns the cloud id; a missing
cloudWorkspaceIdfails loudly; the SDK relay-id fallback is rejected; an
rk_env token is rejected and not echoed. (5 fail on main.)local-surface-command.test.ts: cloud id for cloud APIs, relaycast id for
the enrollment lookup.deploy-command.test.ts: login prints the cloud id, or warns when it is absent.
pnpm test results: deploy 297/297, cli 395/395, local-surface 19/19, mcp-workforce 27/27.
Release note
Needs a patch release of @agentworkforce/deploy, @agentworkforce/cli and
agentworkforce. It is not published by this PR.
š¤ Generated with Claude Code
[!NOTE]
Medium Risk
Changes central workspace auth resolution used by most CLI cloud commands; behavior is stricter (fail-fast) but corrects mis-scoped API paths and bad tokens.
Overview
Fixes 403 Forbidden (and confusing 401) after agentworkforce login by scoping cloud API calls to the cloud workspace UUID, not the rw_⦠relaycast id.
resolveWorkspaceToken (@agentworkforce/deploy) now returns the cloud id as workspace, adds relaycastWorkspaceId for relaycast/fleet only, and stops when resolve omits a real cloud id (including when normalizers would silently fall back to a relay id). WORKFORCE_WORKSPACE_TOKEN values that look like relaycast keys (rk_ā¦) are rejected up front with setup guidance.
agentworkforce login prints the cloud workspace id and warns if the workspace has no linked cloud workspace. local-surface uses the cloud id for deployments and POST /api/v1/fleet/local-surface, but still keys fleet enrollment off the relaycast id (with a resolve call when CI env auth only has the cloud id).
Docs and changelog clarify cloud vs relaycast ids and correct CI env vars for deploy, deployments list, destroy, runs, trigger, and related commands.
Reviewed by Cursor Bugbot for commit 04a4659217aa5f0e37879c34af23bee9666ec320. Bugbot is set up for automated code reviews on this repo. Configure here.