@skyhook-io/radar-app 1.22.0 → 1.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/package.json +1 -1
  2. package/src/App.tsx +98 -29
  3. package/src/RadarApp.tsx +5 -0
  4. package/src/api/client.ts +18 -1
  5. package/src/api/cnpg-history.ts +3 -3
  6. package/src/api/cnpg-storage.ts +3 -3
  7. package/src/api/diagnose.test.ts +34 -0
  8. package/src/api/diagnose.ts +17 -4
  9. package/src/api/radarFeatures.test.ts +13 -1
  10. package/src/api/radarFeatures.ts +2 -0
  11. package/src/api/resourceActions.test.ts +829 -0
  12. package/src/api/resourceActions.ts +584 -0
  13. package/src/api/resourceActions.ui.test.tsx +1882 -0
  14. package/src/api/reviewedActionMutation.ts +56 -28
  15. package/src/api/substrateHealth.ts +2 -3
  16. package/src/api/traffic.ts +13 -5
  17. package/src/api/workloadMetrics.test.ts +11 -2
  18. package/src/api/workloadMetrics.ts +2 -2
  19. package/src/api/workloadSource.test.tsx +857 -0
  20. package/src/api/workloadSource.ts +292 -0
  21. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  22. package/src/components/APIUnreachableBanner.tsx +20 -0
  23. package/src/components/ConnectionErrorView.test.tsx +63 -2
  24. package/src/components/ConnectionErrorView.tsx +88 -68
  25. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  26. package/src/components/diagnose/AnalysisStory.test.tsx +12 -0
  27. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  28. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  29. package/src/components/diagnose/DiagnoseContext.question.test.tsx +34 -1
  30. package/src/components/diagnose/DiagnoseContext.tsx +28 -3
  31. package/src/components/diagnose/DiagnoseSurface.tsx +5 -4
  32. package/src/components/diagnose/Home.test.tsx +6 -0
  33. package/src/components/diagnose/Home.tsx +13 -3
  34. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  35. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +61 -0
  36. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  37. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  38. package/src/components/diagnose/InvestigationView.followupFailure.test.tsx +122 -0
  39. package/src/components/diagnose/InvestigationView.tsx +130 -25
  40. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +1 -1
  41. package/src/components/diagnose/LocalDiagnoseAction.tsx +2 -2
  42. package/src/components/diagnose/QuestionComposer.test.tsx +16 -2
  43. package/src/components/diagnose/QuestionComposer.tsx +13 -8
  44. package/src/components/diagnose/diagnoseEvidenceTypes.ts +47 -8
  45. package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +153 -0
  46. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +9 -13
  47. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +21 -5
  48. package/src/components/diagnose/investigationEvidence/bodies/network.tsx +63 -26
  49. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  50. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  51. package/src/components/diagnose/investigationState.ts +9 -0
  52. package/src/components/diagnose/launch.ts +1 -1
  53. package/src/components/diagnose/parts.test.tsx +11 -3
  54. package/src/components/diagnose/toolCallLabel.ts +3 -0
  55. package/src/components/dock/PodDebugSession.test.tsx +66 -0
  56. package/src/components/dock/PodDebugSession.tsx +3 -1
  57. package/src/components/dock/TerminalTab.test.tsx +43 -3
  58. package/src/components/dock/TerminalTab.tsx +10 -1
  59. package/src/components/helm/HelmReleaseDrawer.tsx +1 -1
  60. package/src/components/helm/InstallWizard.tsx +1 -1
  61. package/src/components/home/ActivitySummary.tsx +3 -8
  62. package/src/components/home/ClusterHealthCard.tsx +91 -17
  63. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  64. package/src/components/home/HomeView.tsx +6 -26
  65. package/src/components/home/TopologyPreview.test.tsx +31 -30
  66. package/src/components/home/TopologyPreview.tsx +19 -28
  67. package/src/components/home/mcpToolCatalog.ts +4 -4
  68. package/src/components/resources/PodEvictAction.test.tsx +951 -0
  69. package/src/components/resources/PodEvictAction.tsx +167 -0
  70. package/src/components/resources/ResourcesView.tsx +3 -0
  71. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  72. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  73. package/src/components/resources/renderers/WorkloadRenderer.tsx +7 -1
  74. package/src/components/settings/LocalConnectionSettings.tsx +4 -4
  75. package/src/components/settings/SettingsDialog.tsx +23 -18
  76. package/src/components/settings/integrationQueries.test.ts +98 -0
  77. package/src/components/settings/integrationQueries.ts +36 -0
  78. package/src/components/traffic/TrafficView.reconnect.test.tsx +229 -0
  79. package/src/components/traffic/TrafficView.tsx +91 -35
  80. package/src/components/ui/Markdown.test.tsx +37 -0
  81. package/src/components/ui/Markdown.tsx +15 -2
  82. package/src/components/useContextSwitchFlow.test.tsx +27 -2
  83. package/src/components/useContextSwitchFlow.tsx +20 -22
  84. package/src/components/workload/WorkloadView.tsx +83 -4
  85. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  86. package/src/context/ConnectionContext.tsx +24 -5
  87. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  88. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  89. package/src/context/DiagnoseCustomization.tsx +20 -2
  90. package/src/hooks/useEventSource.test.tsx +275 -4
  91. package/src/hooks/useEventSource.ts +278 -51
  92. package/src/index.ts +1 -0
  93. package/src/utils/navigation.test.ts +1 -6
  94. package/src/utils/navigation.ts +9 -44
  95. package/src/utils/network-policy-navigation.test.ts +21 -36
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyhook-io/radar-app",
3
- "version": "1.22.0",
3
+ "version": "1.22.2",
4
4
  "description": "Radar's full web UI as a reusable React component. Used by Radar's own binary and by external consumers like Radar Cloud.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/App.tsx CHANGED
@@ -9,10 +9,11 @@ import { HomeView } from './components/home/HomeView'
9
9
  import { DebugOverlay } from './components/DebugOverlay'
10
10
  import { GlobalDiagnoseButton } from './components/diagnose/LocalDiagnoseAction'
