-
Notifications
You must be signed in to change notification settings - Fork 61
refactor: sandbox details header + live indicator determination #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,7 +36,6 @@ import { | |||||||||||||
| SANDBOX_MONITORING_CHART_FG_VAR, | ||||||||||||||
| SANDBOX_MONITORING_CHART_LINE_WIDTH, | ||||||||||||||
| SANDBOX_MONITORING_CHART_STROKE_VAR, | ||||||||||||||
| SANDBOX_MONITORING_LIVE_DATA_THRESHOLD_MS, | ||||||||||||||
| } from '../utils/constants' | ||||||||||||||
| import { ChartOverlayLayer } from './chart-overlays' | ||||||||||||||
| import { useChartOverlays } from './use-chart-overlays' | ||||||||||||||
|
|
@@ -60,7 +59,6 @@ const CHART_CONNECTOR_LINE_OPACITY = 0.8 | |||||||||||||
| const CHART_OUT_OF_BRUSH_ALPHA = 0.25 | ||||||||||||||
| const CHART_AXIS_LABEL_FONT_SIZE = 12 | ||||||||||||||
| const CHART_Y_AXIS_SCALE_FACTOR = 1.5 | ||||||||||||||
| const CHART_LIVE_WINDOW_STEPS = 2 | ||||||||||||||
| const CHART_LIVE_OUTER_DOT_SIZE = 16 | ||||||||||||||
| const CHART_LIVE_MIDDLE_DOT_SIZE = 10 | ||||||||||||||
| const CHART_LIVE_INNER_DOT_SIZE = 6 | ||||||||||||||
|
|
@@ -306,10 +304,10 @@ function SandboxMetricsChart({ | |||||||||||||
| [isMobile] | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| const liveWindowMs = useMemo(() => { | ||||||||||||||
| const liveMetricThresholdMs = useMemo(() => { | ||||||||||||||
| const duration = | ||||||||||||||
| xAxisMax !== undefined && xAxisMin !== undefined ? xAxisMax - xAxisMin : 0 | ||||||||||||||
| return CHART_LIVE_WINDOW_STEPS * calculateStepForDuration(duration) | ||||||||||||||
| return calculateStepForDuration(duration) | ||||||||||||||
|
||||||||||||||
| return calculateStepForDuration(duration) | |
| const stepMs = calculateStepForDuration(duration) | |
| // Allow a slightly wider live window than a single step so the live | |
| // indicator remains stable despite normal polling, ingestion, or render lag. | |
| return Math.max(stepMs * 2, 15_000) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,14 @@ | |
| import { useCallback, useEffect, useMemo, useRef } from 'react' | ||
| import { useDashboard } from '@/features/dashboard/context' | ||
| import { useSandboxContext } from '@/features/dashboard/sandbox/context' | ||
| import { calculateStepForDuration } from '@/features/dashboard/sandboxes/monitoring/utils' | ||
| import { getMsUntilNextAlignedInterval } from '@/lib/hooks/use-aligned-refetch-interval' | ||
| import type { SandboxMetric } from '@/server/api/models/sandboxes.models' | ||
| import { useTRPCClient } from '@/trpc/client' | ||
| import { | ||
| SANDBOX_LIFECYCLE_EVENT_KILLED, | ||
| SANDBOX_MONITORING_DEFAULT_PRESET_ID, | ||
| SANDBOX_MONITORING_DEFAULT_RANGE_MS, | ||
| SANDBOX_MONITORING_LIVE_DATA_THRESHOLD_MS, | ||
| SANDBOX_MONITORING_LIVE_POLLING_MS, | ||
| SANDBOX_MONITORING_OVERFETCH_MIN_MS, | ||
| SANDBOX_MONITORING_OVERFETCH_RATIO, | ||
|
|
@@ -256,12 +256,16 @@ | |
| return latest | ||
| }, [metricsQuery.data]) | ||
|
|
||
| const liveMetricThresholdMs = useMemo( | ||
| () => calculateStepForDuration(fetchTimeframe.end - fetchTimeframe.start), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| [fetchTimeframe.end, fetchTimeframe.start] | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Controller and chart use different durations for thresholdMedium Severity The controller computes Additional Locations (1)Reviewed by Cursor Bugbot for commit 3c7d849. Configure here. |
||
|
|
||
| const isLive = | ||
| shouldPoll && | ||
| latestMetricTimestampMs !== null && | ||
| Date.now() - latestMetricTimestampMs <= | ||
| SANDBOX_MONITORING_LIVE_DATA_THRESHOLD_MS | ||
| Date.now() - latestMetricTimestampMs <= liveMetricThresholdMs | ||
|
Comment on lines
+259
to
+267
|
||
|
|
||
|
Check failure on line 268 in src/features/dashboard/sandbox/monitoring/state/use-sandbox-monitoring-controller.ts
|
||
|
Comment on lines
+260
to
268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 The controller computes Extended reasoning...What the bug is and how it manifests This PR replaces the old shared The specific code path In Why existing code doesn't prevent it The old Impact For any visible timeframe sitting just below a bucket boundary (~57.7–60 minutes, ~5h45m–6h, ~11h30m–12h, etc.), the controller declares the sandbox live (isLive=true, isPolling=true) while the chart's threshold is 6× smaller. With a 5s polling interval plus typical network/server latency, data will routinely arrive 6–30s old. In this range the header live indicator says "live" but the chart live dot flickers off — contradictory UI state visible to users in the common 1-hour monitoring window. Step-by-step proof
How to fix The cleanest fix is to compute |
||
| return { | ||
| lifecycleBounds, | ||
| lifecycleEvents: sandboxLifecycle?.events ?? [], | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
item.labelas the Reactkeycan be unstable because some labels are dynamic (runningLabel,timeoutLabel) and will change as the sandbox state changes. That will cause items to remount and can reset internal state/effects in child components. Prefer a separate stableidfield for the key (and keeplabelpurely for display).