perf(api): take member email from the WorkOS token claim, skip the user fetch (AP-256)#403
Conversation
…er fetch (AP-256)
The dashboard WorkOS client's JWT Template now emits a `zaks-io:email` claim.
When a verified token carries it, resolveWorkOsIdentity takes the email straight
from the claim (the verified `sub` is the authoritative user id) and skips the
per-request `GET /user_management/users/{id}` WorkOS call (~100ms p50 on every
authed request). CLI and MCP tokens have no such template and fall back to the
existing user fetch, which still guards user_id_mismatch.
Authorization (member scopes) is unchanged: it stays in our database, never the
token. Operator status stays the WorkOS role claim. Documents the roles vs scopes
vs permissions distinction at the Scope enum and in ADR 0082, which also records
the AP-256 latency finding: the ~1-2.7s on authed routes is cold isolate + cold
Hyperdrive connection warmup (identical preview/prod, resolves with traffic), not
the auth path -- Neon autosuspend is off and Hyperdrive caching is on, so there
is no infra knob to turn.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
AP-256 Cut authed route loader latency (~1s blank wait on sidebar navigation)
ProblemClicking a sidebar page in All file:line references below are from a read-only pass over Candidate levers (ranked by expected impact)1. Every authed navigation does a blocking POST to
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
agent-paste PR preview is ready. API: https://agent-paste-api-pr-403.isaac-a46.workers.dev |
|
agent-paste PR preview resources were cleaned up. The shared Preview GitHub Environment is retained for future preview deploys. |
What
The dashboard WorkOS client's JWT Template now emits a
zaks-io:emailclaim. When a verified token carries it,resolveWorkOsIdentitytakes the email straight from the claim (the verifiedsubis the authoritative user id) and skips the per-requestGET /user_management/users/{id}WorkOS call (~100ms p50 on every authed request).CLI and MCP tokens come from separate WorkOS clients without the template, so they fall back to the existing user fetch — which still guards
user_id_mismatch. The existing tests for that path are unchanged and green.Why
AP-256 began as "authed dashboard navigation feels slow (1–3s)." Measured against Axiom (
cloudflareotel.traces): the ~1–2.7s is cold isolate + cold Hyperdrive→Postgres connection warmup, identical on preview and production, because neither has continuous traffic pre-launch (warm isolates serve the same routes in 1–171ms). That resolves with real traffic and has no infra knob (Neon autosuspend already off, Hyperdrive caching already on). The one real, always-present, code-fixable cost was the ~100ms WorkOS user-fetch — which this removes for dashboard requests.Scope (deliberately minimal)
verifyWorkOsAccessToken(RS256 sig + issuer + exp + client_id). The droppeduser_id_mismatchcheck is safe on the claim path — email andsubcome from the same verified token, and the downstream authorization join key isworkos_user_id(=sub), not email.scopesstay in our DB, never the token. Operator status stays the WorkOSroleclaim. We do not use WorkOSpermissionsor organizations.Scopeenum and in ADR 0082 (Accepted), which also records the cold-start latency finding so the next person doesn't re-chase it.workspace_idinto WorkOS metadata to skip the authz DB lookup, and dropped it (noise vs the warmup floor, would add the first WorkOS write call + a backfill). See the ADR's "Considered and dropped".Verification
pnpm verifygreen (96 turbo tasks).pnpm test:coveragegreen, above the ratcheted floors (88/82/88/88).clientspan toapi.workos.com GET /user_management/users, while CLI/MCP still do.🤖 Generated with Claude Code