Skip to content

fix(tui): the Brokers tab keeps its cursor on a broker when a refresh returns fewer - #389

Merged
bmscomp merged 1 commit into
mainfrom
fix/tui-brokers-cursor-clamp
Oct 18, 2026
Merged

bmscomp merged 1 commit into
mainfrom
fix/tui-brokers-cursor-clamp

Conversation

@bmscomp

@bmscomp bmscomp commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Item 1.3 of the CLI performance and stability plan (finding F8). Independent of the other Wave 1 PRs.

Why

kates tui's Brokers tab panics when the broker list shrinks. On main (6f4cf61), cli/tui/brokers.go:45-48 stores a refresh without looking at the cursor, cli/tui/tui.go:57 refreshes every 10 s, and View() indexes m.info.Brokers[m.cursor] (:116). With the cursor on the last broker and that broker gone, because it died or was scaled away, the next refresh ends the dashboard with index out of range [2] with length 2. That is exactly when the dashboard is wanted.

Changes

cli/tui/brokers.go: the brokersLoadedMsg case clamps the cursor to the last broker, or 0 when there are none. The nil-check the plan asks for is already there: View() returns "No brokers found." for a nil or empty list before it indexes, and the key handler skips a nil info.

brokers.go's import block is not gofmt-sorted on main. It is left as it is, to keep the diff to the fix.

Tests

Added TestBrokersRefreshWithFewerBrokers:

  • 3 brokers with the cursor on the third, then a refresh with 2: the cursor is 1 and View() renders broker 1.
  • Then a refresh with none: the cursor is 0 and the view says "No brokers found".

On main's brokers.go the test panics with index out of range [2] with length 2.

Run locally, passing:

  • cd cli && go test ./..., go test -race ./tui, go vet ./....
  • golangci-lint run --new-from-rev=origin/main ./...: 0 issues.
  • scripts/check-cli-style.sh and scripts/check-cli-compat.sh: OK.
  • The backend suite, which cli/** triggers (Build & Test): this PR touches nothing under kates/. ./mvnw test on main's kates/ tree ran 1,254 tests with 0 failures and 0 errors, once for all of Wave 1.

Skipped locally: govulncheck, as go.mod is unchanged.

CI only: ./mvnw verify with the *IT tests, the Kind and Docker jobs, CodeQL and Trivy.

… returns fewer

The Brokers tab refreshes every 10 s and stored the new broker list without
looking at the cursor. With the cursor on the last broker and that broker gone
(it died, or was scaled away), View indexed past the end and the dashboard
died with "index out of range [2] with length 2", exactly when it was wanted.

A refresh now clamps the cursor to the last broker, or 0 with none. View
already handles a nil or empty list. TestBrokersRefreshWithFewerBrokers
shrinks 3 brokers to 2 with the cursor on the third, then to none.
@bmscomp
bmscomp merged commit bf01d35 into main Oct 18, 2026
55 checks passed
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