Skip to content

Commit d7ff637

Browse files
fix(settings): each environment gets the idle compaction form its server reads
Review follow-ups on the compatibility fix: - The all-environments scope sent one patch, built from a representative environment's settings, to every environment. The panel now sends the mode as idleCompaction and the planner translates it per destination. - A server with no settings file sent no idleCompaction, so clients took it for one from before modes. Every load now carries both fields. - "Never" is disabled for a server that has only the on/off switch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c734c56 commit d7ff637

6 files changed

Lines changed: 60 additions & 15 deletions

File tree

‎apps/server/src/serverSettings.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ it.layer(NodeServices.layer)("server settings", (it) => {
226226
}).pipe(Effect.provide(layerServerSettings())),
227227
);
228228

229+
it.effect("tells clients it reads idle compaction modes before any settings are saved", () =>
230+
Effect.gen(function* () {
231+
const service = yield* ServerSettingsModule.ServerSettingsService;
232+
const settings = yield* service.getSettings;
233+
assert.equal(settings.idleCompaction, "onReturn");
234+
assert.strictEqual(settings.compactIdleThreads, false);
235+
}).pipe(Effect.provide(layerServerSettings())),
236+
);
237+
229238
it.effect("saves through a symlinked settings file without replacing the link", () =>
230239
Effect.gen(function* () {
231240
const config = yield* ServerConfig.ServerConfig;

‎apps/server/src/serverSettings.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,13 @@ const make = Effect.gen(function* () {
685685
});
686686
}
687687
} else {
688-
// Settings saved by a server that kept the mode in `compactIdleThreads`
689-
// move it to `idleCompaction`, so that switch goes to clients as a boolean.
690-
settings = withIdleCompaction(decoded.value, globalIdleCompaction(decoded.value));
688+
settings = decoded.value;
691689
}
692690
}
691+
// Settings saved by a server that kept the mode in `compactIdleThreads` move
692+
// it to `idleCompaction`, so that switch goes to clients as a boolean. The
693+
// defaults gain the field too, which tells clients this server reads modes.
694+
settings = withIdleCompaction(settings, globalIdleCompaction(settings));
693695

694696
// A file that failed to decode must stay on disk for the user to repair.
695697
const settingsFileTrusted = Option.isNone(parseFailure);

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type DesktopUpdateChannel,
99
IDLE_COMPACTION_MODES,
1010
globalIdleCompaction,
11-
idleCompactionPatch,
11+
readsIdleCompactionModes,
1212
ProviderDriverKind,
1313
type ProviderInstanceId,
1414
type SidebarProjectGroupingMode,
@@ -1006,9 +1006,7 @@ export function GeneralSettingsPanel() {
10061006
<SettingResetButton
10071007
label="compact idle threads"
10081008
onClick={() =>
1009-
updateSettings(
1010-
idleCompactionPatch(settings, globalIdleCompaction(DEFAULT_UNIFIED_SETTINGS)),
1011-
)
1009+
updateSettings({ idleCompaction: globalIdleCompaction(DEFAULT_UNIFIED_SETTINGS) })
10121010
}
10131011
/>
10141012
) : null
@@ -1018,7 +1016,7 @@ export function GeneralSettingsPanel() {
10181016
value={globalIdleCompaction(settings)}
10191017
onValueChange={(value) => {
10201018
const mode = IDLE_COMPACTION_MODES.find((candidate) => candidate.value === value);
1021-
if (mode) updateSettings(idleCompactionPatch(settings, mode.value));
1019+
if (mode) updateSettings({ idleCompaction: mode.value });
10221020
}}
10231021
>
10241022
<SelectTrigger size="sm" className="w-full sm:w-56" aria-label="Compact idle threads">
@@ -1032,7 +1030,13 @@ export function GeneralSettingsPanel() {
10321030
</SelectTrigger>
10331031
<SelectPopup align="end" alignItemWithTrigger={false}>
10341032
{IDLE_COMPACTION_MODES.map((mode) => (
1035-
<SelectItem hideIndicator key={mode.value} value={mode.value}>
1033+
<SelectItem
1034+
hideIndicator
1035+
key={mode.value}
1036+
value={mode.value}
1037+
// A server from before modes has only the on/off switch, so it cannot store "Never".
1038+
disabled={mode.value === "off" && !readsIdleCompactionModes(settings)}
1039+
>
10361040
{mode.label}
10371041
</SelectItem>
10381042
))}

‎apps/web/src/components/settings/scopedSettings.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ describe("scoped settings writes", () => {
192192
]);
193193
});
194194

