Skip to content

Refresh only what changed, and skip annotations for service accounts - #289

Merged
coryodaniel merged 5 commits into
dashboardfrom
dashboard-light-refresh
Nov 30, 2026
Merged

coryodaniel merged 5 commits into
dashboardfrom
dashboard-light-refresh

Conversation

@coryodaniel

Copy link
Copy Markdown
Member

Stacked on #286.

Lighter on the API, from the platform team's notes.

Annotations and service accounts. A service account never sends alphaAnnotations: the dashboard asks Viewer.Get once per session and skips annotations when the viewer is KindServiceAccount. For anyone else, a refusal (403, FORBIDDEN, or "permission"/"service account" in the message) stops further calls for the session. Refusals show no error. The legend's red "need a personal access token" line is gone, and other failures still get the muted note.

What a refresh reads.

When Before After
--refresh tick (default 30s) dashboardEnvironments for each ring, plus runtimes, applications, annotations dashboardEnvironmentStatus for the environment ids already in view
Every environment in view streaming as above nothing; the timer only re-arms (while the audit log is polled)
Deployment or alarm event in view full read status read
instance.created, instance.deleted, instance.moved, connection.created, connection.deleted in view; any remote_reference.* or environment_default.* full read full read
Start, refocus, search, r, after approve or deploy full read full read

The status query returns each instance's status, deployed version, available upgrade, firing alarm count, alarms, bundle, latest provision and latest deployment. It's merged into a copy of the snapshot. Environments, dependencies and instances it doesn't already know are ignored, so the graph keeps its shape and nothing on the map moves. The full query keeps its name, dashboardEnvironments, so call counts compare by operation. Cost stays in the full read, since it's last month's figure. Both queries go through the complexity retry. The recorded and tutorial APIs serve the status query from their data.

Forks (environment.*) and link.* events name no environment, so they trigger nothing. A new fork shows after a refocus or r.

🤖 Generated with Claude Code

coryodaniel and others added 2 commits November 28, 2026 10:21
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 33s —— View job


Review of #289: refresh only what changed, skip annotations for service accounts

I read the diff against dashboard-postmortem and checked it against applySnapshot, environmentFields and after. I did not run make check, the tests or make docs, so those still need a CI pass.

Verdict: The design is sound and I found nothing blocking. The status query selects the same sub-fields as environmentFields for everything it overwrites (bundle, latestProvision, latestDeployment, alarms). Because of that, the merge in withStatus can't drop fields the views rely on. cost, dependencies and resources stay untouched, so the graph shape is stable. after(0, …) returns nil, which matches the flag text for --refresh 0.

Worth a look

  1. notesForbidden matches on message substrings (annotations.go). strings.Contains(msg, "permission") will also swallow unrelated errors, such as an upstream proxy or network error that happens to say "permission denied". With the sticky noNotes flag, one such error silences annotations and hides the muted note for the rest of the session. Consider limiting the substring checks to errors where gql.ClassifyError returns nothing more specific. Alternatively, only set the sticky flag on the classified ErrForbidden and let the substring cases suppress the note without latching.

  2. A status event is dropped while a read is in flight (readAfter, status.go). The status && !m.loading guard means a deployment event that arrives during a full read is ignored. If the full read started before the event, the map can show stale status until the next tick. The old deployed && !m.loading code did the same, so this isn't a regression. It matters more now that, when every environment in view streams, the tick does nothing. In that case the only recovery is the next event. A pendingStatus flag that fires one status read when loading clears would close the gap. This is optional.

  3. Broad full-read triggers. remote_reference.* and environment_default.* trigger a full read for any environment, in view or not, and layout bypasses the loading guard. This is intended per the PR description. On an org with heavy remote-reference churn it could be chatty, because each event cancels and restarts a full read. Debouncing would be cheap if it shows up in practice.

  4. whoOnce consumes the context of the first caller. If the first Viewer.Get fails, for example because that fetch was cancelled, the result is never retried. A service account would then fall through to one 403 on alphaAnnotations, which notesForbidden catches, so the outcome is correct. It's only a wasted call. A one-line note on that fallback would help the next reader.

Nits

  • The refreshStatus doc comment ends with "and read it then", which is ambiguous. Something like "…so the status is read only when one arrives" would be clearer.
  • recordedAPI.EnvironmentStatus returns full environments, which is fine because withStatus picks only the fields it needs. The tutorial API does the same.

Tests

The status merge and the annotation gating are covered. I'd add one case to status_test.go for readAfter with a status event while loading is true. It would pin down the behavior in item 2, whichever way you decide it.

coryodaniel and others added 2 commits November 28, 2026 10:37
…vents that land during a read

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

Copy link
Copy Markdown
Member Author

Fixed in ea1cc0b, with #286 merged in:

  • 1: only a classified refusal (403 or a FORBIDDEN code) stops annotations for the session. A message that merely mentions "permission" hides the error for that read but doesn't latch.
  • 2: a deployment or alarm event that arrives during a read sets pendingStatus, and one status read runs when that read lands. TestStatusEventDuringARead fails without the fix.
  • 3: there's now a WHY comment on the viewer-check fallback, and the refreshStatus comment is reworded.