11
11
  import { switchInProgress } from './api/contextSwitch'
12
+ import { connectionHeaderValue } from './api/connectionBinding'
12
13
  import { ContextSwitchActions } from './components/ContextSwitchActions'
13
14
  import { investigationWorkspaceSearch, isInvestigationWorkspacePath, useDiagnoseLayout } from './components/diagnose/DiagnoseContext'
14
15
  import { DiagnoseSurface } from './components/diagnose/DiagnoseSurface'
15
- import { type IssueTimelineEventTarget, TopologyGraph, TopologySearch, TopologyBreadcrumb, TopologyFilterSidebar, TopologyControls, FreshnessControl, gitOpsRouteForKind, gitOpsRouteForResource, ScopePill, PaneLoader, usePhoneLayout, PHONE_MEDIA_QUERY } from '@skyhook-io/k8s-ui'
16
+ import { type IssueTimelineEventTarget, TopologyGraph, TopologySearch, TopologyBreadcrumb, TopologyFilterSidebar, TopologyControls, FreshnessControl, gitOpsRouteForKind, gitOpsRouteForResource, ScopePill, PaneLoader, usePhoneLayout, PHONE_MEDIA_QUERY, passesKindFilter, isStandaloneReplicaSet } from '@skyhook-io/k8s-ui'
16
17
  import { resetNavigationMap } from '@skyhook-io/k8s-ui/utils/navigation'
17
18
  import { topologyNodeResourceKind } from '@skyhook-io/k8s-ui/utils/topology-neighborhood'
18
19
  import { useAPIResources, findAPIResourceForRoute } from './api/apiResources'
@@ -56,6 +57,7 @@ import { ConnectionProvider, useConnection, refreshQueriesAfterReconnect } from
56
57
  import { DisconnectedView, FailedSwitchView } from './components/SwitchAwareConnectionError'
57
58
  import { SyncProgressPanel } from './components/SyncProgressPanel'
58
59
  import { NoClusterAccessBanner } from './components/NoClusterAccessBanner'
60
+ import { APIUnreachableBanner } from './components/APIUnreachableBanner'
59
61
  import { CapabilitiesProvider, useCapabilitiesContext } from './contexts/CapabilitiesContext'
60
62
  import { RadarUpgradeProvider } from './context/RadarUpgrade'
61
63
  import { UserMenu } from './components/UserMenu'
@@ -73,6 +75,7 @@ import { DiagnosticsOverlay, type DiagnosticsFocus } from './components/ui/Diagn
73
75
  import { useEventSource } from './hooks/useEventSource'
74
76
  import { useResetViewsOnContextChange } from './hooks/useResetViewsOnContextChange'
75
77
  import { debugNamespaceLog, refetchOnResourceEvents, resourceEventKey, useNamespaces, useNamespaceScope, useSetActiveNamespace, isAppliedNamespaceSwitch, useAuthMe, useAuditBadges, useClusterInfo, useCapabilities } from './api/client'
78
+ import { createWorkloadSourceInvalidator, type WorkloadSourceInvalidator } from './api/workloadSource'
76
79
  import { buildAuditSeverityMap } from './utils/auditBadges'
77
80
  import { isInNamespaceScope, scopeNodesToNamespaces } from './utils/topology-namespace'
78
81
  import { routePath, apiUrl, getApiBase, getAuthHeaders, getCredentialsMode, stripBasename } from './api/config'
@@ -147,7 +150,7 @@ type ExtendedMainView = MainView | 'traffic' | 'cost' | 'capacity' | 'cnpg' | 'v
147
150
  // Views that have been laid out for phone width (640px and below). The rest
148
151
  // keep their desktop width on a phone and scroll sideways; add a view here in
149
152
  // the PR that gives it a phone layout.
150
- const PHONE_READY_VIEWS: ReadonlySet<ExtendedMainView> = new Set<ExtendedMainView>(['issues', 'resources', 'helm', 'home', 'topology', 'capacity'])
153
+ const PHONE_READY_VIEWS: ReadonlySet<ExtendedMainView> = new Set<ExtendedMainView>(['issues', 'resources', 'helm', 'home', 'topology', 'capacity', 'investigations'])
151
154
 
152
155
  // Extract view from URL path
153
156
  function getViewFromPath(pathname: string): ExtendedMainView {
@@ -382,6 +385,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
382
385
  dismissForNavigation: dismissDiagnoseForNavigation,
383
386
  contentGutter,
384
387
  maximized: diagnoseMaximized,
388
+ fullWidthForced: diagnoseFillsViewport,
385
389
  } = useDiagnoseLayout()
386
390
  // Hand off to a host-owned URL. The host's `onHostNavigate` (Radar Cloud's
387
391
  // cross-tree swap) navigates same-document so the chrome morphs instead of
@@ -636,6 +640,10 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
636
640
  const [showPolicyEffect, setShowPolicyEffect] = useState(false)
637
641
  // Topology filter state
638
642
  const [visibleKinds, setVisibleKinds] = useState<Set<NodeKind>>(() => new Set(DEFAULT_VISIBLE_KINDS))
643
+ // Whether the user has chosen for ReplicaSets (their toggle, Show all, Hide
644
+ // all). Until then the kind stays off, hiding the ReplicaSets that collapse
645
+ // into a Deployment or Rollout, but standalone ones show.
646
+ const [replicaSetsChosen, setReplicaSetsChosen] = useState(false)
639
647
  // Phones start with the filters collapsed to their icon rail: expanded, the
640
648
  // panel took two thirds of the width from the graph.
