Skip to content

fix(prisma-cloud): an unchanged deploy no longer replaces a service that depends on another service - #446

Merged
wmadden merged 7 commits into
mainfrom
fix/unchanged-deploy-keeps-consumer-version
Nov 20, 2026
Merged

wmadden merged 7 commits into
mainfrom
fix/unchanged-deploy-keeps-consumer-version

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The storefront-auth example has two services. The storefront depends on auth, so Composer gives the storefront auth's URL:

export default appRoot('storefront-auth', ({ provision }) => {
  const signingKey = provision(variable.secret({ name: 'AUTH_SIGNING_SECRET' }));
  const auth = provision(authModule, { input: { signingKey } });
  provision(storefrontService, { deps: { auth: auth.rpc } }); // the storefront calls auth
});

Run prisma deploy twice without changing anything. This is what the second deploy does to the storefront.

Before this change, it builds a new version of the storefront and deletes the old one:

▸ creating replacement storefront-auth.storefront.deployment
✔ created storefront-auth.storefront.deployment (23.5s)
storefront-auth.storefront.deployment: Cleaning up replaced resource...

After this change, it leaves the storefront's version alone:

✔ updated storefront-auth.storefront.deployment (3.0s)

This happened to every service that depends on another service, on every deploy.

The decision

A service now publishes its URL from the service itself, not from its latest version. The rest of this description explains why that fixes the problem, and the one thing that had to be added to keep deploys in the same order as before.

Background: the three platform objects behind a service

Composer deploys each service as three Alchemy resources:

  • Prisma.App: the service. It has a stable ID and a stable domain, both set when it is created.
  • Prisma.EnvironmentVariable: one per environment variable the service reads.
  • Prisma.Deployment: one version of the service's code. Deploying creates a deployment, starts it and promotes it, which makes it the live version.

Two more facts matter here:

  • The platform copies a service's environment variables into a version only when the version is created. So when a variable's value changes, Composer must create a new version. It does this by listing every variable's value in the deployment's triggers: when a trigger changes, Alchemy replaces the deployment.
  • Alchemy first plans a deploy, then applies it. While planning, a value that another resource will only produce during apply is unknown. Alchemy treats an unknown trigger as changed, because it cannot prove it is the same.

In this description the service that is depended on (auth) is the producer, and the service that depends on it (the storefront) is the consumer.

Why the storefront was replaced every time

Auth published its URL from its Prisma.Deployment. A deployment is promoted again on every deploy, so everything it reports is unknown while planning, on every deploy.

The chain was:

  1. Auth's URL comes from auth's deployment, so it is unknown while planning.
  2. The storefront has an environment variable holding that URL, so that variable's value is unknown.
  3. That value is one of the storefront deployment's triggers, so the trigger counts as changed.
  4. Alchemy replaces the storefront's deployment.

The fix

Auth's URL is the domain of its Prisma.App. That domain is set when the App is created and never changes, so on every later deploy it is known while planning. It is the same string the deployment reported. A service already read its own origin from its App; now a service's published URL comes from the same place.

 outputs: {
-  url: deployment.appEndpointDomain,
+  url: endpointDomainOf(provisioned, address),   // the App's domain
   projectId: provisioned.projectId,
   serviceId: deployment.appId,
 },

serviceId still comes from the deployment on purpose. A custom domain reads it, and a custom domain is attached to the live version, so it has to wait until the version is promoted.

Keeping the order in which services go live

The old URL had a useful side effect. Because the storefront's variable waited for auth's deployment, auth always went live before the storefront's new version was created. That matters when one deploy changes both: if the storefront starts calling a method auth has just added, auth must be live first.

Reading the URL from the App removes that wait, so this change adds it back explicitly. A consumer's deployment now waits for everything its producers publish, which includes each producer's serviceId, the value that is ready only once the producer is live.

const producerOutputs = graph.edges
  .filter((edge) => edge.kind === 'dependency' && edge.to === id)
  .flatMap((edge) => Object.values(lowered.get(edge.from) ?? {}))
  .filter(Output.isOutput);

