CedarCopilot wants to merge 1 commit into staging from fix/oauth-callback-blocking-getthreadcount
Libra ran this behavior against the change and confirmed the check detects when it breaks.
Changed code: auth-initial-sync.ts.
Live on prod, 0 of 2 surfaces working, 1 day left
Libra found 2 production surfaces on prod but could not judge any of them yet. 2 surfaces had no requests at all. Libra checks hourly for 3 days after each deploy.
connectionHandlerHook awaited getThreadCount() , an unbounded select+dedupe across crm_email_events/crm_events , on every Google sign-in (not just first-time connections), blocking the /api/auth/callback/google response.state/code , failing as a confusing state_mismatch for real users (cedarcopilot.com, warp.co, greptile.com) on 2026-09-18.elb_status_code=460 (client closed the connection) followed, in the same instant, by an identical-URL retry that got a real 302 state_mismatch response 242ms later.auth-initial-sync.ts and call it fire-and-forget (void, never await) from connectionHandlerHook, so nothing in this path can block the callback response regardless of query latency.getThreadCount (unbounded select + JS Set dedupe) with hasSyncedThreads (LIMIT 1 existence check) in services/mail/threads/get.ts , its one caller only ever checked === 0.state_mismatch login error copy , it blamed the browser for dropping a cookie, which is rarely the actual cause.Full investigation (Axiom traces/logs + ALB access logs, code walkthrough, decision points) in apps/server/src/lib/BUGREPORT-oauth-callback-getthreadcount-timeout.md.
apps/server/src/services/mail/threads/__tests__/get.test.ts, apps/server/src/lib/__tests__/auth-initial-sync.test.ts , both fail against the pre-fix code (missing export / unbounded query), pass after the fix.apps/server/src/lib/__tests__/auth-connection-cleanup.test.ts and auth-callback-logging.test.ts (neighboring auth-hook tests) still pass.pnpm --filter @zero/server run types clean.state_mismatch failures correlating with slow crm_email_events queries in Axiom.š¤ Generated with Claude Code
The behavioral fix appears sound, but the explicit repository requirement against TypeScript assertions must be satisfied before merging.
### Issue 1
apps/server/src/lib/__tests__/auth-initial-sync.test.ts:54
This test calls the helper with `void` itself instead of exercising `connectionHandlerHook`. It would therefore still pass if the production call at `auth.ts:289` changed back to `await`, reintroducing the slow OAuth callback without any test failure. Add coverage around the production hook, or extract its invocation into a directly testable function whose settlement can be checked while `hasSyncedThreads` remains pending.
Note: If this suggesti
| Surface | Requests | Errors | p95 | Users | Verdict |
|---|---|---|---|---|---|
| /login | 0 ā 0 | 0 ā 0 (0%) | not measured | 0 | No traffic No requests recorded since this deploy. |
| /api/auth/callback/google | 0 ā 0 | 0 ā 0 (0%) | not measured | 0 | No traffic No requests recorded since this deploy. |