Repository navigation
feat(prisma-cloud): deploy state moves behind the platform Alchemy state API, with a deploy lease - #209
Conversation
Rewrites the hosted state layer around alchemy's stock HTTP state client
pointed at /v1/projects/{p}/branches/{b}/alchemy-state, with a server-side
deploy lease acquired around the run (heartbeat every 20s on a forked
fiber; released as a finalizer; 409 contention fails fast naming the
holder). The migration guard survives re-pointed: an empty API scope with
live Compute apps on the branch refuses loudly — the stage predates the
platform state API.
Deletes the interim machinery it replaces: the per-stage
prisma-composer-state database bootstrap/ownership/deletion, the SQL
store and schema, the Postgres session advisory lock and its liveness
checker, the destroy teardown that deleted the state database, and the
self-spawned Postgres test harness. The postgres dependency is gone from
every package. Bumps @prisma/management-api-sdk to ^1.57.0 for the typed
lease routes. New tests drive the REAL stock client against an
in-process fake of the state API wire contract.
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The destroy teardown that read the shell token is gone with the interim state store; the invariant list follows. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
- drop the architecture.config.json entry for the deleted teardown.ts - seed a replaced-status resource in the getReplacedResources test so it proves inclusion as well as exclusion - rewrite the CI Postgres-service comment to name the suites that still use it, and drop the stale "no Postgres connection" clause from the state layer test - register the Alchemy-State-Lease-Id header with effect's header redaction (Headers.CurrentRedactedNames), merged into the state layer's outputs, so a logged failed request renders the lease id as <redacted> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… layer merge The round-2 test provided redactLeaseHeader directly, so deleting the Layer.merge line in layer.ts would have left it green. The new test renders the header inside runLayer (the full stateLayerAgainst context) and asserts <redacted>; the standalone test shrinks to the control showing effect's default redaction does not cover the header. Also rewraps a ragged comment in layer.test.ts. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Records the decision D1 implemented: state behind the Management API (alchemy's stock HttpStateApi wire contract per Branch, stock client), with a server-side per-(stack, stage) deploy lease. Supersedes ADR-0010 (advisory lock -> lease, fail-fast contention preserved) and the storage half of ADR-0034 (Branch scoping and lifetime stand); closes ADR-0012 as obsolete via its own pick-up trigger. Banners on all three; index updated. Prose docs updated to the new story: layering.md's provisioning-state spectrum (the platform-hosted step is now real; server-side runs is the remaining future step), deploy-cli.md, the deploying guide (state paragraph, destroy order, a combined legacy-upgrade section covering both older store generations and the up-front refusal), the glossary state store entry, and gotchas.md's reference to the deleted bootstrap code. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
- admit the wire-contract fake and its drift obligation instead of claiming no test suite of our own - state the honest experimental-routes consequence: a route move breaks installed versions until users upgrade; the /version probe detects contract drift but does not prevent the break - attribute the TTL clamp and the encryption/key-length facts inline to the server PRs, the only place a reader can check them Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
Warning Review limit reached
Next review available in: 54 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Summary by CodeRabbit
WalkthroughThe PR moves Prisma Cloud deploy state from Composer-owned PostgreSQL databases to Alchemy’s HTTP state API, scoped to each Branch. The state layer now resolves branches, acquires server-side deploy leases, sends lease headers with state requests, and maintains lease heartbeats. PostgreSQL bootstrap, migrations, advisory locks, teardown deletion, and related exports are removed. Tests now use an in-process state API fake and cover state operations, leases, migration guards, cleanup, and branch resolution. Documentation and ADRs describe the new lifecycle and migration procedure. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/empty-scope.test.ts`:
- Around line 43-53: Extend the test around check(state) in “the message says
the stage predates the platform state API and how to cut over” to assert that
the error message also contains the required fresh-redeployment instruction.
Keep the existing assertions for legacy-stage wording, the previous Composer
version, and stage deletion unchanged.
In
`@packages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/fake-state-api.ts`:
- Around line 99-103: Update FakeStateApi.stop() to resolve immediately when
this.server is absent, and track/force-close any open sockets before awaiting
server.close() so shutdown does not wait on keep-alive connections. Preserve
rejection of close errors and ensure the returned promise always settles
deterministically.
In `@packages/1-prisma-cloud/0-lowering/lowering/src/state/empty-scope.ts`:
- Around line 13-33: Update scopeOccupied to check all legacy resource types for
the branch, rather than relying only on app resources. Include Database and
Connection resources alongside Apps, and return true when any such resource
exists so failOnEmptyScopeWithLiveApps cannot proceed with an empty platform
state.
In `@packages/1-prisma-cloud/0-lowering/lowering/src/state/layer.ts`:
- Around line 94-101: Update the empty-scope handling around scopeOccupied and
failOnEmptyScopeWithLiveApps to detect all Composer-managed resource types on
the branch, not only applications, before allowing the deployment to proceed.
Extend or replace the guard so database- and bucket-only legacy stages with live
resources are rejected, while truly resource-free scopes retain the current
behavior, and add a regression test covering a database-only legacy stage.
In `@packages/1-prisma-cloud/0-lowering/lowering/src/state/lease.ts`:
- Around line 154-161: Update the lease-release response handling in the
Effect.flatMap callback to treat every non-2xx status as a failure and emit a
warning, rather than returning Effect.void for non-404 responses. Preserve the
existing specific message for status 404, and provide an appropriate failure
warning for other unsuccessful statuses such as 409 and 5xx.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 88198151-f152-4684-8960-1876ec59bfde
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (45)
.github/workflows/ci.ymlarchitecture.config.jsondocs/design/03-domain-model/glossary.mddocs/design/03-domain-model/layering.mddocs/design/10-domains/deploy-cli.mddocs/design/90-decisions/ADR-0010-deploys-hold-a-session-advisory-lock.mddocs/design/90-decisions/ADR-0012-the-state-store-speaks-sql-directly.mddocs/design/90-decisions/ADR-0034-deploy-state-lives-in-the-stage-branch.mddocs/design/90-decisions/ADR-0045-deploy-state-lives-behind-the-platform-state-api.mddocs/design/90-decisions/README.mddocs/guides/deploying.mdgotchas.mdpackages/1-prisma-cloud/0-lowering/lowering/package.jsonpackages/1-prisma-cloud/0-lowering/lowering/src/client.tspackages/1-prisma-cloud/0-lowering/lowering/src/exports/state.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/bootstrap.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/delete.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/empty-scope.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/fake-management-api.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/fake-state-api.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/harness.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/layer.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/lock.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/ownership.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/service.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/state-api.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/state.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/transient.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/bootstrap.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/delete.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/discovery.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/empty-scope.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/errors.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/layer.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/lease.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/lock.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/schema.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/service.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/transient.tspackages/1-prisma-cloud/1-extensions/target/src/__tests__/invariants.test.tspackages/1-prisma-cloud/1-extensions/target/src/__tests__/teardown.test.tspackages/1-prisma-cloud/1-extensions/target/src/control/extension.tspackages/1-prisma-cloud/1-extensions/target/src/teardown.tspackages/9-public/composer-prisma-cloud/package.jsonpackages/9-public/composer/package.json
💤 Files with no reviewable changes (19)
- architecture.config.json
- packages/1-prisma-cloud/0-lowering/lowering/src/exports/state.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/tests/ownership.test.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/tests/service.test.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/schema.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/tests/delete.test.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/tests/state.test.ts
- packages/1-prisma-cloud/1-extensions/target/src/teardown.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/service.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/tests/transient.test.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/lock.ts
- packages/1-prisma-cloud/1-extensions/target/src/tests/teardown.test.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/transient.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/tests/bootstrap.test.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/bootstrap.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/tests/harness.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/discovery.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/tests/lock.test.ts
- packages/1-prisma-cloud/0-lowering/lowering/src/state/delete.ts
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…h resources - the cutover guard now lists databases and buckets alongside Compute apps (Connections excluded: children of databases), so a legacy stage holding only a database or bucket is refused instead of silently re-provisioned; renamed to failOnEmptyScopeWithLiveResources, message reworded, regression tests for database-only / bucket-only / mixed branches; docs (ADR-0045, deploying guide) match the new wording - releaseDeployLease logs a warning for every non-2xx release response (the lease stays live until TTL), keeping the specific 404 message - FakeStateApi.stop() is deterministic: resolves immediately with no server and destroys open keep-alive sockets before close() Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
commit: |
…uched Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/design/03-domain-model/layering.md`:
- Around line 123-128: Qualify the concurrency guarantees in the layering
description and the corresponding statement in docs/guides/deploying.md (line
39) so they apply only while the server-side per-(stack, stage) lease remains
live. Do not claim that deployers can never race after lease expiry unless lease
loss actively interrupts the running apply.
In `@docs/guides/deploying.md`:
- Line 39: Update docs/guides/deploying.md lines 39-39 and 110-110 to describe
state lifetime separately: clarify what happens when a stage is deleted, when
production is destroyed, and when the Project itself is deleted. Remove or
qualify the claim that the production Branch always survives so it remains
consistent with the documented removal of an empty Project and its default
Branch.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 876fe750-0558-42dc-a651-115e544b38b4
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (14)
docs/design/03-domain-model/glossary.mddocs/design/03-domain-model/layering.mddocs/design/10-domains/deploy-cli.mddocs/design/90-decisions/ADR-0010-deploys-hold-a-session-advisory-lock.mddocs/design/90-decisions/ADR-0012-the-state-store-speaks-sql-directly.mddocs/design/90-decisions/ADR-0034-deploy-state-lives-in-the-stage-branch.mddocs/design/90-decisions/ADR-0045-deploy-state-lives-behind-the-platform-state-api.mddocs/guides/deploying.mdpackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/empty-scope.test.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/fake-management-api.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/fake-state-api.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/empty-scope.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/layer.tspackages/1-prisma-cloud/0-lowering/lowering/src/state/lease.ts
…rdown state lifetimes Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Integration fixes after rebasing onto main (PR #209 replaced the SQL state store with the platform state API): - legacy-resources.test.ts round-trip suite now drives the REAL hosted layer (stateLayerAgainst -> stock HTTP client -> on-read migration) against the in-process fake state API instead of the deleted SQL store and Postgres harness; the pure migration and provider acceptance tests are unchanged - the adoption ADR is renumbered ADR-0046 (main took 0043-0045); references updated - lockfile regenerated on main's pins (effect beta.103 constellation, @prisma/management-api-sdk ^1.57.0, no postgres) plus @effect/platform-node for the upstream providers Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
* docs(drive): open alchemy-provider-adoption project — spec, plan, design notes Adopt the upstream alchemy/Prisma provider for the six overlapping resources, keep Composer emulators local, contribute buckets + the generic Postgres state store upstream. Slices TML-3154/3155/3156. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * feat(lowering): alchemy beta.67 foundation — bump, PrismaComposer type-ids, aliases Bump alchemy 2.0.0-beta.59 -> .67 (13 pins) + forced effect beta.100 train. Rename the provider collection tag and the eight resource type-ids from Prisma.* to PrismaComposer.* so they cannot collide with the upstream alchemy/Prisma provider; old ids wired as aliases so existing state rows resolve (beta.67 ResourceOptions.aliases). One-line pnpm patch for upstream Aliases typing under exactOptionalPropertyTypes; Schedule.both removal handled with Schedule.upTo (during is inverted in beta.100, verified by probe). Part of alchemy-provider-adoption (TML-3154). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * feat(lowering): adopt upstream alchemy/Prisma postgres resources Delete Composer's Project/Database/Connection resources; register upstream's classes in the PrismaComposer collection over a profile-store-free PrismaEnvironment (PRISMA_SERVICE_TOKEN + shared managementApiBaseUrl resolver honored identically by our SDK client). Descriptors bind directConnectionString explicitly; branch stages create with branchId and a generated physical name (upstream's reconcile reverts external attach/rename, so create-then-PATCH is not viable); production keeps explicit names. Legacy state rows migrate on read in the hosted store (type-ids + attribute shapes), proven against upstream's real diff/read/reconcile incl. a no-rotation guard; the one-time branch-stage rename + default-connection rotation is documented in docs/guides/deploying.md. Local-target providers rebind the emulators to upstream's classes. Part of alchemy-provider-adoption (TML-3154). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(drive): draft upstream alchemy PR body Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(drive): rewrite upstream PR body — grounding example, narrative, alternatives Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(drive): unwrap PR body — GitHub renders single newlines as breaks Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(drive): add embedder DX sample to upstream PR body Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * feat(lowering): adopt upstream alchemy/Prisma compute resources Replace ComputeService/Deployment/EnvironmentVariable with upstream App/Deployment/EnvironmentVariable (not composite Compute: the COMPOSER_*_ORIGIN self-edge needs the App created before env rows, and Compute owns env rows in a map our per-key state cannot migrate into). The env->deployment ordering edge rides the app prop as an Output (deployment-edge.ts) — riding artifactPath would leave the diff unresolved for brand-new env rows and silently skip code deploys; proven by tests driving alchemy's real Output machinery. Legacy compute rows migrate on read incl. poison-row neutralization; the platform DATABASE_URL is no longer overwritten (system-managed; authoring-side ban remains). Local target rebinds the emulators to upstream classes. Known regressions recorded in design notes: env value changes no longer redeploy (upstream ask filed) and App delete retry budget is ~3.75s (upstream ask filed). Part of alchemy-provider-adoption (TML-3155). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(design): ADR-0043 — Prisma Cloud resources come from the upstream Alchemy provider Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * fix(lowering): report migrated poison rows as retained, correct migration docs Legacy poison DATABASE_URL rows are retired with removalPolicy retain: the engine drops the state row, calls no API, and prints "retained" — the previous "deleted" was false (the platform variable survives, still holding the "-" placeholder on migrated stages). deploying.md, alchemy-lowering.md and the design notes now say so, with the optional manual cleanup calls. Part of alchemy-provider-adoption (TML-3155). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * feat(lowering): env changes always reach the running app again Restore the pre-swap guarantee that a deploy ships what you declared: the deploy hook hard-links the content-addressed artifact into a per-deploy-generation path, so upstream Deployment plans a replace every deploy (the updatedAt route is impossible: not in stables, and the env diff plans update every deploy, so plan-time values are unresolved). No secret material in state. The app ordering edge is untouched. Cost is the pre-swap profile: one deployment replacement per service per deploy, until the pinned alchemy version includes Deployment.redeployOn — the swap is one edit at the marked seam. Part of alchemy-provider-adoption (TML-3155). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(drive): Composer PR body Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(design): rewrite ADR-0043 — grounding example, durable statements only Grounding code first, decision led, alternatives last. Removed transient project/process references and corrected two statements the implementation had already overtaken (env changes now always ship via per-generation artifact paths; upstream dev mode is dual registration, not an option we pass). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(design): DATABASE_URL is self-healed on first deploy, not absent createDatabase: false removes the default database but not the variable: the platform heals a missing DATABASE_URL template on the first Compute deploy from any ready database on the Project (verified in the control plane: healDefaultDatabaseUrl via materializeDeployEnv). The authoring-side name ban is the line that holds. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * feat(lowering): claim DATABASE_URL with poison values at provision application.provision claims DATABASE_URL/DATABASE_URL_POOLED (production + preview, project-level) with "-" via create-only POSTs, skipping 409s. The platform build-runner self-heals a missing DATABASE_URL template on first deploy from any ready database, so without the claim a bypass reader quietly gets a live credential to one of the app's own databases; with it, direct readers fail loudly. The rows are never alchemy resources (nothing in state, upstream never owns them); legacy projects with platform-seeded rows 409 and no-op. Part of alchemy-provider-adoption (TML-3155). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs: DATABASE_URL is claimed with a poison value at provision The lowering doc and deploy guide describe the create-only claim, why it exists (the platform fills a missing DATABASE_URL from any ready database on first deploy), and that manual deletion is not useful — the claim or the platform recreates the row; a user-set value wins over both. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs: address PR 197 review — stale names, propagation claims, --fresh wording ADR index origin API naming (App.appEndpointDomain per ADR-0043), layering Service row, glossary beta pin, spec open question resolved, design-notes provider-scope claim, gotchas branch-attach fix line matches its cause, --fresh documented as data-destroying, and the two propagation passages now describe env changes reaching the running deployment. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * feat(lowering): deployment replaced when its environment changes, reused otherwise Replace the per-run generation path with a deploy fingerprint: the artifact hard-link directory is named from a hash of the service's environment material, so upstream's artifactPath comparison replaces exactly when the environment or artifact changed. The material is non-secret by construction (ADR-0042 rows carry literals and pointers); pointed platform variables contribute updatedAt metadata, read at preflight and carried across the CLI->alchemy process boundary on a new framework preflight-transport channel (the in-process implementation lost the timestamps at spawn — caught in review, now covered by a boundary-spanning test). Secret-bearing rows contribute wiring identity only; the accepted narrowing is recorded in the module. Docs updated to the shipped mechanism. Part of alchemy-provider-adoption (TML-3155); addresses PR 197 A11. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * refactor(local-target): one implementation of the shared upstream-attribute helpers The compute and postgres provider families each carried their own byte-identical DEV_TIMESTAMP, isRecord and projectIdOfInput. They now import them from src/upstream-attributes.ts, so the 'local' project fallback and the stamped timestamp cannot drift between the two. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * fix(lowering): retire only LEGACY poison rows, decided by the props shape Upstream's own EnvironmentVariable rows carry the same type-id as the legacy ones, so a key match alone would retire a live, upstream-managed DATABASE_URL variable from state on every read. poisonKeyOf now applies the same props-shape discriminator the rest of the module uses. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * fix(lowering): migrate a replaced poison row's old generation before retiring it The retirement returned early, so the displaced generation nested under `old` kept its legacy shape and reached the engine unmigrated. The old chain is rewritten first; the retirement now happens on the fully migrated row. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * fix(lowering): finish the rebase onto the platform state API (main) Integration fixes after rebasing onto main (PR #209 replaced the SQL state store with the platform state API): - legacy-resources.test.ts round-trip suite now drives the REAL hosted layer (stateLayerAgainst -> stock HTTP client -> on-read migration) against the in-process fake state API instead of the deleted SQL store and Postgres harness; the pure migration and provider acceptance tests are unchanged - the adoption ADR is renumbered ADR-0046 (main took 0043-0045); references updated - lockfile regenerated on main's pins (effect beta.103 constellation, @prisma/management-api-sdk ^1.57.0, no postgres) plus @effect/platform-node for the upstream providers Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * refactor: address operator review — plain names, shared util, terse comments - rename mangleExtensionId to envVarSafeExtensionId; comments say the literal transformation - cut the oversized comments this PR added (deploy-fingerprint 85-line header, preflight-transport, legacy-resources, providers, deployment-edge, pointer-timestamps, local-target, extension, descriptors/compute, test headers) to the constraints the code cannot express - replace local-target's isRecord with effect's Predicate.isObject - extract the resource type-id strings in Bucket/BucketKey into consts (with the legacy alias ids named too) - rename the "poison" vocabulary: database-url-poison.ts becomes database-url-claim.ts (claimDatabaseUrlKeys, PLACEHOLDER_VALUE, RESERVED_DATABASE_URL_KEYS); legacy-resources' retirePoisonRow becomes retireDatabaseUrlClaimRow; tests and docs follow Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * fix: address PR 197 review — atomic copy fallback, async hashing, early preflight-env, doc alignment Review fixes, one per finding: - deploy-fingerprint: the no-hardlink copy fallback writes through a temp file and renames, and a racing EEXIST is success — no reader can see a partial artifact. - local-target compute: the artifact hash uses async file APIs so a large artifact no longer blocks the whole converge's event loop. - execute-deploy-destroy: the preflight transport env is serialized right after the preflight loop, so an extension-id collision fails as DEPLOY.PREFLIGHT_FAILED before the stack file is written. - serializer: the input row's secret names are sorted and unique, so a binding refactor that reorders or duplicates leaves cannot move the deploy fingerprint. - preflight-transport test asserts both colliding extension ids by name. - legacy-resources: round-trip test covers getReplacedResources through the real layer. - Docs: deploying.md and the Drive assets describe fingerprint-based replacement (not always-redeploy), ADR-0048 records the create-only DATABASE_URL claim beside the never-modify rule, gotchas.md records the stable-identity secret exception, alchemy-lowering.md credits the upstream classes, spec.md closes the settled adoption questions, design-notes.md spells out the 3.75s retry arithmetic. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs(drive): PR-body asset — upstream #1061 merged, swap waits on a release Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * fix: address PR 197 re-review — resolved dependency values move the fingerprint, env-scoped reporter URL Code, one per finding: - compute serialize: a dependency-input value already resolved at plan time is authored config (ADR-0042 keeps secret values behind pointers and resources, which are still Outputs), so its text is hashed — a changed producer setting (a store's bucket) now replaces the consumer's deployment. Resource-built values stay withheld. - compute deploy: fingerprintedArtifactPath runs inside Effect.try so filesystem failures are deploy errors, not defects. - serializer: secret names for the fingerprint are collected from the pointers the document actually carries, not from every bound leaf a schema transform may drop. - preflight: updatedAt rows compare by parsed time, not string order. - builds reporter: the Management API base URL resolves from the supplied env map, not process env, so a custom-env run reports to the host its credentials target. - legacy-resources: the two stacked doc comments on CLAIMED_DATABASE_URL_KEYS are one block. - Tests: preflight-transport compares against containerEnvVarName; deployment-edge pins that the combined app expression resolves to the app id; preflight pins recency (a newer template beats an older branch override); local-dev integration rejects an empty or missing env.json. Docs: ADR-0048 names the real ownership boundary (upstream support, not Management API existence) and the legacy-state scope split against ADR-0045; deploying.md documents the stable-identity secret exception; pdp-data-model.md notes the create-only claim; plan.md and spec.md reflect the one-PR slice-3 override and the verified DoD items. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * chore(drive): drop the PR-body asset files The PR bodies live on the PRs themselves; the checked-in copies only go stale. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * fix: apply code-review findings — one host resolver, Output-safe fingerprints, paired env rows Correctness: - The CLI engine host resolves PRISMA_API_URL before PRISMA_MANAGEMENT_API_URL, the same precedence every other Prisma Cloud client uses, so one env var can no longer split a deploy across two API hosts. Pinned by a runtime test. - A dependency value that is any alchemy Output stays withheld in the deploy fingerprint — upstreamAny emptiness alone let a literal- or effect-built Output be pushed as an object that hashed as null for every value. - managementApiBaseUrl's env-record branch treats an empty variable as unset, matching the Config branch. - The CLI blanks every extension's preflight transport variable it did not produce, so a stale value exported into the shell cannot read as this run's payload. Structure and reuse: - compute serialize keeps each env row's resource and fingerprint entry in one list element, so a row cannot exist without its entry. - The reserved DATABASE_URL key set and the artifact content type each have one definition (database-url-claim.ts, compute/artifact.ts). - The fingerprint material sorts by its unique row key instead of restringifying rows in the comparator; the serializer's secret collector is a required parameter. - The generated stack header no longer claims the file is independently runnable without the CLI-provided environment. Conventions (per the operator's global rules): the new ADR, the .drive project docs, the deploying.md upgrade section, and a gotchas.md bullet are unwrapped to one paragraph per line; 'gates' becomes 'blocks'; the coined 'restart-amplifies' is replaced with a plain description. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> * docs+test: address final review round — legacy-state scope in index and guide, fallback URL test The ADR index and the deploying guide qualify on-read migration to platform-state-API rows (retired SQL stores stay destroy-only, ADR-0045); the spec names liveProviderLayer as a temporary-dependency cleanup, not a composition blocker; the runtime test pins the fallback to PRISMA_MANAGEMENT_API_URL when PRISMA_API_URL is empty. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
At a glance
After this PR, a composer deploy stores its provisioning state in the platform itself, using Alchemy's own stock HTTP state client pointed at our Management API — plus a server-side lease that keeps two deploys of one stage from running at once:
Before this PR, that same state lived in a small hidden Prisma Postgres database named
prisma-composer-statethat composer created inside every deploy stage, guarded by a Postgres advisory lock. All of that machinery is deleted here — about 1,200 lines of store, lock, and bootstrap code plus their tests.The decision
Composer's deploy state moves behind the platform's new Alchemy state API, and deploy serialization moves from a client-held Postgres lock to a server-enforced lease. The server side shipped in prisma/pdp-control-plane#4816 (schema) and #4817 (API), merged 2026-08-07; the routes are experimental. This PR is the composer half: point the state layer at the API, wrap the run in the lease, and delete the interim store.
Why deploy state exists, and why it was a database
Alchemy (like Terraform) works by diffing the desired resource graph against a state store — its record of what it provisioned last time. Whoever can read that store deploys incrementally; whoever cannot, provisions duplicates. So composer hosts state where every credentialed machine can reach it. Until now that meant composer built its own store from public primitives: a
prisma-composer-statedatabase in each stage's Branch, bootstrapped on every deploy (find-or-create the database, verify ownership via a marker table, migrate the schema, mint a fresh connection string), and serialized by a session advisory lock with a liveness re-checker.That store worked, but it cost a database quota slot per stage, appeared in the Console where a user could delete it out from under live deployments, and carried real proof burden (the lock's crash-release behaviour was verified against one specific driver — ADR-0012 records why). Our own ADRs called it an interim and named "a platform-side state API" as the end state. That API now exists, so the interim dies: ADR-0012's recorded pick-up trigger — "the platform-side state API lands … this record closes as obsolete" — has fired.
How it works now
The state client is Alchemy's, unmodified. The server implements Alchemy's stock
HttpStateApiwire contract verbatim, so composer'sprismaStateLayer(packages/1-prisma-cloud/0-lowering/lowering/src/state/layer.ts) just builds the stockmakeHttpStateStorefrom the pinned[email protected]— the pin is unchanged, and the layer's public type is unchanged, so nothing upstream of it moves. Auth is the same workspace service token composer already deploys with.The lease replaces the lock. Alchemy's contract has no locking concept, so the server adds one object: a per-(stack, stage) lease. Composer acquires it before the run, heartbeats it every 20 s on a background fiber, and releases it when the run ends (
state/lease.ts). The old lock's two properties carry over in simpler form:409naming the current holder and stops immediately — no queueing, same operator experience as the advisory lock.Enforcement moved server-side, which deletes a whole class of client code: every state operation without a live lease fails
409, a status the stock client treats as fatal (no retry), so a lost lease stops a deploy after at most one extra request. The old client-side liveness re-checker has no replacement because it has no job left. The lease id is a capability token: it is heldRedacted, and its header is added to effect's log-redaction names (mutation-tested).What happens to existing stages
No data migration, matching the precedent ADR-0034 set for the previous store move. A stage deployed with an older composer has live resources but no API-hosted state, and deploying over it with fresh state would silently re-provision duplicates — the exact failure hosted state exists to prevent. So the existing empty-scope check is re-pointed at the API and made stricter: if the state scope is empty but the Branch already has live resources (apps, databases — including the old
prisma-composer-statedatabase itself — or buckets), the deploy refuses and tells the operator to destroy with the previous composer version or delete the stage/branch, then redeploy fresh. Legacy state databases are never read and never deleted: deleting a stage's Branch cleans its one up; production's is a documented one-slot manual cleanup.docs/guides/deploying.md§ "Upgrading from an older state store" walks through it.Tests and live proof
The wire contract is exercised by the real stock client, not a mock of it: an in-process fake of the server (double-encoded
fqn,200+ JSONnullfor absent values,PUTecho, lease enforcement) sits on a real TCP port, and the pinned client drives the fullStateServiceround-trip against it. Request-counted tests prove the fail-fast claims: contention is one request, and a lost lease fails the next state operation in exactly one request.Proven live against
api.prisma.io:examples/bucketdeployed end-to-end to an ephemeral stage with zero databases created on the Branch; a deploy against a held lease failed immediately naming the holder; an identical redeploy was a pure no-op; destroy removed the stage Branch and its state with it. Workspace typecheck/lint/test green; cast ratchet flat.Docs follow the code: new ADR-0045 records the decision; ADR-0010 and ADR-0012 get supersession banners; ADR-0034 a partial one (its Branch-scoping and lifetime reasoning carries over).
@prisma/management-api-sdkmoves^1.50.0→^1.57.0for the typed lease routes.Alternatives considered
🤖 Generated with Claude Code