#Connection lost while action was in flight
22 messages · Page 1 of 1 (latest)
Hi @dense harness. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
This error message itself is mentioned only briefly in the Discord thread you saw, and the knowledge sources don’t give a definitive “if you see this in prod, do X” recipe. I can only infer likely causes from nearby docs and similar “dev works, prod doesn’t” reports.
Here are the concrete things that are covered and that commonly break when switching from dev to prod:
-
Check your Convex URL and env vars (very common)
In a similar “works on Vercel / fails locally” thread, the root cause was a malformedNEXT_PUBLIC_CONVEX_URL(extra/, typo, etc.), which produced connection timeouts. [Nextjs SSC thread]
On Vercel prod, verify in the dashboard that:NEXT_PUBLIC_CONVEX_URLis exactly the.convex.cloudURL for your production deployment, with no trailing/.CONVEX_DEPLOYMENT(if you use it) matches the production deployment name.- You redeployed after changing these.
-
Confirm you’re actually talking to the production deployment
When you created a production deployment and updated env vars, it’s easy to still be calling the dev deployment or a stale URL. The “Convex only working in development and not production” thread was ultimately caused by misconfigured auth/webhook setup, but the first debugging step was confirming the correct URLs and keys were in use. [Dev vs prod issue] -
Make sure the production deployment isn’t paused
If a deployment is paused, all new function calls return an error. [Pause deployment]
In the Convex dashboard, open your production deployment and check that it’s not in the “Paused” state.
-
Check Convex logs for the production deployment
- In dev, you see full error messages; in prod, client errors are redacted to just
"Server Error"and the function name. [Error reporting dev vs prod] - Open the Logs tab for the production deployment and see if your failing calls show up there at all:
- If they don’t appear, it’s likely a network / URL / env issue (the request never reaches Convex).
- If they do appear with stack traces, the failure is inside your action; use that stack trace to debug.
- In dev, you see full error messages; in prod, client errors are redacted to just
-
Network / hosting environment issues
There are examples offetch/ connect timeouts when the Convex URL is wrong or unreachable from the environment (VPS, etc.). [Node fetch timeout; Connect timeout]
If your prod environment has stricter egress rules or a proxy, that can also cause “connection lost while action was in flight”. -
Auth / webhook differences between dev and prod
In one “dev works, prod doesn’t” case, the real issue was missing auth/webhook configuration in prod, so users weren’t properly created and all subsequent operations failed. [Dev vs prod issue]
If you use OAuth or a custom auth provider, double‑check:- You created a separate OAuth “app” for production with correct callback URL.
- You set the right env vars for prod (client ID/secret, webhook signing secret, etc.). [OAuth production setup]
Given the limited information in the sources, I can’t say exactly which of these is your root cause, but the most likely culprits from similar reports are:
- Misconfigured
NEXT_PUBLIC_CONVEX_URL/CONVEX_DEPLOYMENTin Vercel prod. - Production deployment paused.
- Missing auth/webhook secrets in prod so actions fail server‑side.
If you share:
- Your prod
NEXT_PUBLIC_CONVEX_URLvalue (sanitized), - A screenshot of the Convex production deployment URL page,
- And whether the failing calls appear in the prod logs,
I can help you narrow it down further based only on what’s in these docs/threads.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@dense harness Kapa.ai is still learning and improving, please let me know how I did by reacting below.
CONVEX_DEPLOYMENT=prod:hushed-turtle-976
NEXT_PUBLIC_CONVEX_URL=https://hushed-turtle-976.convex.cloud
NEXT_PUBLIC_CONVEX_SITE_URL=https://hushed-turtle-976.convex.site
@slender ridge
Let me check the knowledge base for you again. One moment! :books:
Your env vars look correctly formed and match the documented patterns:
CONVEX_DEPLOYMENT=prod:hushed-turtle-976
NEXT_PUBLIC_CONVEX_URL=<https://hushed-turtle-976.convex.cloud>
NEXT_PUBLIC_CONVEX_SITE_URL=<https://hushed-turtle-976.convex.site>
NEXT_PUBLIC_CONVEX_URL should indeed be the .convex.cloud URL with no trailing slash, and that’s what you have. [React URL config]
Given that, the “connection lost while action was in flight” error is likely not from a malformed URL. From the available docs/threads, the next concrete checks are:
-
Confirm the production deployment is active, not paused
In the Convex dashboard, open thehushed-turtle-976production deployment and make sure it’s not paused. A paused deployment causes all new calls to fail. [Env vars & deployments] -
Check if the failing calls show up in Convex prod logs
- If they don’t appear in the logs at all, the requests aren’t reaching Convex → likely a network / hosting / CORS issue between Vercel and Convex, similar to other “dev works, prod doesn’t” reports. [Dev vs prod issue]
- If they do appear with stack traces, then the error is inside your action; use the prod logs to see the real exception (client only shows a generic error in prod). [Error reporting dev vs prod]
-
Verify Vercel is actually using these env vars
- In Vercel project settings → Environment Variables, confirm these three are set for the Production environment and that you’ve done a fresh deploy after setting them.
- If you’re using
npx convex deploy --cmd 'npm run build'as the Vercel build command, Convex will also inject the correct Convex URL into the build. [Vercel build command]
-
If you use Convex Auth or webhooks, confirm prod secrets
Several “works in dev, fails in prod” cases were caused by missing or mismatched auth-related env vars (e.g.JWT_PRIVATE_KEY, webhook signing secrets) in the Convex production deployment. [ConvexAuth env issue; Dev vs prod issue]
From the knowledge sources alone I can’t pinpoint the exact cause beyond these checks. The most actionable next step is:
- Look at the production logs for
hushed-turtle-976while reproducing the error and see whether the actions appear and what error is logged. That will distinguish between a connectivity problem and a server-side failure.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@dense harness Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@slender ridge
- the production deployment is active
- the failing calls don't appear
- I set the env variables but I don't use
npx convex deploy --cmd 'npm run build'is that an issue ? - I use better auth
Let me check the knowledge base for you again. One moment! :books:
Because your failing calls don’t show up in Convex logs, the requests are not reaching Convex at all. That points to how your frontend is built / configured in Vercel, not to Better Auth or your Convex code.
From the docs and threads, there are two key points:
1. You should use npx convex deploy --cmd 'npm run build' as the Vercel build command
The Convex–Vercel integration is designed so that Convex deploys and your frontend build happen together via:
npx convex deploy --cmd 'npm run build'
as the Vercel “Build Command”. [Vercel guide; How it works]
This does three important things:
- Reads
CONVEX_DEPLOY_KEYfrom Vercel env. - Sets the Convex URL env var (e.g.
NEXT_PUBLIC_CONVEX_URL) for the build to point at your production deployment. - Pushes your Convex functions to that production deployment.
If you don’t use this command and just run next build (or similar), Convex is never involved in the build, and your frontend may be built with the wrong or missing Convex URL, leading to failed connections that never hit Convex.
Action:
In Vercel → Project → Settings → Build & Development Settings:
-
Set Build Command to:
npx convex deploy --cmd 'next build'(or your equivalent
npm run buildscript). [Vercel guide] -
Ensure
CONVEX_DEPLOY_KEYis set for Production in Vercel env vars. [Vercel guide]
Then trigger a fresh deploy.
2. Better Auth itself is not the connection issue
The Better Auth integration for Convex is configured entirely on the Convex side (component, auth.config.ts, convex/auth.ts, etc.) plus Convex env vars like BETTER_AUTH_SECRET and SITE_URL. [Better Auth Next guide]
Those affect authentication logic, but not whether HTTP requests reach Convex. Since your calls don’t appear in logs, the problem is earlier in the chain (frontend → Convex URL / network).
Still, for production you should:
- Set
BETTER_AUTH_SECRETandSITE_URLon the production Convex deployment (vianpx convex env set ... --prodor dashboard). [Better Auth Next guide] - Ensure your frontend uses the correct
NEXT_PUBLIC_SITE_URL/SITE_URLas per the Better Auth example. [Better Auth Next guide]
Summary of concrete steps
-
In Vercel, change Build Command to:
npx convex deploy --cmd 'next build'and ensure
CONVEX_DEPLOY_KEYis set for Production. [Vercel guide; How it works] -
Keep your existing:
CONVEX_DEPLOYMENT=prod:hushed-turtle-976 NEXT_PUBLIC_CONVEX_URL=<https://hushed-turtle-976.convex.cloud> NEXT_PUBLIC_CONVEX_SITE_URL=<https://hushed-turtle-976.convex.site> -
Redeploy, then re-test and check Convex production logs again. If the calls now appear there, any remaining errors will be from your action/auth logic and can be debugged from the stack traces.
The knowledge sources don’t describe any other supported way to coordinate Convex + Vercel production builds, so if you still see “connection lost while action was in flight” after doing the above, I don’t have more specific guidance from the docs/threads.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@dense harness Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I don't have CONVEX_DEPLOY_KEY @slender ridge
@slender ridge I don't have CONVEX_DEPLOY_KEY
Let me check the knowledge base for you again. One moment! :books:
You’ll need to create one; that’s the supported way to wire Convex to Vercel production.
From the docs, the flow is:
-
Create a production deployment (if you haven’t yet)
In the Convex dashboard, switch the deployment picker to Production to create the production deployment if it doesn’t exist yet. [Deploy docs note] -
Generate a Production deploy key in Convex
- Go to your project’s Project Settings page in the Convex dashboard.
- In the Production deploy keys section, click Generate Production Deploy Key. [Vercel hosting]
- Copy the key; it will look like
prod:qualified-jaguar-123|eyJ2...0=. [Deploy key types]
-
Add
CONVEX_DEPLOY_KEYto Vercel (Production only)- In Vercel → your project → Settings → Environment Variables.
- Add a variable named
CONVEX_DEPLOY_KEYwith the value you copied. - Under Environment, select only Production. [Vercel hosting]
-
Use the Convex deploy command as your build command
In Vercel → Build & Development Settings → Build Command, set:npx convex deploy --cmd 'next build'(or your equivalent
npm run build). [Vercel hosting; How it works]
With CONVEX_DEPLOY_KEY set and that build command, npx convex deploy will:
- Use the key to target your production deployment. [Deploy key types]
- Set the Convex URL env var for the build.
- Push your Convex functions to production. [How it works]