641
649
  const [filterSidebarCollapsed, setFilterSidebarCollapsed] = useState(
@@ -716,6 +724,11 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
716
724
  // Views with a deliberate phone layout. On a phone every other view keeps
717
725
  // its desktop width and scrolls sideways rather than squeezing.
718
726
  const phoneScroll = isMobile && !PHONE_READY_VIEWS.has(mainView)
727
+ // Investigations own their responsive panes. A narrow embedded window can
728
+ // have a fine pointer (or a tablet keyboard); the host width is the boundary.
729
+ const investigationFillsHost = embedded && (
730
+ mainView === 'investigations' || (diagnoseOpen && (diagnoseMaximized || diagnoseFillsViewport))
731
+ )
719
732
 
720
733
  // On a history Pop (back/forward) the URL is authoritative. The URL-write
721
734
  // effect, running with not-yet-synced state, would otherwise write the stale
@@ -1174,6 +1187,10 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1174
1187
  timer: number | null
1175
1188
  }>({ updatedKinds: new Set(), gitopsRowsChanged: false, gitopsCountsChanged: false, timer: null })
1176
1189
  const timelineInvalidationRef = useRef<{ timer: number | null }>({ timer: null })
1190
+ const workloadSourceInvalidatorRef = useRef<WorkloadSourceInvalidator | null>(null)
1191
+ if (!workloadSourceInvalidatorRef.current) {
1192
+ workloadSourceInvalidatorRef.current = createWorkloadSourceInvalidator()
1193
+ }
1177
1194
 
1178
1195
  const handleK8sEvent = useCallback((event: K8sEvent) => {
1179
1196
  // The timeline consumes every frame — including the K8s Event kind the
@@ -1196,6 +1213,8 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1196
1213
  // Skip K8s Event kind — informational, not resource mutations
1197
1214
  if (event.kind === 'Event') return
1198
1215
 
1216
+ workloadSourceInvalidatorRef.current?.handleEvent(queryClient, event)
1217
+
1199
1218
  const kind = kindToPluralWithGroup(event.kind, event.group ?? '')
1200
1219
  const structural = event.operation === 'add' || event.operation === 'delete'
1201
1220
  const applicationWorkload = ['deployments', 'statefulsets', 'daemonsets', 'rollouts'].includes(kind)
@@ -1309,6 +1328,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1309
1328
  fastInvalidationRef.current = { changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null }
1310
1329
  slowInvalidationRef.current = { updatedKinds: new Set(), gitopsRowsChanged: false, gitopsCountsChanged: false, timer: null }
1311
1330
  timelineInvalidationRef.current = { timer: null }
1331
+ workloadSourceInvalidatorRef.current?.reset()
1312
1332
  }, [])
1313
1333
 
1314
1334
  // SSE connection for real-time updates — no namespace filter for small/medium clusters (frontend filters).
@@ -1317,7 +1337,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1317
1337
  const sseMode = topologyMode === 'fleet' ? 'resources' : topologyMode
1318
1338
  // The context this tab's views were last reset for.
1319
1339
  const shownContextRef = useRef<string | null>(null)
1320
- const { topology, connected: eventStreamConnected, connecting: eventStreamConnecting, reconnect: reconnectEventStream, applyContextChange } = useEventSource(namespaces, sseMode as 'resources' | 'traffic', {
1340
+ const { topology, topologyStatus, connected: eventStreamConnected, connecting: eventStreamConnecting, reconnect: reconnectEventStream, applyContextChange } = useEventSource(namespaces, sseMode as 'resources' | 'traffic', {
1321
1341
  onContextSwitchComplete: endSwitch,
1322
1342
  onContextSwitchProgress: updateProgress,
1323
1343
  onContextChanged: (context) => {
@@ -1334,6 +1354,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1334
1354
  fastInvalidationRef.current = { changedKinds: new Set(), changedObjects: new Set(), structuralKinds: new Set(), environmentNamespaces: new Set(), environmentPods: new Map(), secretsChanged: false, timer: null }
1335
1355
  slowInvalidationRef.current = { updatedKinds: new Set(), gitopsRowsChanged: false, gitopsCountsChanged: false, timer: null }
1336
1356
  timelineInvalidationRef.current = { timer: null }
1357
+ workloadSourceInvalidatorRef.current?.reset()
1337
1358
 
1338
1359
  // Close any open drawers/overlays — old cluster's resources don't exist on the new one
1339
1360
  // (?full=1 is cleared by the URL reset below).
@@ -1379,11 +1400,13 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1379
1400
  onConnectionStateChange: updateConnectionFromSSE,
1380
1401
  onDeferredReady: () => {
1381
1402
  // Deferred informers (secrets, events, configmaps, etc.) have finished syncing.
1382
- // Refetch dashboard so counts, warning events, and cert health fill in.
1403
+ // Refetch dashboard so counts, warning events, and cert health fill in, and
1404
+ // fetched graphs, which only the Topology screen gets streamed.
1383
1405
  queryClient.invalidateQueries({ queryKey: ['dashboard'] })
1406
+ queryClient.invalidateQueries({ queryKey: ['topology'] })
1384
1407
  },
1385
1408
  onK8sEvent: handleK8sEvent,
1386
- }, forceNamespaceFilter, showPolicyEffect)
1409
+ }, forceNamespaceFilter, showPolicyEffect, mainView === 'topology')
1387
1410
 
1388
1411
  useContextSwitchOutcome(applyContextChange)
1389
1412
  useResetViewsOnContextChange(connection.state, connection.context, shownContextRef, applyContextChange)
@@ -1394,7 +1417,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1394
1417
  // to a stale namespace while sidebar/topology show a different one. Small
1395
1418
  // clusters never set forceNamespaceFilter and skip this path entirely.
1396
1419
  useEffect(() => {
1397
- const isLarge = forceNamespaceFilter !== undefined || topology?.requiresNamespaceFilter === true
1420
+ const isLarge = forceNamespaceFilter !== undefined || topologyStatus?.requiresNamespaceFilter === true
1398
1421
  if (!isLarge) return
1399
1422
  if (namespaces.length === 0) {
1400
1423
  setForceNamespaceFilter(prev => (prev === undefined ? prev : undefined))
@@ -1406,14 +1429,15 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1406
1429
  if (cur.length === next.length && cur.every((ns, i) => ns === next[i])) return prev
1407
1430
  return [...namespaces]
1408
1431
  })
1409
- }, [namespaces, forceNamespaceFilter, topology?.requiresNamespaceFilter])
1432
+ }, [namespaces, forceNamespaceFilter, topologyStatus?.requiresNamespaceFilter])
1410
1433
 
