Skip to content

Commit dd1529a

Browse files
fixfonclaude
andcommitted
fix(server): provider health interval can't drop below 30 seconds
A saved or patched providerHealthRefreshInterval was used verbatim, so a 5s override made background provider probes run back-to-back. The resolved interval is now lifted to a 30s minimum (0 still disables), and the two Settings fields commit a normalized value instead of persisting every keystroke. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 18656a3 commit dd1529a

8 files changed

Lines changed: 87 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ import {
102102
backgroundActivityOverrideSettings,
103103
buildProviderInstanceUpdatePatch,
104104
durationToSeconds,
105-
normalizeIntervalSeconds,
105+
normalizeProviderHealthIntervalSeconds,
106106
PROVIDER_HEALTH_INTERVAL_STEP_SECONDS,
107107
} from "./SettingsPanels.logic";
108108
import {
@@ -1244,14 +1244,14 @@ export function EnvironmentProviderSettings({
12441244
step={PROVIDER_HEALTH_INTERVAL_STEP_SECONDS}
12451245
size="sm"
12461246
className="w-32"
1247-
onValueChange={(value) =>
1247+
onValueCommitted={(value) =>
12481248
updateSettings(
12491249
backgroundActivityOverrideSettings(
12501250
settings.backgroundActivity,
12511251
resolvedBackgroundActivity,
12521252
{
12531253
providerHealthRefreshInterval: Duration.seconds(
1254-
normalizeIntervalSeconds(value),
1254+
normalizeProviderHealthIntervalSeconds(value),
12551255
),
12561256
},
12571257
),

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getChangedTypographySettingLabels,
1717
hasChangedBackgroundActivitySettings,
1818
isProjectGroupingEnabled,
19+
normalizeProviderHealthIntervalSeconds,
1920
projectGroupingModeFromToggle,
2021
resolveBackgroundActivityProfileOption,
2122
} from "./SettingsPanels.logic";
@@ -255,3 +256,13 @@ describe("getChangedBrowserSettingLabels", () => {
255256
]);
256257
});
257258
});
259+
260+
describe("provider health interval input", () => {
261+
it("keeps 0 as disabled and lifts other committed values to the 30s minimum", () => {
262+
expect(normalizeProviderHealthIntervalSeconds(0)).toBe(0);
263+
expect(normalizeProviderHealthIntervalSeconds(null)).toBe(0);
264+
expect(normalizeProviderHealthIntervalSeconds(5)).toBe(30);
265+
expect(normalizeProviderHealthIntervalSeconds(30)).toBe(30);
266+
expect(normalizeProviderHealthIntervalSeconds(600)).toBe(600);
267+
});
268+
});

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import type {
88
SidebarProjectGroupingMode,
99
UnifiedSettings,
1010
} from "@t3tools/contracts";
11-
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
11+
import {
12+
DEFAULT_UNIFIED_SETTINGS,
13+
MIN_PROVIDER_HEALTH_REFRESH_INTERVAL,
14+
} from "@t3tools/contracts/settings";
1215
import {
1316
getBackgroundActivityBaseProfile,
1417
normalizeBackgroundActivitySettings,
@@ -295,6 +298,17 @@ export function normalizeIntervalSeconds(value: number | null, minimum = 0): num
295298
return Math.max(minimum, Math.round(value));
296299
}
297300

301+
/**
302+
* Seconds to persist for a committed provider health interval: 0 disables
303+
* periodic checks, anything else is at least the server's minimum.
304+
*/
305+
export function normalizeProviderHealthIntervalSeconds(value: number | null): number {
306+
const seconds = normalizeIntervalSeconds(value);
307+
return seconds === 0
308+
? 0
309+
: Math.max(seconds, Duration.toMillis(MIN_PROVIDER_HEALTH_REFRESH_INTERVAL) / 1_000);
310+
}
311+
298312
export function backgroundActivityOverrideSettings(
299313
current: BackgroundActivitySettings,
300314
resolved: ReturnType<typeof resolveServerBackgroundActivitySettings>,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ import {
149149
getChangedBrowserSettingLabels,
150150
getChangedTypographySettingLabels,
151151
normalizeIntervalSeconds,
152+
normalizeProviderHealthIntervalSeconds,
152153
PROVIDER_HEALTH_INTERVAL_STEP_SECONDS,
153154
hasChangedBackgroundActivitySettings,
154155
isProjectGroupingEnabled,
@@ -1008,14 +1009,14 @@ function BackgroundActivityAdvancedDialog({
10081009
step={PROVIDER_HEALTH_INTERVAL_STEP_SECONDS}
10091010
size="sm"
10101011
className="w-32"
1011-
onValueChange={(value) =>
1012+
onValueCommitted={(value) =>
10121013
updateSettings(
10131014
backgroundActivityOverrideSettings(
10141015
settings.backgroundActivity,
10151016
resolvedBackgroundActivity,
10161017
{
10171018
providerHealthRefreshInterval: Duration.seconds(
1018-
normalizeIntervalSeconds(value),
1019+
normalizeProviderHealthIntervalSeconds(value),
10191020
),
10201021
},
10211022
),

‎packages/contracts/src/settings.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@ export interface BranchNamingOptions {
860860

861861
export const DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL = Duration.seconds(30);
862862
export const DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL = Duration.minutes(5);
863+
/** Shortest positive provider health interval. 0 still disables periodic checks. */
864+
export const MIN_PROVIDER_HEALTH_REFRESH_INTERVAL = Duration.seconds(30);
863865

864866
export const BackgroundActivityProfile = Schema.Literals([
865867
"balanced",

‎packages/provider-core/src/server/managedProvider.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ describe("makeManagedServerProvider", () => {
348348
yield* PubSub.publish(serverSettingsChanges, nextServerSettings);
349349
yield* Effect.yieldNow;
350350

351-
yield* TestClock.adjust("999 millis");
351+
// A 1s interval is lifted to the 30s minimum, so nothing runs at 1s.
352+
yield* TestClock.adjust("29999 millis");
352353
assert.strictEqual(yield* Ref.get(checkCalls), 1);
353354
yield* TestClock.adjust("1 millis");
354355
yield* Deferred.await(periodicCheckDone);

‎packages/shared/src/backgroundActivitySettings.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
DEFAULT_BACKGROUND_ACTIVITY_PROFILE,
55
DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL,
66
DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL,
7+
MIN_PROVIDER_HEALTH_REFRESH_INTERVAL,
78
type ServerSettings,
89
} from "@t3tools/contracts";
910
import * as Duration from "effect/Duration";
@@ -75,6 +76,18 @@ export function getBackgroundActivityBaseProfile(
7576
return backgroundActivity.profile;
7677
}
7778

79+
/**
80+
* Lifts a positive provider health interval to the minimum so a saved or
81+
* patched override cannot make background probes run back-to-back. Zero stays
82+
* zero because it disables periodic checks.
83+
*/
84+
export function clampProviderHealthRefreshInterval(interval: Duration.Duration): Duration.Duration {
85+
const millis = Duration.toMillis(interval);
86+
return millis > 0 && millis < Duration.toMillis(MIN_PROVIDER_HEALTH_REFRESH_INTERVAL)
87+
? MIN_PROVIDER_HEALTH_REFRESH_INTERVAL
88+
: interval;
89+
}
90+
7891
export function resolveBackgroundActivitySettings(
7992
backgroundActivity: BackgroundActivitySettings,
8093
): ResolvedBackgroundActivitySettings {
@@ -85,8 +98,9 @@ export function resolveBackgroundActivitySettings(
8598
profile: baseProfile,
8699
automaticGitFetchInterval:
87100
overrides.automaticGitFetchInterval ?? preset.automaticGitFetchInterval,
88-
providerHealthRefreshInterval:
101+
providerHealthRefreshInterval: clampProviderHealthRefreshInterval(
89102
overrides.providerHealthRefreshInterval ?? preset.providerHealthRefreshInterval,
103+
),
90104
hostPowerMonitorActiveInterval:
91105
overrides.hostPowerMonitorActiveInterval ?? preset.hostPowerMonitorActiveInterval,
92106
hostPowerMonitorIdleInterval:

‎packages/shared/src/serverSettings.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,42 @@ describe("serverSettings helpers", () => {
811811

812812
expect(resolved.pauseWhenOnBattery).toBe(false);
813813
});
814+
815+
describe("provider health interval floor", () => {
816+
const resolveInterval = (override: Duration.Duration) =>
817+
Duration.toMillis(
818+
resolveServerBackgroundActivitySettings({
819+
...DEFAULT_SERVER_SETTINGS,
820+
backgroundActivity: {
821+
schemaVersion: 1,
822+
profile: "custom",
823+
baseProfile: "balanced",
824+
overrides: { providerHealthRefreshInterval: override },
825+
},
826+
}).providerHealthRefreshInterval,
827+
);
828+
829+
it("lifts a persisted override below the minimum to the minimum", () => {
830+
expect(resolveInterval(Duration.seconds(5))).toBe(30_000);
831+
});
832+
833+
it("lifts a legacy flat interval below the minimum", () => {
834+
expect(
835+
Duration.toMillis(
836+
resolveServerBackgroundActivitySettings({
837+
...DEFAULT_SERVER_SETTINGS,
838+
providerHealthRefreshInterval: Duration.seconds(1),
839+
}).providerHealthRefreshInterval,
840+
),
841+
).toBe(30_000);
842+
});
843+
844+
it("keeps zero (disabled) and values at or above the minimum", () => {
845+
expect(resolveInterval(Duration.zero)).toBe(0);
846+
expect(resolveInterval(Duration.seconds(30))).toBe(30_000);
847+
expect(resolveInterval(Duration.seconds(45))).toBe(45_000);
848+
});
849+
});
814850
});
815851

816852
describe("worktreesDirectory", () => {

0 commit comments

Comments
 (0)