Skip to content

Commit 6a822e6

Browse files
t3dotggclaude
andcommitted
fix(web): honest provider access states for remote devices
Addresses review findings on the per-device providers panel. - Treat unresolved primary session scopes as loading instead of editable, so controls are never offered before permissions are known - Render provider status rows for read-only sessions instead of replacing the whole panel with a blocking message - Distinguish a hydrating environment catalog from having no devices Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 1b3e79a commit 6a822e6

3 files changed

Lines changed: 111 additions & 28 deletions

File tree

‎apps/web/src/components/settings/ProviderSettingsPanel.logic.test.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("provider environment access", () => {
5050
classifyProviderEnvironmentAccess({
5151
connectionPhase: "connected",
5252
hasServerConfig: true,
53-
canOperate: true,
53+
operateAccess: "granted",
5454
}),
5555
).toEqual({ kind: "editable" });
5656
});
@@ -60,7 +60,17 @@ describe("provider environment access", () => {
6060
classifyProviderEnvironmentAccess({
6161
connectionPhase: "connected",
6262
hasServerConfig: false,
63-
canOperate: true,
63+
operateAccess: "granted",
64+
}),
65+
).toEqual({ kind: "loading" });
66+
});
67+
68+
it("waits for unresolved operate access instead of assuming it is editable", () => {
69+
expect(
70+
classifyProviderEnvironmentAccess({
71+
connectionPhase: "connected",
72+
hasServerConfig: true,
73+
operateAccess: "pending",
6474
}),
6575
).toEqual({ kind: "loading" });
6676
});
@@ -70,7 +80,7 @@ describe("provider environment access", () => {
7080
classifyProviderEnvironmentAccess({
7181
connectionPhase: "connected",
7282
hasServerConfig: true,
73-
canOperate: false,
83+
operateAccess: "denied",
7484
}),
7585
).toEqual({ kind: "read-only" });
7686
});
@@ -82,7 +92,7 @@ describe("provider environment access", () => {
8292
classifyProviderEnvironmentAccess({
8393
connectionPhase,
8494
hasServerConfig: true,
85-
canOperate: true,
95+
operateAccess: "granted",
8696
}),
8797
).toEqual({ kind: "unavailable" });
8898
},
@@ -93,7 +103,7 @@ describe("provider environment access", () => {
93103
classifyProviderEnvironmentAccess({
94104
connectionPhase: "error",
95105
hasServerConfig: true,
96-
canOperate: true,
106+
operateAccess: "granted",
97107
}),
98108
).toEqual({ kind: "error" });
99109
});

‎apps/web/src/components/settings/ProviderSettingsPanel.logic.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export type ProviderEnvironmentAccess =
4949
| { readonly kind: "unavailable" }
5050
| { readonly kind: "error" };
5151

