Skip to content

fix: let zitadel doctor --fix make the app URL setup 0.1.0 registered deployable - #2401

Merged
fforootd merged 1 commit into
mainfrom
fix/cli-doctor-preview-issuer-origin
Oct 27, 2026
Merged

fforootd merged 1 commit into
mainfrom
fix/cli-doctor-preview-issuer-origin

Conversation

@fforootd

Copy link
Copy Markdown
Member

Summary

The upgrade gap. zitadel setup 0.1.0 registered the app's URL (ZITADEL_ISSUER, e.g. http://localhost:3000) as a preview origin; 0.2.0's setup registers it as primary. deploy lands only on primary origins, so a project set up with 0.1.0 fails its first 0.2.0 deploy with E_VALIDATION "The project has no primary origin to deploy to". The hint, origin add <url> --kind primary, then fails with E_CONFLICT ("the pattern is already stored with a different kind"). Today the only way out is origin rm <url> then origin add <url> --kind primary, which #2399 documents in the 0.2.0 release note. This PR removes the need for those manual steps.

  • doctor check issuer-origin (apps/cli/src/commands/doctor/checks/issuer-origin.ts): warns when the project has no primary origin but holds its configured issuer as a preview origin. It asks the server only when .zitadel/secret records the issuer as preview-only, which 0.1.0 wrote alongside the origin. Every other project gets no request, so doctor stays offline for them. A server it cannot reach skips the check: doctor carries on past a failed probe. The warning's advisory suggests doctor --fix.
  • doctor --fix makes the issuer primary. The API has no kind change (only addOrigin / removeOrigin in api/openapi/endpoints/projects/by_id/origins/), so the fix removes the pattern and adds it back as primary. If the add fails, it puts the preview pattern back, because an empty origin list admits every origin. It then moves the pattern from preview_origins to primary_origins in .zitadel/secret.
  • deploy's error (noPrimaryOriginError) now suggests the step that works for the project:
    • doctor --fix when the project holds its issuer as a preview origin and is the project .zitadel/secret records, which is the one doctor repairs.
    • origin rm then origin add --kind primary for any other project that holds its issuer as a preview origin.
    • origin add <issuer> --kind primary with the resolved ZITADEL_ISSUER otherwise.
    • The <url> placeholder hint and origin list when no issuer resolves.
      All of them are built with the SuggestedCommand builders and carry the run's selector.
  • issuerHeldAsPreview / recordedOrigins / originOf live in src/lib/origins.ts, shared by the check and deploy. configuredIssuer is pulled out of patch-context.ts's resolveIssuer, so the check reads the issuer the same way the repairs do.
  • @zitadel/api-mock already answers origin.kind_conflict for an existing pattern with another kind, so it needed no change.

Validation

  • moon run cli:typecheck cli:lint cli:test passes.
  • New unit tests:
    • tests/unit/commands/doctor/checks/issuer-origin.test.ts covers the check and the fix against the platform mock: warn, no request when the secret records a primary origin, a project made primary by hand, an issuer with a trailing slash, an unreachable server, a missing issuer or secret, the fix on the server and in the secret, dry run, and the rollback when the server refuses the primary add.
    • tests/unit/lib/origins.test.ts.
    • tests/unit/commands/deploy.test.ts covers every branch of noPrimaryOriginError.
    • A new case in tests/unit/commands/doctor.test.ts covers the advisory.
  • New specs:
    • doctor.spec.ts: doctor --fix makes the issuer setup 0.1.0 registered as a preview origin primary.
    • deploy.spec.ts: such a project's deploy suggests doctor --fix.
  • node scripts/check-pr-title.mjs accepts the title.

Release notes / changeset

.changeset/cli-doctor-preview-issuer-origin.md (@zitadel/cli: patch). It tells 0.1.0 users to run zitadel doctor --fix once before their first zitadel deploy, and says what doctor and deploy now report.

Notes

  • Once this ships, build: correct the deploy release note and tell 0.1.0 projects how to add a primary origin #2399's manual origin rm / origin add steps can become "run zitadel doctor --fix".
  • The fix's remove-then-add leaves a short window with no origins for a project whose only origin is the issuer, and an empty list admits every origin. A kind-change operation on the API would close it.
  • The check gates on the local .zitadel/secret record. A project whose secret records a primary origin while the server holds the issuer as preview-only is not detected. 0.1.0 never wrote that combination. deploy's error still routes such a project to the right step, because it reads the server.
  • SKILL.md's Origins rule now names the issuer-origin warning and the repair.

🤖 Generated with Claude Code

… deployable

