The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 07:00 UTC
fix(web): interval settings save when editing ends, not per keystroke (#24673)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Nov 1, 2026 at 16:01 UTC
b8badda42e92bb2d0e58f521490c2bdf9d83252a
5 files changed
+189
-104
apps/web/src/components/settings/BackgroundActivitySettings.tsx
+25
-72
@@ -22,13 +22,6 @@ import {
22
DialogPopup,
23
DialogTitle,
24
} from "../ui/dialog";
25
-import {
26
- NumberField,
27
- NumberFieldDecrement,
28
- NumberFieldGroup,
29
- NumberFieldIncrement,
30
- NumberFieldInput,
31
-} from "../ui/number-field";
25
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
26
import { Switch } from "../ui/switch";
27
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
@@ -36,10 +29,10 @@ import {
29
backgroundActivityOverrideSettings,
30
backgroundActivitySharedPolicySettings,
31
durationToSeconds,
39
- normalizeIntervalSeconds,
32
PROVIDER_HEALTH_INTERVAL_STEP_SECONDS,
33
resolveBackgroundActivityProfileOption,
34
} from "./SettingsPanels.logic";
35
+import { IntervalSecondsField } from "./IntervalSecondsField";
36
import { PolicyTooltip, SettingResetButton, SettingsRow } from "./settingsLayout";
37
import { searchableSetting } from "./settingsSearch";
38
@@ -185,32 +178,22 @@ function BackgroundActivityAdvancedDialog({
178
</p>
179
</div>
180
<div className="flex shrink-0 items-center gap-2">
188
- <NumberField
181
+ <IntervalSecondsField
182
+ label="Git fetch interval"
183
value={automaticGitFetchIntervalSeconds}
184
min={0}
185
step={5}
192
- size="sm"
193
- className="w-32"
194
- onValueChange={(value) =>
186
+ onCommit={(seconds, options) =>
187
updateSettings(
188
backgroundActivityOverrideSettings(
189
settings.backgroundActivity,
190
resolvedBackgroundActivity,
199
- {
200
- automaticGitFetchInterval: Duration.seconds(
201
- normalizeIntervalSeconds(value),
202
- ),
203
- },
191
+ { automaticGitFetchInterval: Duration.seconds(seconds) },
192
),
193
+ options,
194
)
195
}
207
- >
208
- <NumberFieldGroup>
209
- <NumberFieldDecrement aria-label="Decrease Git fetch interval" />
210
- <NumberFieldInput aria-label="Git fetch interval in seconds" />
211
- <NumberFieldIncrement aria-label="Increase Git fetch interval" />
212
- </NumberFieldGroup>
213
- </NumberField>
196
+ />
197
<span className="text-xs text-muted-foreground">seconds</span>
198
</div>
199
</div>
@@ -224,32 +207,22 @@ function BackgroundActivityAdvancedDialog({
207
</p>
208
</div>
209
<div className="flex shrink-0 items-center gap-2">
227
- <NumberField
210
+ <IntervalSecondsField
211
+ label="provider health interval"
212
value={providerHealthRefreshIntervalSeconds}
213
min={0}
214
step={PROVIDER_HEALTH_INTERVAL_STEP_SECONDS}
231
- size="sm"
232
- className="w-32"
233
- onValueChange={(value) =>
215
+ onCommit={(seconds, options) =>
216
updateSettings(
217
backgroundActivityOverrideSettings(
218
settings.backgroundActivity,
219
resolvedBackgroundActivity,
238
- {
239
- providerHealthRefreshInterval: Duration.seconds(
240
- normalizeIntervalSeconds(value),
241
- ),
242
- },
220
+ { providerHealthRefreshInterval: Duration.seconds(seconds) },
221
),
222
+ options,
223
)
224
}
246
- >
247
- <NumberFieldGroup>
248
- <NumberFieldDecrement aria-label="Decrease provider health interval" />
249
- <NumberFieldInput aria-label="Provider health interval in seconds" />
250
- <NumberFieldIncrement aria-label="Increase provider health interval" />
251
- </NumberFieldGroup>
252
- </NumberField>
225
+ />
226
<span className="text-xs text-muted-foreground">seconds</span>
227
</div>
228
</div>
@@ -262,32 +235,22 @@ function BackgroundActivityAdvancedDialog({
235
</p>
236
</div>
237
<div className="flex shrink-0 items-center gap-2">
265
- <NumberField
238
+ <IntervalSecondsField
239
+ label="active host power interval"
240
value={hostPowerMonitorActiveIntervalSeconds}
241
min={5}
242
step={5}
269
- size="sm"
270
- className="w-32"
271
- onValueChange={(value) =>
243
+ onCommit={(seconds, options) =>
244
updateSettings(
245
backgroundActivityOverrideSettings(
246
settings.backgroundActivity,
247
resolvedBackgroundActivity,
276
- {
277
- hostPowerMonitorActiveInterval: Duration.seconds(
278
- normalizeIntervalSeconds(value, 5),
279
- ),
280
- },
248
+ { hostPowerMonitorActiveInterval: Duration.seconds(seconds) },
249
),
250
+ options,
251
)
252
}
284
- >
285
- <NumberFieldGroup>
286
- <NumberFieldDecrement aria-label="Decrease active host power interval" />
287
- <NumberFieldInput aria-label="Active host power interval in seconds" />
288
- <NumberFieldIncrement aria-label="Increase active host power interval" />
289
- </NumberFieldGroup>
290
- </NumberField>
253
+ />
254
<span className="text-xs text-muted-foreground">seconds</span>
255
</div>
256
</div>
@@ -300,32 +263,22 @@ function BackgroundActivityAdvancedDialog({
263
</p>
264
</div>
265
<div className="flex shrink-0 items-center gap-2">
303
- <NumberField
266
+ <IntervalSecondsField
267
+ label="idle host power interval"
268
value={hostPowerMonitorIdleIntervalSeconds}
269
min={5}
270
step={30}
307
- size="sm"
308
- className="w-32"
309
- onValueChange={(value) =>
271
+ onCommit={(seconds, options) =>
272
updateSettings(
273
backgroundActivityOverrideSettings(
274
settings.backgroundActivity,
275
resolvedBackgroundActivity,
314
- {
315
- hostPowerMonitorIdleInterval: Duration.seconds(
316
- normalizeIntervalSeconds(value, 5),
317
- ),
318
- },
276
+ { hostPowerMonitorIdleInterval: Duration.seconds(seconds) },
277
),
278
+ options,
279
)
280
}
322
- >
323
- <NumberFieldGroup>
324
- <NumberFieldDecrement aria-label="Decrease idle host power interval" />
325
- <NumberFieldInput aria-label="Idle host power interval in seconds" />
326
- <NumberFieldIncrement aria-label="Increase idle host power interval" />
327
- </NumberFieldGroup>
328
- </NumberField>
281
+ />
282
<span className="text-xs text-muted-foreground">seconds</span>
283
</div>
284
</div>
apps/web/src/components/settings/IntervalSecondsField.tsx
new
+77
@@ -0,0 +1,77 @@
1
+import { useState } from "react";
2
+import {
3
+ NumberField,
4
+ NumberFieldDecrement,
5
+ NumberFieldGroup,
6
+ NumberFieldIncrement,
7
+ NumberFieldInput,
8
+} from "../ui/number-field";
9
+import { normalizeIntervalSeconds } from "./SettingsPanels.logic";
10
+
11
+export function IntervalSecondsField({
12
+ label,
13
+ value,
14
+ min,
15
+ step,
16
+ onCommit,
17
+}: {
18
+ label: string;
19
+ value: number;
20
+ min: number;
21
+ step: number;
22
+ onCommit: (seconds: number, options: { onFailed: () => void }) => void;
23
+}) {
24
+ const [field, setField] = useState({
25
+ saved: value,
26
+ draft: value as number | null,
27
+ committed: value,
28
+ revision: 0,
29
+ });
30
+ if (field.saved !== value) {
31
+ setField({ ...field, saved: value, draft: value, committed: value });
32
+ }
33
+
34
+ return (
35
+ <NumberField
36
+ value={field.draft}
37
+ min={min}
38
+ step={step}
39
+ size="sm"
40
+ className="w-32"
41
+ onValueChange={(draft) => setField((current) => ({ ...current, draft }))}
42
+ onValueCommitted={(next) => {
43
+ if (next === null) {
44
+ setField((current) => ({ ...current, draft: current.saved }));
45
+ return;
46
+ }
47
+ const seconds = normalizeIntervalSeconds(next, min);
48
+ if (seconds === field.committed) {
49
+ setField((current) => ({ ...current, draft: seconds }));
50
+ return;
51
+ }
52
+ const revision = field.revision + 1;
53
+ setField((current) => ({ ...current, draft: seconds, committed: seconds, revision }));
54
+ onCommit(seconds, {
55
+ onFailed: () =>
56
+ setField((current) =>
57
+ current.revision !== revision
58
+ ? current
59
+ : {
60
+ ...current,
61
+ committed: current.saved,
62
+ draft: current.draft === seconds ? current.saved : current.draft,
63
+ },
64
+ ),
65
+ });
66
+ }}
67
+ >
68
+ <NumberFieldGroup>
69
+ <NumberFieldDecrement aria-label={`Decrease ${label}`} />
70
+ <NumberFieldInput
71
+ aria-label={`${label.charAt(0).toUpperCase()}${label.slice(1)} in seconds`}
72
+ />
73
+ <NumberFieldIncrement aria-label={`Increase ${label}`} />
74
+ </NumberFieldGroup>
75
+ </NumberField>
76
+ );
77
+}
apps/web/src/components/settings/ProviderSettingsPanel.environment.browser.test.tsx
+56
@@ -8,6 +8,7 @@ import {
8
type ServerProvider,
9
type UnifiedSettings,
10
} from "@t3tools/contracts";
11
+import * as Duration from "effect/Duration";
12
import { AsyncResult, type Atom } from "effect/reactivity";
13
import type { ReactNode } from "react";
14
import { describe, expect, it, vi } from "vite-plus/test";
@@ -357,3 +358,58 @@ describe("EnvironmentProviderSettings routing", () => {
358
);
359
});
360
});
361
+
362
+describe("EnvironmentProviderSettings health check interval", () => {
363
+ it("commits interval drafts and allows retrying rejected edits", async () => {
364
+ await setup();
365
+ await using _screen = await render(panel());
366
+ const input = page.getByRole("textbox", { name: "Provider health check interval in seconds" });
367
+
368
+ await userEvent.type(input, "{ArrowUp}{ArrowDown}");
369
+ expect(
370
+ state.updateSettings.mock.calls.map(([patch]) =>
371
+ Duration.toSeconds(patch.backgroundActivity.overrides.providerHealthRefreshInterval),
372
+ ),
373
+ ).toEqual([330, 300]);
374
+ state.updateSettings.mockClear();
375
+
376
+ // Replacing 300 with 120 passes through 30, 3, an empty field, 1 and 12.
377
+ await userEvent.type(input, "{Backspace}{Backspace}{Backspace}120");
378
+ await expect.element(input).toHaveValue("120");
379
+ expect(state.updateSettings).not.toHaveBeenCalled();
380
+
381
+ await userEvent.tab();
382
+ expect(
383
+ state.updateSettings.mock.calls.map(([patch]) =>
384
+ Duration.toSeconds(patch.backgroundActivity.overrides.providerHealthRefreshInterval),
385
+ ),
386
+ ).toEqual([120]);
387
+
388
+ await act(() => state.updateSettings.mock.calls.at(-1)?.[1]?.onFailed?.());
389
+ await expect.element(input).toHaveValue("300");
390
+ await userEvent.type(input, "{Backspace}{Backspace}{Backspace}120");
391
+ await userEvent.tab();
392
+ expect(
393
+ state.updateSettings.mock.calls.map(([patch]) =>
394
+ Duration.toSeconds(patch.backgroundActivity.overrides.providerHealthRefreshInterval),
395
+ ),
396
+ ).toEqual([120, 120]);
397
+
398
+ const rejectPrevious = state.updateSettings.mock.calls.at(-1)?.[1]?.onFailed;
399
+ await userEvent.type(input, "{ArrowUp}");
400
+ await act(() => rejectPrevious?.());
401
+ await expect.element(input).toHaveValue("150");
402
+ });
403
+
404
+ it("restores the saved interval when a cleared field loses focus", async () => {
405
+ await setup();
406
+ await using _screen = await render(panel());
407
+ const input = page.getByRole("textbox", { name: "Provider health check interval in seconds" });
408
+
409
+ await userEvent.type(input, "{Backspace}{Backspace}{Backspace}");
410
+ await userEvent.tab();
411
+
412
+ await expect.element(input).toHaveValue("300");
413
+ expect(state.updateSettings).not.toHaveBeenCalled();
414
+ });
415
+});
apps/web/src/components/settings/ProviderSettingsPanel.tsx
+7
-24
@@ -84,13 +84,6 @@ import {
84
EmptyMedia,
85
EmptyTitle,
86
} from "../ui/empty";
87
-import {
88
- NumberField,
89
- NumberFieldDecrement,
90
- NumberFieldGroup,
91
- NumberFieldIncrement,
92
- NumberFieldInput,
93
-} from "../ui/number-field";
87
import { ScrollArea } from "../ui/scroll-area";
88
import { Toggle, ToggleGroup } from "../ui/toggle-group";
89
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
@@ -98,6 +91,7 @@ import { stackedThreadToast, toastManager } from "../ui/toast";
91
import { AddProviderInstanceDialog } from "./AddProviderInstanceDialog";
92
import { useManagedPolicy } from "~/state/managedPolicy";
93
import { ExpandableText } from "./ExpandableText";
94
+import { IntervalSecondsField } from "./IntervalSecondsField";
95
import { ProviderInstanceCard } from "./ProviderInstanceCard";
96
import { useSecretSources } from "./SecretSourceInput";
97
import { UsageProviderSettings } from "./UsageProviderSettings";
@@ -112,7 +106,6 @@ import {
106
backgroundActivityOverrideSettings,
107
buildProviderInstanceUpdatePatch,
108
durationToSeconds,
115
- normalizeIntervalSeconds,
109
PROVIDER_HEALTH_INTERVAL_STEP_SECONDS,
110
} from "./SettingsPanels.logic";
111
import {
@@ -1128,32 +1121,22 @@ export function EnvironmentProviderSettings({
1121
!canWriteSettings && "opacity-50 select-none",
1122
)}
1123
>
1131
- <NumberField
1124
+ <IntervalSecondsField
1125
+ label="provider health check interval"
1126
value={providerHealthRefreshIntervalSeconds}
1127
min={0}
1128
step={PROVIDER_HEALTH_INTERVAL_STEP_SECONDS}
1135
- size="sm"
1136
- className="w-32"
1137
- onValueChange={(value) =>
1129
+ onCommit={(seconds, options) =>
1130
updateSettings(
1131
backgroundActivityOverrideSettings(
1132
settings.backgroundActivity,
1133
resolvedBackgroundActivity,
1142
- {
1143
- providerHealthRefreshInterval: Duration.seconds(
1144
- normalizeIntervalSeconds(value),
1145
- ),
1146
- },
1134
+ { providerHealthRefreshInterval: Duration.seconds(seconds) },
1135
),
1136
+ options,
1137
)
1138
}
1150
- >
1151
- <NumberFieldGroup>
1152
- <NumberFieldDecrement aria-label="Decrease provider health check interval" />
1153
- <NumberFieldInput aria-label="Provider health check interval in seconds" />
1154
- <NumberFieldIncrement aria-label="Increase provider health check interval" />
1155
- </NumberFieldGroup>
1156
- </NumberField>
1139
+ />
1140
<span className="text-xs text-muted-foreground">seconds</span>
1141
</div>
1142
}
apps/web/src/hooks/useSettings.ts
+24
-8
@@ -588,8 +588,12 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
588
reportFailure: false,
589
});
590
const { environments } = useEnvironments();
591
- const persistServerSettings = async (request: Parameters<typeof persist>[0]) => {
591
+ const persistServerSettings = async (
592
+ request: Parameters<typeof persist>[0],
593
+ onFailed?: () => void,
594
+ ) => {
595
const result = await persist(request);
596
+ if (result._tag === "Failure") onFailed?.();
597
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
598
const label =
599
environments.find((environment) => environment.environmentId === request.environmentId)
@@ -604,7 +608,10 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
608
return result;
609
};
610
const sharedSettingsSyncTargetIds = useSharedSettingsSyncTargetIds(true);
607
- const updateSettings = (patch: UnifiedSettingsPatch) => {
611
+ const updateSettings = (
612
+ patch: UnifiedSettingsPatch,
613
+ options?: { readonly onFailed?: () => void },
614
+ ) => {
615
const { serverPatch, clientPatch } = splitPatch(patch);
616
617
const canWriteServerPatch =
@@ -613,6 +620,7 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
620
readEnvironmentScope(environmentId, scope),
621
);
622
if (Object.keys(serverPatch).length > 0 && !canWriteServerPatch) {
623
+ options?.onFailed?.();
624
toastManager.add({
625
type: "warning",
626
title: "Setting not saved",
@@ -622,18 +630,20 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
630
if (Object.keys(serverPatch).length > 0 && canWriteServerPatch) {
631
const { sharedPatch, localPatch } = splitSharedServerPatch(serverPatch);
632
// Dropping the write silently leaves the control looking saved.
625
- const warnUnsaved = (description = PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE) =>
626
- toastManager.add({
633
+ const warnUnsaved = (description = PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE) => {
634
+ options?.onFailed?.();
635
+ return toastManager.add({
636
type: "warning",
637
title: "Setting not saved",
638
description,
639
});
640
+ };
641
if (Object.keys(localPatch).length > 0) {
642
if (environmentId) {
633
- void persistServerSettings({
634
- environmentId,
635
- input: { patch: localPatch },
636
- });
643
+ void persistServerSettings(
644
+ { environmentId, input: { patch: localPatch } },
645
+ options?.onFailed,
646
+ );
647
} else {
648
warnUnsaved();
649
}
@@ -688,6 +698,12 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
698
result: await persist(request),
699
})),
700
).then((outcomes) => {
701
+ if (
702
+ deniedLabels.length > 0 ||
703
+ outcomes.some(({ result }) => result._tag === "Failure")
704
+ ) {
705
+ options?.onFailed?.();
706
+ }
707
const failures = outcomes.flatMap(({ label, result }) => {
708
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return [];
709
const error = squashAtomCommandFailure(result);