perf(web): take workspace provisioning off the navigation critical path (AP-256)#397
Conversation
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 |
…th (AP-256) Authed navigation blocked on a synchronous `/v1/auth/web/callback` round-trip in the `_authed` layout loader before any page could paint. Split the loader into two parts: - `loadAuthedSession` now resolves identity from the validated WorkOS token alone (no API call), so the layout paints immediately. - `provisionWebMemberSession` keeps the callback DB write intact but the layout fires it after first paint via a cached `webSessionQuery`, so it runs at most once per stale window instead of once per navigation. Also: - Add per-query `staleTime` so repeat navigation serves cache instead of refetching (lists 2m, stable resources 5m); window-focus and explicit invalidation still force fresh reads. - Migrate the access-links route to the query cache (was a bare loader fn). - Defer artifact-detail revisions: they only feed the secondary access-link panel, so they load via `useQuery` instead of gating first paint. - Parallelize the billing-return status+invoices fetch. - Add cheap upstream-timing logs in the web API client (method/path/status/ request_id only, never token or body) so the API-side latency work tracked on AP-256 can be measured. Note: Axiom traces show the dominant cost (~2.7s) is server-side in the API worker (per-request WorkOS JWKS fetch + a Hyperdrive/Neon connection stall), not the web layer. That work is the next phase on AP-256. This change is the correct web-side improvement and ships independently. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0bd98a0 to
48974da
Compare
|
agent-paste PR preview is ready. API: https://agent-paste-api-pr-397.isaac-a46.workers.dev |
|
agent-paste PR preview resources were cleaned up. The shared Preview GitHub Environment is retained for future preview deploys. |
Summary
Authed navigation felt slow: clicking a sidebar item paused for ~1s+ before anything painted. The
_authedlayout loader was blocking on a synchronousPOST /v1/auth/web/callbackround-trip (a DB write) before rendering. This splits identity resolution (free, from the validated token) from workspace provisioning (the DB write), and moves the write off the navigation critical path.It also adds query-cache
staleTimeso repeat navigation serves cache instead of refetching, and defers non-critical loads.Changes
web-loaders.ts):loadAuthedSessionnow resolves identity from the validated WorkOS token alone — no API call — so the layout paints immediately.provisionWebMemberSessionkeeps the/v1/auth/web/callbackDB write intact, but the layout fires it after first paint via a cachedwebSessionQuery(at most one provisioning round-trip per stale window, not one per navigation).staleTime(queries.ts): lists 2m, stable resources (keys/settings/billing/session) 5m. Window-focus and explicit invalidation (mutations, SSE) still force fresh reads.ensureQueryData+useSuspenseQuery, invalidation-based refresh).useQueryin the background instead of gating first paint.api-client.ts): method/path/status/request_id only — never token or body. Lets us measure the API-side latency work that's next on AP-256.Risk
Low, web-only. No schema/migration changes. The callback write still happens on every authed session (just not blocking paint, and deduped per stale window). First-run default-key secret is correctly read from the cached session (it's only returned once on first provisioning). The dashboard's 100-artifact fetch was intentionally not trimmed — its live/expiring/total stats are computed client-side from that full list and the workspace API exposes no counts; trimming would silently break the stats. That belongs to a separate API contract change.
Where the real latency is (next phase, same ticket)
Axiom traces of authenticated preview traffic show the dominant cost is server-side in
agent-paste-api-preview, not the web layer: ~2.7s per/v1/web/*call, driven by (1) a per-request WorkOS JWKS fetch (~660ms p95) and (2) a ~1.2s Hyperdrive/Neon connection stall. This web change is the correct, independent first step; the API-side caching + connection work is the high-leverage follow-up tracked on AP-256.Test plan
pnpm --filter @agent-paste/web lint— cleanpnpm --filter @agent-paste/web typecheck— cleanpnpm --filter @agent-paste/web test:coverage— 332 passed, coverage above floors (stmt 93.3 / branch 86.55 / fn 95.37 / line 94.86)agent-paste-web-preview);/307,/dashboard200, no 5xx🤖 Generated with Claude Code