Skip to content

Read md/v1/health as JSON with a state and a color - #307

Merged
coryodaniel merged 5 commits into
mainfrom
health-v2-object
Dec 1, 2026
Merged

coryodaniel merged 5 commits into
mainfrom
health-v2-object

Conversation

@coryodaniel

@coryodaniel coryodaniel commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Refs massdriver-cloud/massdriver#3914

Server: https://github.com/massdriver-cloud/massdriver/pull/3915

This changes md/v1/health from text to JSON. The dashboard reads it as {"state": "Rolling out", "color": "blue"}:

  • state (required) is the word shown with the dot.
  • color (optional) is green, amber, red, blue, purple, gray, or a #RRGGBB hex color. Without it, the dot takes the color of the state, as before.

A text value under md/v1/health no longer shows on the dashboard. Write the JSON form instead:

mass alpha stash set billing-dev-app.md/v1/health \
  '{"state": "Rolling out", "color": "blue"}' \
  --format json --ttl 600

The key name is the same, so the dashboard keeps using stash.KeyHealthV1 from the SDK. The tutorial, the help docs, and the generated docs now use the JSON form.

🤖 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 30, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 27s —— View job


Review of #307: color health dots from md/v2/health

The change looks correct and is well tested. I read the diff and the surrounding code but did not run make check or make docs. The points below are small.

What I checked

  • md/v2/health is tried first and md/v1/health is the fallback (automaticNewest, widgets.go). The v1 TEXT path still works, and TestWidgetsFromWellKnownKeys covers a v2 entry beating a v1 one.
  • statusDotColor handles the named colors, a #RRGGBB hex and the state fallback. The ticker tests cover each of these, including an invalid hex.
  • clearStash resets HealthColor, so no stale color is left behind.
  • The pinned instance.status_dot widget accepts a color input, and TestPinnedWidgets covers it.

Suggestions

  1. The ticker can disagree with the dashboard. wellKnownWidget in tickerwidgets.go uses specFor, which also matches the v1 key. If an instance has both keys and a script updates md/v1/health, the ticker draws that v1 value. The dashboard still shows the v2 state, because v2 wins. Before drawing a v1 change, check whether the same scope has a valid v2 entry and skip it if so. This only matters when both keys are set, so it may not be worth fixing.

  2. An invalid v2 entry falls back to v1. A md/v2/health entry with no state, or with a non-string one, fails resolve, so v1 is used. That is probably the intended behavior, but the PR text says "v2 wins when an instance has both keys". Either confirm the fallback is intended or add a test for it.

  3. color is cleaned differently on the two paths. The graph path uses clean(str(v, "color")) (widgets.go). The ticker path in drawWidget passes str(v, "color") through raw, while state is trimmed. A color like " red" or "red\n" would be rejected on the ticker and, depending on what clean does, possibly accepted on the dashboard. Trimming it in statusDotColor would make both paths behave the same.

  4. Doc comments on unexported helpers. CLAUDE.md says there are none on unexported helpers. The new comments on statusDotColor (theme.go), olderSpecs and automaticNewest (widgets.go) fall under that rule. The "read only when the newest one is not set" note on olderSpecs is the one comment that explains why, so I would keep it. I would drop the other two or fold them into it.

  5. Small cleanup. hexColor is declared after statusDotColor in theme.go. Move it above the function, or into a var block with the other package-level values.

  6. Missing unit test. statusDotColor has no direct test. The ticker table covers every branch except green and red, and detail.go and scene.go have no test of their own. A small table in a theme_test.go for statusDotColor would fix that.

  7. Local constant. keyHealthV2 is defined locally because the SDK has no stash.KeyHealthV2 yet. When the SDK adds one, switch to it. This follows the "SDK owns the shared definitions" principle in CLAUDE.md.

Docs and helpdocs are updated in both docs/helpdocs and docs/generated. CI will regenerate the docs and fail on any diff, so run make docs once more to be sure.

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

Copy link
Copy Markdown
Member Author

