`prisma dev` shares one env.json between every `--name` run from a directory, so a stack can start with another stack's addresses
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- cli, testing-qa, tooling
Research direction
Start with the dev entry points that compute devDir and DEV_DIR in @prisma/composer-cli, then inspect envStore, LocalEnvironmentVariableProvider, LocalDeploymentProvider, runDevPreflight, and runDevTeardown in @prisma/composer-prisma-cloud. Trace Alchemy's noop and state behavior in Plan.ts and Apply.ts. Add a local-target test for the A, B, A sequence and verify per-name environments, safe --fresh behavior, and upgrade recovery.
Written by the indexing model from the issue text.
Description
What is wrong
prisma dev keeps the environment rows of a local stack in <project>/.prisma-composer/dev/env.json. The path depends on the directory, not on the stack name given with --name. When two names are started from one directory, the second start overwrites the first stack's rows with its own.
When the first name is started again, Alchemy plans every unchanged EnvironmentVariable resource as noop, so nothing writes the first stack's rows back. Any of its services whose deployment is re-applied on that start (because its code changed) gets its environment from the file, which now holds the other stack's values. That service then talks to the other stack's services.
Who it hurts: anyone who runs more than one --name from one checkout, for example a developer who keeps a seeded stack and a scratch stack, or several agents that each run a stack from one worktree. Nothing reports the mix-up. In the case that led to this issue, sign-in to one stack failed with "Invalid origin", because its web service sent sign-in to the other stack's auth service. I saw it happen to the web service only. From the source, the same code path also hands over database URLs and service keys: in my run, env.json held the other stack's COMPOSER_APP_DATABASE_URL, so an API whose deployment was re-applied would have read and written the other stack's database.
Versions
@prisma/composer0.21.0@prisma/composer-prisma-cloud0.21.0 (the compute and Postgres emulator daemons report 0.21.0)@prisma/composer-cli0.25.0, throughprisma8.0.0-rc.19alchemy2.0.0-beta.74- Node 24.13.0, macOS
How to reproduce
I reproduced it with the Asks application (prisma/asks at commit c70a404). Its module.ts provisions six services; the web service depends on app (the API) and on the auth module's auth.service. In Asks, pnpm dev is a small wrapper (scripts/dev.mjs) that sets two env params, ASKS_ENV (the stack name) and ASKS_WEB_URL (the web's own port, read from the compute emulator), and then runs prisma dev module.ts in deploy/. The wrapper plays no part in the fault.
pnpm install
cp deploy/.env.example deploy/.env # platform credentials as placeholders
pnpm dev --name envjson-a --no-interactive --yes # wait for "ready", then Ctrl-C
pnpm dev --name envjson-b --no-interactive --yes # wait for "ready", then Ctrl-C
# change any line of the web service, for example the <title> in apps/web/app/root.tsx
pnpm dev --name envjson-a --no-interactive --yes # wait for "ready" and leave it running
pnpm dev --name envjson-b --no-interactive --yes # in a second terminal, the same directory
# a sign-in with a made-up account: 401 means the origin was accepted, 403 INVALID_ORIGIN means it was refused
curl -X POST http://localhost:<envjson-a web port>/api/auth/sign-in/email \
-H 'content-type: application/json' -H 'origin: http://localhost:<envjson-a web port>' \
-d '{"email":"[email protected]","password":"not-a-password"}'
To see what a service was started with, read ~/.prisma-composer/emulators/compute/apps.json under <app>.services.<service>.env.
I did not build a minimal module. From the source below, any module in which one service depends on another should show the same thing: start prisma dev module.ts --name a, stop it, start and stop --name b from the same directory, change the dependent service's code, and start --name a again. The dependent service's COMPOSER_<SERVICE>_<DEP>_URL should then name b's port. This is untested.
What I saw
The emulator gave each stack its own ports. envjson-a: web 3031, auth.service 3034, app 3036. envjson-b: web 3037, auth.service 3039, app 3042.
- First start of envjson-a:
env.jsonheldCOMPOSER_WEB_SESSION_URL=http://localhost:3034,COMPOSER_WEB_API_URL=http://localhost:3036,COMPOSER_WEB_INPUT={"environment":"envjson-a"}andCOMPOSER_AUTH_SERVICE_INPUTwithbaseUrlhttp://localhost:3031. The test sign-in answered 401 (origin accepted). - envjson-b from the same directory:
env.jsonwas rewritten with envjson-b's values (COMPOSER_WEB_SESSION_URL=http://localhost:3039,COMPOSER_WEB_API_URL=http://localhost:3042,environmentenvjson-b,baseUrlhttp://localhost:3037). Its sign-in answered 401. - envjson-a again, nothing changed: all 66 resources planned
noopand Alchemy printedDone: 0 succeeded.env.jsonstayed byte for byte the file envjson-b wrote. The services were restarted from the env the compute emulator had kept from step 1, so sign-in still answered 401. The file was wrong, but nothing read it on this start. - envjson-a again, after one changed line in the web's source: the plan was
[web-deploy] updateand 65noop,Done: 2 succeeded. The web service of envjson-a was then running with envjson-b's values; only its port was its own:
envjson-a/web: port 3031 status running
COMPOSER_WEB_API_URL = http://localhost:3042
COMPOSER_WEB_AUTHAPI_URL = http://localhost:3039
COMPOSER_WEB_INPUT = {"environment":"envjson-b"}
COMPOSER_WEB_ORIGIN = "http://localhost:3037"
COMPOSER_WEB_PORT = 3031
COMPOSER_WEB_SESSION_URL = http://localhost:3039
With envjson-b stopped, envjson-a's sign-in answered 502 auth proxy: upstream unreachable. With envjson-b started beside it, envjson-a's sign-in answered 403 {"message":"Invalid origin","code":"INVALID_ORIGIN"}, and envjson-b's auth service logged ERROR [Better Auth]: Invalid origin: http://localhost:3031. envjson-b's own sign-in still answered 401.
Cause
The dev directory has no stack name in it. In @prisma/composer-cli 0.25.0, dist/execute-dev-BLCK5wF7-CuzMSK7T.mjs line 1765 is const devDir = path.join(cwd, DEV_DIR);, with DEV_DIR = ".prisma-composer/dev" (dist/local-target-BOGjATc2.mjs line 5). The generated alchemy.run.ts does the same at line 1622: const devDir = path.join(process.cwd(), DEV_DIR);.
The Alchemy state does have the stack name in it. The generated stack is rendered with name: <the --name value> and deployed with stage: "dev" (line 1845), and Alchemy's localState() keeps rows under .alchemy/state/<stack>/<stage>/ (alchemy/src/State/LocalState.ts lines 105 to 106). So each name has its own record of which rows it already wrote, but all names share the file those rows are written to.
In @prisma/composer-prisma-cloud 0.21.0, dist/local-target.mjs:
- Lines 5701 to 5703:
envStore(devDir)ispath.join(devDir, "env.json"), documented as "everyEnvironmentVariablerow, key → value. Last write wins." - Lines 5862 to 5871:
LocalEnvironmentVariableProvider.reconcilewrites a row into that file. It runs only on create or update. - Lines 5821 to 5829 and 5922:
LocalDeploymentProvider.reconcilebuilds the child's environment withmaterializeEnv(input.devDir, address, port), which reads every row from the file, and sends it to the compute emulator withputDeployment. - Line 6254:
runDevPreflightwritessecrets.jsoninto the same shared directory, soenvSecretvalues have the same problem. - Lines 6288 to 6295:
runDevTeardown(used by--fresh) deletes.alchemy/state/${app}/dev, which belongs to one name, but also all of${cwd}/${DEV_DIR}, which belongs to every name. So--freshon one name also deletes the other names'env.json,secrets.jsonand unpacked artifacts.
Why an unchanged stack does not write the file again: Alchemy plans an update only when the props differ from that stack's own state (alchemy/src/Plan.ts lines 1398 to 1407, havePropsChanged(oldProps, news)), and a noop node calls no provider (alchemy/src/Apply.ts line 625). A deployment is still re-applied when its artifact changes or when one of its own rows changes (Deployment.triggers, described in dist/s3-credentials-resource-CLB5qGGZ-D0XhVg6M.mjs lines 355 to 368). That re-applied deployment reads the shared file and gets whatever the last stack wrote.
Expected behaviour
Each stack name started from one directory keeps its own environment. Starting another name, stopping it, or running --fresh on it never changes what an existing name's services are started with.
Recommendation
Put everything that belongs to one stack under a directory named after it, for example .prisma-composer/dev/<app>/env.json and .prisma-composer/dev/<app>/secrets.json, and have runDevTeardown delete only that directory. The unpacked artifacts are named by their content hash, so they can stay shared, but then --fresh must not delete them while another name's emulator entries still point at them.
The move also needs one guard. A row that is noop is never written again, so after an upgrade the new per-name file starts empty, and the first re-applied deployment would get no rows at all. Before the converge, the dev command should check whether the stack's file is missing while the stack's Alchemy state has rows, and in that case force an update of that stack's EnvironmentVariable rows, so the file is filled from the stack's own values.
Until this is fixed, users can avoid it by running each --name from its own checkout or worktree.
Acceptance criteria
- Start name A, then name B, then A again from one directory, with a change to one service's code before the last start. Every service of A runs with A's URLs, origins, inputs, service keys and database URLs. B is the same when it is started next.
- A and B can run at the same time from one directory, and each keeps its own environment.
prisma dev --name A --freshdoes not delete or change B's files.- A project that ran with the shared
env.jsonbefore the fix, and is then upgraded, does not start a re-applied deployment with an empty or another stack's environment. - The local target has a test for the A, B, A sequence with a re-applied deployment.
Out of scope
- The order in which the compute emulator gives out ports.
- The auth module's
baseUrlbeing a param that the consumer must set by hand (a separate issue). - Emulator daemons shared between macOS accounts.
Related: prisma/composer#329 (the emulator runs every connection in one session). Found while building Asks (prisma/asks). Agent: tyr-16
- Dominant language
- TypeScript
- Stars
- 6
- Forks
- 2
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 33
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from prisma/composer
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 67/100
Maintainers usually reply within 1 day
Similar issues
-
agent/guide documentation help wanted stage/010-actionable
Difficulty 1/5 Under an hour Newbie friendliness 82/100
kubestellar/console-marketplace#1101 ·
Maintainers usually reply within 1 day
-
Java Edition Tests
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JSPrismarine/JSPrismarine#4178 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
totec448-spec/chat-on-steroids#2394 ·
Maintainers usually reply within 1 day
-
github_actions
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
StellarHyperion/stellarhyperion-backend#499 ·
Maintainers usually reply within 1 day