Skip to content

Investigate the 30 to 40 second cold start after every production deploy #424

Description

@charlesrhoward

Problem

The first request to /api/control/sessions, /api/sandbox and /api/models after a deploy takes 30 to 40 seconds, and /api/github/owners returns one 503. During that window Control shows "No sessions yet". Two deploys on 2026-09-07 reproduced it.

Ruled out: Vercel is on Fluid compute in iad1, Neon is in us-east-1 with suspend_timeout_seconds: 0 (compute never sleeps). No module-scope pool creation or top-level await was found in the Control routes. The likely cause is the size of the import graph: app/api/control/chat/_lib/execute.ts pulls about 25 first-party modules that fan out into the full tool, harness and model-resolver tree, plus Sentry init in instrumentation.ts.

Where

  • app/api/control/chat/_lib/execute.ts (import graph root)
  • instrumentation.ts:5 (dynamic import of the Sentry server config)
  • app/api/models/route.ts:227-243 (six parallel queries, no caching, on the hot path of every picker)

Fix

This is an investigation with a measured outcome, not a guessed change.

  1. Measure. Use Vercel's runtime logs or a Sentry transaction on the first request after a deploy and record where the time goes: function init, first DB connection, first query, Sentry init.
  2. Report the breakdown in this issue before changing code.
  3. Then fix the largest bucket. Likely candidates: lazy-import the tool registry inside the handler instead of at module scope; cache /api/models per user for 60 seconds; warm the function with a post-deploy ping in deploy-production.yml.

Exit criteria

  • A comment on this issue with the measured breakdown for one cold request.
  • After the fix, first-request latency for /api/control/sessions after a deploy is under 5 seconds, measured the same way and posted here.
  • No behaviour change to the routes other than latency.

Out of scope

The UI loading states. Those are covered by the session list and picker issues and should land regardless.

https://claude.ai/code/session_01SQ4nS96XYRztd5w9QkubPf

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Reliability or a user-visible class of bug.infraperfBundle size, latency, cold start.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions