The best way to control Claude Code, Codex and more from any computer or phone
fix(settings): older clients connect again after idle compaction modes (#23454)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 22, 2026 at 02:31 UTC
43879d970204eb28092d098deb4c842a22a9ab75
9 files changed
+228
-38
apps/server/src/serverSettings.test.ts
+23
@@ -212,6 +212,29 @@ it.layer(NodeServices.layer)("server settings", (it) => {
212
}).pipe(Effect.provide(layerServerSettings())),
213
);
214
215
+ it.effect("moves an idle compaction mode saved in the legacy switch to its own field", () =>
216
+ Effect.gen(function* () {
217
+ const config = yield* ServerConfig.ServerConfig;
218
+ const fs = yield* FileSystem.FileSystem;
219
+ const service = yield* ServerSettingsModule.ServerSettingsService;
220
+ yield* fs.writeFileString(config.settingsPath, `{ "compactIdleThreads": "off" }`);
221
+
222
+ const settings = yield* service.getSettings;
223
+ // Shipped clients decode the switch as a boolean and drop the config otherwise.
224
+ assert.strictEqual(settings.compactIdleThreads, false);
225
+ assert.equal(settings.idleCompaction, "off");
226
+ }).pipe(Effect.provide(layerServerSettings())),
227
+ );
228
+
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
+
238
it.effect("saves through a symlinked settings file without replacing the link", () =>
239
Effect.gen(function* () {
240
const config = yield* ServerConfig.ServerConfig;
apps/server/src/serverSettings.ts
+7
@@ -15,6 +15,8 @@ import {
15
ServerSettings,
16
ServerSettingsError,
17
type ServerSettingsPatch,
18
+ globalIdleCompaction,
19
+ withIdleCompaction,
20
} from "@t3tools/contracts";
21
import * as Cache from "effect/Cache";
22
import * as Cause from "effect/Cause";
@@ -117,6 +119,7 @@ const normalizeServerSettings = (
119
encodeServerSettings(settings).pipe(
120
Effect.flatMap(decodeServerSettings),
121
Effect.map(foldProviderInstanceEnabledFlags),
122
+ Effect.map((next) => withIdleCompaction(next, globalIdleCompaction(next))),
123
Effect.map((next) => ({ ...next, ...deriveLegacyProjectOverrides(next) })),
124
Effect.mapError(
125
(cause) =>
@@ -685,6 +688,10 @@ const make = Effect.gen(function* () {
688
settings = decoded.value;
689
}
690
}
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));
695
696
// A file that failed to decode must stay on disk for the user to repair.
697
const settingsFileTrusted = Option.isNone(parseFailure);
apps/web/src/components/settings/SettingsPanels.tsx
+21
-12
@@ -7,6 +7,7 @@ import { useEffect, useRef, useState } from "react";
7
import {
8
type DesktopUpdateChannel,
9
IDLE_COMPACTION_MODES,
10
+ globalIdleCompaction,
11
ProviderDriverKind,
12
type ProviderInstanceId,
13
type SidebarProjectGroupingMode,
@@ -51,6 +52,7 @@ import {
52
} from "./useScopedSettings";
53
import { useScopedModelDisabledReason } from "./useScopedModelAvailability";
54
import { useSettingsScope } from "./SettingsScopeContext";
55
+import { scopedIdleCompaction } from "./scopedSettings";
56
import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";
57
import { useDesktopUpdateState } from "../../state/desktopUpdate";
58
import {
@@ -785,7 +787,8 @@ export function GeneralSettingsPanel() {
787
const settings = useScopedSettings();
788
const updateSettings = useUpdateScopedSettings();
789
const navigate = useNavigate();
788
- const { scope, environment, connectedEnvironments, target } = useSettingsScope();
790
+ const { scope, environment, connectedEnvironments, target, targets } = useSettingsScope();
791
+ const idleCompaction = scopedIdleCompaction(targets.length > 0 ? targets : [{ settings }]);
792
const environmentId = environment?.environmentId ?? null;
793
const isEnvironmentScope = scope.environmentIds.length === 1 && environmentId !== null;
794
const hasServerTargets = connectedEnvironments.length > 0;
@@ -996,40 +999,46 @@ export function GeneralSettingsPanel() {
999
1000
<SettingsRow
1001
serverScoped
999
- settingKeys={["compactIdleThreads"]}
1002
+ settingKeys={["idleCompaction", "compactIdleThreads"]}
1003
+ mixed={idleCompaction.mixed}
1004
{...searchableSetting("compact-idle-threads")}
1005
description="When to compact an idle Claude thread over 200,000 tokens: after you return, just before its prompt cache expires, or never. Each Claude provider can override this."
1006
resetAction={
1003
- settings.compactIdleThreads !== DEFAULT_UNIFIED_SETTINGS.compactIdleThreads ? (
1007
+ globalIdleCompaction(settings) !== globalIdleCompaction(DEFAULT_UNIFIED_SETTINGS) ? (
1008
<SettingResetButton
1009
label="compact idle threads"
1010
onClick={() =>
1007
- updateSettings({
1008
- compactIdleThreads: DEFAULT_UNIFIED_SETTINGS.compactIdleThreads,
1009
- })
1011
+ updateSettings({ idleCompaction: globalIdleCompaction(DEFAULT_UNIFIED_SETTINGS) })
1012
}
1013
/>
1014
) : null
1015
}
1016
control={
1017
<Select
1016
- value={settings.compactIdleThreads}
1018
+ value={idleCompaction.mixed ? null : globalIdleCompaction(settings)}
1019
onValueChange={(value) => {
1020
const mode = IDLE_COMPACTION_MODES.find((candidate) => candidate.value === value);
1019
- if (mode) updateSettings({ compactIdleThreads: mode.value });
1021
+ if (mode) updateSettings({ idleCompaction: mode.value });
1022
}}
1023
>
1024
<SelectTrigger size="sm" className="w-full sm:w-56" aria-label="Compact idle threads">
1025
<SelectValue>
1024
- {
1025
- IDLE_COMPACTION_MODES.find((mode) => mode.value === settings.compactIdleThreads)
1026
- ?.label
1026
+ {(value: string | null) =>
1027
+ value === null
1028
+ ? "Mixed"
1029
+ : IDLE_COMPACTION_MODES.find((mode) => mode.value === value)?.label
1030
}
1031
</SelectValue>
1032
</SelectTrigger>
1033
<SelectPopup align="end" alignItemWithTrigger={false}>
1034
{IDLE_COMPACTION_MODES.map((mode) => (
1032
- <SelectItem hideIndicator key={mode.value} value={mode.value}>
1035
+ <SelectItem
1036
+ hideIndicator
1037
+ key={mode.value}
1038
+ value={mode.value}
1039
+ // A server from before modes has only the on/off switch, so it cannot store "Never".
1040
+ disabled={mode.value === "off" && !idleCompaction.neverAvailable}
1041
+ >
1042
{mode.label}
1043
</SelectItem>
1044
))}
apps/web/src/components/settings/scopedSettings.test.ts
+37
@@ -17,6 +17,7 @@ import {
17
planProjectOverridesClear,
18
planScopedSettingsClear,
19
planScopedSettingsPatch,
20
+ scopedIdleCompaction,
21
resolveScopedSettingsTargets,
22
scopedSettingsAreMixed,
23
scopedSettingsSource,
@@ -192,6 +193,42 @@ describe("scoped settings writes", () => {
193
]);
194
});
195
196
+ it("compares idle compaction by mode, and offers Never only where every server stores it", () => {
197
+ const fixed = {
198
+ settings: {
199
+ ...DEFAULT_SERVER_SETTINGS,
200
+ compactIdleThreads: false,
201
+ idleCompaction: "onReturn" as const,
202
+ },
203
+ };
204
+ const modes = {
205
+ settings: { ...DEFAULT_SERVER_SETTINGS, compactIdleThreads: "onReturn" as const },
206
+ };
207
+ const legacy = { settings: { ...DEFAULT_SERVER_SETTINGS, compactIdleThreads: false } };
208
+ expect(scopedIdleCompaction([fixed, modes])).toEqual({ mixed: false, neverAvailable: true });
209
+ expect(scopedIdleCompaction([fixed, legacy])).toEqual({ mixed: false, neverAvailable: false });
210
+ expect(
211
+ scopedIdleCompaction([fixed, { settings: { ...fixed.settings, idleCompaction: "off" } }])
212
+ .mixed,
213
+ ).toBe(true);
214
+ });
215
+
216
+ it("sends an idle compaction mode in the form each environment's server reads", () => {
217
+ const targets = [
218
+ environment("Fixed", { settings: { compactIdleThreads: false, idleCompaction: "onReturn" } }),
219
+ environment("Modes", { settings: { compactIdleThreads: "onReturn" } }),
220
+ environment("Switch", { settings: { compactIdleThreads: false } }),
221
+ ];
222
+ const plan = planScopedSettingsPatch(resolveSettingsScope({}, [], targets), targets, {
223
+ idleCompaction: "beforeCacheExpires",
224
+ });
225
+ expect(plan.serverWrites.map((write) => write.patch)).toEqual([
226
+ { idleCompaction: "beforeCacheExpires" },
227
+ { compactIdleThreads: "beforeCacheExpires" },
228
+ { compactIdleThreads: true },
229
+ ]);
230
+ });
231
+
232
it("writes an aggregate preference only to connected environments with loaded configuration", async () => {
233
const persistServer = vi.fn().mockResolvedValue({ _tag: "Success" });
234
const persistClient = vi.fn();
apps/web/src/components/settings/scopedSettings.ts
+30
-5
@@ -2,7 +2,10 @@ import {
2
ClientSettingsSchema,
3
type ClientSettingsPatch,
4
type EnvironmentId,
5
+ globalIdleCompaction,
6
+ idleCompactionPatch,
7
isNullableProjectSettingsOverride,
8
+ readsIdleCompactionModes,
9
PROJECT_SCOPED_SERVER_SETTING_KEYS,
10
type ProjectId,
11
type ProjectScopedServerSettingKey,
@@ -138,6 +141,19 @@ export function scopedSettingsAreMixed(
141
);
142
}
143
144
+/**
145
+ * Servers store the idle compaction mode differently by version, so selected
146
+ * environments are compared by the mode each resolves to, and "Never" is offered
147
+ * only when every one of them can store it.
148
+ */
149
+export function scopedIdleCompaction(targets: readonly Pick<ScopedSettingsTarget, "settings">[]) {
150
+ const modes = targets.map((candidate) => globalIdleCompaction(candidate.settings));
151
+ return {
152
+ mixed: modes.some((mode) => mode !== modes[0]),
153
+ neverAvailable: targets.every((candidate) => readsIdleCompactionModes(candidate.settings)),
154
+ };
155
+}
156
+
157
export type ScopedSettingSource = ProjectSettingSource | "mixed";
158
159
export function scopedSettingsSource(
@@ -201,6 +217,13 @@ function projectOverrideWrites(
217
return [...writes.values()];
218
}
219
220
+/** Puts an idle compaction mode in the form each destination server reads. */
221
+function forDestination(previous: ServerSettings, patch: ServerSettingsPatch): ServerSettingsPatch {
222
+ if (patch.idleCompaction === undefined) return patch;
223
+ const { idleCompaction, compactIdleThreads: _legacy, ...rest } = patch;
224
+ return { ...rest, ...idleCompactionPatch(previous, idleCompaction) };
225
+}
226
+
227
export function planScopedSettingsPatch(
228
scope: ResolvedSettingsScope,
229
environments: readonly ScopedSettingsEnvironment[],
@@ -278,12 +301,13 @@ export function planScopedSettingsPatch(
301
environmentId: environment.environmentId,
302
label: environment.label,
303
previous,
281
- patch:
304
+ patch: forDestination(
305
+ previous,
306
previous.worktreeCleanup != null &&
283
- serverPatch.storageCleanup &&
284
- Object.keys(serverPatch.storageCleanup).some((key) =>
285
- key.startsWith("worktree"),
286
- )
307
+ serverPatch.storageCleanup &&
308
+ Object.keys(serverPatch.storageCleanup).some((key) =>
309
+ key.startsWith("worktree"),
310
+ )
311
? {
312
...serverPatch,
313
worktreeCleanup: {
@@ -299,6 +323,7 @@ export function planScopedSettingsPatch(
323
},
324
}
325
: serverPatch,
326
+ ),
327
},
328
];
329
})
packages/contracts/src/settings.test.ts
+34
-4
@@ -8,12 +8,15 @@ import {
8
ClientSettingsPatch,
9
ClaudeSettings,
10
DEFAULT_SERVER_SETTINGS,
11
+ globalIdleCompaction,
12
+ idleCompactionPatch,
13
requiredScopesForProjectMutation,
14
resolveIdleCompaction,
15
resolveProjectProviderInstanceEnabled,
16
resolveProviderInstanceEnabled,
17
ServerSettings,
18
ServerSettingsPatch,
19
+ withIdleCompaction,
20
} from "./settings.ts";
21
22
const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
@@ -138,7 +141,7 @@ describe("custom model settings", () => {
141
describe("resolveIdleCompaction", () => {
142
it("lets a Claude instance override the global default", () => {
143
const settings = decodeServerSettings({
141
- compactIdleThreads: "off",
144
+ idleCompaction: "off",
145
providerInstances: {
146
claude_work: { driver: "claudeAgent", config: { idleCompaction: "onReturn" } },
147
claude_personal: { driver: "claudeAgent" },
@@ -151,11 +154,38 @@ describe("resolveIdleCompaction", () => {
154
expect(resolveIdleCompaction(settings, ProviderInstanceId.make("claudeAgent"))).toBe("off");
155
});
156
154
- it("keeps the legacy beta switch's behavior", () => {
155
- expect(decodeServerSettings({ compactIdleThreads: true }).compactIdleThreads).toBe(
157
+ it("reads the mode from the legacy switch, in either form servers saved it", () => {
158
+ expect(globalIdleCompaction(decodeServerSettings({ compactIdleThreads: true }))).toBe(
159
"beforeCacheExpires",
160
);
158
- expect(decodeServerSettings({}).compactIdleThreads).toBe("onReturn");
161
+ expect(globalIdleCompaction(decodeServerSettings({ compactIdleThreads: "off" }))).toBe("off");
162
+ expect(globalIdleCompaction(decodeServerSettings({}))).toBe("onReturn");
163
+ });
164
+
165
+ it("keeps the legacy switch a boolean, as shipped clients decode it", () => {
166
+ const encode = Schema.encodeSync(Schema.toCodecJson(ServerSettings));
167
+ for (const mode of ["onReturn", "beforeCacheExpires", "off"] as const) {
168
+ const encoded = encode(withIdleCompaction(DEFAULT_SERVER_SETTINGS, mode)) as {
169
+ readonly compactIdleThreads: unknown;
170
+ readonly idleCompaction: unknown;
171
+ };
172
+ expect(encoded.compactIdleThreads).toBe(mode === "beforeCacheExpires");
173
+ expect(encoded.idleCompaction).toBe(mode);
174
+ }
175
+ });
176
+
177
+ it("patches the field the server reads", () => {
178
+ expect(
179
+ idleCompactionPatch({ compactIdleThreads: false, idleCompaction: "onReturn" }, "off"),
180
+ ).toEqual({
181
+ idleCompaction: "off",
182
+ });
183
+ expect(idleCompactionPatch({ compactIdleThreads: "onReturn" }, "off")).toEqual({
184
+ compactIdleThreads: "off",
185
+ });
186
+ expect(idleCompactionPatch({ compactIdleThreads: false }, "beforeCacheExpires")).toEqual({
187
+ compactIdleThreads: true,
188
+ });
189
});
190
});
191
packages/contracts/src/settings.ts
+46
-16
@@ -652,17 +652,12 @@ export const IDLE_COMPACTION_MODES = [
652
export const IdleCompactionMode = Schema.Literals(IDLE_COMPACTION_MODES.map((mode) => mode.value));
653
export type IdleCompactionMode = typeof IdleCompactionMode.Type;
654
655
-// `compactIdleThreads` was a beta on/off switch for compacting before the cache expires.
656
-const LegacyCompactIdleThreads = Schema.Boolean.pipe(
657
- Schema.decodeTo(
658
- IdleCompactionMode,
659
- SchemaTransformation.transform({
660
- decode: (enabled): IdleCompactionMode => (enabled ? "beforeCacheExpires" : "onReturn"),
661
- encode: (mode) => mode === "beforeCacheExpires",
662
- }),
663
- ),
664
-);
665
-const IdleCompactionModeSetting = Schema.Union([IdleCompactionMode, LegacyCompactIdleThreads]);
655
+// `compactIdleThreads` was a beta on/off switch for compacting before the cache
656
+// expires. Shipped clients decode it as a boolean and drop the whole server config
657
+// otherwise, so it stays a boolean on the wire and the mode lives in
658
+// `idleCompaction`. Servers before that split sent the mode here, so a string is
659
+// still read.
660
+const LegacyCompactIdleThreads = Schema.Union([Schema.Boolean, IdleCompactionMode]);
661
662
const INSTANCE_IDLE_COMPACTION_MODES = [
663
{ value: "default", label: "Use default" },
@@ -1202,9 +1197,10 @@ export const ServerSettings = Schema.Struct({
1197
sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
1198
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
1199
),
1205
- compactIdleThreads: IdleCompactionModeSetting.pipe(
1206
- Schema.withDecodingDefault(Effect.succeed("onReturn" as const)),
1200
+ compactIdleThreads: LegacyCompactIdleThreads.pipe(
1201
+ Schema.withDecodingDefault(Effect.succeed(false)),
1202
),
1203
+ idleCompaction: Schema.optionalKey(IdleCompactionMode),
1204
snoozeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
1205
autoResumeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
1206
sidebarAutoSettleKeepPullRequests: Schema.Boolean.pipe(
@@ -1380,8 +1376,41 @@ export const resolveProjectProviderInstanceEnabled = (
1376
1377
const decodeClaudeSettings = Schema.decodeUnknownOption(ClaudeSettings);
1378
1379
+type IdleCompactionSettings = Pick<ServerSettings, "compactIdleThreads" | "idleCompaction">;
1380
+
1381
+/** The environment-wide idle compaction mode, from whichever field the settings carry. */
1382
+export const globalIdleCompaction = (settings: IdleCompactionSettings): IdleCompactionMode =>
1383
+ settings.idleCompaction ??
1384
+ (typeof settings.compactIdleThreads === "string"
1385
+ ? settings.compactIdleThreads
1386
+ : settings.compactIdleThreads
1387
+ ? "beforeCacheExpires"
1388
+ : "onReturn");
1389
+
1390
+/** Sets the mode, and the legacy switch shipped clients still read alongside it. */
1391
+export const withIdleCompaction = <S extends IdleCompactionSettings>(
1392
+ settings: S,
1393
+ mode: IdleCompactionMode,
1394
+): S => ({ ...settings, idleCompaction: mode, compactIdleThreads: mode === "beforeCacheExpires" });
1395
+
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
+
1400
+/**
1401
+ * The patch that sets `mode` in the form the server's settings show it reads:
1402
+ * the mode for a server that has `idleCompaction` or kept the mode in the legacy
1403
+ * field, the boolean switch for a server from before modes.
1404
+ */
1405
+export const idleCompactionPatch = (settings: IdleCompactionSettings, mode: IdleCompactionMode) =>
1406
+ settings.idleCompaction !== undefined
1407
+ ? { idleCompaction: mode }
1408
+ : readsIdleCompactionModes(settings)
1409
+ ? { compactIdleThreads: mode }
1410
+ : { compactIdleThreads: mode === "beforeCacheExpires" };
1411
+
1412
export const resolveIdleCompaction = (
1384
- settings: Pick<ServerSettings, "providerInstances" | "compactIdleThreads">,
1413
+ settings: Pick<ServerSettings, "providerInstances" | "compactIdleThreads" | "idleCompaction">,
1414
instanceId: ProviderInstanceId,
1415
): IdleCompactionMode => {
1416
const instance = Object.hasOwn(settings.providerInstances, instanceId)
@@ -1391,7 +1420,7 @@ export const resolveIdleCompaction = (
1420
Option.map((config) => config.idleCompaction),
1421
Option.getOrElse(() => "default" as const),
1422
);
1394
- return override === "default" ? settings.compactIdleThreads : override;
1423
+ return override === "default" ? globalIdleCompaction(settings) : override;
1424
};
1425
1426
export const ServerSettingsOperation = Schema.Literals([
@@ -1535,7 +1564,8 @@ export const ServerSettingsPatch = Schema.Struct({
1564
deviceHosts: Schema.optionalKey(SshDeviceHostConfigs),
1565
easDeviceHosts: Schema.optionalKey(EasDeviceHostConfigs),
1566
sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
1538
- compactIdleThreads: Schema.optionalKey(IdleCompactionMode),
1567
+ compactIdleThreads: Schema.optionalKey(LegacyCompactIdleThreads),
1568
+ idleCompaction: Schema.optionalKey(IdleCompactionMode),
1569
sidebarAutoSettleKeepPullRequests: Schema.optionalKey(Schema.Boolean),
1570
sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
1571
autoResumeLimitedThreads: Schema.optionalKey(Schema.Boolean),
packages/shared/src/serverSettings.test.ts
+10
@@ -52,6 +52,16 @@ describe("fallbackTextGenerationModelSelection", () => {
52
});
53
54
describe("serverSettings helpers", () => {
55
+ it("translates a shipped client's idle compaction switch into a mode", () => {
56
+ const off = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, { idleCompaction: "off" });
57
+ expect([off.idleCompaction, off.compactIdleThreads]).toEqual(["off", false]);
58
+ // Turning the old switch off keeps "Never" instead of reverting to the default.
59
+ const stillOff = applyServerSettingsPatch(off, { compactIdleThreads: false });
60
+ expect(stillOff.idleCompaction).toBe("off");
61
+ const on = applyServerSettingsPatch(off, { compactIdleThreads: true });
62
+ expect([on.idleCompaction, on.compactIdleThreads]).toEqual(["beforeCacheExpires", true]);
63
+ });
64
+
65
it("changes a cleanup rule without replacing the machine's other rules", () => {
66
const enabled = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
67
storageCleanup: { worktreeAfterDays: 8, worktreeOnMerge: true, logsAfterDays: 30 },
packages/shared/src/serverSettings.ts
+20
-1
@@ -4,6 +4,8 @@ import {
4
DEFAULT_TEXT_GENERATION_MODEL,
5
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER,
6
defaultInstanceIdForDriver,
7
+ globalIdleCompaction,
8
+ type IdleCompactionMode,
9
isProviderAvailable,
10
isUnconfiguredDefaultInstanceEnabled,
11
resolveProjectProviderInstanceEnabled,
@@ -18,6 +20,7 @@ import {
20
type ServerProvider,
21
ServerSettings,
22
type ServerSettingsPatch,
23
+ withIdleCompaction,
24
} from "@t3tools/contracts";
25
import * as Option from "effect/Option";
26
import * as Schema from "effect/Schema";
@@ -359,6 +362,22 @@ function translateLegacyProjectOverridePatch(
362
} as ServerSettingsPatch;
363
}
364
365
+/**
366
+ * A client from before `idleCompaction` patches the old boolean switch. Turning
367
+ * it off keeps "Never" rather than reverting to the default.
368
+ */
369
+function patchedIdleCompaction(
370
+ current: ServerSettings,
371
+ patch: ServerSettingsPatch,
372
+): IdleCompactionMode {
373
+ if (patch.idleCompaction !== undefined) return patch.idleCompaction;
374
+ const legacy = patch.compactIdleThreads;
375
+ if (legacy === undefined) return globalIdleCompaction(current);
376
+ if (typeof legacy === "string") return legacy;
377
+ if (legacy) return "beforeCacheExpires";
378
+ return globalIdleCompaction(current) === "off" ? "off" : "onReturn";
379
+}
380
+
381
export function applyServerSettingsPatch(
382
current: ServerSettings,
383
rawPatch: ServerSettingsPatch,
@@ -598,7 +617,7 @@ export function applyServerSettingsPatch(
617
normalizedBackgroundActivity,
618
);
619
const nextWithReplacements = {
601
- ...nextWithReplacementsBase,
620
+ ...withIdleCompaction(nextWithReplacementsBase, patchedIdleCompaction(current, patch)),
621
...deriveLegacyProjectOverrides(nextWithReplacementsBase),
622
backgroundActivity: normalizedBackgroundActivity,
623
automaticGitFetchInterval: resolvedBackgroundActivity.automaticGitFetchInterval,