const deployment = yield* Prisma.Deployment(resourceId(address, 'deployment'), {
  app: appAfter(provisioned.serviceId, serialized.environment, producerOutputs),
  …
});

The wait is attached to the deployment's app prop and not to triggers. The upstream provider treats an unknown app as unchanged, so the wait changes the order and can never cause a replacement. The deployment's wait for its own environment variables already worked this way; appAfterEnvironment is renamed appAfter and takes the producers' outputs as well.

This stays inside the Prisma Cloud packages. It uses the graph and the outputs that core already hands to every descriptor, and it does not check what kind of node a producer is.

Smaller changes

  • One function, endpointDomainOf, reads an App's domain. Three places had their own copy of the check for a missing domain. Its error names the service.
  • The fake Management API used by the lowering package's tests is exported from that package's test-support entry, so the new tests share it. The package is private; nothing new ships.
  • The design docs that drew the URL coming from the deployment are corrected, and the decision record on using the upstream Alchemy provider has a dated amendment that states where the URL comes from and how the order is kept.

How it was checked

New tests in compute-redeploy-apply.test.ts run Alchemy's real plan and apply against a fake Management API:

Scenario What the test asserts
Deploy twice, nothing changed No second deployment for either service
Only the producer's artifact changes The producer gets a new deployment; the consumer keeps its own
First deploy The producer is promoted before the consumer's deployment is created
Both artifacts change The same order

Each test was seen to fail with its part of the change removed: the URL put back on the deployment, the wait removed, serviceId taken from the App, or the promotion turned off.

On Prisma Cloud, with storefront-auth under a throwaway app name:

  • On main, the unchanged second deploy replaced the storefront's version.
  • On this branch, it did not.
  • A change to auth alone gave auth a new version and left the storefront's in place.
  • When both changed, auth's new version was live before the storefront's new version was created.
  • The storefront answered 200 and reached auth after every deploy.

Not covered

A consumer whose own code changes is still replaced, as it should be. In storefront-auth that happens more often than you would expect: every fresh Next.js build of the storefront produces a slightly different artifact, so a rebuild makes a new version even with no source change. That has a different cause and is not addressed here.

Alternatives considered

  • Let the services in one deploy go live at the same time. This is the fix without the added wait. It is simpler, but a consumer that calls a method its producer has just added could fail until the producer is live.
  • Keep the URL on the deployment and leave it out of the triggers. A trigger exists because the platform copies variables into a version only at creation. Leaving a variable out would mean a real change to it never reaches the running service.

Agent: kurtz-83

🤖 Generated with Claude Code

…of a service that reads another service's URL

A service's url output came from its deployment, which promotes itself on every deploy, so the url was unknown while planning. A consumer writes that url into an environment row and its deployment's triggers, and an unknown trigger replaces the deployment. Every deploy made a new version of every such consumer, even with nothing changed.

The url output is now the App's endpoint domain, which is known from the App's create and does not change, the same value a service's own origin already uses. serviceId still waits for the promotion, because a custom domain reads it and is bound to the live deployment.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
…he docs say a service's url comes from its App

One function reads an App's endpoint domain for a service's url, for serviceOrigin and for a service's own origin, and its error names the service. The design docs now draw a reading service's url row from the App, and no longer say the create-time domain is a placeholder.

The tests also check that the reading service's row holds the url, that a new artifact for the service being read replaces only that service's deployment, and that reserve publishes the App's domain. The fake Management API used by the apply tests is now exported from @internal/lowering/scratch-stack.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
…keeps-consumer-version

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
… the services it reads are promoted

Taking a service's url from its App removed the edge that made a reading service's deployment wait for its provider's promotion. A reading service's Deployment now also waits, through its app prop, on every output of the services and resources it reads. A Compute provider's serviceId resolves only after its promotion, so the order is kept on a first deploy and when both services change.

The wait is on app, not in triggers, and an unresolved app counts as unchanged, so an unchanged reading service is still not replaced. appAfterEnvironment is renamed appAfter, since it now orders the deployment after its provider outputs as well as its environment rows.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
…ever promoted, and the docs name producers and consumers