No change:

  • Item 3, the broad full-read triggers: kept as described. Debouncing can come if the org's remote-reference churn shows up.

@claude please review.

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 2m 4s —— View job


Review of #289 after ea1cc0b

I read status.go, annotations.go and the model.go and focus.go changes. I ran go test ./internal/commands/dashboard/ and it passes. I did not run make check (lint) or make docs.

Verdict: All three fixes do what the comment says, and I found nothing blocking.

  • Annotation latch: Annotations latches noNotes only when forbidden(err) is true, which means gql.ClassifyError returned ErrForbidden. A message that only mentions "permission" or "service account" hides the error through notesRefused but doesn't stop later calls. readAnnotations applies the same rule.
  • Viewer check fallback: mayAnnotate now has a comment on why a failed Viewer.Get is fine. A service account falls through to one classified 403, which latches.
  • Event during a read: readAfter sets pendingStatus when a status event arrives while loading is true. applyRead runs one status read after the in-flight read lands. TestStatusEventDuringARead checks the sequence: the event lands mid-read, then one status read follows and no extra layout read.

Things I checked

  • Cancelled reads: A read that a newer one cancelled returns early in applySnapshot because its seq no longer matches. loading stays true, so applyRead doesn't fire the pending read early, and it runs when the latest read lands.
  • Failed read: pendingStatus is also consumed after a failed read. That costs at most one extra status read per event and falls back to a full read if m.snap is nil. This is fine.
  • Layout read replacing a pending status read: If a layout event starts a full read while pendingStatus is set, the status read still runs after it. It is redundant, since the full read already carries the newer status, but harmless. You could clear pendingStatus in fetch() to save one call. This is optional.

Nits

  • notesRefused still returns true on any error text containing "permission", so a flaky proxy error with that word is hidden for one read and retried on the next. That is the behavior you described, and it only costs a call per tick.
  • refreshStatus re-arms the timer with after(m.cfg.Refresh, …). When Refresh is 0, after returns nil, so the timer ends. This matches the flag text.

No change requested for the full-read triggers. Keeping them as described is reasonable.

Each poll re-reads the last 30 seconds, so a busy org filled the read with
events already shown and the footer said so on every poll. A full read also
carries the newest status, so it clears a pending status read.

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

Copy link
Copy Markdown
Member Author

f1abfdb:

  • Cut-short toast: each poll re-reads the last 30 seconds, so on a busy org the read filled with events already shown and the footer said "more than 500 events" on every poll, hiding the key line. It now shows only when the oldest event read is newer than the last one seen. TestModelEvents covers both: a cut-short read inside the overlap stays quiet, and one past it says so.
  • Pending status read: fetch() clears pendingStatus, since a full read carries the newer status. Taken from your optional note.

No change: notesRefused hiding a "permission" message for one read, and --refresh 0 ending the timer, are both as intended.

@claude please review.

@claude

claude Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 2m 14s —— View job


Review of #289 after f1abfdb

I read the model.go change and its test, and traced readAudit, freshEvents and pendingStatus. I ran go test . in internal/commands/dashboard and it passes. I did not run make check (lint) or make docs. This commit doesn't touch commands, flags or helpdocs.

Verdict: Both changes are correct and I found nothing blocking.

Cut-short toast (model.go:613)

  • readAudit pages newest-first, then reverses, so Events[0] is the oldest event of the newest N. If it is newer than m.since, events between since and it were missed, and the toast is right to show. If it is at or before m.since, the read only filled up with events already seen.
  • The check runs before freshEvents advances m.since, so it compares against the previous poll's high-water mark, as intended.
  • The new test covers both sides. The overlap case reuses api.eventReads[:3], so the two cases share fixtures.

fetch() clears pendingStatus (model.go:266)

  • fetch() is the only caller of startRead for full reads. Clearing the flag there is safe because an event that sets the flag mid-read sets it again after fetch() has run.
  • A status event that lands during the new read re-latches it, so nothing is lost.

Nits

  • Stash events and m.since. freshEvents skips stash* events with continue before advancing m.since. On an org whose busy traffic is mostly stash events and whose other events are quiet, m.since lags behind. A truncated poll could then have a stash event as Events[0] that is newer than since, and the toast would show on every poll again. This is an edge case. If it matters, advance m.since before the stash continue.
  • Equal timestamps. Events[0].At.After(m.since) is false when the two are equal. An event with the same timestamp as the high-water mark but a different ID could be missed without a toast. That is very unlikely, and !Before would flip the trade-off toward false positives, so I'd leave it.
  • Wording. The toast says "more than 1 events" when the limit is 1, which only happens in the test fixture. The real limit is eventLimit, so there's nothing to change.

No changes requested.

Base automatically changed from dashboard-postmortem to dashboard November 30, 2026 06:12
@coryodaniel
coryodaniel merged commit 55e2486 into dashboard Nov 30, 2026
2 checks passed
@coryodaniel
coryodaniel deleted the dashboard-light-refresh 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