1411
1434
  // Apply live topology updates only when not paused. While paused, buffer the
1412
- // latest snapshot so we can apply it instantly when the user resumes.
1435
+ // latest snapshot so we can apply it instantly when the user resumes. Leaving
1436
+ // the Topology screen clears the stream's graph; a paused one keeps its buffer.
1413
1437
  useEffect(() => {
1414
1438
  if (!topologyPaused) {
1415
1439
  setDisplayedTopology(topology)
1416
- } else {
1440
+ } else if (topology) {
1417
1441
  pendingTopologyRef.current = topology
1418
1442
  }
1419
1443
  }, [topology, topologyPaused])
@@ -1429,9 +1453,20 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1429
1453
  })
1430
1454
  }, [])
1431
1455
 
1432
- // Track CRD discovery status from topology (more direct than cluster-info)
1433
- // When discovery completes, topology will auto-update via SSE with new CRD nodes
1434
- const crdDiscoveryStatus = topology?.crdDiscoveryStatus
1456
+ // CRD discovery status arrives with every topology cycle, as topology_status
1457
+ // on screens that don't draw the graph.
1458
+ const crdDiscoveryStatus = topologyStatus?.crdDiscoveryStatus
1459
+ // Finished discovery adds custom resources to fetched graphs (Timeline,
1460
+ // Applications, a workload's page); only the Topology screen gets its graph
1461
+ // pushed.
1462
+ const previousDiscoveryRef = useRef(crdDiscoveryStatus)
1463
+ useEffect(() => {
1464
+ // Starting discovery isn't broadcast, so a tab may see idle go straight to ready.
1465
+ if ((previousDiscoveryRef.current === 'idle' || previousDiscoveryRef.current === 'discovering') && crdDiscoveryStatus === 'ready') {
1466
+ queryClient.invalidateQueries({ queryKey: ['topology'] })
1467
+ }
1468
+ previousDiscoveryRef.current = crdDiscoveryStatus
1469
+ }, [crdDiscoveryStatus, queryClient])
1435
1470
  const clusterConnectionState = connection.state
1436
1471
  const clusterConnected = clusterConnectionState === 'connected'
1437
1472
  const liveUpdatesDisconnected = clusterConnected && !eventStreamConnected && !eventStreamConnecting
@@ -1441,9 +1476,11 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1441
1476
  const syncProgressLabel = connection.syncStatus
1442
1477
  ? `Loading cluster data — ${connection.syncStatus.criticalSynced + connection.syncStatus.deferredSynced} of ${connection.syncStatus.criticalTotal + connection.syncStatus.deferredTotal} ready`
1443
1478
  : 'Connecting'
1479
+ const apiUnreachable = clusterConnected && Boolean(connection.apiUnreachableSince)
1444
1480
  const headerConnectionLabel =
1445
1481
  clusterConnectionState === 'disconnected' ? 'Disconnected' :
1446
1482
  clusterConnectionState === 'connecting' ? syncProgressLabel :
1483
+ apiUnreachable ? "Can't reach the API server" :
1447
1484
  liveUpdatesDisconnected ? 'Live updates disconnected' :
1448
1485
  clusterLoadState.loading ? `Connected — ${clusterLoadState.message}` :
1449
1486
  crdDiscoveryStatus === 'discovering' ? 'Connected — discovering Custom Resources...' :
@@ -1451,6 +1488,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1451
1488
  const headerConnectionDisplayLabel =
1452
1489
  clusterConnectionState === 'disconnected' ? 'Disconnected' :
1453
1490
  clusterConnectionState === 'connecting' ? syncProgressLabel :
1491
+ apiUnreachable ? 'API server unreachable' :
1454
1492
  liveUpdatesDisconnected ? 'Live updates disconnected' :
1455
1493
  showClusterWarmupLabel ? clusterLoadState.message :
1456
1494
  crdDiscoveryStatus === 'discovering' ? 'Discovering Custom Resources…' :
@@ -1825,7 +1863,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1825
1863
  // Filter by namespace (client-side) and by visible kinds
1826
1864
  const nsSet = namespaces.length > 0 ? new Set(namespaces) : null
1827
1865
  const filteredNodes = displayedTopology.nodes.filter(node =>
1828
- effectiveKinds.has(node.kind) && isInNamespaceScope(node, nsSet)
1866
+ (topologyMode === 'fleet' ? effectiveKinds.has(node.kind) : passesKindFilter(node, effectiveKinds, !replicaSetsChosen)) && isInNamespaceScope(node, nsSet)
1829
1867
  )
1830
1868
  const filteredNodeIds = new Set(filteredNodes.map(n => n.id))
1831
1869
 
@@ -1848,7 +1886,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1848
1886
  nodes: filteredNodes,
1849
1887
  edges: filteredEdges,
1850
1888
  }
1851
- }, [displayedTopology, visibleKinds, namespaces, topologyMode])
1889
+ }, [displayedTopology, visibleKinds, namespaces, topologyMode, replicaSetsChosen])
1852
1890
 
1853
1891
  // Namespace-scoped but NOT kind-filtered: the sidebar derives its kind list
1854
1892
  // and visible/hidden footer counts from this prop, so handing it the
@@ -1860,6 +1898,21 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1860
1898
  return scopeNodesToNamespaces(displayedTopology.nodes, namespaces)
1861
1899
  }, [displayedTopology, namespaces])
1862
1900
 