195+
it("sends an idle compaction mode in the form each environment's server reads", () => {
196+
const targets = [
197+
environment("Fixed", { settings: { compactIdleThreads: false, idleCompaction: "onReturn" } }),
198+
environment("Modes", { settings: { compactIdleThreads: "onReturn" } }),
199+
environment("Switch", { settings: { compactIdleThreads: false } }),
200+
];
201+
const plan = planScopedSettingsPatch(resolveSettingsScope({}, [], targets), targets, {
202+
idleCompaction: "beforeCacheExpires",
203+
});
204+
expect(plan.serverWrites.map((write) => write.patch)).toEqual([
205+
{ idleCompaction: "beforeCacheExpires" },
206+
{ compactIdleThreads: "beforeCacheExpires" },
207+
{ compactIdleThreads: true },
208+
]);
209+
});
210+
195211
it("writes an aggregate preference only to connected environments with loaded configuration", async () => {
196212
const persistServer = vi.fn().mockResolvedValue({ _tag: "Success" });
197213
const persistClient = vi.fn();

‎apps/web/src/components/settings/scopedSettings.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ClientSettingsSchema,
33
type ClientSettingsPatch,
44
type EnvironmentId,
5+
idleCompactionPatch,
56
isNullableProjectSettingsOverride,
67
PROJECT_SCOPED_SERVER_SETTING_KEYS,
78
type ProjectId,
@@ -201,6 +202,13 @@ function projectOverrideWrites(
201202
return [...writes.values()];
202203
}
203204

205+
/** Puts an idle compaction mode in the form each destination server reads. */
206+
function forDestination(previous: ServerSettings, patch: ServerSettingsPatch): ServerSettingsPatch {
207+
if (patch.idleCompaction === undefined) return patch;
208+
const { idleCompaction, compactIdleThreads: _legacy, ...rest } = patch;
209+
return { ...rest, ...idleCompactionPatch(previous, idleCompaction) };
210+
}
211+
204212
export function planScopedSettingsPatch(
205213
scope: ResolvedSettingsScope,
206214
environments: readonly ScopedSettingsEnvironment[],
@@ -278,12 +286,13 @@ export function planScopedSettingsPatch(
278286
environmentId: environment.environmentId,
279287
label: environment.label,
280288
previous,
281-
patch:
289+
patch: forDestination(
290+
previous,
282291
previous.worktreeCleanup != null &&
283-
serverPatch.storageCleanup &&
284-
Object.keys(serverPatch.storageCleanup).some((key) =>
285-
key.startsWith("worktree"),
286-
)
292+
serverPatch.storageCleanup &&
293+
Object.keys(serverPatch.storageCleanup).some((key) =>
294+
key.startsWith("worktree"),
295+
)
287296
? {
288297
...serverPatch,
289298
worktreeCleanup: {
@@ -299,6 +308,7 @@ export function planScopedSettingsPatch(
299308
},
300309
}
301310
: serverPatch,
311+
),
302312
},
303313
];
304314
})

‎packages/contracts/src/settings.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,10 @@ export const withIdleCompaction = <S extends IdleCompactionSettings>(
13931393
mode: IdleCompactionMode,
13941394
): S => ({ ...settings, idleCompaction: mode, compactIdleThreads: mode === "beforeCacheExpires" });
13951395

1396+
/** Whether a server reads modes, rather than only the boolean switch from before them. */
1397+
export const readsIdleCompactionModes = (settings: IdleCompactionSettings) =>
1398+
settings.idleCompaction !== undefined || typeof settings.compactIdleThreads === "string";
1399+
13961400
/**
13971401
* The patch that sets `mode` in the form the server's settings show it reads:
13981402
* the mode for a server that has `idleCompaction` or kept the mode in the legacy
@@ -1401,7 +1405,7 @@ export const withIdleCompaction = <S extends IdleCompactionSettings>(
14011405
export const idleCompactionPatch = (settings: IdleCompactionSettings, mode: IdleCompactionMode) =>
14021406
settings.idleCompaction !== undefined
14031407
? { idleCompaction: mode }
1404-
: typeof settings.compactIdleThreads === "string"
1408+
: readsIdleCompactionModes(settings)
14051409
? { compactIdleThreads: mode }
14061410
: { compactIdleThreads: mode === "beforeCacheExpires" };
14071411

0 commit comments

Comments
 (0)