Skip to content

feat: make the CLI refuse a local server that another release started - #2360

Closed
fforootd wants to merge 7 commits into
mainfrom
claude/cli-local-server-version
Closed

fforootd wants to merge 7 commits into
mainfrom
claude/cli-local-server-version

Conversation

@fforootd

@fforootd fforootd commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

Until now only zitadel start and zitadel setup (and setup only for a server running as a process) compared a running local server's release with the CLI's. Once clients call the API under /api/v1 (ADR 077, §5 "Versions"), a newer CLI talking to a server an older release left running fails on its first request with req.not_found and nothing that says why. This PR makes every command that sends a local server requests check its release first.

  • LocalServer.outdated(cwd, serverUrl, …) decides it in one place. It returns a mismatch only when all of these hold:
    • the nearest .zitadel/local/runtime.json names the server the command is about to call (sameLocalServer);
    • that record's own process or container is the one running and answering, checked only on a mismatch so the common path costs one file read;
    • it runs another release: server_version for a process, and for a container the tag of a published ghcr.io/zitadel/nextgen:<version> image, compared with the image a bare start would run (ZITADEL_LOCAL_IMAGE, else the CLI's default).
  • Some servers are never refused: an override binary (ZITADEL_SERVER_BINARY, which records override or a dev+<commit> version), a moving tag such as latest, any other image, or a record that cannot be read (doctor's to report).
  • LocalServer.assertCurrent refuses such a server with E_CONFLICT. Its next_commands are start --cwd <dir that holds the server>, then the command again when the caller can name it. setup's existing message, hint and details keys are kept.
  • Where the check runs, before the first request:
    • EnvironmentCommand.connect, which covers every project command, before it asks for the project id or the credential;
    • zitadel api, after --dry-run;
    • zitadel console;
    • zitadel env add, before it creates a project;
    • zitadel setup, for the --server it was given, the local server the wizard picked (a gap until now: the check only saw the flag's server), and setup --dev-port on an app that is already set up.
  • start keeps restarting such a server, and stop, reset, logs and status still work on it. status's user probe degrades to unknown.
  • zitadel doctor gets a warning-level runtime-version check whose advice is the same start --cwd. A path that needs shell quoting leaves the command out, as doctor's other runtime advice does.
  • claim-as-admin runs only inside setup, after setup's check, so it needs no call of its own.
  • SKILL.md and apps/cli/src/lib/local-server/AGENTS.md record the behavior and the rule for new commands.

Validation

All commands were run from apps/cli unless the line says otherwise. Every vitest line uses corepack pnpm exec vitest run.

  • moon run cli:typecheck: passed.
  • moon run cli:lint: passed after biome format --write rewrapped one line of a test.
  • corepack pnpm run build: passed (the command tests drive dist/).
  • vitest runs, all passing:
    • tests/unit/lib/oclif/environment-command.test.ts tests/unit/commands/api.test.ts tests/unit/commands/console.test.ts tests/unit/commands/env/add.test.ts tests/unit/lib/local-server/server.test.ts: 97 tests.
    • tests/unit/commands/claim.test.ts -t "server local": 4 tests.
    • tests/unit/commands/doctor.test.ts -t "release|advisoryForWarnings": 4 tests.
    • tests/unit/commands/setup/index.test.ts -t "local server|runtime start left|nobody to ask|local-runtime-missing": 5 tests, including setup's existing refusal test, unchanged.
    • tests/unit/commands/setup.test.ts -t "setup asked on a terminal": 6 tests, including the new wizard case.
    • tests/unit/commands/setup.test.ts -t "setup --dev-port": 5 tests.
    • tests/unit/docs tests/unit/lib/oclif/reference.test.ts tests/unit/lib/warnings.test.ts: 21 tests.
  • After the latest merge of main (see Notes): moon run cli:typecheck cli:lint cli:test: pass, 4818 tests, with a locally built apps/server-win32-x64/bin/nextgen.exe moved aside: server-binary.test.ts expects it to be missing.
  • Before that merge, moon run cli:test on this branch alone: 4314 passed. On a local branch that merges all five ADR 077 PRs (docs: amend and accept ADR 077 on the /api/v1 prefix #2356, feat: accept /api/v1 paths in the SDK and dev-proxy gates #2357, this one, feat: serve the API under /api/v1 and deprecate the root paths #2358 and feat!: call the API under /api/v1 #2359): 4338 passed.
  • The e2e lanes ran only on that combined branch; see feat!: call the API under /api/v1 #2359.

Release notes / changeset

.changeset/cli-local-server-release-check.md, @zitadel/cli minor:

zitadel setup, zitadel console, zitadel api, zitadel env add and every command that works on a project now refuse a running local server that another CLI release started, as a process or a container, before they send it anything: that server serves its own release's API. Run zitadel start to restart it on this release (its data stays), then run the command again. zitadel doctor warns about such a server.

Notes

  • This is the local-server half of the ADR 077 rollout's "path gates" step. It is independent of the sdk-core and dev-proxy gates (feat: accept /api/v1 paths in the SDK and dev-proxy gates #2357), and can merge before or after them.
  • Readers refuse rather than restart, as setup already did: a restart is start's decision, in the directory that holds the server, and it may be a parent of the one the command runs in.
  • claim.test.ts's running-server fixture now records the bundled server version. It used the helper's default 1.0.0, which the new check correctly refuses.
  • main is merged in six times to resolve conflicts:
    • imports and tests both sides added, in doctor.test.ts, env/add.test.ts and setup.test.ts. This PR's doctor test now passes the selector argument that advisoryForWarnings gained on main;
    • doctor's call to its local runtime checks, which main now skips for a project on a hosted server. runtime-version is one of them, so it is skipped there too, and the hosted-project test's list of local runtime checks names it;
    • code both sides added in the same places. LocalServer keeps outdated and assertCurrent beside main's port helpers. In setup, the wizard's branch keeps this PR's check of the local server the wizard picked, and main's warning about a taken app port is the branch for a run that asks nothing. This PR's wizard test now answers main's questions: the port only when it is taken, and the new password minimum;
    • doctor's local runtime checks again: main now passes them the parent folder a runtime came from, for the runtime check's message, and this PR its release options, for runtime-version. They take both, this PR's first, because main's is optional.
    • env add's imports: main moved its first deploy into deployInitialRelease (feat: deploy .zitadel/ at the end of zitadel setup #2461), and this PR imports LocalServer there for its check. The file takes both. Nothing main added sends a local server requests without the check: the deploy setup now ends with goes to the server this PR already checks, and main's new policies test connects through EnvironmentCommand.connect, which runs it.
  • stop, reset, logs and status are deliberately unchecked: they are how a user gets rid of a stale server.

🤖 Generated with Claude Code

fforootd and others added 2 commits October 26, 2026 00:24
Only `start` and `setup` (for a process server) compared a running local
server's release with the CLI's. Once clients call the API under /api/v1
(ADR 077), a newer CLI against a server an older release left running fails
on its first request with nothing that says why.

LocalServer.outdated decides once: the nearest record names the server the
command is about to call, its own process or container runs, and it runs
another release (the server version for a process, the image tag of a
published image for a container; overrides and moving tags are never
compared). LocalServer.assertCurrent refuses such a server with E_CONFLICT
and suggests `start --cwd <dir>`, then the command again where the caller
can name it.

It runs before the first request in EnvironmentCommand.connect (every
project command), `api`, `console`, `env add`, `setup` (the flag's server,
the server the wizard picked, and `--dev-port`). `start` keeps restarting
such a server; `doctor` warns (`runtime-version`) and suggests the same
`start`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er-version

Resolves the conflicts in doctor.test.ts and env/add.test.ts, where both
sides added imports and tests. The runtime-version advice test now passes
the selector argument that advisoryForWarnings gained on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Oct 29, 2026 11:07am UTC

Request Review

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 4332305

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@zitadel/cli Minor
@zitadel/testing Minor
@zitadel/server Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-darwin-arm64 Minor
@zitadel/server-win32-x64 Minor
@zitadel/api Minor
@zitadel/config Minor
@zitadel/components Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-react Minor
@zitadel/sdk-vue Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-tanstack-start Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…er-version

Resolves the conflict in setup.test.ts, where both sides added an import:
main's expectedPublicCliCommand and this branch's aBinaryRecord.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er-version

Resolves the conflict in doctor's call to the local runtime checks: main
now skips them for a project on a hosted server, and this branch passes
them the CLI release for the runtime-version check. The call keeps both,
so runtime-version is skipped with the other local runtime checks; it has
no local server record to read there anyway. main's test list of local
runtime checks gains runtime-version, so its hosted-project test covers
the new check too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er-version

Resolves three conflicts where both sides added code in the same place:

- server.ts: this branch's LocalServer.outdated and assertCurrent, beside
  main's isPortFree and nextFreePort;
- setup: the wizard's branch keeps this branch's check of the local server
  the wizard picked, and main's warning about a taken app port follows as
  the branch for a run that asks nothing;
- setup.test.ts: both sides' imports.

The wizard test for a local server another release started now answers
main's questions: the port is free, so it is not asked, and the new
password minimum is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er-version

Resolves the conflicts in doctor's local runtime checks: main now passes
them the parent folder a runtime came from, for the runtime check's
message, and this branch its release options, for runtime-version. They
take both, this branch's first, because main's is optional, and each
check list keeps main's runtime check followed by the release check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er-version

Resolves the conflict in env add's imports: main moved the command's
first deploy into deployInitialRelease, and this branch imports
LocalServer there for its release check. The file takes both. Nothing
main added reaches a local server around the check: setup's new deploy
goes to the server this branch already checks, and policies test
connects through EnvironmentCommand.connect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 43323056 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant