@devries-cameron20 / t3code-1 / commits / b2e86d7902
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): an invalid provider setting is refused at its field instead of taking the provider offline (#35100)

Julius Marminge committed Nov 12, 2026 at 02:41 UTC b2e86d79020358d51bae4c30eb415c1a5da7c132
2 files changed +79 -14
apps/web/src/components/settings/ProviderSettingsForm.test.ts
+18
@@ -52,6 +52,24 @@ describe("ProviderSettingsForm helpers", () => {
52 expect(next).toEqual({ forkOwned: 1 });
53 });
54
55 + it("does not store a text value its field's schema rejects", () => {
56 + const claude = providerClients.get(ProviderDriverKind.make("claudeAgent"));
57 + expect(claude).toBeDefined();
58 + const autoCompactWindow = deriveProviderSettingsFields(claude!).find(
59 + (field) => field.key === "autoCompactWindow",
60 + );
61 + expect(autoCompactWindow).toBeDefined();
62 +
63 + for (const invalid of ["300k", "50000"]) {
64 + expect(
65 + nextProviderConfigWithFieldValue({ launchArgs: "--x" }, autoCompactWindow!, invalid),
66 + ).toEqual({ launchArgs: "--x" });
67 + }
68 + expect(
69 + nextProviderConfigWithFieldValue({ launchArgs: "--x" }, autoCompactWindow!, "300000"),
70 + ).toEqual({ launchArgs: "--x", autoCompactWindow: "300000" });
71 + });
72 +
73 it("stores false boolean fields when true is the default", () => {
74 const next = nextProviderConfigWithFieldValue(
75 undefined,
apps/web/src/components/settings/ProviderSettingsForm.tsx
+61 -14
@@ -42,6 +42,8 @@ export interface ProviderSettingsFieldModel {
42 /** Typed `SettingsSecretValue`: may name a secret provider reference instead of a value. */
43 readonly acceptsSecretReference?: boolean | undefined;
44 readonly defaultBooleanValue?: boolean | undefined;
45 + /** Whether the field's schema decodes a typed string; one it rejects is never stored. */
46 + readonly accepts?: ((value: string) => boolean) | undefined;
47
48 readonly options?: ReadonlyArray<ProviderSettingsFormOption> | undefined;
49 }
@@ -89,6 +91,13 @@ function readFieldBooleanDefault(
91 return Option.isSome(decoded) && typeof decoded.value === "boolean" ? decoded.value : undefined;
92 }
93
94 +function fieldAcceptsString(
95 + fieldSchema: ProviderClientDefinition["settingsSchema"]["fields"][string],
96 +): (value: string) => boolean {
97 + const decode = Schema.decodeUnknownOption(fieldSchema as Schema.Decoder<unknown>);
98 + return (value) => Option.isSome(decode(value));
99 +}
100 +
101 export function deriveProviderSettingsFields(
102 definition: SettingsFormDefinition,
103 value?: unknown,
@@ -142,6 +151,7 @@ export function deriveProviderSettingsFields(
151 ...(formAnnotation.control === "switch"
152 ? { defaultBooleanValue: readFieldBooleanDefault(fieldSchema) }
153 : {}),
154 + accepts: fieldAcceptsString(fieldSchema),
155 ...(formAnnotation.control === "select" && formAnnotation.options
156 ? { options: formAnnotation.options }
157 : {}),
@@ -322,7 +332,7 @@ export function nextProviderConfigWithFieldValue(
332 const trimmed = value.trim();
333 if (field.clearWhenEmpty === "omit" && trimmed.length === 0) {
334 delete base[field.key];
325 - } else {
335 + } else if (field.accepts?.(value) !== false) {
336 base[field.key] = value;
337 }
338 return Object.keys(base).length > 0 ? base : undefined;
@@ -434,6 +444,50 @@ function ProviderSettingsSelect({
444 );
445 }
446
447 +function ProviderSettingsTextInput({
448 + field,
449 + value,
450 + inputId,
451 + descriptionId,
452 + onChange,
453 +}: {
454 + readonly field: ProviderSettingsFieldModel;
455 + readonly value: unknown;
456 + readonly inputId: string;
457 + readonly descriptionId: string | undefined;
458 + readonly onChange: ProviderSettingsFormProps["onChange"];
459 +}) {
460 + const [rejected, setRejected] = useState<string | null>(null);
461 + return (
462 + <div className="flex w-full min-w-0 flex-col gap-1 @min-[32rem]/settings-row:w-56">
463 + <DraftInput
464 + id={inputId}
465 + aria-describedby={descriptionId}
466 + size="sm"
467 + className="w-full max-w-full"
468 + type={field.control === "password" ? "password" : undefined}
469 + autoComplete={field.control === "password" ? "off" : undefined}
470 + value={rejected ?? readProviderConfigString(value, field.key)}
471 + placeholder={field.placeholder}
472 + onCommit={(next) => {
473 + const clears = field.clearWhenEmpty === "omit" && next.trim().length === 0;
474 + if (!clears && field.accepts?.(next) === false) {
475 + setRejected(next);
476 + return;
477 + }
478 + setRejected(null);
479 + onChange(nextProviderConfigWithFieldValue(value, field, next));
480 + }}
481 + aria-invalid={rejected !== null || undefined}
482 + spellCheck={false}
483 + />
484 + {rejected !== null ? (
485 + <p className="text-2xs text-destructive">Enter a valid value. It was not saved.</p>
486 + ) : null}
487 + </div>
488 + );
489 +}
490 +
491 function FieldFrame(props: {
492 readonly variant: ProviderSettingsFormProps["variant"];
493 readonly children: ReactNode;
@@ -541,19 +595,12 @@ function ProviderSettingsFieldRow({
595 ) : null}
596 </div>
597 ) : (
544 - <DraftInput
545 - id={inputId}
546 - aria-describedby={descriptionId}
547 - size="sm"
548 - className="w-full max-w-full @min-[32rem]/settings-row:w-56"
549 - type={field.control === "password" ? "password" : undefined}
550 - autoComplete={field.control === "password" ? "off" : undefined}
551 - value={readProviderConfigString(value, field.key)}
552 - placeholder={field.placeholder}
553 - onCommit={(next) => {
554 - onChange(nextProviderConfigWithFieldValue(value, field, next));
555 - }}
556 - spellCheck={false}
598 + <ProviderSettingsTextInput
599 + field={field}
600 + value={value}
601 + inputId={inputId}
602 + descriptionId={descriptionId}
603 + onChange={onChange}
604 />
605 );
606