Skip to content

fix(desktop): keep window title in sync with cluster context switches#604

Merged
nadaverell merged 2 commits intomainfrom
fix/cross-clusters-bug
May 3, 2026
Merged

fix(desktop): keep window title in sync with cluster context switches#604
nadaverell merged 2 commits intomainfrom
fix/cross-clusters-bug

Conversation

@eliran-ops
Copy link
Copy Markdown
Contributor

@eliran-ops eliran-ops commented May 3, 2026

What

Register an OnContextSwitch callback in the desktop app's startup() so the OS window title re-renders whenever the user switches kubeconfig contexts via the in-page cluster selector.

  • cmd/desktop/app.go: extract formatWindowTitle(contextName), add injectable setWindowTitle field, register an OnContextSwitch callback that calls updateWindowTitle(newContext).
  • cmd/desktop/main.go: use the new helper for the initial title (was duplicated inline).
  • cmd/desktop/app_test.go: regression coverage for formatWindowTitle, the update sequence (initial → switch → disconnect), and the nil-ctx guard before startup.

Why

The Wails window title was set exactly once in domReady and never refreshed. After switching contexts in-app, the OS titlebar kept pointing at the cluster Radar booted with (commonly prod) while the in-page selector and the data layer were on the new cluster — a state mismatch that's especially dangerous in a fleet UI: one of those moments where you click "Delete" thinking you're in dev. Hooking into the existing k8s.OnContextSwitch notification (already used by the SSE broadcaster at internal/server/sse.go:235) means the title now derives from the same source of truth as the data layer.

Where to start reading

  • cmd/desktop/app.go:57-69 — the new OnContextSwitch registration in startup().
  • cmd/desktop/app.go:43-55formatWindowTitle + updateWindowTitle.

Risky vs mechanical

  • Risky-ish: the registration in startup(). The callback fires from another goroutine after PerformContextSwitch completes; safe because (a) a.ctx is written before the registration call in the same goroutine, and (b) OnContextSwitch synchronizes via contextSwitchMu (Lock on register / RLock on dispatch), giving happens-before to the callback.
  • Mechanical: formatWindowTitle extraction + the inline domReady/main.go cleanup.

Not included

  • Browser/standalone build: nothing in the web frontend currently sets document.title dynamically, so there's nothing to fix there. If we ever start setting it, hook the existing context_changed SSE event the broadcaster already emits.
  • Destructive-action confirmations re-displaying the cluster name: separate hardening pass, would touch a lot of UI surface.

Made with Cursor


Note

Low Risk
Low risk: desktop-only window title updates and new context-name parsing helpers; main behavior change is registering an additional OnContextSwitch callback and should not affect cluster operations beyond UI labeling.

Overview
Keeps the desktop OS window title continuously in sync with kubeconfig context changes by registering a k8s.OnContextSwitch callback during DesktopApp.startup() and routing all title updates through a new updateWindowTitle helper.

Extracts formatWindowTitle to centralize title rendering, including shortening provider-specific context strings via new clusterShortName parsing (GKE/EKS ARN/eksctl/AKS) so the title matches the in-app cluster selector.

Adds unit tests covering title formatting, successive context switches (including disconnect/empty context), and a nil-ctx guard via an injectable setWindowTitle function; main.go now uses formatWindowTitle for the initial Wails Title.

Reviewed by Cursor Bugbot for commit a2fee49. Bugbot is set up for automated code reviews on this repo. Configure here.

The Wails window title was set once on DOM ready and never refreshed.
After an in-page context switch via the cluster selector, the OS
titlebar kept pointing at the previous cluster (commonly the prod one
Radar booted with) while the in-page selector and data layer reflected
the new cluster — exactly the kind of state mismatch that invites
running destructive actions on the wrong cluster.

Register an OnContextSwitch callback in startup() that re-renders the
title from the same kubeconfig context the data layer is using.
Extracted formatWindowTitle() so main.go's initial title and the live
updates share one shape definition.

Co-authored-by: Cursor <cursoragent@cursor.com>
Port the cluster-name parser from packages/k8s-ui/src/utils/context-name.ts
to a private Go helper and run the kubeconfig context name through it
before composing the window title. So instead of

    Radar — arn:aws:eks:us-east-1:171782501968:cluster/packagear-prod-eks

the OS title bar now reads

    Radar — packagear-prod-eks

— exactly what the in-page cluster selector shows for the same cluster.
This closes the residual cosmetic asymmetry: title and selector are now
literally identical for any GKE/EKS-ARN/eksctl/AKS-shaped context, with
graceful pass-through for user-named contexts and the in-cluster sentinel.

Tests mirror the TS suite case-for-case (cmd/desktop/context_name_test.go).

Co-authored-by: Cursor <cursoragent@cursor.com>
@nadaverell nadaverell merged commit 9e6d544 into main May 3, 2026
8 checks passed
@nadaverell nadaverell deleted the fix/cross-clusters-bug branch May 3, 2026 09:45
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.

3 participants