@@ -40,7 +40,11 @@ import {
4040} from "~/themePalette" ;
4141import * as Struct from "effect/Struct" ;
4242import { primaryServerSettingsAtom , serverEnvironment } from "~/state/server" ;
43- import { useEnvironments , usePrimaryEnvironment } from "~/state/environments" ;
43+ import {
44+ type EnvironmentPresentation ,
45+ useEnvironments ,
46+ usePrimaryEnvironment ,
47+ } from "~/state/environments" ;
4448import { useAtomCommand } from "~/state/use-atom-command" ;
4549import { useTheme } from "./useTheme" ;
4650
@@ -312,14 +316,26 @@ export function usePrimarySettings<T = UnifiedSettings>(
312316 return useMergedSettings ( useAtomValue ( primaryServerSettingsAtom ) , selector ) ;
313317}
314318
319+ /**
320+ * Whether an environment can hold every shared key right now. Gated on the
321+ * auto-settlement capability because it is the newest of the shared keys: a
322+ * server that has it has all of them. Older servers drop unknown keys on
323+ * write, so a mismatch against them could never clear, and their decoded
324+ * defaults must not be treated as real values.
325+ */
326+ function supportsSharedSettings ( environment : EnvironmentPresentation ) : boolean {
327+ return (
328+ environment . connection . phase === "connected" &&
329+ environment . serverConfig ?. environment . capabilities . threadAutoSettlement === true
330+ ) ;
331+ }
332+
315333/** Environments that can receive a shared settings write right now. */
316334function useConnectedEnvironmentIds ( ) : ReadonlyArray < EnvironmentId > {
317335 const { environments } = useEnvironments ( ) ;
318336 return useMemo (
319337 ( ) =>
320- environments
321- . filter ( ( environment ) => environment . connection . phase === "connected" )
322- . map ( ( environment ) => environment . environmentId ) ,
338+ environments . filter ( supportsSharedSettings ) . map ( ( environment ) => environment . environmentId ) ,
323339 [ environments ] ,
324340 ) ;
325341}
@@ -388,8 +404,12 @@ export function useSharedSettingsSync() {
388404 const primaryEnvironmentId = primaryEnvironment ?. environmentId ?? null ;
389405 // Read the loaded config, not `primaryServerSettingsAtom`: that atom falls
390406 // back to defaults while the primary is disconnected, and "apply to all"
391- // must never push defaults over real values.
392- const primarySettings = primaryEnvironment ?. serverConfig ?. settings ?? null ;
407+ // must never push defaults over real values. Same for a primary too old to
408+ // hold the shared keys: its decoded defaults are not a source of truth.
409+ const primarySettings =
410+ primaryEnvironment !== null && supportsSharedSettings ( primaryEnvironment )
411+ ? ( primaryEnvironment . serverConfig ?. settings ?? null )
412+ : null ;
393413 const { environments } = useEnvironments ( ) ;
394414 const persistServerSettings = useAtomCommand (
395415 serverEnvironment . updateSettings ,
@@ -404,7 +424,7 @@ export function useSharedSettingsSync() {
404424 environments : environments . map ( ( environment ) => ( {
405425 environmentId : environment . environmentId ,
406426 label : environment . label ,
407- connected : environment . connection . phase === "connected" ,
427+ connected : supportsSharedSettings ( environment ) ,
408428 settings : environment . serverConfig ?. settings ?? null ,
409429 } ) ) ,
410430 } ) ,
0 commit comments