|
| 1 | +--- |
| 2 | +title: kitcn deploy must forward Convex deployment env |
| 3 | +date: 2026-04-15 |
| 4 | +category: integration-issues |
| 5 | +module: cli |
| 6 | +problem_type: integration_issue |
| 7 | +component: tooling |
| 8 | +symptoms: |
| 9 | + - `kitcn deploy` fails in CI even when `CONVEX_DEPLOY_KEY` is set |
| 10 | + - Convex reports missing deployment configuration or asks for `convex login` |
| 11 | + - `bunx convex deploy` works with the same CI environment |
| 12 | +root_cause: wrong_api |
| 13 | +resolution_type: code_fix |
| 14 | +severity: high |
| 15 | +tags: |
| 16 | + - convex |
| 17 | + - deploy |
| 18 | + - ci |
| 19 | + - env |
| 20 | + - cli |
| 21 | +--- |
| 22 | + |
| 23 | +# kitcn deploy must forward Convex deployment env |
| 24 | + |
| 25 | +## Problem |
| 26 | + |
| 27 | +`kitcn deploy` wrapped `convex deploy` with `createBackendCommandEnv()` and |
| 28 | +therefore cleared `CONVEX_DEPLOY_KEY`, `CONVEX_DEPLOYMENT`, and self-hosted |
| 29 | +deployment env vars. CI deploys then fell back to anonymous or unconfigured |
| 30 | +Convex behavior. |
| 31 | + |
| 32 | +## Symptoms |
| 33 | + |
| 34 | +- CI logs say no Convex deployment configuration was found. |
| 35 | +- Convex suggests `convex login`, which is wrong for CI. |
| 36 | +- Passing `--env-file` works because Convex reads that file itself. |
| 37 | + |
| 38 | +## What Didn't Work |
| 39 | + |
| 40 | +- Keeping the deployment env wipe globally. That is correct for local dev and |
| 41 | + codegen, but deploy is the opposite contract: ambient CI env is the target. |
| 42 | +- Forwarding env only to the first `convex deploy` call. Post-deploy migration |
| 43 | + and aggregate backfill calls also need the same deployment target. |
| 44 | + |
| 45 | +## Solution |
| 46 | + |
| 47 | +Keep the default backend env wipe, but add a deploy-specific override sourced |
| 48 | +from the ambient Convex deployment env keys. |
| 49 | + |
| 50 | +```ts |
| 51 | +const deployCommandEnv = |
| 52 | + backend === 'convex' ? getConvexDeploymentCommandEnv() : undefined; |
| 53 | + |
| 54 | +env: createBackendCommandEnv(deployCommandEnv); |
| 55 | +``` |
| 56 | + |
| 57 | +Pass the same `deployCommandEnv` into post-deploy migration and aggregate |
| 58 | +backfill flows so the whole deploy pipeline targets the same deployment. |
| 59 | + |
| 60 | +## Why This Works |
| 61 | + |
| 62 | +Convex deployment env is not incidental process noise in CI. It is the target |
| 63 | +selection API for `convex deploy` and follow-up `convex run` calls. |
| 64 | + |
| 65 | +`kitcn dev` and `kitcn codegen` still clear ambient deployment env by default, |
| 66 | +so stale shell variables do not hijack local development. |
| 67 | + |
| 68 | +## Prevention |
| 69 | + |
| 70 | +- Test deploy wrappers with ambient `CONVEX_DEPLOY_KEY`, not only CLI flags. |
| 71 | +- When a deploy command fans out into post-deploy `run` commands, carry the |
| 72 | + same target env through the whole flow. |
| 73 | + |
| 74 | +## Related Issues |
| 75 | + |
| 76 | +- [#208](https://github.com/udecode/kitcn/issues/208) |
| 77 | +- [#209](https://github.com/udecode/kitcn/issues/209) |
| 78 | +- [kitcn dev must honor remote Convex deployments from .env.local](/Users/zbeyens/git/better-convex/docs/solutions/integration-issues/dev-must-honor-remote-convex-deployments-from-env-local-20260404.md) |
0 commit comments