Skip to content

Commit c734c56

Browse files
fix(settings): older clients connect again after idle compaction modes
#23037 turned settings.compactIdleThreads from a boolean into a mode string. Every client built before it decodes that field as a boolean, so the server config snapshot failed to decode and the connection dropped ("did not answer") on any server since, even with the setting at its default. compactIdleThreads goes back to the boolean shipped clients read (true for "beforeCacheExpires") and the mode moves to a new idleCompaction field. The server writes both on load and on every patch; settings saved with the mode string are migrated on load, and a shipped client's boolean patch maps to a mode without turning "Never" back into the default. The settings panel patches whichever form the connected server reads. Checked by connecting with v0.1.1-nightly.20261020.3411's own schemas: the config snapshot now decodes against this server, and fails at settings.compactIdleThreads against v0.1.2-preview.20261022.3511. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 96bae54 commit c734c56

7 files changed

Lines changed: 138 additions & 31 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ it.layer(NodeServices.layer)("server settings", (it) => {
212212
}).pipe(Effect.provide(layerServerSettings())),
213213
);
214214

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+
215229
it.effect("saves through a symlinked settings file without replacing the link", () =>
216230
Effect.gen(function* () {
217231
const config = yield* ServerConfig.ServerConfig;

‎apps/server/src/serverSettings.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
ServerSettings,
1616
ServerSettingsError,
1717
type ServerSettingsPatch,
18+
globalIdleCompaction,
19+
withIdleCompaction,
1820
} from "@t3tools/contracts";
1921
import * as Cache from "effect/Cache";
2022
import * as Cause from "effect/Cause";
@@ -117,6 +119,7 @@ const normalizeServerSettings = (
117119
encodeServerSettings(settings).pipe(
118120
Effect.flatMap(decodeServerSettings),
119121
Effect.map(foldProviderInstanceEnabledFlags),
122+
Effect.map((next) => withIdleCompaction(next, globalIdleCompaction(next))),
120123
Effect.map((next) => ({ ...next, ...deriveLegacyProjectOverrides(next) })),
121124
Effect.mapError(
122125
(cause) =>
@@ -682,7 +685,9 @@ const make = Effect.gen(function* () {
682685
});
683686
}
684687
} else {
685-
settings = decoded.value;
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));
686691
}
687692
}
688693

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { useEffect, useRef, useState } from "react";
77
import {
88
type DesktopUpdateChannel,
99
IDLE_COMPACTION_MODES,
10+
globalIdleCompaction,
11+
idleCompactionPatch,
1012
ProviderDriverKind,
1113
type ProviderInstanceId,
1214
type SidebarProjectGroupingMode,
@@ -996,34 +998,35 @@ export function GeneralSettingsPanel() {
996998

997999
<SettingsRow
9981000
serverScoped
999-
settingKeys={["compactIdleThreads"]}
1001+
settingKeys={["idleCompaction", "compactIdleThreads"]}
10001002
{...searchableSetting("compact-idle-threads")}
10011003
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."
10021004
resetAction={
1003-
settings.compactIdleThreads !== DEFAULT_UNIFIED_SETTINGS.compactIdleThreads ? (
1005+
globalIdleCompaction(settings) !== globalIdleCompaction(DEFAULT_UNIFIED_SETTINGS) ? (
10041006
<SettingResetButton
10051007
label="compact idle threads"
10061008
onClick={() =>
1007-
updateSettings({
1008-
compactIdleThreads: DEFAULT_UNIFIED_SETTINGS.compactIdleThreads,
1009-
})
1009+
updateSettings(
1010+
idleCompactionPatch(settings, globalIdleCompaction(DEFAULT_UNIFIED_SETTINGS)),
1011+
)
10101012
}
10111013
/>
10121014
) : null
10131015
}
10141016
control={
10151017
<Select
1016-
value={settings.compactIdleThreads}
1018+
value={globalIdleCompaction(settings)}
10171019
onValueChange={(value) => {
10181020
const mode = IDLE_COMPACTION_MODES.find((candidate) => candidate.value === value);
1019-
if (mode) updateSettings({ compactIdleThreads: mode.value });
1021+
if (mode) updateSettings(idleCompactionPatch(settings, mode.value));
10201022
}}
10211023
>
10221024
<SelectTrigger size="sm" className="w-full sm:w-56" aria-label="Compact idle threads">
10231025
<SelectValue>
10241026
{
1025-
IDLE_COMPACTION_MODES.find((mode) => mode.value === settings.compactIdleThreads)
1026-
?.label
1027+
IDLE_COMPACTION_MODES.find(
1028+
(mode) => mode.value === globalIdleCompaction(settings),
1029+
)?.label
10271030
}
10281031
</SelectValue>
10291032
</SelectTrigger>

‎packages/contracts/src/settings.test.ts‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import {
88
ClientSettingsPatch,
99
ClaudeSettings,
1010
DEFAULT_SERVER_SETTINGS,
11+
globalIdleCompaction,
12+
idleCompactionPatch,
1113
requiredScopesForProjectMutation,
1214
resolveIdleCompaction,
1315
resolveProjectProviderInstanceEnabled,
1416
resolveProviderInstanceEnabled,
1517
ServerSettings,
1618
ServerSettingsPatch,
19+
withIdleCompaction,
1720
} from "./settings.ts";
1821

1922
const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
@@ -138,7 +141,7 @@ describe("custom model settings", () => {
138141
describe("resolveIdleCompaction", () => {
139142
it("lets a Claude instance override the global default", () => {
140143
const settings = decodeServerSettings({
141-
compactIdleThreads: "off",
144+
idleCompaction: "off",
142145
providerInstances: {
143146
claude_work: { driver: "claudeAgent", config: { idleCompaction: "onReturn" } },
144147
claude_personal: { driver: "claudeAgent" },
@@ -151,11 +154,38 @@ describe("resolveIdleCompaction", () => {
151154
expect(resolveIdleCompaction(settings, ProviderInstanceId.make("claudeAgent"))).toBe("off");
152155
});
153156

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(
156159
"beforeCacheExpires",
157160
);
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+
});
159189
});
160190
});
161191

‎packages/contracts/src/settings.ts‎

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -652,17 +652,12 @@ export const IDLE_COMPACTION_MODES = [
652652
export const IdleCompactionMode = Schema.Literals(IDLE_COMPACTION_MODES.map((mode) => mode.value));
653653
export type IdleCompactionMode = typeof IdleCompactionMode.Type;
654654

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]);
666661

667662
const INSTANCE_IDLE_COMPACTION_MODES = [
668663
{ value: "default", label: "Use default" },
@@ -1202,9 +1197,10 @@ export const ServerSettings = Schema.Struct({
12021197
sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
12031198
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
12041199
),
1205-
compactIdleThreads: IdleCompactionModeSetting.pipe(
1206-
Schema.withDecodingDefault(Effect.succeed("onReturn" as const)),
1200+
compactIdleThreads: LegacyCompactIdleThreads.pipe(
1201+
Schema.withDecodingDefault(Effect.succeed(false)),
12071202
),
1203+
idleCompaction: Schema.optionalKey(IdleCompactionMode),
12081204
snoozeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
12091205
autoResumeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
12101206
sidebarAutoSettleKeepPullRequests: Schema.Boolean.pipe(
@@ -1380,8 +1376,37 @@ export const resolveProjectProviderInstanceEnabled = (
13801376

13811377
const decodeClaudeSettings = Schema.decodeUnknownOption(ClaudeSettings);
13821378

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+
/**
1397+
* The patch that sets `mode` in the form the server's settings show it reads:
1398+
* the mode for a server that has `idleCompaction` or kept the mode in the legacy
1399+
* field, the boolean switch for a server from before modes.
1400+
*/
1401+
export const idleCompactionPatch = (settings: IdleCompactionSettings, mode: IdleCompactionMode) =>
1402+
settings.idleCompaction !== undefined
1403+
? { idleCompaction: mode }
1404+
: typeof settings.compactIdleThreads === "string"
1405+
? { compactIdleThreads: mode }
1406+
: { compactIdleThreads: mode === "beforeCacheExpires" };
1407+
13831408
export const resolveIdleCompaction = (
1384-
settings: Pick<ServerSettings, "providerInstances" | "compactIdleThreads">,
1409+
settings: Pick<ServerSettings, "providerInstances" | "compactIdleThreads" | "idleCompaction">,
13851410
instanceId: ProviderInstanceId,
13861411
): IdleCompactionMode => {
13871412
const instance = Object.hasOwn(settings.providerInstances, instanceId)
@@ -1391,7 +1416,7 @@ export const resolveIdleCompaction = (
13911416
Option.map((config) => config.idleCompaction),
13921417
Option.getOrElse(() => "default" as const),
13931418
);
1394-
return override === "default" ? settings.compactIdleThreads : override;
1419+
return override === "default" ? globalIdleCompaction(settings) : override;
13951420
};
13961421

13971422
export const ServerSettingsOperation = Schema.Literals([
@@ -1535,7 +1560,8 @@ export const ServerSettingsPatch = Schema.Struct({
15351560
deviceHosts: Schema.optionalKey(SshDeviceHostConfigs),
15361561
easDeviceHosts: Schema.optionalKey(EasDeviceHostConfigs),
15371562
sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
1538-
compactIdleThreads: Schema.optionalKey(IdleCompactionMode),
1563+
compactIdleThreads: Schema.optionalKey(LegacyCompactIdleThreads),
1564+
idleCompaction: Schema.optionalKey(IdleCompactionMode),
15391565
sidebarAutoSettleKeepPullRequests: Schema.optionalKey(Schema.Boolean),
15401566
sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
15411567
autoResumeLimitedThreads: Schema.optionalKey(Schema.Boolean),

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ describe("fallbackTextGenerationModelSelection", () => {
5252
});
5353

5454
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+
5565
it("changes a cleanup rule without replacing the machine's other rules", () => {
5666
const enabled = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
5767
storageCleanup: { worktreeAfterDays: 8, worktreeOnMerge: true, logsAfterDays: 30 },

‎packages/shared/src/serverSettings.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
DEFAULT_TEXT_GENERATION_MODEL,
55
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER,
66
defaultInstanceIdForDriver,
7+
globalIdleCompaction,
8+
type IdleCompactionMode,
79
isProviderAvailable,
810
isUnconfiguredDefaultInstanceEnabled,
911
resolveProjectProviderInstanceEnabled,
@@ -18,6 +20,7 @@ import {
1820
type ServerProvider,
1921
ServerSettings,
2022
type ServerSettingsPatch,
23+
withIdleCompaction,
2124
} from "@t3tools/contracts";
2225
import * as Option from "effect/Option";
2326
import * as Schema from "effect/Schema";
@@ -359,6 +362,22 @@ function translateLegacyProjectOverridePatch(
359362
} as ServerSettingsPatch;
360363
}
361364

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+
362381
export function applyServerSettingsPatch(
363382
current: ServerSettings,
364383
rawPatch: ServerSettingsPatch,
@@ -598,7 +617,7 @@ export function applyServerSettingsPatch(
598617
normalizedBackgroundActivity,
599618
);
600619
const nextWithReplacements = {
601-
...nextWithReplacementsBase,
620+
...withIdleCompaction(nextWithReplacementsBase, patchedIdleCompaction(current, patch)),
602621
...deriveLegacyProjectOverrides(nextWithReplacementsBase),
603622
backgroundActivity: normalizedBackgroundActivity,
604623
automaticGitFetchInterval: resolvedBackgroundActivity.automaticGitFetchInterval,

0 commit comments

Comments
 (0)