zitadel setup 0.1.0 registered the app's URL (ZITADEL_ISSUER) as a preview
origin; deploy lands only on primary origins, and origin add --kind primary
refuses the stored pattern as a kind conflict. A new doctor check
(issuer-origin) warns about such a project, and doctor --fix removes the
pattern and adds it back as primary, then records it so in .zitadel/secret.
deploy's no-primary-origin error now suggests the step that works for the
project: doctor --fix, origin rm then add, or origin add with the issuer.

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

vercel Bot commented Oct 27, 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 27, 2026 6:02pm UTC

Request Review

@zitadel-kanban zitadel-kanban Bot moved this to Inbox in Engineering Kanban Oct 27, 2026
@fforootd
fforootd marked this pull request as ready for review October 27, 2026 18:02
Copilot AI balanced review requested due to automatic review settings October 27, 2026 18:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-27T18:09:00.952557Z 415f5d9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 415f5d9

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

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

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

Copilot AI 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.

🔵 Needs a closer look

doctor --fix performs a non-atomic remove-then-add mutation of project origins on the server that can briefly leave a project with no origins (admitting all), a migration-sensitive behavior that warrants final human sign-off.

1 open issue
What changed in this PR

This PR closes an upgrade gap for CLI users: a project set up with zitadel 0.1.0 registered its app URL (ZITADEL_ISSUER) as a preview origin, but 0.2.0's deploy only lands on primary origins, so the first deploy fails and the obvious origin add --kind primary hint is rejected as a kind conflict. The change teaches doctor to detect and repair this state and deploy to suggest the step that actually works, plus shared origin helpers and updated agent docs.

Changes:

  • New doctor check issuer-origin (+ --fix) that warns when the project holds its issuer as a preview origin with no primary, and repairs it by remove-then-add as primary on the server and in .zitadel/secret (with rollback if the add fails).
  • Restructured deploy's "no primary origin" error (noPrimaryOriginError) to route each project to the correct remedy (doctor --fix, origin rm+origin add, or origin add <issuer>), backed by new shared helpers in src/lib/origins.ts and an extracted configuredIssuer.
  • Unit + integration tests, a @zitadel/cli patch changeset, and a SKILL.md Origins note.
File Description
apps/​cli/​src/​lib/​origins.ts New shared helpers (issuerHeldAsPreview, recordedOrigins, originOf) used by the check and deploy.
apps/​cli/​src/​commands/​doctor/​checks/​issuer-origin.ts New check+fix that detects and repairs a preview-held issuer.
apps/​cli/​src/​commands/​doctor/​checks/​index.ts Registers IssuerOriginCheck in the sanity-check battery.
apps/​cli/​src/​commands/​doctor/​index.ts Adds the warning advisory suggesting doctor --fix.
apps/​cli/​src/​commands/​doctor/​patch-context.ts Extracts configuredIssuer so the check reads the issuer like the repairs do.
apps/​cli/​src/​commands/​deploy.ts Replaces the inline error with noPrimaryOriginError routing to the right remedy.
apps/​cli/​skills/​zitadel-cli/​SKILL.md Documents the issuer-origin warning and repair.
.changeset/​cli-doctor-preview-issuer-origin.md Customer-facing @zitadel/cli patch note.
apps/​cli/​tests/​helpers/​project.ts Adds hasItsIssuerAsAPreviewOrigin() test fixture.
apps/​cli/​tests/​unit/​lib/​origins.test.ts Unit coverage for the shared helpers.
apps/​cli/​tests/​unit/​commands/​doctor/​checks/​issuer-origin.test.ts Unit coverage for the check and fix (including rollback).
apps/​cli/​tests/​unit/​commands/​doctor.test.ts Covers the new advisory.
apps/​cli/​tests/​unit/​commands/​deploy.test.ts Covers every branch of noPrimaryOriginError.
apps/​cli/​tests/​integration/​doctor.spec.ts Integration: doctor --fix makes the issuer primary.
apps/​cli/​tests/​integration/​deploy.spec.ts Integration: deploy suggests doctor --fix.

Review effort: Balanced

@@ -0,0 +1,44 @@
/** One of a project's origins, as the API returns it and `.zitadel/secret` records it. */
export type ProjectOrigin = Readonly<{ pattern: string; kind: string }>;
Merged via the queue into main with commit 26785b5 Oct 27, 2026
18 checks passed
@fforootd
fforootd deleted the fix/cli-doctor-preview-issuer-origin branch October 27, 2026 18:13
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Oct 27, 2026

This branch was successfully deployed

1 active deployment
Preview — 415f5d93 Deployed Oct 27, 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.

2 participants