Skip to content

feat(stack): re-plan changed endpoint ports when a stopped stack starts - #6950

Open
jgoux wants to merge 11 commits into
developfrom
juliengoux/cli-2587-apply-configtoml-port-changes-when-a-stopped-stack-starts
Open

jgoux wants to merge 11 commits into
developfrom
juliengoux/cli-2587-apply-configtoml-port-changes-when-a-stopped-stack-starts

Conversation

@jgoux

@jgoux jgoux commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

With [experimental] stack enabled, changing a port in config.toml (including removing the fixed ports a legacy supabase init writes) used to make the next supabase start fail with "cannot change on the saved stack". The only way out was to destroy the stack and lose its data. Now, when a stopped stack starts, it applies endpoint port changes and prints each one, for example api: 54321 → 26199.

  • The re-plan runs inside the stack owner's startup, while the owner holds the stack lease and before it binds any endpoints, so concurrent starts attach to the winning owner instead of racing it.
  • The changed endpoints' intents are saved in one document, and the ports are claimed through the owner's normal port acquisition, with the usual conflict and loopback-occupancy checks.
  • If owner startup fails or is interrupted after that save, the previous saved stack is restored. Ports that another stack claimed in the meantime are left to it, so the next start reports a normal conflict.
  • Endpoints whose configuration didn't change keep their saved ports. A running stack still has to be stopped first. Postgres major-version and artifact-version changes are still rejected, with the error added in the base PR.
  • The requested configuration reaches the spawned owner through a private, short-lived file instead of its command line, so secrets in it don't appear in process listings. The same applies to the stack definition sent on first registration.
  • Planning a start now treats the request as a complete composition, so excluded services no longer pin the shared API port.

ADR 0017 is amended: saved ports stay stable unless the configuration deliberately changes them on a stopped stack.

jgoux added 5 commits October 1, 2026 10:17
…ects a config change

Maps each incompatible plan path (endpoint port, db major version) to the
config.toml key or SUPABASE_*_PORT env var that set it, shows the saved and
requested values, and suggests reverting it or running the stack's exact
destroy command with a data-loss warning.
…mplete

Always suggest the exact --stack-id destroy command instead of an unquoted
--stack <name> that re-resolves against the caller's current workdir, carry
structured per-change records (service, path, key, saved, requested) plus
the recreate command on the JSON/stream-json error envelope via
MachineErrorContext, and collect every incompatible member into one error
instead of reporting only the first, deduplicating shared API port lines.

Use the production planSupabaseComposition planner in the start handler's
integration tests instead of a hand-rolled approximation, and derive the
port-setting table and createCreations' env-override calls from one shared
definition per port to prevent drift.
…name-the-changed-setting-and-the-fix-when-a-saved-stack
…in the stack error

Same-major Postgres version differences and catalog-pinned artifact versions have
no config.toml key or env var, so the incompatible-stack error no longer suggests
reverting major_version or an editable setting for them: it names the full saved
and requested builds, drops the revert sentence when nothing is editable, and
explains the fix in plain language. Mixed rejections keep the revert advice for
the editable keys only, with singular/plural grammar matching their count.

destroyCommandFor now takes only the stack id (it never read the name) and is
computed once per rejection, reused for both the error suggestion and the
JSON/stream-json envelope's recreate_command.

Move planSupabaseComposition's export from the main @supabase/stack/effect
entrypoint to @supabase/stack/testing, since the CLI only needs it to build a
realistic test double for its own composition plan.
@jgoux
jgoux requested a review from a team as a code owner October 1, 2026 14:43
@jgoux jgoux self-assigned this Oct 1, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 AI Review

Both independent reviews were available. Verified all five findings against the checked-out code and trusted conventions: one major rollback race, two minor concerns, and two nits. No findings overlapped.

Findings

Severity Location Category Sources Claim
🟠 MAJOR packages/stack/src/StackHost.ts:584 concurrency codex Startup rollback can overwrite mutations committed by an attaching client because RPC becomes available before startup can no longer fail.
🟡 MINOR packages/stack/src/StackHost.ts:584 error-handling codex Restoration failures are silently discarded, so failed startup can leave changed endpoint intents or claims persisted without reporting that rollback failed.
🟡 MINOR packages/stack/src/StackHost.ts:511 correctness claude An endpoint intent change can produce a port-change report whose from and to numbers are identical, including text such as api: 26199 → 26199 and a matching endpoint_changes entry.
⚪ NIT apps/cli/src/commands/experimental/stack/start/start.handler.ts:505 code-quality claude A stopped existing stack that reaches the normal start path resolves requested creations twice, repeating Functions dotenv reads when Functions is enabled.
⚪ NIT packages/stack/src/composition/EndpointReplan.integration.test.ts:54 comments codex The new test comment contains implementation audit-trail language and exceeds the trusted repository convention for concise fixture explanations.

