fix(dev): give services local ports in dependency order #350
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #350"
general
weight: 0.35
wmadden-electric
Linked issue
n/a. Found by the nightly getting-started check, which follows the Composer getting-started guide from an empty directory.
Summary
The getting-started guide builds two services:
quotes, and a publicgatewaythat calls it. The guide saysquotesruns on port 3000 andgatewayon 3001, and has the reader runcurl localhost:3001to get a quote through the gateway. In about half of freshprisma dev module.tsruns, the ports come out the other way round:The
curlreachesquotes, which only accepts calls from other services, so the reader gets a 401 instead of a quote. This happened in 3 of 7 fresh runs on Composer 0.29.0.With this PR,
prisma devgives services their local ports in dependency order: a service gets its port before the services that call it. Services that don't depend on each other go in the order the module declares them. On a fresh start, each service gets the lowest free port from 3000 up, soquotesalways gets 3000 andgateway3001. A warm start keeps the ports services already have, as before.Why the ports swapped
Locally, each service becomes one
Prisma.Appresource. When Alchemy applies anApp, its provider asks the Compute emulator for the service's port, and the emulator hands a new service the lowest free port from 3000 up.The
Appresources depend only on the project, not on each other, so Alchemy applies them at the same time. Whichever request reaches the emulator first gets 3000. The gateway does depend onquotes, but on thequotesApp's identity, and that doesn't order the two port requests.Reserving the ports first, in graph order
Before Alchemy runs, the Prisma Cloud extension's
emulatorshook now reserves a port for each service, one at a time, ingraph.nodesorder. Core already sorts that list with dependencies first and ties in declaration order. The work is done by a newreserveServicePorts(container, serviceAppNames)in@internal/local-target, which calls the emulator'sensureServiceonce per service and waits for each.When Alchemy then applies the
Appresources in parallel, each provider asks for a port that already exists and gets it back unchanged. A failed reservation names the service it was for.Making
--freshstart from 3000 as wellThe new rule is that a fresh start gives the lowest free ports from 3000.
prisma dev --freshis the user's way to get a fresh start, and in two cases it didn't give those ports:1. The Compute emulator was stopped, for example after a reboot. Teardown skipped the delete for a stopped emulator. The emulator then restarted and reloaded the old ports, including swapped ones. Teardown now starts the Compute emulator before deleting the app, and a failed delete stops the run. Postgres and buckets keep their old behaviour: they are skipped when they aren't running.
2.
--freshran shortly after the previous run. The emulator chooses ports with theget-portpackage, which holds every port it hands out for up to 30 seconds. The freed ports were still held, so the app got 3002 and 3003. The emulator now releases those held ports when it deletes an app. Other apps' ports stay safe, because the emulator's saved state already keeps them out of every allocation.One name for each
Appand its reservationA reservation only helps if it uses the same name the
Appresource uses for that service. A newserviceAppName(address)in the Prisma Cloud extension now produces both, so they can't drift apart.Docs
The rule is now in
docs/design/10-domains/local-dev.md,docs/guides/running-locally.mdand the core-concepts skill, worded the same in the guide and the skill. In core, theemulatorshook's description now says it also prepares emulator state for each node before Alchemy runs.Testing performed
local-target/src/__tests__/compute-port-order.test.ts(new; a real Compute emulator in its own directory for each test):- each
Appprovider gets the port reserved for its service, even when the providers run at the same time in reverse order, 10 times over;- an app that already has ports keeps them;
- a dotted address maps to one emulator service;
- a failed reservation names the service.
The first test fails without the reservation.
target/src/__tests__/local-target-emulators.test.ts(new): for a graph shaped like the getting-started app, the hook reservesquotesthengateway, after the Compute emulator is up. When nothing orders the services, it reserves them in declaration order, and only services.target/src/__tests__/local-target-teardown.test.ts(new): teardown starts the Compute emulator before deleting the app.dev-emulators/src/__tests__/compute-multi-app.test.ts(new case): an app that is deleted and then reserved again gets back the ports it freed. Before the fix it got 3002 instead of 3000.@internal/local-target17 pass,@internal/prisma-cloud395 pass,compute-multi-appandcompute-deployment23 pass.pnpm turbo run typecheckfor@internal/local-target,@internal/prisma-cloud,@internal/dev-emulatorsand@internal/core;biome checkon the changed files;pnpm lint:deps.Checklist
git commit -s) per the [DCO](../CONTRIBUTING.md#developer-certificate-of-origin-dco). The DCO status check will block merge if any commit is missing aSigned-off-by:trailer.feat,fix,chore,docs,refactor,test,build) — PR titles drive the auto-generated release notes.n/aif the change is doc-only / refactor with no behavioural delta).Notes for the reviewer
Alternatives considered:
Appresources in dependency order, so Alchemy applies them one after another. This would add ordering to the deploy graph that only local dev needs, and slow the hosted deploy for it. Services that don't depend on each other would still race.prisma devat the reservation; before, it stopped it at the deploy step. The natural place for a timeout isadminFetchin the emulator client, but every emulator call uses it, including the long-running log stream. That is a separate, broader change.Not fixed here: the emulator's port allocation isn't atomic, so two
prisma devprocesses for different apps can still be handed the same port at the same moment. And--freshstill skips the Postgres and buckets deletes when those emulators are stopped.Agent: maui-32