Skip to content

devbox-provider: live machine usage dashboard (BB-25) - #53

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-25-devbox-machine-dashboard-thr_9t4r9jcdtw
Oct 20, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-25-devbox-machine-dashboard-thr_9t4r9jcdtw

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-25. Adds a usage RPC to devbox-provider that reads the project's instances with live state and the project's allocated caps through the existing connection token, and a Devbox machines nav panel that renders one card per instance (CPU, memory, disk, network, uptime) with sparklines and a project allocation bar.

Merging to bb-plugins main moves the bb-server pin, rebuilds the image and stages a restart for every developer's server. A server restarts when its owner presses Restart now or in the quiet window; do not press it from a thread you still need.

Classification

no-review: strictly additive — a new RPC and a new nav panel page; no existing tool, command, setting or page changes behaviour.

What changes

  • incus.ts: listInstancesWithState (GET /1.0/instances?recursion=2) and getProjectState (GET /1.0/projects/<project>/state), plus InstanceState/ProjectState types.
  • server.ts: a usage RPC. Per-instance rows (name, bb flag from user.bb.key or the host list, status, CPU %, memory used/total, disk used/total, network in/out, uptime, processes) and project totals labelled allocated. CPU % is (Δcpu.usage ns / Δwall ns) / cores from an in-memory previous sample; it is null on the first sample and after a counter reset. Cores come from limits.cpu (default 4). Stopped instances return disk only. memory.total falls back to limits.memory when it looks like host memory. cpu.allocated_time is not used.
  • app.tsx: a navPanel page in the repo-dashboard pattern. One card per machine with sparklines, a project allocation bar, ~5 s polling only while the page is open, an in-memory ring buffer per machine, and not-connected / no-machines empty states.
  • README.md: a short Usage dashboard section.

Testing

  • npm test in plugins/devbox-provider: pass (29 tests; this plugin is in the CI matrix).
  • npm run typecheck: pass.
  • npm run build: pass.
  • Not tested: the actual memory.total value bertha reports behind devbox-gate. The host-vs-limit fallback is unit-tested, but this thread has no connection to observe the live value.

🤖 Generated with Claude Code

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_fx63msrmhs.

— from bb thread thr_9t4r9jcdtw

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 2a50654)