52+
/**
53+
* Whether the session may change provider configuration on an environment.
54+
* `pending` means the answer is still unknown, which must not be presented as
55+
* editable: rendering controls we already know might be rejected only turns a
56+
* permission problem into a failed write.
57+
*/
58+
export type ProviderOperateAccess = "granted" | "denied" | "pending";
59+
5260
export function classifyProviderEnvironmentAccess(input: {
5361
readonly connectionPhase:
5462
| "available"
@@ -58,18 +66,18 @@ export function classifyProviderEnvironmentAccess(input: {
5866
| "connected"
5967
| "error";
6068
readonly hasServerConfig: boolean;
61-
readonly canOperate: boolean | null;
69+
readonly operateAccess: ProviderOperateAccess;
6270
}): ProviderEnvironmentAccess {
6371
if (input.connectionPhase === "error") {
6472
return { kind: "error" };
6573
}
6674
if (input.connectionPhase !== "connected") {
6775
return { kind: "unavailable" };
6876
}
69-
if (!input.hasServerConfig) {
77+
if (!input.hasServerConfig || input.operateAccess === "pending") {
7078
return { kind: "loading" };
7179
}
72-
if (input.canOperate === false) {
80+
if (input.operateAccess === "denied") {
7381
return { kind: "read-only" };
7482
}
7583
return { kind: "editable" };

‎apps/web/src/components/settings/ProviderSettingsPanel.tsx‎

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
5757
import { AddProviderInstanceDialog } from "./AddProviderInstanceDialog";
5858
import { ProviderInstanceCard } from "./ProviderInstanceCard";
5959
import { DRIVER_OPTIONS, getDriverOption } from "./providerDriverMeta";
60+
import {
61+
getProviderSummary,
62+
getProviderVersionLabel,
63+
PROVIDER_STATUS_STYLES,
64+
type ProviderStatusKey,
65+
} from "./providerStatus";
6066
import { buildProviderInstanceUpdatePatch } from "./SettingsPanels.logic";
6167
import {
6268
SettingResetButton,
@@ -68,6 +74,7 @@ import {
6874
import {
6975
buildProviderEnvironmentOptions,
7076
classifyProviderEnvironmentAccess,
77+
type ProviderOperateAccess,
7178
resolveSelectedProviderEnvironmentId,
7279
} from "./ProviderSettingsPanel.logic";
7380

@@ -154,22 +161,18 @@ function EnvironmentUnavailableRow({
154161
accessKind,
155162
}: {
156163
readonly environment: EnvironmentPresentation;
157-
readonly accessKind: "loading" | "read-only" | "unavailable" | "error";
164+
readonly accessKind: "loading" | "unavailable" | "error";
158165
}) {
159166
const title =
160167
accessKind === "loading"
161168
? "Loading provider settings"
162-
: accessKind === "read-only"
163-
? "Provider settings are read only"
164-
: accessKind === "error"
165-
? "Could not connect to this device"
166-
: "Provider settings are unavailable";
169+
: accessKind === "error"
170+
? "Could not connect to this device"
171+
: "Provider settings are unavailable";
167172
const description =
168173
accessKind === "loading"
169174
? `Waiting for ${environment.label}'s configuration.`
170-
: accessKind === "read-only"
171-
? `This session can view ${environment.label}, but it cannot change provider configuration.`
172-
: connectionStatusText(environment.connection);
175+
: connectionStatusText(environment.connection);
173176
return (
174177
<SettingsSection title="Providers">
175178
<SettingsRow
@@ -188,7 +191,7 @@ function EnvironmentUnavailableRow({
188191
}
189192

190193
export function ProviderSettingsPanel() {
191-
const { environments } = useEnvironments();
194+
const { environments, isReady } = useEnvironments();
192195
const primaryEnvironmentId = usePrimaryEnvironmentId();
193196
const options = useMemo(
194197
() => buildProviderEnvironmentOptions(environments, primaryEnvironmentId),
@@ -219,9 +222,15 @@ export function ProviderSettingsPanel() {
219222
{showDeviceList ? (
220223
<SettingsSection title="Devices">
221224
{options.length === 0 ? (
225+
// The catalog hydrates asynchronously, so an empty list before it is
226+
// ready means "not loaded yet", not "nothing is connected".
222227
<SettingsRow
223-
title="No connected devices"
224-
description="Connect an execution environment before configuring providers."
228+
title={isReady ? "No connected devices" : "Loading devices"}
229+
description={
230+
isReady
231+
? "Connect an execution environment before configuring providers."
232+
: "Reading connected execution environments."
233+
}
225234
/>
226235
) : (
227236
<div className="grid gap-1 sm:grid-cols-2">
@@ -291,18 +300,25 @@ function SelectedEnvironmentProviderSettings({
291300
// Remote connection brokers request the standard client scopes, which include
292301
// orchestration:operate. The environment RPC layer remains authoritative if a
293302
// custom remote credential grants less access.
294-
const canOperate = isPrimary
295-
? window.desktopBridge
296-
? true
297-
: primarySessionState.data?.authenticated
298-
? (primarySessionState.data.scopes ?? []).includes(AuthOrchestrationOperateScope)
299-
: null
300-
: true;
303+
const operateAccess: ProviderOperateAccess = !isPrimary
304+
? "granted"
305+
: window.desktopBridge
306+
? "granted"
307+
: primarySessionState.isPending
308+
? "pending"
309+
: primarySessionState.data?.authenticated
310+
? (primarySessionState.data.scopes ?? []).includes(AuthOrchestrationOperateScope)
311+
? "granted"
312+
: "denied"
313+
: "denied";
301314
const access = classifyProviderEnvironmentAccess({
302315
connectionPhase: environment.connection.phase,
303316
hasServerConfig: environment.serverConfig !== null,
304-
canOperate,
317+
operateAccess,
305318
});
319+
if (access.kind === "read-only") {
320+
return <ReadOnlyProviderSettings environment={environment} />;
321+
}
306322
if (access.kind !== "editable") {
307323
return <EnvironmentUnavailableRow environment={environment} accessKind={access.kind} />;
308324
}
@@ -314,6 +330,55 @@ function SelectedEnvironmentProviderSettings({
314330
);
315331
}
316332

333+
/**
334+
* Connected devices this session may read but not reconfigure. The provider
335+
* catalogue is still worth showing — knowing which providers a box has and
336+
* whether they are authenticated is most of the value — so render each one as
337+
* a status row and omit every mutation control.
338+
*/
339+
function ReadOnlyProviderSettings({
340+
environment,
341+
}: {
342+
readonly environment: EnvironmentPresentation;
343+
}) {
344+
const providers = environment.serverConfig?.providers ?? EMPTY_SERVER_PROVIDERS;
345+
return (
346+
<SettingsSection title="Providers">
347+
<SettingsRow
348+
title="Read only"
349+
description={`This session can view ${environment.label}, but it cannot change provider configuration.`}
350+
/>
351+
{providers.map((provider) => {
352+
const driverOption = getDriverOption(provider.driver);
353+
const summary = getProviderSummary(provider);
354+
const versionLabel = getProviderVersionLabel(provider.version);
355+
return (
356+
<SettingsRow
357+
key={provider.instanceId}
358+
title={
359+
<span className="inline-flex items-center gap-2">
360+
<span
361+
className={cn(
362+
"size-2 rounded-full",
363+
PROVIDER_STATUS_STYLES[provider.status as ProviderStatusKey].dot,
364+
)}
365+
aria-hidden
366+
/>
367+
{driverOption?.label ?? String(provider.driver)}
368+
{versionLabel ? (
369+
<code className="text-[11px] text-muted-foreground">{versionLabel}</code>
370+
) : null}
371+
</span>
372+
}
373+
description={summary.detail ?? summary.headline}
374+
status={summary.detail ? summary.headline : null}
375+
/>
376+
);
377+
})}
378+
</SettingsSection>
379+
);
380+
}
381+
317382
export function EnvironmentProviderSettings({
318383
environmentId,
319384
environmentLabel,

0 commit comments

Comments
 (0)