Fixed:

  • 4: Removed the comments on statusDotColor and automaticNewest. The olderSpecs comment stays.
  • 5: hexColor now sits above statusDotColor.
  • 6: The ticker table now covers green, red, and gray too, so every branch of statusDotColor has a case. The repo keeps tests on the exported surface, so no theme_test.go.

Not fixed:

  • 1: The ticker shows the change that happened, with its own value. A md/v1/health write is still a real write to that key. The map shows the v2 state, as the server does.
  • 2: The server checks every md/ write against the key's schema, so a md/v2/health entry without a string state cannot exist. No extra test.
  • 3: Same reason. The server accepts only the six names or #RRGGBB, so " red" or "red\n" cannot reach either path.
  • 7: The SDK has no KeyHealthV2 yet. The CLI switches to it once the SDK adds it.

@coryodaniel

Copy link
Copy Markdown
Member Author

@claude please review.

@claude

claude Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

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


Re-review of #307

I read the full diff and ran go test ./internal/commands/dashboard/. It passes. I did not run make check or make docs.

Your replies to my earlier review

  • Points 4, 5 and 6 look resolved.
  • Points 1, 2 and 7 are fine as you explain them.

One caveat on point 3

  • Your argument holds for md/v2/health, because the server checks that key's schema.
  • It does not hold for a widget pinned to instance.status_dot. Its color input can read any stash key, for example status/color in TestPinnedWidgets, and the server does not check those values.
  • A pinned value like " red" would fall back to the state color on both the graph and the ticker. That is harmless and the two paths agree, so nothing needs fixing.
  • The graph path runs clean(...) on the color and the ticker path passes it through raw. Pinned input is the only way an odd value gets there, so I would not change anything for it.

Anything else
I found no bugs. These parts check out:

  • v2 is tried first and v1 is the fallback.
  • clearStash resets HealthColor.
  • Newsworthy and StashEmoji handle the v2 key.
  • The pinned state and color inputs resolve correctly.
  • The tests cover every named color, a hex color, no color and an invalid hex.

The PR looks good to merge once CI is green. CI regenerates the docs, so it will flag any make docs diff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coryodaniel coryodaniel changed the title Color the dashboard's health dots from md/v2/health Read md/v1/health as JSON with a state and a color Nov 30, 2026
@coryodaniel

Copy link
Copy Markdown
Member Author

@claude please review.

@claude

claude Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

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


Review of #307: read md/v1/health as JSON with a state and a color

I read the diff and ran go test ./internal/commands/dashboard/, which passes. I did not run make check or make docs. This is a different change from the one I reviewed earlier. The md/v2/health key is gone, and md/v1/health is now JSON.

One bug: the canvas map ignores color

scene.go:420-423 still colors an instance's dot on the map from the state alone:

case healthColor(inst.Health) == colorRed && s.Frame%6 < 3:
    return colorRedDim
case inst.Health != "":
    return healthColor(inst.Health)

This PR switched the side panel (detail.go) and the ticker (tickerwidgets.go) to statusDotColor. The ring dots on the canvas were not switched. As a result, {"state": "Rolling out", "color": "blue"} shows a blue dot in the side panel and on the ticker, but a gray dot on the map. The map is the place the PR text says the dashboard "takes the color" from. The tests don't catch this because none of them render the scene's dot color for an instance with a HealthColor.

Suggested fix: use inst.dotColor() in both cases, so the red blink also applies to "color": "red".

dc := inst.dotColor()
...
case inst.Health != "" && dc == colorRed && s.Frame%6 < 3:
    return colorRedDim
case inst.Health != "":
    return dc

The first case needs the inst.Health != "" guard. Without it, an empty health would take the red-blink branch only if healthColor("") is red, which it is not, so the guard keeps the old behavior. Add a scene test with a colored health, as the rest of the scene tests do.