1901
+ // ReplicaSets are on screen when the kind is on, or by default when some
1902
+ // are standalone. The sidebar's toggle shows that: it reads "on" when every
1903
+ // ReplicaSet in view is standalone and so shown, keeping Show all available
1904
+ // while any other ReplicaSet (a Rollout's during a transition) is hidden.
1905
+ const replicaSetsShown = useMemo(() => {
1906
+ if (visibleKinds.has('ReplicaSet')) return true
1907
+ if (replicaSetsChosen || topologyMode === 'fleet') return false
1908
+ const inView = filterSidebarNodes.filter(n => n.kind === 'ReplicaSet')
1909
+ return inView.length > 0 && inView.every(isStandaloneReplicaSet)
1910
+ }, [visibleKinds, replicaSetsChosen, topologyMode, filterSidebarNodes])
1911
+ const sidebarKinds = useMemo(
1912
+ () => (replicaSetsShown && !visibleKinds.has('ReplicaSet') ? new Set<NodeKind>([...visibleKinds, 'ReplicaSet']) : visibleKinds),
1913
+ [replicaSetsShown, visibleKinds],
1914
+ )
1915
+
1863
1916
  // Cluster Audit findings, joined onto topology nodes by the audit key the
1864
1917
  // backend stamps on each node (data.auditKey). Only badge-worthy findings
1865
1918
  // reach the graph; the raw auditDanger/auditWarning property names remain at
@@ -1891,12 +1944,24 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1891
1944
  // collisions — rebuilding the string can't match those reliably.
1892
1945
  const selectedNodeId = useMemo(() => {
1893
1946
  if (!selectedResource) return undefined
1894
- const match = findSelectedTopologyNode(topology, selectedResource)
1947
+ const match = findSelectedTopologyNode(displayedTopology, selectedResource)
1895
1948
  return match?.id
1896
- }, [selectedResource, topology])
1949
+ }, [selectedResource, displayedTopology])
1897
1950
 
1898
1951
  // Filter handlers
1899
1952
  const handleToggleKind = useCallback((kind: NodeKind) => {
1953
+ if (kind === 'ReplicaSet') {
1954
+ // The toggle shows what's on screen: on while standalone ReplicaSets
1955
+ // show by default, so the first click hides them.
1956
+ setReplicaSetsChosen(true)
1957
+ setVisibleKinds(prev => {
1958
+ const next = new Set(prev)
1959
+ if (replicaSetsShown) next.delete(kind)
1960
+ else next.add(kind)
1961
+ return next
1962
+ })
1963
+ return
1964
+ }
1900
1965
  setVisibleKinds(prev => {
1901
1966
  const next = new Set(prev)
1902
1967
  if (next.has(kind)) {
@@ -1906,20 +1971,22 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1906
1971
  }
1907
1972
  return next
1908
1973
  })
1909
- }, [])
1974
+ }, [replicaSetsShown])
1910
1975
 
1911
1976
  const handleShowAllKinds = useCallback(() => {
1912
1977
  // Include all static kinds plus any dynamic CRD kinds from the topology
1913
1978
  const allKinds = new Set<NodeKind>(ALL_NODE_KINDS)
1914
- if (topology?.nodes) {
1915
- for (const node of topology.nodes) {
1979
+ if (displayedTopology?.nodes) {
1980
+ for (const node of displayedTopology.nodes) {
1916
1981
  allKinds.add(node.kind)
1917
1982
  }
1918
1983
  }
1984
+ setReplicaSetsChosen(true)
1919
1985
  setVisibleKinds(allKinds)
1920
- }, [topology])
1986
+ }, [displayedTopology])
1921
1987
 
1922
1988
  const handleHideAllKinds = useCallback(() => {
1989
+ setReplicaSetsChosen(true)
1923
1990
  setVisibleKinds(new Set())
1924
1991
  }, [])
1925
1992
 
@@ -1938,8 +2005,8 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
1938
2005
  scroll sideways at desktop width instead (see PHONE_READY_VIEWS). */}
1939
2006
  <div
1940
2007
  className={`relative flex bg-theme-base ${navCustomization.embedded ? 'h-full min-h-0' : 'h-screen'}`}