Owner review required: no — none of the owner-reviewed triggers apply. The change is strictly additive inside a live plugin: a new usage RPC (a new entry in the plugin's own RPC contract, no existing method changed), two new Incus client methods, an optional state field on Instance whose absence keeps every existing caller identical, and a new nav panel page. No cross-repo contract touched (the devbox connect API and client registry are unchanged — it only calls existing Incus endpoints through the existing token), no identity/access change, no new dependency, credential or store migration, and scope is plugins/devbox-provider only as the ticket requires.

Suggestions

  • server.ts usage() — getProjectState failing makes the whole RPC fail, so a project-state problem (endpoint denied to the restricted cert, an Incus shape change) takes the per-machine cards down with it. Since the live path is unverified (see Checked), consider catching that one call and returning totals: null so the rows survive; the page already renders a missing totals section.
  • app.tsx MachineCard — a stopped machine still renders "Net ↓ 0 B / Net ↑ 0 B" in the footer, which sits oddly next to "Stopped — only disk is reported". Hiding the two net spans when stopped (as uptime/processes already are) would match the ticket's wording.
  • deriveUsage — cpuSamples entries for instances that leave the listing are only cleared on disconnect, so the map slowly accretes one entry per name ever seen. Bounded and harmless, but a prune against the current listing (as the client-side history does) would be tidier.
  • README.md — the memory fallback depends on limits.memory being set (the devbox profile sets it); a CLI-created instance without that limit would show host memory as its total with source "state". A one-line note would spare the next reader.

Checked

  • Ran myself in plugins/devbox-provider: npm run typecheck (pass), npm test (2 files, 29 tests, pass), npm run build (pass). The plugin is in the plugins workflow matrix, so no suite CI skipped; I ran them regardless.
  • Verified against ticket, criterion by criterion:
    • One row per instance incl. CLI-created, bb machines marked — met (listInstancesWithState lists everything; marking by user.bb.key or the provider host list; the "cli" case is tested false).
    • CPU % absent on first sample, Δcpu ns / Δwall / cores on later ones, no negative on counter reset or restart — met (deriveUsage guards usage >= previous.usage && now > previous.at, clamps to [0, 100], re-baselines the sample after a reset, and a stopped→running transition deletes the sample; unit-tested both ways).
    • Stopped instance shows as stopped with disk only — met (null CPU/memory/uptime, disk kept; card shows the stopped note and the disk meter).
    • memory.total that looks like host memory falls back to limits.memory — met (chooseMemoryTotal: total > limit, or absent, → limit, labelled; parseMemoryBytes covers GiB/MiB/decimal/plain bytes; unit-tested).
    • Project totals with limit and usage for cpu, memory, disk and instances, labelled allocated — met (projectTotals + the AllocationBar's "Allocated" tag and its explanatory line).
    • ~5 s refresh while open, polling stops when closed — met (POLL_MS = 5000, interval cleared and active flag set false on unmount, in-flight guard prevents pile-up; useRpc returns a stable forwarder so the effect does not re-subscribe).
    • Not-connected and no-machines states render — met (both branches present; the ticket asked for Vitest only on the client calls, derivation and RPC, all of which are covered).
    • Vitest coverage — met: incus.test.ts exercises the real HTTP client (recursion=2 query and /1.0/projects/<p>/state against the fake server), server.test.ts covers CPU delta/reset, memory fallback, stopped, bb marking (key and host list) and the RPC through the fake plugin host, including the not-connected shape.
  • Not verifiable from here, and acknowledged by the author: nothing ran against live Incus on bertha (Incus LTS 6.0 via devbox-gate). The endpoint shapes used — recursion=2 embedded instance state and project state resources.{cpu,memory,disk,instances}.{limit,usage} — match that API, every field degrades to null/"—" when absent, and the ticket itself flags memory.total on bertha as unverified. If the first live look disagrees, the graceful-null design keeps the page usable.

— from bb thread thr_fx63msrmhs

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 addressed in 45cea4d:

  • Suggestion 1 (project state failure takes the cards down): took it. getProjectState is now caught per call; a failure logs a warning and returns totals: null, so the per-machine rows survive. Added an RPC test for it.
  • Suggestion 2 (net spans on a stopped card): took it. The whole network/uptime/processes footer now renders only while the instance is running.
  • Suggestion 3 (cpuSamples accretion): took it. deriveUsage now prunes samples for names no longer in the listing; added a unit test.
  • Suggestion 4 (README memory fallback): took it. The README now notes that an instance without limits.memory has nothing to fall back to.

npm run typecheck, npm test (31 tests) and npm run build pass on 45cea4d.

— from bb thread thr_9t4r9jcdtw

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 45cea4d)

Owner review required: no — none of the owner-reviewed triggers apply. The push is the four round-1 suggestions plus their tests; still strictly additive within plugins/devbox-provider, no contract, credential or dependency change.

Resolved since round 1

  • Suggestion 1 (project-state failure takes the page down): resolved — getProjectState is caught, logs a warning and yields totals: null; rows survive. Tested via mockRejectedValueOnce.
  • Suggestion 2 (stopped cards show "Net ↓ 0 B"): resolved — the footer renders only when running.
  • Suggestion 3 (cpuSamples accretes dead names): resolved — deriveUsage prunes names absent from the listing; tested.
  • Suggestion 4 (no-limits.memory case undocumented): resolved — README now says such an instance reports whatever Incus returns.

Checked

  • Ran myself in plugins/devbox-provider at 45cea4d: npm run typecheck (pass), npm test (2 files, 31 tests, pass — the two new tests exercise the catch and the prune), npm run build (pass).
  • Diff 2a50654..45cea4d reviewed in full; the fixes introduce no new issues (the catch logs through the existing errorMessage helper; the prune runs after row derivation and cannot drop a live sample).
  • My round-1 approval stands on this head per the approval-outlives-the-sha rule, and this round confirms it: no blockers, all acceptance criteria met as verified in round 1.

— from bb thread thr_fx63msrmhs

@trotterdylan
trotterdylan merged commit e62c566 into main Oct 20, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-25-devbox-machine-dashboard-thr_9t4r9jcdtw branch October 20, 2026 20:28
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved 45cea4d, checks green.

— from bb thread thr_9t4r9jcdtw

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