The ordering tests now assert the exact sequence of the producer's promotion and the consumer's deployment create, so a missing promotion fails them. Code, tests and docs use producer and consumer for the two ends of a dependency edge. The serviceId output says both reasons it comes from the deployment, the edge helper's comment says only what a caller needs, and the self-origin value is endpointDomainOf itself.

The edge decision record has a dated amendment: a service's url comes from its App, and a consumer's deployment waits for its producers' promotion through the app prop, never through triggers. The Prisma Cloud docs and core's lowering steps state what is true now.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@prisma-gizmo

prisma-gizmo Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

✅ Gizmo reviewed aa57e4c — posted 0 inline comment(s) this pass.

Open findings: none

Change walkthrough

This delta retires the framework's DATABASE_URL placeholder claim and tightens how the Prisma Cloud extension receives credentials, with the design docs and tests brought in line.

Extension (control/extension.ts) — The once-per-lowering application.provision hook no longer claims the project's DATABASE_URL/DATABASE_URL_POOLED keys with an inert "-" placeholder via a direct Management API create; it is now a pure Effect.sync that only resolves the CLI-ensured Project into the application handle. This is safe because the premise of the claim is gone: Composer creates Projects with createDatabase: false, so the platform writes neither variable on its projects and there is nothing to shadow. A claimDatabaseUrlKeys helper has no remaining references anywhere in the repo. The same hunk passes the whole credentials object to Prisma.providers(...) and prismaStateLayer(...) instead of unwrapping credentials?.client at the call site — both callees accept Pick<CallerCredentials<ManagementApiClient>, 'client'> and unwrap via composerClientOf in the lowering package, so the plumbing is type-consistent and the client-origin logic lives in one place.

Tests (control-lowering.test.ts) — The databaseUrlClaims recorder is removed and the two application.provision tests now assert only that no environment variable is declared, matching the simplified hook. A new end-to-end test runs the real core lowering() over a stubbed Management API client (GET/PATCH/DELETE throw, so unexpected traffic fails loudly) and asserts that no /v1/environment-variables POST carries a DATABASE_URL or DATABASE_URL_POOLED key — the same wire shape the removed claim used, so the regression it guards against is the one that actually existed.

Design docs — alchemy-lowering.md replaces the placeholder-claim section with the new stance plus an explicit note on what a service reading process.env.DATABASE_URL behind the framework's back sees (nothing on a Composer Project; the platform's value on a project created outside Composer with a default database; legacy placeholder rows stay until the user deletes them, with deploying.md as the migration reference). pdp-data-model.md rewrites consequence 3 to match, ADR-0048 records the claim approach as a rejected alternative and amends its consequences, and the ADR index mirrors the amended summary. All four documents and the code tell the same story.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d44dc711-ea0f-4ace-bd9c-bc0f4a77061e
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@prisma/composer@446
npm i https://pkg.pr.new/@prisma/composer-cli@446
npm i https://pkg.pr.new/@prisma/composer-prisma-cloud@446

commit: aa57e4c

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New findings: 🟡 1 minor · trace

@wmadden-electric wmadden-electric changed the title fix(prisma-cloud): an unchanged deploy no longer makes a new version of a service that reads another service's URL fix(prisma-cloud): an unchanged deploy no longer replaces a service that depends on another service Nov 20, 2026
…umer again

The shared missing-domain error named only the producing service. It now also says which consumer's serviceOrigin could not be resolved, as the message did before the check was shared.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden
wmadden enabled auto-merge (squash) November 20, 2026 06:15

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New findings: none · trace

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Gizmo finding is open and the head commit has been reviewed. Approving.

…keeps-consumer-version

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New findings: none · trace

@prisma-gizmo prisma-gizmo Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Gizmo finding is open and the head commit has been reviewed. Approving.

@wmadden
wmadden merged commit 8fd4fc3 into main Nov 20, 2026
34 of 35 checks passed
@wmadden
wmadden deleted the fix/unchanged-deploy-keeps-consumer-version branch November 20, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants