Skip to content

Draw stash values on the ticker as their widgets - #284

Merged
coryodaniel merged 7 commits into
dashboardfrom
dashboard-ticker-widgets
Nov 30, 2026
Merged

coryodaniel merged 7 commits into
dashboardfrom
dashboard-ticker-widgets

Conversation

@coryodaniel

@coryodaniel coryodaniel commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Stacked on #282.

The live ticker draws a stash change the way the Massdriver UI draws its widget, instead of key = {json}:

Key On the ticker
md/v1/health ● degraded, green for healthy/ok/up, amber for degraded/warning/recovering, red for down/failed/error
md/v1/usage ▮▮▮▮▮▮▮▮▯▯ 82/100 % CPU, amber from 80% and red from 95%
md/v1/traffic 40/s · ✕7 · 180ms, with errors amber from 1 to 9 and red from 10
md/v1/banner ⚑ Load test until 5pm in its level's color
md/v1/links 🔗 Grafana, runbooks.example.com: http(s) links only, at most 8, a link without a label named by its host
A key a widget annotation pins That widget, which wins over the well-known one

The thresholds, levels and link rules follow the UI's shared/annotations (widgetViews.js, canvasWidgets.js, traffic.test.js). The key is left off: the emoji (🩺 📊 📈 📣 🔗) and the widget say what changed, and the key shows only when the value has nothing to show, as for a deleted key. Only keys a widget draws, well-known or pinned, reach the ticker or rise over the map. A script's other keys stay quiet. Lines, including the scope prefix for non-environment scopes, are cleaned of control characters and clipped to 60 cells.

Graph.StashEvent now takes the annotations and the stash, which it needs to resolve a pinned widget's other inputs. Event gains Widget, the colored line. Detail stays plain text for write-ups and replays.

🤖 Generated with Claude Code

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

Copy link
Copy Markdown
Member Author

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 1m 36s —— View job


Review of #284: Draw stash values on the ticker as their widgets

The change is clean and follows the layering rules in CLAUDE.md. go test ./internal/commands/dashboard/ passes and go vet is clean. I didn't run make check (lint) or make docs.

What I checked

  • StashEvent keeps Detail as plain text by stripping Widget, and TestStashEvent asserts the two agree.
  • Every line starts with its key, including pinned widgets, so a change always says which key moved.
  • Escape handling holds: TestTickerWidgetStripsEscapes covers OSC 8 links, CSI sequences and bidi overrides in the value, the key and the link labels.
  • Clipping is cell-aware. Widgets go through ansi.Truncate and text through clip, and the test asserts the output never exceeds 60 cells.
  • Table-driven tests with a color assertion (painted) cover the thresholds. The edge cases are included: usage past its max, a missing max, a missing pinned input, and a well-known key in the wrong format.

Suggestions (none blocking)

  1. Non-deterministic lookup. wellKnownWidget (tickerwidgets.go) ranges over the widgetSpecs map to match spec.key == c.Key. If two specs ever share a key, the one chosen varies from run to run. Sorting the keys, or building a key→surface index, would make this deterministic.
  2. CLAUDE.md comment rule. The doc comment on the unexported tickerRoom const restates what the code says. The rules say no doc comments on unexported helpers, so I'd drop it. The "Uncleaned, unlike Apply…" and "The UI's header names…" comments explain why, so they're fine.
  3. Scope prefix is outside the 60-cell budget. In StashEvent, the kind id · prefix for non-environment scopes is added after truncation. Those lines can run wider than 60 cells by roughly the length of the scope. This is probably acceptable, since the old code behaved the same way, but the PR description says values are clipped to 60.
  4. Unchecked integer conversions. int(errs) in the traffic widget can overflow on absurdly large JSON numbers, and negative or NaN-like values aren't guarded. The effect is a cosmetic wrong number, not a crash.
  5. Cost of withEntry. It clones the whole stash map for every change. That's fine at current sizes, but a burst of stream updates will do this per event.
  6. Test gap. There's no case for the pinned-wins-over-well-known precedence the PR describes. A pinned annotation on md/v1/health, or on a key that also has a well-known widget, would lock that in.

Overall this looks good to merge, with the optional cleanups above.

coryodaniel and others added 2 commits November 28, 2026 01:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	internal/commands/dashboard/api.go
#	internal/commands/dashboard/stash.go
#	internal/commands/dashboard/stash_test.go
@coryodaniel

Copy link
Copy Markdown
Member Author

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 1m 44s —— View job


Review of #284: Draw stash values on the ticker as their widgets

go test ./internal/commands/dashboard/ passes. I didn't run make check (lint) or make docs.

The code follows the layering and test rules in CLAUDE.md. Widgets are cell-clipped and escape-stripped, and the tests cover thresholds, clipping and escapes. One correction to the earlier review and a few findings follow.

Correction to the previous review

It said every line starts with its key. That is wrong, and so is the PR description ("Every line still starts with its key, so a widget pinned to any key says which key changed"). After c03f98b the key is left off unless there is nothing else to show:

  • TickerWidget returns the bare widget or value (● down, 82/100 % CPU).
  • The tests assert this, for example Detail: "● down now", and the stash_test.go ticker expectations no longer contain the key.
  • The table rows in the PR body (● degraded, ⚑ Load test until 5pm) agree with the code.

Suggestion: update the PR description to match. The emoji (🩺, 📊) and the scope prefix now carry the context. Two different keys that both draw as ● down can't be told apart on the ticker, except by the emoji.

Findings

  1. Scope prefix is outside the 60-cell budget (stash.go, StashEvent). The kind id · prefix is added after TickerWidget truncates, so project, team or other non-environment lines can run well past 60 cells. The PR says values are clipped to 60. Either reword the PR, or budget tickerRoom minus the prefix width.
  2. Conversion before clamping (tickerwidgets.go, drawWidget). int(value/limit*usageBarCells+0.5) runs before the min/max clamp. For +Inf, NaN, or values past int range, Go leaves the result implementation-defined, so the clamp can't be relied on. Clamp the float first. int(errs) in the traffic widget has the same problem, and a negative errs is skipped only because of the > 0 guard. The effect is cosmetic.
  3. Non-deterministic lookup (wellKnownWidget). It ranges over the widgetSpecs map matching spec.key. If two surfaces ever share a key, the winner changes between runs. Today the keys look distinct, so this is latent. Sorting the names would make it deterministic.
  4. Doc comments on unexported identifiers. CLAUDE.md says none on unexported helpers. This applies to the tickerRoom comment. The Widget field comment on Event is on an exported field, so it's fine. The "Uncleaned, unlike Apply…" and "The UI's header names…" comments explain why and are fine.
  5. Test gap: pin vs. well-known. The PR says a pinned widget wins over the well-known one. pinnedWidget is tested only on a non-well-known key (db/connections). Add a case with a pinned annotation on md/v1/health or md/v1/usage that resolves to a different drawing.
  6. Cost of withEntry. It clones the whole stash map and the affected scope's map for every change, and StashEvent runs once per change in takeStash. That's fine now. A burst of stream updates will be O(changes × stash size).

None of these block the merge. I'd fix the description (above) and finding 2 before merging.

coryodaniel and others added 3 commits November 28, 2026 01:35
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, and keep prefixed lines in budget

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

Copy link
Copy Markdown
Member Author

Fixed in 0eb6158, with #282 merged in:

  • Description: corrected. The key is left off the ticker, and only keys a widget draws reach it.
  • 2: usage fill and error counts are clamped as floats before converting to int.
  • 3: wellKnownWidget walks the widget names in sorted order.
  • 1: a scope-prefixed line is truncated to the 60-cell budget after the prefix is added.
  • 4: the tickerRoom comment is gone.
  • 5: a new case pins a usage widget to md/v1/usage against a different max, and the pin wins (40/50, amber).

No change:

  • 6: withEntry copies only the outer stash map and the one changed scope. That's cheap enough for the batches the stream sends.

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 1m 44s —— View job


Review of #284: Draw stash values on the ticker as their widgets

go test ./internal/commands/dashboard/ passes. I didn't run make check (lint) or make docs.

All six points from the last round are addressed in 0eb6158:

  • Usage fill and error counts are clamped as floats before int().
  • wellKnownWidget walks slices.Sorted(maps.Keys(widgetSpecs)).
  • The scope-prefixed line is truncated after the prefix is added.
  • The tickerRoom comment is gone.

I found nothing blocking. These are all minor:

  1. Deleted keys in non-environment scopes carry no scope prefix (stash.go, StashEvent). The prefix is skipped when c.Entry == nil, so a deleted project-scoped key reads as just the faint key. The old code behaved the same way. Two scopes that delete the same key are indistinguishable on the ticker, apart from the event ID. If that matters, drop the c.Entry != nil condition.

  2. The emoji is set in two places (stash.go and feed.go). StashEvent sets Emoji: StashEmoji(c.Key, ...), then takeStash overwrites it with the Newsworthy emoji. For a pinned widget on a key like db/connections, StashEvent alone gives a different emoji than the feed does. Replays or other callers of StashEvent would get the key-based one. Computing it once, inside StashEvent, would keep them consistent.

  3. withEntry is redundant on the live path. takeStash sets m.stash = st before calling StashEvent, so the stash passed in already contains the change. The re-apply is harmless and probably still needed for other callers, so I'd leave it.

  4. Newsworthy ranges over widgetSpecs. It returns on the first match, and the emoji depends only on the key, so the order doesn't change the result. It could be a direct key lookup, but this isn't worth changing.

  5. Test gap. The new pin-wins case covers md/v1/usage. There's still no case for a deleted key in a non-environment scope, which would lock in the behavior in point 1 either way.

Good to merge from my side. Point 2 is the one I'd consider fixing first.

Base automatically changed from dashboard-ergonomics to dashboard November 30, 2026 06:12
@coryodaniel
coryodaniel merged commit 2e7a13a into dashboard Nov 30, 2026
2 checks passed
@coryodaniel
coryodaniel deleted the dashboard-ticker-widgets branch November 30, 2026 06:12
@coryodaniel

Copy link
Copy Markdown
Member Author

Folded into #272.

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