Smaller points

  1. The ticker passes color through raw. drawWidget calls statusDotColor(strings.TrimSpace(state), str(v, "color")), and the graph path runs clean(...) on it. The server only accepts the six names or #RRGGBB, so the two paths agree for any value the server accepts. A pinned widget can still read an arbitrary key, and there both paths fall back to the state color. Nothing needs changing.
  2. A text value under md/v1/health is now dropped. This is intended, and the PR text says so. TestWidgetsFromWellKnownKeys covers it with billing-dev-app. The ticker table covers it with "well-known key in the wrong format", which draws the raw down.
  3. Docs are consistent. docs/helpdocs and docs/generated carry the same text, and the example uses --format json. CI will confirm that make docs produces no diff.

Everything else checks out. The widget spec now declares format: "JSON" with state required and color optional. clearStash resets HealthColor. The tutorial's demo data uses the JSON form.

The scene dot is the one change I would make before merging.
· branch health-v2-object

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

Copy link
Copy Markdown
Member Author

Fixed:

  • The map now draws the health color. instanceColor uses inst.dotColor() for both the red blink and the dot color, so "color": "red" also blinks. TestSceneDrawsHealthColor covers it and fails without the fix.

Not changed:

  • The inst.Health != "" guard on the blink case. dotColor() with an empty health and no color falls back to healthColor(""), which is gray, so the case cannot match. state is required, so a color never comes without a health.
  • Smaller points 1 to 3: the review says no change is needed.

@coryodaniel

Copy link
Copy Markdown
Member Author

@claude please review.

@claude

claude Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

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


Review of #307: read md/v1/health as JSON with a state and a color

The map fix from the last round is in and I found no new problems. I read the diff and ran go test ./internal/commands/dashboard/, which passes. I did not run make check or make docs.

Map color

  • instanceColor in scene.go now uses inst.dotColor() for both the red blink and the dot color. "color": "red" now blinks too.
  • healthColor( is now called only from statusDotColor. The side panel, the ticker, the map and the pinned widget all go through the same function.
  • TestSceneDrawsHealthColor checks that the map draws a #AB12CD health color.

Your reply on the inst.Health != "" guard

  • I agree it isn't needed. With an empty health and no color, dotColor() falls back to healthColor(""), which is gray, so the blink case can't match.

Checked and fine

  • The health widget spec now declares JSON, with state required and color optional.
  • clearStash resets HealthColor.
  • A text value under md/v1/health is dropped. TestWidgetsFromWellKnownKeys covers this with billing-dev-app.
  • The ticker table covers all six named colors, a hex color, no color and an invalid hex.
  • The tutorial demo data and the help text use the JSON form.

I have no further changes to suggest. The PR looks good to merge once CI is green. CI regenerates the docs, so it will flag any make docs diff.
· branch health-v2-object

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 30, 2026 •

Copy link
Copy Markdown

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


Review of #307: read md/v1/health as JSON with a state and a color

I found no new problems. I read the full diff against origin/main and ran go test ./internal/commands/dashboard/, which passes. I did not run make check or make docs.

Checked

  • healthColor is now called only from statusDotColor. The side panel, the ticker, the map's red blink and dot color, and the pinned instance.status_dot widget all go through dotColor() or statusDotColor.
  • The health widget spec declares format: "JSON", with state required and color optional. The pinned widget accepts a color input, and TestPinnedWidgets covers it.
  • clearStash resets HealthColor, so no stale color is left behind.
  • A text value under md/v1/health is dropped. TestWidgetsFromWellKnownKeys covers this with billing-dev-app.
  • Test coverage:
    • The ticker table covers all six named colors, a hex color, no color and an invalid hex.
    • TestSceneDrawsHealthColor covers the map.
    • The stash tests and the tutorial demo data use the JSON form.
  • The md/v1/health help text and the generated docs show the same JSON example.

The PR looks good to merge once CI is green. CI regenerates the docs, so it will flag any make docs diff.
· branch health-v2-object

@coryodaniel
coryodaniel merged commit 65ba14c into main Dec 1, 2026
5 checks passed
@coryodaniel
coryodaniel deleted the health-v2-object branch December 1, 2026 00:04
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