migration(0004): backfill workspace_token kind for cloud-agent-box keys#43
migration(0004): backfill workspace_token kind for cloud-agent-box keys#43khaliqgant wants to merge 1 commit into
Conversation
The pre-#42 `/v1/tokens/workspace` route in @relayauth/server@0.2.9 landed rows in api_keys with `kind='api_key'` and `workspace_id=NULL` even when the caller asked for a workspace token. The key value uses the relay_ws_ prefix, so the apiKeyAuth middleware accepts it as a bearer, but resolveWorkspaceToken (used by /v1/tokens/path) rejects because kind != 'workspace_token' — surfacing as 401 workspace_token_required in the cloud-agent box-warm flow. The route fix that correctly sets kind/workspace_id at mint time is in PR #42 (`feat(tokens): implement path-scoped relayfile tokens`), part of the next published release. This migration cleans up rows that were already stored incorrectly so they resolve as workspace tokens once the new route code is deployed. Scope is narrow: only rows whose name matches the documented `cloud-agent-box:<workspaceId>` shape (cloud-web-worker mint pattern in packages/web/lib/relay-workspaces.ts:mintRelayAuthWorkspaceToken). Idempotent — the `kind='api_key' AND revoked_at IS NULL` guards keep re-runs harmless. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing — this migration leaks consumer-specific naming ( |
Summary
The pre-#42
/v1/tokens/workspaceroute in @relayauth/server@0.2.9 stored rows inapi_keyswithkind='api_key'andworkspace_id=NULLeven when the caller requested a workspace token. The key value carries therelay_ws_prefix and is accepted by the apiKeyAuth middleware, butresolveWorkspaceToken(used by/v1/tokens/path) rejects them becausekind != 'workspace_token'— surfacing as401 workspace_token_requiredin the cloud-agent box-warm flow.The route fix that correctly sets
kind/workspace_idat mint time is already in main via #42 (feat(tokens): implement path-scoped relayfile tokens). This migration cleans up rows that were stored incorrectly under the old route so they resolve as workspace tokens once the new code is deployed.Scope
Only rows matching the documented
cloud-agent-box:<workspaceId>shape (cloud-web-worker mint pattern, seecloud:packages/web/lib/relay-workspaces.ts:mintRelayAuthWorkspaceToken). Idempotent — thekind='api_key' AND revoked_at IS NULLguards make re-runs harmless.How this surfaces
Pear's cloud-agent attach flow (cloud-web-worker → relayauth
/v1/tokens/workspace→ relayauth/v1/tokens/path) was failing withworkspace_token_required. Manual D1 patches in prod confirmed: once these rows are corrected (and the new route code is deployed), the box-warm chain completes and Pear attaches.Release / deploy chain
@relayauth/serverrelease (e.g.0.3.0) including this migration + the feat(tokens): implement path-scoped relayfile tokens #42 route fix.@relayauth/serverinAgentWorkforce/cloud(follow-up PR).relayauthD1 in each stage + deploys the worker with the kind-correct route. New mints land withkind='workspace_token'directly; this migration only catches the leftover bad rows.🤖 Generated with Claude Code