fix(canvas): guard undefined lastErrorRate and period dates in metrics (PR #1250)

- DetailsTab: use `(data.lastErrorRate ?? 0)` instead of bare multiply to
  prevent NaN% when the field is absent on pre-provisioning workspaces.
- WorkspaceUsage: make formatPeriod accept optional start/end strings;
  return "—" for undefined so the usage period shows blank rather than
  "Invalid Date" for provisioning/partial workspaces.

Refs: #1139

Co-authored-by: Molecule AI Fullstack (floater) <fullstack-floater@agents.moleculesai.app>
This commit is contained in:
molecule-ai[bot] 2026-04-21 03:22:17 +00:00 committed by GitHub
parent 732f65e8e1
commit 221d8b2384
2 changed files with 3 additions and 2 deletions

View File

@ -98,7 +98,8 @@ export function WorkspaceUsage({ workspaceId }: WorkspaceUsageProps) {
);
}
function formatPeriod(start: string, end: string): string {
function formatPeriod(start: string | undefined, end: string | undefined): string {
if (!start || !end) return "—";
const fmt = (s: string) =>
new Date(s).toLocaleDateString(undefined, {
month: "short",

View File

@ -189,7 +189,7 @@ export function DetailsTab({ workspaceId, data }: Props) {
<Row label="Parent" value={data.parentId || "root"} mono />
<Row label="Active Tasks" value={String(data.activeTasks)} />
{data.status === "degraded" && (
<Row label="Error Rate" value={`${(data.lastErrorRate * 100).toFixed(0)}%`} />
<Row label="Error Rate" value={`${((data.lastErrorRate ?? 0) * 100).toFixed(0)}%`} />
)}
{isRestartable && (
<div className="pt-2">