GeezerVison is showing github.com — fix(settings): older clients connect again after idle compaction mode… · pingdotgg/t3code@43879d9
File treeExpand file treeCollapse file tree Open diff view settings web/src/components/settings
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/serverSettings.test.ts +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -212,6 +212,29 @@ it.layer(NodeServices.layer)("server settings", (it) => { | 212 | 212 | }).pipe(Effect.provide(layerServerSettings())), | 213 | 213 | ); | 214 | 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 | + | 215 | 238 | it.effect("saves through a symlinked settings file without replacing the link", () => | 216 | 239 | Effect.gen(function* () { | 217 | 240 | const config = yield* ServerConfig.ServerConfig; | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/serverSettings.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,8 @@ import { | 15 | 15 | ServerSettings, | 16 | 16 | ServerSettingsError, | 17 | 17 | type ServerSettingsPatch, | | 18 | + globalIdleCompaction, | | 19 | + withIdleCompaction, | 18 | 20 | } from "@t3tools/contracts"; | 19 | 21 | import * as Cache from "effect/Cache"; | 20 | 22 | import * as Cause from "effect/Cause"; | @@ -117,6 +119,7 @@ const normalizeServerSettings = ( | 117 | 119 | encodeServerSettings(settings).pipe( | 118 | 120 | Effect.flatMap(decodeServerSettings), | 119 | 121 | Effect.map(foldProviderInstanceEnabledFlags), | | 122 | + Effect.map((next) => withIdleCompaction(next, globalIdleCompaction(next))), | 120 | 123 | Effect.map((next) => ({ ...next, ...deriveLegacyProjectOverrides(next) })), | 121 | 124 | Effect.mapError( | 122 | 125 | (cause) => | @@ -685,6 +688,10 @@ const make = Effect.gen(function* () { | 685 | 688 | settings = decoded.value; | 686 | 689 | } | 687 | 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)); | 688 | 695 |
| 689 | 696 | // A file that failed to decode must stay on disk for the user to repair. | 690 | 697 | const settingsFileTrusted = Option.isNone(parseFailure); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/SettingsPanels.tsx +21-12Lines changed: 21 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ import { useEffect, useRef, useState } from "react"; | 7 | 7 | import { | 8 | 8 | type DesktopUpdateChannel, | 9 | 9 | IDLE_COMPACTION_MODES, | | 10 | + globalIdleCompaction, | 10 | 11 | ProviderDriverKind, | 11 | 12 | type ProviderInstanceId, | 12 | 13 | type SidebarProjectGroupingMode, | @@ -51,6 +52,7 @@ import { | 51 | 52 | } from "./useScopedSettings"; | 52 | 53 | import { useScopedModelDisabledReason } from "./useScopedModelAvailability"; | 53 | 54 | import { useSettingsScope } from "./SettingsScopeContext"; | | 55 | +import { scopedIdleCompaction } from "./scopedSettings"; | 54 | 56 | import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings"; | 55 | 57 | import { useDesktopUpdateState } from "../../state/desktopUpdate"; | 56 | 58 | import { | @@ -785,7 +787,8 @@ export function GeneralSettingsPanel() { | 785 | 787 | const settings = useScopedSettings(); | 786 | 788 | const updateSettings = useUpdateScopedSettings(); | 787 | 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 }]); | 789 | 792 | const environmentId = environment?.environmentId ?? null; | 790 | 793 | const isEnvironmentScope = scope.environmentIds.length === 1 && environmentId !== null; | 791 | 794 | const hasServerTargets = connectedEnvironments.length > 0; | @@ -996,40 +999,46 @@ export function GeneralSettingsPanel() { | 996 | 999 |
| 997 | 1000 | <SettingsRow | 998 | 1001 | serverScoped | 999 | | - settingKeys={["compactIdleThreads"]} | | 1002 | + settingKeys={["idleCompaction", "compactIdleThreads"]} | | 1003 | + mixed={idleCompaction.mixed} | 1000 | 1004 | {...searchableSetting("compact-idle-threads")} | 1001 | 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." | 1002 | 1006 | resetAction={ | 1003 | | - settings.compactIdleThreads !== DEFAULT_UNIFIED_SETTINGS.compactIdleThreads ? ( | | 1007 | + globalIdleCompaction(settings) !== globalIdleCompaction(DEFAULT_UNIFIED_SETTINGS) ? ( | 1004 | 1008 | <SettingResetButton | 1005 | 1009 | label="compact idle threads" | 1006 | 1010 | onClick={() => | 1007 | | - updateSettings({ | 1008 | | - compactIdleThreads: DEFAULT_UNIFIED_SETTINGS.compactIdleThreads, | 1009 | | - }) | | 1011 | + updateSettings({ idleCompaction: globalIdleCompaction(DEFAULT_UNIFIED_SETTINGS) }) | 1010 | 1012 | } | 1011 | 1013 | /> | 1012 | 1014 | ) : null | 1013 | 1015 | } | 1014 | 1016 | control={ | 1015 | 1017 | <Select | 1016 | | - value={settings.compactIdleThreads} | | 1018 | + value={idleCompaction.mixed ? null : globalIdleCompaction(settings)} | 1017 | 1019 | onValueChange={(value) => { | 1018 | 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 }); | 1020 | 1022 | }} | 1021 | 1023 | > | 1022 | 1024 | <SelectTrigger size="sm" className="w-full sm:w-56" aria-label="Compact idle threads"> | 1023 | 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 | 1027 | 1030 | } | 1028 | 1031 | </SelectValue> | 1029 | 1032 | </SelectTrigger> | 1030 | 1033 | <SelectPopup align="end" alignItemWithTrigger={false}> | 1031 | 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 | + > | 1033 | 1042 | {mode.label} | 1034 | 1043 | </SelectItem> | 1035 | 1044 | ))} | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/scopedSettings.test.ts +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,7 @@ import { | 17 | 17 | planProjectOverridesClear, | 18 | 18 | planScopedSettingsClear, | 19 | 19 | planScopedSettingsPatch, | | 20 | + scopedIdleCompaction, | 20 | 21 | resolveScopedSettingsTargets, | 21 | 22 | scopedSettingsAreMixed, | 22 | 23 | scopedSettingsSource, | @@ -192,6 +193,42 @@ describe("scoped settings writes", () => { | 192 | 193 | ]); | 193 | 194 | }); | 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 | + | 195 | 232 | it("writes an aggregate preference only to connected environments with loaded configuration", async () => { | 196 | 233 | const persistServer = vi.fn().mockResolvedValue({ _tag: "Success" }); | 197 | 234 | const persistClient = vi.fn(); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/scopedSettings.ts +30-5Lines changed: 30 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,10 @@ import { | 2 | 2 | ClientSettingsSchema, | 3 | 3 | type ClientSettingsPatch, | 4 | 4 | type EnvironmentId, | | 5 | + globalIdleCompaction, | | 6 | + idleCompactionPatch, | 5 | 7 | isNullableProjectSettingsOverride, | | 8 | + readsIdleCompactionModes, | 6 | 9 | PROJECT_SCOPED_SERVER_SETTING_KEYS, | 7 | 10 | type ProjectId, | 8 | 11 | type ProjectScopedServerSettingKey, | @@ -138,6 +141,19 @@ export function scopedSettingsAreMixed( | 138 | 141 | ); | 139 | 142 | } | 140 | 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 | + | 141 | 157 | export type ScopedSettingSource = ProjectSettingSource | "mixed"; | 142 | 158 |
| 143 | 159 | export function scopedSettingsSource( | @@ -201,6 +217,13 @@ function projectOverrideWrites( | 201 | 217 | return [...writes.values()]; | 202 | 218 | } | 203 | 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 | + | 204 | 227 | export function planScopedSettingsPatch( | 205 | 228 | scope: ResolvedSettingsScope, | 206 | 229 | environments: readonly ScopedSettingsEnvironment[], | @@ -278,12 +301,13 @@ export function planScopedSettingsPatch( | 278 | 301 | environmentId: environment.environmentId, | 279 | 302 | label: environment.label, | 280 | 303 | previous, | 281 | | - patch: | | 304 | + patch: forDestination( | | 305 | + previous, | 282 | 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 | + ) | 287 | 311 | ? { | 288 | 312 | ...serverPatch, | 289 | 313 | worktreeCleanup: { | @@ -299,6 +323,7 @@ export function planScopedSettingsPatch( | 299 | 323 | }, | 300 | 324 | } | 301 | 325 | : serverPatch, | | 326 | + ), | 302 | 327 | }, | 303 | 328 | ]; | 304 | 329 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/contracts/src/settings.test.ts +34-4Lines changed: 34 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,12 +8,15 @@ import { | 8 | 8 | ClientSettingsPatch, | 9 | 9 | ClaudeSettings, | 10 | 10 | DEFAULT_SERVER_SETTINGS, | | 11 | + globalIdleCompaction, | | 12 | + idleCompactionPatch, | 11 | 13 | requiredScopesForProjectMutation, | 12 | 14 | resolveIdleCompaction, | 13 | 15 | resolveProjectProviderInstanceEnabled, | 14 | 16 | resolveProviderInstanceEnabled, | 15 | 17 | ServerSettings, | 16 | 18 | ServerSettingsPatch, | | 19 | + withIdleCompaction, | 17 | 20 | } from "./settings.ts"; | 18 | 21 |
| 19 | 22 | const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema); | @@ -138,7 +141,7 @@ describe("custom model settings", () => { | 138 | 141 | describe("resolveIdleCompaction", () => { | 139 | 142 | it("lets a Claude instance override the global default", () => { | 140 | 143 | const settings = decodeServerSettings({ | 141 | | - compactIdleThreads: "off", | | 144 | + idleCompaction: "off", | 142 | 145 | providerInstances: { | 143 | 146 | claude_work: { driver: "claudeAgent", config: { idleCompaction: "onReturn" } }, | 144 | 147 | claude_personal: { driver: "claudeAgent" }, | @@ -151,11 +154,38 @@ describe("resolveIdleCompaction", () => { | 151 | 154 | expect(resolveIdleCompaction(settings, ProviderInstanceId.make("claudeAgent"))).toBe("off"); | 152 | 155 | }); | 153 | 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( | 156 | 159 | "beforeCacheExpires", | 157 | 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 | + }); | 159 | 189 | }); | 160 | 190 | }); | 161 | 191 |
| |
|