1941
- style={{ minWidth: isMobile && mainView === 'issues'
1942
- ? 0 // Issue rows adapt to the space beside the rail, even on a 360px phone.
2008
+ style={{ minWidth: investigationFillsHost || (isMobile && mainView === 'issues')
2009
+ ? 0 // Embedded investigations fill the host; mobile issue rows adapt beside the rail.
1943
2010
  : (isMobile ? 360 : 800) + (showNavRail ? (navRailEffectivePinned ? 176 : 56) : 0) }}
1944
2011
  >
1945
2012
  {showNavRail && (
@@ -2003,7 +2070,9 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
2003
2070
  className={`block w-2.5 h-2.5 shrink-0 rounded-full ${
2004
2071
  clusterConnectionState === 'disconnected' || liveUpdatesDisconnected
2005
2072
  ? 'bg-red-500'
2006
- : clusterConnectionState === 'connecting' || crdDiscoveryStatus === 'discovering' || clusterLoadState.loading
2073
+ : apiUnreachable
2074
+ ? 'bg-amber-400'
2075
+ : clusterConnectionState === 'connecting' || crdDiscoveryStatus === 'discovering' || clusterLoadState.loading
2007
2076
  ? 'bg-amber-400 animate-pulse'
2008
2077
  : 'bg-green-500'
2009
2078
  }`}
@@ -2213,6 +2282,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
2213
2282
 
2214
2283
  {dismissed && <p className="m-auto text-sm text-theme-text-secondary">{contextSwitch?.phase === 'stopping' ? 'Stopping the switch…' : 'The switch is still running. Resources will appear when the cluster is ready.'}</p>}
2215
2284
  {contentReady && <NoClusterAccessBanner />}
2285
+ {contentReady && connection.apiUnreachableSince && <APIUnreachableBanner since={connection.apiUnreachableSince} />}
2216
2286
  {/* Main content - only show when connected and authenticated */}
2217
2287
  {/* inert while a fullscreen detail overlay covers the views — keeps the
2218
2288
  retained background list out of the focus order + a11y tree (the visual
@@ -2240,7 +2310,6 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
2240
2310
  {!viewsSyncGated && mainView === 'home' && (
2241
2311
  <HomeView
2242
2312
  namespaces={namespaces}
2243
- topology={topology}
2244
2313
  fallbackClusterLoadState={showHomeClusterLoadFallback ? clusterLoadState : undefined}
2245
2314
  onNavigateToView={setMainView}
2246
2315
  onNavigateToIssue={takeover.issues ? undefined : (id) => setMainView('issues', { issue: id })}
@@ -2299,7 +2368,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
2299
2368
  {/* Topology view */}
2300
2369
  {!viewsSyncGated && mainView === 'topology' && (
2301
2370
  <>
2302
- {topology?.requiresNamespaceFilter && namespaces.length === 0 ? (
2371
+ {topologyStatus?.requiresNamespaceFilter && namespaces.length === 0 ? (
2303
2372
  /* Large cluster: prompt user to select a namespace */
2304
2373
  <div className="flex-1 flex items-center justify-center">
2305
2374
  <div className="max-w-md w-full mx-4 text-center">
@@ -2338,7 +2407,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
2338
2407
  <div className={isMobile && !filterSidebarCollapsed ? 'absolute inset-y-0 left-0 z-20 flex shadow-theme-lg' : 'contents'}>
2339
2408
  <TopologyFilterSidebar
2340
2409
  nodes={filterSidebarNodes}
2341
- visibleKinds={visibleKinds}
2410
+ visibleKinds={sidebarKinds}
2342
2411
  onToggleKind={handleToggleKind}
2343
2412
  onShowAll={handleShowAllKinds}
2344
2413
  onHideAll={handleHideAllKinds}
@@ -2383,7 +2452,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
2383
2452
  )}
2384
2453
  <TopologySearch
2385
2454
  nodes={filteredTopology?.nodes ?? []}
2386
- allNodes={topology?.nodes}
2455
+ allNodes={displayedTopology?.nodes}
2387
2456
  viewModeLabel={topologyMode === 'fleet' ? 'Fleet' : topologyMode === 'traffic' ? 'Network Flow' : 'Resources'}
2388
2457
  onNodeSelect={handleNodeClick}
2389
2458
  onZoomToNode={(id) => setTopologyFocus((prev) => ({ id, nonce: (prev?.nonce ?? 0) + 1 }))}
@@ -2448,7 +2517,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
2448
2517
  initialViewMode={(searchParams.get('view') as 'list' | 'swimlane') || undefined}
2449
2518
  initialFilter={(searchParams.get('filter') as 'all' | 'changes' | 'k8s_events' | 'warnings' | 'unhealthy') || undefined}
2450
2519
  initialTimeRange={(searchParams.get('time') as '5m' | '30m' | '1h' | '6h' | '24h' | 'all') || undefined}
2451
- requiresNamespaceFilter={topology?.requiresNamespaceFilter && namespaces.length === 0}
2520
+ requiresNamespaceFilter={topologyStatus?.requiresNamespaceFilter && namespaces.length === 0}
2452
2521
  availableNamespaces={availableNamespaces}
2453
2522
  availableNamespacesError={availableNamespacesError?.message}
2454
2523
  onNamespaceSelect={(ns) => {
@@ -2787,7 +2856,7 @@ function App({ manageDocumentTitle = false, documentTitleSuffix, onClusterLoadSt
2787
2856
  <CapabilitiesProvider>
2788
2857
  <RadarUpgradeProvider>
2789
2858
  <ContextSwitchProvider>
2790
- <DockProvider>
2859
+ <DockProvider connectionId={connectionHeaderValue}>
2791
2860
  <KeyboardShortcutProvider>
2792
2861
  <AppInner
2793
2862
  manageDocumentTitle={manageDocumentTitle}
package/src/RadarApp.tsx CHANGED
@@ -51,6 +51,7 @@ import { DiagnoseCustomizationProvider } from "./context/DiagnoseCustomization";
51
51
  import type {
52
52
  RenderDiagnoseAction,
53
53
  RenderInvestigationRunActions,
54
+ RenderInvestigationFindingsFooter,
54
55
  RenderInvestigationRefusalAction,
55
56
  DiagnoseConsentCopy,
56
57
  } from "./context/DiagnoseCustomization";
@@ -135,6 +136,8 @@ export interface RadarAppProps {
135
136
  renderDiagnoseAction?: RenderDiagnoseAction;
136
137
  /** Host-owned controls for the focused investigation; absent in standalone Radar. */
137
138
  renderInvestigationRunActions?: RenderInvestigationRunActions;
139
+ /** Host content at the end of the current investigation's Findings pane. */
140
+ renderInvestigationFindingsFooter?: RenderInvestigationFindingsFooter;
138
141
  /** Host action beside a refused investigation start or follow-up, e.g. Radar
139
142
  * Cloud's "Upgrade" when the organization has used its investigations.
140
143
  * Absent in standalone Radar, whose backend sends no refusal details. */
@@ -243,6 +246,7 @@ export function RadarApp({
243
246
  documentTitleSuffix,
244
247
  renderDiagnoseAction,
245
248
  renderInvestigationRunActions,
249
+ renderInvestigationFindingsFooter,
246
250
  renderInvestigationRefusalAction,
247
251
  diagnoseConsent,
248
252
  initialPath,
@@ -285,6 +289,7 @@ export function RadarApp({
285
289
  value={renderDiagnoseAction ?? defaultDiagnoseAction}
286
290
  consentCopy={diagnoseConsent}
287
291
  renderRunActions={renderInvestigationRunActions}
292
+ renderFindingsFooter={renderInvestigationFindingsFooter}
288
293
  renderRefusalAction={renderInvestigationRefusalAction}
289
294
  >
290
295
  <DiagnoseProvider
package/src/api/client.ts CHANGED
@@ -5,7 +5,7 @@ import { createListRefetchInterval, normalizeResourceList, type ResourceListBody
5
5
  import type { CascadeDetail } from '@skyhook-io/k8s-ui/components/ui/ForceDeleteConfirmDialog'
6
6
  import { canonicalResourceGroup } from '@skyhook-io/k8s-ui/utils/api-resources'
7
7
  import { pluralize } from '@skyhook-io/k8s-ui/utils/pluralize'
8
- import type { ReadGap, ReadGapSet } from '@skyhook-io/k8s-ui/types/read-coverage'
8
+ import type { ReadGap, ReadGapSet, ReadNameSet } from '@skyhook-io/k8s-ui/types/read-coverage'
9
9
  import type { ClusterScope } from '@skyhook-io/k8s-ui/types/cluster-scope'
10
10
  import type { WorkloadHistoryCoverage } from '@skyhook-io/k8s-ui/utils/workload-history-notes'
11
11
  import { knownKindForPluralWithGroup, pluralToKind } from '@skyhook-io/k8s-ui/utils/navigation'
@@ -199,13 +199,19 @@ export function apiFetch(
199
199
  }
200
200
 
201
201
  let authMode: string | undefined;
202
+ let errorCode: string | undefined;
202
203
  try {
203
204
  const body = await response.clone().json();
204
205
  authMode = body.authMode;
206
+ if (typeof body.code === "string") errorCode = body.code;
205
207
  } catch {
206
208
  console.warn("Authentication required (unable to determine auth mode)");
207
209
  }
208
210
 
211
+ if (!authMode && errorCode === "identity_required") {
212
+ return response;
213
+ }
214
+
209
215
  if (authMode === "oidc") {
210
216
  // Only the first 401 in a burst navigates; concurrent 401s within the
211
217
  // window are suppressed so they don't rotate radar_oidc_state. The gate
@@ -256,6 +262,10 @@ export class ApiError extends Error {
256
262
  }
257
263
  }
258
264
 
265
+ export function shouldRetryReplacedMember(failureCount: number, error: unknown): boolean {
266
+ return failureCount < 1 && error instanceof ApiError && (error.status === 409 || error.status === 503);
267
+ }
268
+
259
269
  export function isForbiddenError(error: unknown): boolean {
260
270
  return error instanceof ApiError && error.status === 403;
261
271
  }
@@ -492,6 +502,9 @@ export interface DashboardMetrics {
492
502
  // When false, only requests/capacity are meaningful — live usage (from
493
503
  // metrics-server) is unavailable and usage fields are zero.
494
504
  usageAvailable: boolean;
505
+ // Namespaces whose pods were summed into requestsMillis/requestPercent.
506
+ // Omitted when requests cover the whole cluster or from an older Radar.
507
+ requestsNamespaces?: ReadNameSet;
495
508
  }
496
509
 
497
510
  export interface MetricSummary {
@@ -685,6 +698,8 @@ export interface DashboardNetworkPolicyCoverage {
685
698
  // Workloads left out of totalWorkloads.
686
699
  ignoredNamespaceWorkloads?: number;
687
700
  hostNetworkWorkloads?: number;
701
+ // Kubernetes kind and API group of the counted policies. Older Radars omit it.
702
+ policyKinds?: { kind: string; group: string }[];
688
703
  }
689
704
 
690
705
  export interface DashboardGitOpsControllers {
@@ -4739,6 +4754,8 @@ export function useRightsizingScan(namespaces: string[], context = "") {
4739
4754
  if (inaccessible) {
4740
4755
  previous.current = null;
4741
4756
  queryClient.setQueryData(cache.queryKey, null);
4757
+ } else if (current === null) {
4758
+ previous.current = null;
4742
4759
  } else if (current && current.coverage.workloadsEvaluated > 0) {
4743
4760
  previous.current = { scope, result: current };
4744
4761
  }
@@ -1,6 +1,6 @@
1
1
  import { useQuery } from '@tanstack/react-query'
2
2
  import type { CNPGFleetMetricsReading, Grant } from '@skyhook-io/k8s-ui'
3
- import { fetchJSON, useRadarFeature } from './client'
3
+ import { fetchJSON, shouldRetryReplacedMember, useRadarFeature } from './client'
4
4
  import { shouldRetryRadarQuery } from './radarFeatures'
5
5
  import type { CNPGClusterActivityResponse } from './cnpg'
6
6
 
@@ -76,7 +76,7 @@ export function useCNPGClusterHistory(namespace: string, name: string, range: CN
76
76
  refetchInterval: range === '15m' ? 30_000 : 60_000,
77
77
  refetchIntervalInBackground: false,
78
78
  staleTime: 10_000,
79
- retry: false,
79
+ retry: shouldRetryReplacedMember,
80
80
  placeholderData: (prev) => (prev?.range === range ? prev : undefined),
81
81
  })
82
82
  }
@@ -101,7 +101,7 @@ export function useCNPGFleetMetrics(namespaces: string[], enabled = true) {
101
101
  enabled,
102
102
  staleTime: 20_000,
103
103
  refetchInterval: 60_000,
104
- retry: false,
104
+ retry: shouldRetryReplacedMember,
105
105
  placeholderData: (prev) => prev,
106
106
  })
107
107
  }
@@ -1,6 +1,6 @@
1
1
  import { useQuery } from '@tanstack/react-query'
2
2
  import type { CNPGDiskReading, CNPGMetricIsolation, Grant } from '@skyhook-io/k8s-ui'
3
- import { fetchJSON, useRadarFeature } from './client'
3
+ import { fetchJSON, shouldRetryReplacedMember, useRadarFeature } from './client'
4
4
 
5
5
  export type CNPGPVCRole = 'PG_DATA' | 'PG_WAL' | 'PG_TABLESPACE'
6
6
 
@@ -110,7 +110,7 @@ export function useCNPGClusterStorage(namespace: string, name: string, enabled =
110
110
  refetchInterval: 30_000,
111
111
  refetchIntervalInBackground: false,
112
112
  staleTime: 10_000,
113
- retry: false,
113
+ retry: shouldRetryReplacedMember,
114
114
  placeholderData: (prev) => prev,
115
115
  })
116
116
  }
@@ -132,7 +132,7 @@ export function useCNPGFleetDisk(namespaces: string[], enabled = true) {
132
132
  enabled,
133
133
  staleTime: 20_000,
134
134
  refetchInterval: 60_000,
135
- retry: false,
135
+ retry: shouldRetryReplacedMember,
136
136
  placeholderData: (prev) => prev,
137
137
  })
138
138
  }
@@ -438,3 +438,37 @@ describe("fetchAgents agents normalisation", () => {
438
438
  expect(r.agents.map((a) => a.name)).toEqual(["claude"]);
439
439
  });
440
440
  });
441
+
442
+ describe("Diagnose writes name the tab's connection", () => {
443
+ afterEach(() => vi.unstubAllGlobals());
444
+
445
+ it("sends the connection ID when starting a run and adding a turn", async () => {
446
+ const { observeConnectionStatus, resetConnectionBindingForTest, CONNECTION_HEADER } = await import("./connectionBinding");
447
+ resetConnectionBindingForTest();
448
+ observeConnectionStatus({ connectionId: "conn-a" });
449
+ const fetchMock = vi.fn(async () => new Response(JSON.stringify({ id: "run-1" }), { status: 200 }));
450
+ vi.stubGlobal("fetch", fetchMock);
451
+ await createRun({ kind: "Pod", group: "", namespace: "default", name: "web" });
452
+ await addTurn("run-1", { question: "why?" });
453
+ for (const [, init] of fetchMock.mock.calls as unknown as [string, RequestInit][]) {
454
+ expect((init.headers as Record<string, string>)[CONNECTION_HEADER]).toBe("conn-a");
455
+ }
456
+ expect(fetchMock).toHaveBeenCalledTimes(2);
457
+ resetConnectionBindingForTest();
458
+ });
459
+ });
460
+
461
+ describe("Diagnose names connection refusals in its own words", () => {
462
+ afterEach(() => vi.unstubAllGlobals());
463
+
464
+ it.each([
465
+ ["context_changed", 409, "The cluster changed since this view loaded"],
466
+ ["cluster_unavailable", 503, "Radar isn't connected to a cluster right now"],
467
+ ])("%s", async (code, status, text) => {
468
+ vi.stubGlobal("fetch", vi.fn(async () => new Response(JSON.stringify({ error: "Nothing was changed: …", error_code: code }), { status })));
469
+ const err = await createRun({ kind: "Pod", group: "", namespace: "default", name: "web" }).catch((e: unknown) => e);
470
+ expect(err).toBeInstanceOf(DiagnoseError);
471
+ expect((err as DiagnoseError).message).toContain(text);
472
+ expect((err as DiagnoseError).message).not.toContain("Nothing was changed");
473
+ });
474
+ });
@@ -2,6 +2,7 @@
2
2
  // on the user's own machine/subscription against Radar's MCP; this just starts
3
3
  // the investigation and consumes its SSE event stream.
4
4
  import { getApiBase, getAuthHeaders, getCredentialsMode } from "./config";
5
+ import { connectionHeaderValue, connectionHeaders } from "./connectionBinding";
5
6
 
6
7
  export interface AgentInfo {
7
8
  name: string;
@@ -20,8 +21,10 @@ export interface AgentInfo {
20
21
  /** The backend re-checks the resource after an Apply. Absent means it does not. */
21
22
  verification?: boolean;
22
23
  /** The backend opens a run from a question, with or without a resource.
23
- * Absent means it accepts only a resource. */
24
+ * Also enables resource-pinned questions. */
24
25
  questions?: boolean;
26
+ /** The backend accepts an opening question about one selected resource. */
27
+ targetQuestions?: boolean;
25
28
  }
26
29
 
27
30
  export interface AgentsResponse {
@@ -341,6 +344,13 @@ export interface DiagnoseRefusal {
341
344
  // The sentence to show is `detail` when a host sends one, else `error`. A
342
345
  // host's machine-readable code is `code`, or `error` when that is not the
343
346
  // sentence itself.
347
+ const connectionRefusals: Record<string, string> = {
348
+ context_changed:
349
+ "The cluster changed since this view loaded. Check which cluster you're on and ask again.",
350
+ cluster_unavailable:
351
+ "Radar isn't connected to a cluster right now. Ask again once it reconnects.",
352
+ };
353
+
344
354
  async function diagnoseError(res: Response): Promise<DiagnoseError> {
345
355
  let body: Record<string, unknown> | null = null;
346
356
  try {
@@ -353,7 +363,10 @@ async function diagnoseError(res: Response): Promise<DiagnoseError> {
353
363
  typeof v === "string" && v.trim() !== "" ? v : undefined;
354
364
  const detail = str(body?.detail);
355
365
  const error = str(body?.error);
356
- const message = detail ?? error ?? `request failed (${res.status})`;
366
+ // The connection check refuses before Diagnose runs; its general wording is
367
+ // about writes ("Nothing was changed"), which reads oddly for an investigation.
368
+ const refusal = connectionRefusals[str(body?.error_code) ?? ""];
369
+ const message = refusal ?? detail ?? error ?? `request failed (${res.status})`;
357
370
  return new DiagnoseError(res.status, message, {
358
371
  code: str(body?.code) ?? (detail && error !== detail ? error : undefined),
359
372
  reason: str(body?.reason),
@@ -475,7 +488,7 @@ export async function createRun(
475
488
  const res = await fetch(RUNS(), {
476
489
  method: "POST",
477
490
  credentials: getCredentialsMode(),
478
- headers: { "Content-Type": "application/json", ...getAuthHeaders() },
491
+ headers: { "Content-Type": "application/json", ...getAuthHeaders(), ...connectionHeaders(connectionHeaderValue()) },
479
492
  body: JSON.stringify({ ...target, ...opts }),
480
493
  });
481
494
  if (!res.ok) throw await diagnoseError(res);
@@ -553,7 +566,7 @@ export async function addTurn(
553
566
  const res = await fetch(`${RUNS()}/${id}/turns`, {
554
567
  method: "POST",
555
568
  credentials: getCredentialsMode(),
556
- headers: { "Content-Type": "application/json", ...getAuthHeaders() },
569
+ headers: { "Content-Type": "application/json", ...getAuthHeaders(), ...connectionHeaders(connectionHeaderValue()) },
557
570
  body: JSON.stringify(body),
558
571
  });
559
572
  if (!res.ok) throw await diagnoseError(res);