Stats

Claude findings: 2 · Codex findings: 3 · Confirmed: 5 · Refuted: 0 · Uncertain: 0


Models: claude-opus-5-5 + gpt-6.1-sol · Trigger: auto · Workflow run

This review runs once per PR. A maintainer can request another with a /ai-review comment.

Comment thread packages/stack/src/StackHost.ts Outdated
Comment thread packages/stack/src/StackHost.ts Outdated
Comment thread packages/stack/src/StackHost.ts Outdated
Comment thread apps/cli/src/commands/experimental/stack/start/start.handler.ts
Comment thread packages/stack/src/composition/EndpointReplan.integration.test.ts Outdated
Comment thread packages/stack/src/HostProcess.ts
jgoux added 4 commits October 2, 2026 19:45
…tart

A rejected config change that mixed an editable key (e.g. a port) with a
non-editable one (a catalog-pinned artifact or Postgres build) suggested
reverting the editable key and dropped the non-editable change, but
reverting it alone can't unblock start. Use the destroy-only wording
whenever any non-editable change is present, and lead the change-list
message with a sentence so it reads standalone in text output.

Also document the `stack_changes`/`recreate_command` JSON contract and the
intentional `--yes` omission, and make several integration-test assertions
that lived inside `if (error instanceof StackCommandStartError)` fail
loudly instead of passing vacuously for a different error type.
A changed endpoint on an otherwise-compatible instance now re-plans inside
the stack package's own owner startup, while the new owner alone holds the
stack's lease, instead of rejecting the start. It saves the updated endpoint
intent as one document with the old port claim dropped, just before its own
normal endpoint binding claims the requested port or a freshly chosen
automatic one, reusing every check a live composition bind already applies.
Any startup failure or interruption from that save onward restores the saved
state and claims as they read before the re-plan. The CLI passes the
requested creations into owner startup through a private file and reports
each changed endpoint's old and new port in text, JSON, and stream-json
output. A changed artifact version or PostgreSQL major version still fails
before modifying the stopped composition.
… attach

The saved document and its new endpoint claims now commit, and the rollback
scope ends, before the owner serves RPC or publishes its holder, so a later
startup failure can no longer undo an attached client's own change along with
the re-plan. A restore failure now logs and appends recovery guidance to the
original error instead of being swallowed, and an automatic re-plan that
resolves back to its previous port is no longer reported as a change. The
stopped-stack start handler also reuses the creations already resolved for
the re-plan instead of reading the Functions dotenv a second time.
catchCause never ran on interruption, so an external interrupt landing after
the prepared document saved but before the claim finished skipped the restore
entirely, leaving the saved document with new intents and missing or partial
claims. The commit now runs interruptibly under an uninterruptible mask whose
restore attempt always runs on any unsuccessful exit, including interruption,
and still only extends a genuine typed failure's message with recovery
guidance when the restore itself also fails. Updates the ADR, package
README, and start command's side-effects doc to describe the rollback as
covering only the save-and-claim commit, which finishes before the owner
serves RPC or publishes its holder; a later startup failure keeps the
committed state and the next start reuses it.
@jgoux
jgoux force-pushed the juliengoux/cli-2587-apply-configtoml-port-changes-when-a-stopped-stack-starts branch from 525601f to d5fc82b Compare October 2, 2026 17:54
Base automatically changed from juliengoux/cli-2588-name-the-changed-setting-and-the-fix-when-a-saved-stack to develop October 2, 2026 18:33
jgoux added 2 commits October 2, 2026 21:17
# Conflicts:
#	apps/cli/src/commands/experimental/stack/start/SIDE_EFFECTS.md
#	apps/cli/src/commands/experimental/stack/start/start.handler.ts
#	apps/cli/src/commands/experimental/stack/start/start.integration.test.ts

This branch has not been deployed

No deployments
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.

1 participant