Skip to content

Unify CLI cluster resolution so all commands respect per-app state (MIR-832)#683

Merged
phinze merged 2 commits intomainfrom
phinze/mir-832-cli-cluster-resolution-inconsistency-configcentric-commands
Mar 19, 2026
Merged

Unify CLI cluster resolution so all commands respect per-app state (MIR-832)#683
phinze merged 2 commits intomainfrom
phinze/mir-832-cli-cluster-resolution-inconsistency-configcentric-commands

Conversation

@phinze
Copy link
Copy Markdown
Contributor

@phinze phinze commented Mar 17, 2026

When a user runs cluster switch in an app directory, it saves the chosen cluster to both the global config and per-app state. Commands using AppCentric (like cluster current, deploy) would read that per-app state and target the right cluster. But commands using ConfigCentric (like route list, sandbox list, app list) skipped per-app state entirely and fell back to the global active_cluster. So you could see cluster current report "miren01" while route list silently hits a completely different cluster.

The fix teaches ConfigCentric.LoadCluster() itself to check per-app state when running in an app directory, slotted in between the explicit overrides (-C flag, MIREN_CLUSTER env) and the global fallback. This is the minimal change that fixes the inconsistency without restructuring the command hierarchy. With the logic centralized, AppCentric.LoadCluster() drops its parallel implementation and just delegates, and cluster current replaces its bespoke resolution with a LoadCluster() call.

A sweep of the rest of the CLI commands turned up several more that were doing their own ad-hoc resolution instead of going through LoadCluster()app list, cluster list, cluster export-address, doctor, and doctor auth all got converted. The only intentional exception is deploy's interactive "add a cluster" recovery path, which correctly reads the just-added cluster directly.

Note: doctor could use a deeper rework beyond this scope — it's doing a lot of manual wiring that doesn't quite fit the LoadCluster() model cleanly. Filing a follow-up for that.

Closes MIR-832

When running in an app directory, ConfigCentric now checks per-app
cluster state from app-state.toml after -C flag and MIREN_CLUSTER
env, but before the global active_cluster fallback. This is the same
state that cluster switch saves.

With the resolution logic centralized, AppCentric.LoadCluster() can
drop its parallel implementation and just delegate. cluster current
gets the same treatment — its ad-hoc resolution is replaced with a
LoadCluster() call.
@phinze phinze requested a review from a team as a code owner March 17, 2026 14:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 28e4ea1d-b0ed-4b30-85f5-8142963619d2

📥 Commits

Reviewing files that changed from the base of the PR and between b9072fa and fa8f081.

📒 Files selected for processing (9)
  • cli/commands/app.go
  • cli/commands/app_list.go
  • cli/commands/cluster.go
  • cli/commands/cluster_current.go
  • cli/commands/cluster_export.go
  • cli/commands/config.go
  • cli/commands/config_test.go
  • cli/commands/doctor.go
  • cli/commands/doctor_auth.go

📝 Walkthrough

Walkthrough

This PR refactors cluster resolution logic across multiple CLI commands to use a centralized LoadCluster method instead of individual config/state lookups. The config.go file now handles per-app state checking during cluster resolution, falling back to global settings when an active app's state doesn't specify a cluster. Commands including cluster, cluster_current, cluster_export, doctor, and doctor_auth are updated to call opts.LoadCluster() for cluster retrieval. The app.go command delegates to ConfigCentric.LoadCluster, while app_list.go switches from configuration loading to direct cluster loading. Tests are added to validate environment-based and app-scoped cluster resolution paths, including fallback behavior and CLI flag/environment variable overrides.

📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Several commands were doing their own ad-hoc "-C flag then
ActiveCluster()" dance instead of going through LoadCluster(). This
meant they'd silently ignore per-app state and MIREN_CLUSTER in some
cases. Swept through AppList, ClusterList, ClusterExportAddress,
Doctor, and DoctorAuth to use the unified path.

ClusterList previously duplicated the per-app state lookup manually;
now it just calls LoadCluster() like everyone else.
@phinze phinze force-pushed the phinze/mir-832-cli-cluster-resolution-inconsistency-configcentric-commands branch from fa8f081 to 5cfe8db Compare March 17, 2026 15:03
@phinze phinze merged commit 9732614 into main Mar 19, 2026
12 checks passed
@phinze phinze deleted the phinze/mir-832-cli-cluster-resolution-inconsistency-configcentric-commands branch March 19, 2026 13:44
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