History

Stop rendering tool-sync failures as connection health

Rhys Sullivan committed 2 months ago

Commit c84836d1 parent b5271a65 files · +88 −3Browse files

Unified · Split

5 files
  1. packages/core/sdk/src/index.ts +1 −0
  2. packages/core/sdk/src/shared.ts +1 −0
  3. packages/react/src/components/accounts-section.tsx +12 −0
  4. packages/react/src/lib/use-connection-health.test.ts +53 −1
  5. packages/react/src/lib/use-connection-health.ts +21 −2
packages/core/sdk/src/index.ts+1−0
@@ -134,6 +134,7 @@ export { · 133 unmodified lines
134134 pathNamesASecret,
135135 REDACTED_SAMPLE_VALUE,
136136 identityPathTier,
137+ isToolSyncHealth,
137138 rankResponseSample,
138139 } from "./health-check";
139140
packages/core/sdk/src/shared.ts+1−0
@@ -143,6 +143,7 @@ export { · 142 unmodified lines
143143 candidateIdentityTier,
144144 sortHealthCheckCandidatesByIdentity,
145145 identityPathTier,
146+ isToolSyncHealth,
146147 rankResponseSample,
147148 } from "./health-check";
148149
packages/react/src/components/accounts-section.tsx+12−0
@@ -4,6 +4,7 @@ import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"; · 3 unmodified lines
44 import * as Exit from "effect/Exit";
55 import {
66 IntegrationSlug,
7+ isToolSyncHealth,
78 type Connection,
89 type OAuthClientSummary,
910 type Owner,
@@ -172,6 +173,12 @@ function AccountRow(props: { · 162 unmodified lines
172173 const misconfigured = status === "misconfigured";
173174 const needsHealthAttention = status === "expired" || status === "degraded";
174175 const healthDetail = needsHealthAttention ? probe?.detail : undefined;
176+ // A "Tool sync failing" stamp is about the CATALOG (tools may be stale or
177+ // missing), not the credential — the health hook excludes it from `status`,
178+ // so surface it as its own muted note instead of an unhealthy row.
179+ const syncFailureDetail = isToolSyncHealth(connection.lastHealth)
180+ ? connection.lastHealth?.detail
181+ : undefined;
175182 const missingOAuthScopes = connection.missingOAuthScopes ?? [];
176183
177184 const handleCheck = async () => {
@@ -252,6 +259,11 @@ function AccountRow(props: { · 74 unmodified lines
252259 {healthDetail}
253260 </CardStackEntryDescription>
254261 ) : null}
262+ {syncFailureDetail ? (
263+ <CardStackEntryDescription className="mt-1 overflow-visible whitespace-normal text-clip text-xs text-muted-foreground">
264+ {syncFailureDetail}
265+ </CardStackEntryDescription>
266+ ) : null}
255267 {needsReconsent ? (
256268 <CardStackEntryDescription className="mt-1 text-xs text-muted-foreground">
257269 This connection wasn't granted all the access this integration now needs.
packages/react/src/lib/use-connection-health.test.ts+53−1
@@ -1,7 +1,7 @@
11 import { describe, expect, it } from "@effect/vitest";
22 import type { HealthCheckResult } from "@executor-js/sdk/shared";
33
4−import { HEALTH_REVALIDATE_MS, revalidateQuery } from "./use-connection-health";
4+import { HEALTH_REVALIDATE_MS, presentableHealth, revalidateQuery } from "./use-connection-health";
55
66 const verdict = (status: HealthCheckResult["status"]): HealthCheckResult => ({
77 status,
@@ -46,3 +46,55 @@ describe("revalidateQuery", () => { · 38 unmodified lines
4646 expect(windows, "only the healthy path is gated").toEqual([undefined, undefined, undefined]);
4747 });
4848 });
49+
50+// ---------------------------------------------------------------------------
51+// Tool-sync stamps are not connection health. `toolSyncHealth` writes a
52+// degraded verdict with the "Tool sync failing" detail prefix into
53+// `last_health` when catalog production fails; presenting that as the
54+// connection's health painted whole integration rows "Degraded" (one bad
55+// sweep stamps many connections at once) for credentials that were fine.
56+// ---------------------------------------------------------------------------
57+
58+describe("presentableHealth", () => {
59+ it("passes genuine probe verdicts through untouched", () => {
60+ const expired: HealthCheckResult = {
61+ status: "expired",
62+ checkedAt: Date.now(),
63+ detail: "HTTP 401",
64+ };
65+ expect(presentableHealth(expired), "a probe verdict presents as-is").toBe(expired);
66+ });
67+
68+ it("hides a tool-sync stamp, old (detail-only) and new (reason) alike", () => {
69+ const stamped: HealthCheckResult = {
70+ status: "degraded",
71+ checkedAt: Date.now(),
72+ detail: "Tool sync failing: upstream returned HTTP 429",
73+ reason: "tool_sync_failed",
74+ };
75+ // Stamps written before `reason` existed carry only the detail prefix.
76+ const legacy: HealthCheckResult = {
77+ status: "degraded",
78+ checkedAt: Date.now(),
79+ detail: "Tool sync failing: plugin returned an incomplete tool catalog",
80+ };
81+ expect(presentableHealth(stamped), "a sync stamp is not connection health").toBeNull();
82+ expect(presentableHealth(legacy), "pre-reason stamps hide the same way").toBeNull();
83+ });
84+
85+ it("treats missing verdicts as missing", () => {
86+ expect(presentableHealth(null)).toBeNull();
87+ expect(presentableHealth(undefined)).toBeNull();
88+ });
89+
90+ it("does not hide a probe verdict whose upstream text merely mentions syncing", () => {
91+ // The marker is the detail PREFIX, owned by the sync stamp writer — an
92+ // upstream error that contains similar words elsewhere stays visible.
93+ const probeVerdict: HealthCheckResult = {
94+ status: "degraded",
95+ checkedAt: Date.now(),
96+ detail: "Health check request failed: upstream sync service unavailable",
97+ };
98+ expect(presentableHealth(probeVerdict)).toBe(probeVerdict);
99+ });
100+});
packages/react/src/lib/use-connection-health.ts+21−2
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 import { useCallback, useContext, useEffect, useRef, useState } from "react";
1010 import { RegistryContext, useAtomSet } from "@effect/atom-react";
1111 import * as Exit from "effect/Exit";
12+import { isToolSyncHealth } from "@executor-js/sdk/shared";
1213 import type { Connection, HealthCheckResult, HealthStatus, Owner } from "@executor-js/sdk/shared";
1314
1415 import { checkConnectionHealth, connectionsOptimisticAtom } from "../api/atoms";
@@ -54,6 +55,17 @@ export const revalidateQuery = ( · 39 unmodified lines
5455 ): { readonly ifStaleMs?: number } =>
5556 last?.status === "healthy" ? { ifStaleMs: HEALTH_REVALIDATE_MS } : {};
5657
58+/** The verdict a HEALTH surface may present, or null when the persisted
59+ * verdict is a tool-sync stamp (`isToolSyncHealth`). A "Tool sync failing"
60+ * verdict describes the CATALOG — tools may be stale or missing — not the
61+ * credential, so rendering it as the connection's health painted whole rows
62+ * "Degraded" (an entire integrations list, when one bad sweep stamped many
63+ * connections at once) for connections whose credentials were fine.
64+ * Surfaces show the stamp as its own muted note instead. */
65+export const presentableHealth = (
66+ last: HealthCheckResult | null | undefined,
67+): HealthCheckResult | null => (last == null || isToolSyncHealth(last) ? null : last);
68+
5769 /** Identity of a persisted verdict, for detecting the reconnect transition.
5870 * An OAuth re-mint clears `last_health`, so a verdict giving way to `null`
5971 * means the grant was replaced and the row must re-probe even though it never
@@ -115,7 +127,7 @@ export function useConnectionHealth(connection: Connection): { · 55 unmodified lines
115127 const doCheck = useAtomSet(checkConnectionHealth, { mode: "promiseExit" });
116128 const invalidateConnections = useInvalidateConnections();
117129
118− const probe = freshestVerdict(liveProbe, connection.lastHealth);
130+ const probe = freshestVerdict(liveProbe, presentableHealth(connection.lastHealth));
119131 const status: HealthStatus = probe?.status ?? "unknown";
120132
121133 // Health checks are AUTOMATIC: loading the list revalidates any verdict
@@ -137,6 +149,10 @@ export function useConnectionHealth(connection: Connection): { · 15 unmodified lines
137149 seenEpoch.current = epoch;
138150 if (!firstSight && !cleared) return;
139151 if (healthyAndFresh(last)) return;
152+ // A tool-sync stamp still PROBES (it is non-healthy, and the probe is
153+ // what discovers the credential's real state — a never-probed connection
154+ // whose first sync failed must still surface Expired); it just never
155+ // RENDERS as connection health (see `presentableHealth`).
140156 void doCheck({
141157 params: connectionParams(connection),
142158 query: revalidateQuery(last),
@@ -226,7 +242,10 @@ export function useConnectionsHealth( · 83 unmodified lines
226242
227243 return useCallback(
228244 (connection: Connection) =>
229− freshestVerdict(liveProbes.get(probeKey(connection)) ?? null, connection.lastHealth),
245+ freshestVerdict(
246+ liveProbes.get(probeKey(connection)) ?? null,
247+ presentableHealth(connection.lastHealth),
248+ ),
230249 [liveProbes],
231250 );
232251 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t