| author | |
| committer | |
| log | f47a3fe90354a3dfa14276e3699541d552426276 |
| tree | dc60aadc92e40bb9b58f5fd723245f59ad3e08f5 |
| parent | c7dc3cbd068a93c9fb5027df7bea719d16e4ffbe |
| signature | Signed by PGP key B5690EEEBB952194 |
8 files changed, 204 insertions(+), 42 deletions(-)
apps/mobile/src/features/settings/SettingsRouteScreen.tsx+16-2| ... | ... | @@ -44,6 +44,7 @@ import { |
| 44 | 44 | type ServerSettingsPatch, |
| 45 | 45 | } from "@t3tools/contracts"; |
| 46 | 46 | import { |
| 47 | filterSharedServerPatch, | |
| 47 | 48 | findSharedSettingsMismatches, |
| 48 | 49 | pickSharedServerSettings, |
| 49 | 50 | supportsSharedSettingsSync, |
| ... | ... | @@ -584,11 +585,13 @@ function AutoSettleSettingsRows() { |
| 584 | 585 | const mismatches = findSharedSettingsMismatches({ |
| 585 | 586 | primaryEnvironmentId: reference.environmentId, |
| 586 | 587 | primarySettings: referenceSettings, |
| 588 | primaryCapabilities: reference.serverConfig?.environment.capabilities, | |
| 587 | 589 | environments: environments.map((environment) => ({ |
| 588 | 590 | environmentId: environment.environmentId, |
| 589 | 591 | label: environment.label, |
| 590 | 592 | syncEligible: supportsSharedSettingsSync(environment), |
| 591 | 593 | settings: environment.serverConfig?.settings ?? null, |
| 594 | capabilities: environment.serverConfig?.environment.capabilities, | |
| 592 | 595 | })), |
| 593 | 596 | }); |
| 594 | 597 | |
| ... | ... | @@ -652,11 +655,22 @@ function AutoSettleSettingsRows() { |
| 652 | 655 | <Pressable |
| 653 | 656 | accessibilityRole="button" |
| 654 | 657 | onPress={() => { |
| 655 | const patch = pickSharedServerSettings(referenceSettings); | |
| 658 | const patch = pickSharedServerSettings( | |
| 659 | referenceSettings, | |
| 660 | reference.serverConfig?.environment.capabilities, | |
| 661 | ); | |
| 656 | 662 | for (const mismatch of mismatches) { |
| 663 | const target = environments.find( | |
| 664 | (candidate) => candidate.environmentId === mismatch.environmentId, | |
| 665 | ); | |
| 657 | 666 | void updateSettings({ |
| 658 | 667 | environmentId: mismatch.environmentId, |
| 659 | input: { patch }, | |
| 668 | input: { | |
| 669 | patch: filterSharedServerPatch( | |
| 670 | patch, | |
| 671 | target?.serverConfig?.environment.capabilities, | |
| 672 | ), | |
| 673 | }, | |
| 660 | 674 | }); |
| 661 | 675 | } |
| 662 | 676 | }} |
apps/server/src/environment/ServerEnvironment.ts+1| ... | ... | @@ -219,6 +219,7 @@ export const make = Effect.gen(function* () { |
| 219 | 219 | pullRequests: true, |
| 220 | 220 | threadSettlement: true, |
| 221 | 221 | threadAutoSettlement: true, |
| 222 | threadRestartContinuation: true, | |
| 222 | 223 | threadSnooze: true, |
| 223 | 224 | environmentThemes: true, |
| 224 | 225 | usageLimitSources: true, |
apps/web/src/components/settings/SettingsPanels.tsx+1-1| ... | ... | @@ -2439,7 +2439,7 @@ export function GeneralSettingsPanel() { |
| 2439 | 2439 | <SettingsRow |
| 2440 | 2440 | {...searchableSetting("continue-threads-after-server-update")} |
| 2441 | 2441 | serverScoped |
| 2442 | description="Automatically resume interrupted threads when this environment starts again after an update, crash, or machine restart." | |
| 2442 | description="Automatically resume interrupted threads after an update, crash, or machine restart. Applies to this environment and all connected environments that support it. Update older servers first." | |
| 2443 | 2443 | resetAction={ |
| 2444 | 2444 | settings.continueThreadsAfterServerUpdate !== |
| 2445 | 2445 | DEFAULT_UNIFIED_SETTINGS.continueThreadsAfterServerUpdate ? ( |
apps/web/src/hooks/useSettings.ts+34-25| ... | ... | @@ -26,6 +26,7 @@ import { |
| 26 | 26 | } from "@t3tools/contracts/settings"; |
| 27 | 27 | import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors"; |
| 28 | 28 | import { |
| 29 | filterSharedServerPatch, | |
| 29 | 30 | findSharedSettingsMismatches, |
| 30 | 31 | pickSharedServerSettings, |
| 31 | 32 | splitSharedServerPatch, |
| ... | ... | @@ -368,18 +369,6 @@ export function usePrimarySettingsAvailable(): boolean { |
| 368 | 369 | return primaryEnvironment !== null || !isHostedStaticApp(); |
| 369 | 370 | } |
| 370 | 371 | |
| 371 | /** Environments that can receive a shared settings write right now. */ | |
| 372 | function useSharedSettingsSyncTargetIds(): ReadonlyArray<EnvironmentId> { | |
| 373 | const { environments } = useEnvironments(); | |
| 374 | return useMemo( | |
| 375 | () => | |
| 376 | environments | |
| 377 | .filter(supportsSharedSettingsSync) | |
| 378 | .map((environment) => environment.environmentId), | |
| 379 | [environments], | |
| 380 | ); | |
| 381 | } | |
| 382 | ||
| 383 | 372 | /** |
| 384 | 373 | * Returns an updater that routes each key to the correct backing store. |
| 385 | 374 | * |
| ... | ... | @@ -394,7 +383,7 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) { |
| 394 | 383 | serverEnvironment.updateSettings, |
| 395 | 384 | "server settings update", |
| 396 | 385 | ); |
| 397 | const sharedSettingsSyncTargetIds = useSharedSettingsSyncTargetIds(); | |
| 386 | const { environments } = useEnvironments(); | |
| 398 | 387 | const updateSettings = useCallback( |
| 399 | 388 | (patch: UnifiedSettingsPatch) => { |
| 400 | 389 | const { serverPatch, clientPatch } = splitPatch(patch); |
| ... | ... | @@ -402,11 +391,11 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) { |
| 402 | 391 | if (Object.keys(serverPatch).length > 0) { |
| 403 | 392 | const { sharedPatch, localPatch } = splitSharedServerPatch(serverPatch); |
| 404 | 393 | // Dropping the write silently leaves the control looking saved. |
| 405 | const warnUnsaved = () => | |
| 394 | const warnUnsaved = (description = PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE) => | |
| 406 | 395 | toastManager.add({ |
| 407 | 396 | type: "warning", |
| 408 | 397 | title: "Setting not saved", |
| 409 | description: PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE, | |
| 398 | description, | |
| 410 | 399 | }); |
| 411 | 400 | if (Object.keys(localPatch).length > 0) { |
| 412 | 401 | if (environmentId) { |
| ... | ... | @@ -419,26 +408,38 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) { |
| 419 | 408 | } |
| 420 | 409 | } |
| 421 | 410 | if (Object.keys(sharedPatch).length > 0) { |
| 422 | const targets = new Set(sharedSettingsSyncTargetIds); | |
| 411 | const targets = new Set( | |
| 412 | environments.filter(supportsSharedSettingsSync).map((target) => target.environmentId), | |
| 413 | ); | |
| 423 | 414 | if (environmentId) { |
| 424 | 415 | targets.add(environmentId); |
| 425 | 416 | } |
| 426 | if (targets.size === 0) { | |
| 427 | warnUnsaved(); | |
| 428 | } | |
| 417 | let wroteToTarget = false; | |
| 429 | 418 | for (const targetId of targets) { |
| 419 | const target = environments.find((candidate) => candidate.environmentId === targetId); | |
| 420 | const targetPatch = filterSharedServerPatch( | |
| 421 | sharedPatch, | |
| 422 | target?.serverConfig?.environment.capabilities, | |
| 423 | ); | |
| 424 | if (Object.keys(targetPatch).length === 0) continue; | |
| 425 | wroteToTarget = true; | |
| 430 | 426 | void persistServerSettings({ |
| 431 | 427 | environmentId: targetId, |
| 432 | input: { patch: sharedPatch }, | |
| 428 | input: { patch: targetPatch }, | |
| 433 | 429 | }); |
| 434 | 430 | } |
| 431 | if (!wroteToTarget) { | |
| 432 | warnUnsaved( | |
| 433 | targets.size > 0 ? "Update older servers to save this setting." : undefined, | |
| 434 | ); | |
| 435 | } | |
| 435 | 436 | } |
| 436 | 437 | } |
| 437 | 438 | if (Object.keys(clientPatch).length > 0) { |
| 438 | 439 | persistClientSettingsPatch(clientPatch); |
| 439 | 440 | } |
| 440 | 441 | }, |
| 441 | [environmentId, persistServerSettings, sharedSettingsSyncTargetIds], | |
| 442 | [environmentId, environments, persistServerSettings], | |
| 442 | 443 | ); |
| 443 | 444 | |
| 444 | 445 | return updateSettings; |
| ... | ... | @@ -453,6 +454,7 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) { |
| 453 | 454 | export function useSharedSettingsSync() { |
| 454 | 455 | const primaryEnvironment = usePrimaryEnvironment(); |
| 455 | 456 | const primaryEnvironmentId = primaryEnvironment?.environmentId ?? null; |
| 457 | const primaryCapabilities = primaryEnvironment?.serverConfig?.environment.capabilities; | |
| 456 | 458 | // Read the loaded config, not `primaryServerSettingsAtom`: that atom falls |
| 457 | 459 | // back to defaults while the primary is disconnected, and "apply to all" |
| 458 | 460 | // must never push defaults over real values. Same for a primary too old to |
| ... | ... | @@ -472,28 +474,35 @@ export function useSharedSettingsSync() { |
| 472 | 474 | findSharedSettingsMismatches({ |
| 473 | 475 | primaryEnvironmentId, |
| 474 | 476 | primarySettings, |
| 477 | primaryCapabilities, | |
| 475 | 478 | environments: environments.map((environment) => ({ |
| 476 | 479 | environmentId: environment.environmentId, |
| 477 | 480 | label: environment.label, |
| 478 | 481 | syncEligible: supportsSharedSettingsSync(environment), |
| 479 | 482 | settings: environment.serverConfig?.settings ?? null, |
| 483 | capabilities: environment.serverConfig?.environment.capabilities, | |
| 480 | 484 | })), |
| 481 | 485 | }), |
| 482 | [environments, primaryEnvironmentId, primarySettings], | |
| 486 | [environments, primaryEnvironmentId, primarySettings, primaryCapabilities], | |
| 483 | 487 | ); |
| 484 | 488 | |
| 485 | 489 | const applyToAll = useCallback(() => { |
| 486 | 490 | if (primarySettings === null) { |
| 487 | 491 | return; |
| 488 | 492 | } |
| 489 | const patch = pickSharedServerSettings(primarySettings); | |
| 493 | const patch = pickSharedServerSettings(primarySettings, primaryCapabilities); | |
| 490 | 494 | for (const mismatch of mismatches) { |
| 495 | const target = environments.find( | |
| 496 | (candidate) => candidate.environmentId === mismatch.environmentId, | |
| 497 | ); | |
| 491 | 498 | void persistServerSettings({ |
| 492 | 499 | environmentId: mismatch.environmentId, |
| 493 | input: { patch }, | |
| 500 | input: { | |
| 501 | patch: filterSharedServerPatch(patch, target?.serverConfig?.environment.capabilities), | |
| 502 | }, | |
| 494 | 503 | }); |
| 495 | 504 | } |
| 496 | }, [mismatches, persistServerSettings, primarySettings]); | |
| 505 | }, [environments, mismatches, persistServerSettings, primarySettings, primaryCapabilities]); | |
| 497 | 506 | |
| 498 | 507 | return { mismatches, applyToAll }; |
| 499 | 508 | } |
docs/user/updating.md+7-4| ... | ... | @@ -11,12 +11,15 @@ Server updates restart the connection and can interrupt active agents and |
| 11 | 11 | terminal commands. Saved threads, settings, and project files remain. |
| 12 | 12 | |
| 13 | 13 | **Settings → General → Continue threads after restarts** is off by default. |
| 14 | Enable it for each environment to resume supported active threads after an | |
| 15 | update, crash, or machine restart. T3 Code must start again on that machine; | |
| 14 | Enable it to resume supported active threads after an update, crash, or machine | |
| 15 | restart. Changes are saved to connected environments that support this setting; | |
| 16 | update older servers first. If a supported environment was offline or has a | |
| 17 | different value, use **Apply to all** in Settings after it connects. | |
| 18 | T3 Code must start again on that machine; | |
| 16 | 19 | the setting does not enable automatic startup. Terminal commands may still be |
| 17 | 20 | interrupted, and threads without saved provider resume state need a new message. |
| 18 | If you previously enabled continuation for updates, enable this environment | |
| 19 | setting once to allow recovery without a connected client. | |
| 21 | If you previously enabled continuation for updates, enable this setting once | |
| 22 | to allow recovery without a connected client. | |
| 20 | 23 | |
| 21 | 24 | ## Update a connected server |
| 22 | 25 |
packages/client-runtime/src/state/sharedSettings.test.ts+109-2| ... | ... | @@ -2,6 +2,7 @@ import { DEFAULT_SERVER_SETTINGS, EnvironmentId } from "@t3tools/contracts"; |
| 2 | 2 | import { describe, expect, it } from "@effect/vitest"; |
| 3 | 3 | |
| 4 | 4 | import { |
| 5 | filterSharedServerPatch, | |
| 5 | 6 | findSharedSettingsMismatches, |
| 6 | 7 | pickSharedServerSettings, |
| 7 | 8 | splitSharedServerPatch, |
| ... | ... | @@ -11,6 +12,7 @@ import { |
| 11 | 12 | const primaryId = EnvironmentId.make("env-primary"); |
| 12 | 13 | const laptopId = EnvironmentId.make("env-laptop"); |
| 13 | 14 | const boxId = EnvironmentId.make("env-box"); |
| 15 | const restartCapabilities = { threadRestartContinuation: true }; | |
| 14 | 16 | |
| 15 | 17 | describe("supportsSharedSettingsSync", () => { |
| 16 | 18 | it("accepts only connected servers that advertise the shared-settings capability", () => { |
| ... | ... | @@ -40,16 +42,24 @@ describe("splitSharedServerPatch", () => { |
| 40 | 42 | const { sharedPatch, localPatch } = splitSharedServerPatch({ |
| 41 | 43 | sidebarAutoSettleAfterDays: 7, |
| 42 | 44 | sidebarAutoSettleOnMerge: false, |
| 45 | continueThreadsAfterServerUpdate: true, | |
| 43 | 46 | enableAgentBrowserAccess: false, |
| 44 | 47 | }); |
| 45 | expect(sharedPatch).toEqual({ sidebarAutoSettleAfterDays: 7, sidebarAutoSettleOnMerge: false }); | |
| 48 | expect(sharedPatch).toEqual({ | |
| 49 | sidebarAutoSettleAfterDays: 7, | |
| 50 | sidebarAutoSettleOnMerge: false, | |
| 51 | continueThreadsAfterServerUpdate: true, | |
| 52 | }); | |
| 46 | 53 | expect(localPatch).toEqual({ enableAgentBrowserAccess: false }); |
| 47 | 54 | }); |
| 48 | 55 | }); |
| 49 | 56 | |
| 50 | 57 | describe("pickSharedServerSettings", () => { |
| 51 | 58 | it("returns only the shared keys", () => { |
| 52 | expect(Object.keys(pickSharedServerSettings(DEFAULT_SERVER_SETTINGS)).sort()).toEqual([ | |
| 59 | expect( | |
| 60 | Object.keys(pickSharedServerSettings(DEFAULT_SERVER_SETTINGS, restartCapabilities)).sort(), | |
| 61 | ).toEqual([ | |
| 62 | "continueThreadsAfterServerUpdate", | |
| 53 | 63 | "defaultThreadEnvMode", |
| 54 | 64 | "newWorktreesStartFromOrigin", |
| 55 | 65 | "sidebarAutoSettleAfterDays", |
| ... | ... | @@ -59,9 +69,106 @@ describe("pickSharedServerSettings", () => { |
| 59 | 69 | }); |
| 60 | 70 | }); |
| 61 | 71 | |
| 72 | describe("filterSharedServerPatch", () => { | |
| 73 | it.each([true, false])("preserves supported restart preference %s", (enabled) => { | |
| 74 | const patch = { continueThreadsAfterServerUpdate: enabled, sidebarAutoSettleAfterDays: 7 }; | |
| 75 | expect(filterSharedServerPatch(patch, restartCapabilities)).toEqual(patch); | |
| 76 | }); | |
| 77 | ||
| 78 | it.each([undefined, {}, { threadRestartContinuation: false }])( | |
| 79 | "omits only the unsupported restart preference with capabilities %j", | |
| 80 | (capabilities) => { | |
| 81 | expect( | |
| 82 | filterSharedServerPatch( | |
| 83 | { continueThreadsAfterServerUpdate: true, sidebarAutoSettleAfterDays: 7 }, | |
| 84 | capabilities, | |
| 85 | ), | |
| 86 | ).toEqual({ sidebarAutoSettleAfterDays: 7 }); | |
| 87 | expect(pickSharedServerSettings(DEFAULT_SERVER_SETTINGS, capabilities)).not.toHaveProperty( | |
| 88 | "continueThreadsAfterServerUpdate", | |
| 89 | ); | |
| 90 | }, | |
| 91 | ); | |
| 92 | }); | |
| 93 | ||
| 62 | 94 | describe("findSharedSettingsMismatches", () => { |
| 63 | 95 | const primarySettings = { ...DEFAULT_SERVER_SETTINGS, sidebarAutoSettleAfterDays: 7 }; |
| 64 | 96 | |
| 97 | it.each([true, false])( | |
| 98 | "detects remote restart continuation drift when the preference is %s", | |
| 99 | (enabled) => { | |
| 100 | const settings = { ...primarySettings, continueThreadsAfterServerUpdate: enabled }; | |
| 101 | const remoteSettings = { ...settings, continueThreadsAfterServerUpdate: !enabled }; | |
| 102 | const environment = { | |
| 103 | environmentId: boxId, | |
| 104 | label: "Remote Box", | |
| 105 | syncEligible: true, | |
| 106 | settings: remoteSettings, | |
| 107 | capabilities: restartCapabilities, | |
| 108 | }; | |
| 109 | expect( | |
| 110 | findSharedSettingsMismatches({ | |
| 111 | primaryEnvironmentId: primaryId, | |
| 112 | primarySettings: settings, | |
| 113 | primaryCapabilities: restartCapabilities, | |
| 114 | environments: [environment], | |
| 115 | }), | |
| 116 | ).toEqual([{ environmentId: boxId, label: "Remote Box" }]); | |
| 117 | expect( | |
| 118 | findSharedSettingsMismatches({ | |
| 119 | primaryEnvironmentId: primaryId, | |
| 120 | primarySettings: settings, | |
| 121 | primaryCapabilities: restartCapabilities, | |
| 122 | environments: [ | |
| 123 | { | |
| 124 | ...environment, | |
| 125 | settings: Object.assign( | |
| 126 | {}, | |
| 127 | remoteSettings, | |
| 128 | pickSharedServerSettings(settings, restartCapabilities), | |
| 129 | ), | |
| 130 | }, | |
| 131 | ], | |
| 132 | }), | |
| 133 | ).toEqual([]); | |
| 134 | }, | |
| 135 | ); | |
| 136 | ||
| 137 | it.each([ | |
| 138 | [undefined, restartCapabilities], | |
| 139 | [restartCapabilities, undefined], | |
| 140 | [undefined, undefined], | |
| 141 | ])( | |
| 142 | "ignores restart drift unless both servers support it (%j, %j)", | |
| 143 | (primaryCapabilities, capabilities) => { | |
| 144 | const environment = { | |
| 145 | environmentId: boxId, | |
| 146 | label: "Remote Box", | |
| 147 | syncEligible: true, | |
| 148 | capabilities, | |
| 149 | settings: { ...primarySettings, continueThreadsAfterServerUpdate: true }, | |
| 150 | }; | |
| 151 | const input = { | |
| 152 | primaryEnvironmentId: primaryId, | |
| 153 | primarySettings, | |
| 154 | primaryCapabilities, | |
| 155 | environments: [environment], | |
| 156 | }; | |
| 157 | expect(findSharedSettingsMismatches(input)).toEqual([]); | |
| 158 | expect( | |
| 159 | findSharedSettingsMismatches({ | |
| 160 | ...input, | |
| 161 | environments: [ | |
| 162 | { | |
| 163 | ...environment, | |
| 164 | settings: { ...environment.settings, sidebarAutoSettleAfterDays: 14 }, | |
| 165 | }, | |
| 166 | ], | |
| 167 | }), | |
| 168 | ).toEqual([{ environmentId: boxId, label: "Remote Box" }]); | |
| 169 | }, | |
| 170 | ); | |
| 171 | ||
| 65 | 172 | it("lists sync-eligible environments whose shared settings differ", () => { |
| 66 | 173 | const mismatches = findSharedSettingsMismatches({ |
| 67 | 174 | primaryEnvironmentId: primaryId, |
packages/client-runtime/src/state/sharedSettings.ts+34-8| ... | ... | @@ -21,6 +21,7 @@ import type { EnvironmentConnectionPhase } from "../connection/presentation.ts"; |
| 21 | 21 | |
| 22 | 22 | /** Server keys that hold a user preference rather than machine config. */ |
| 23 | 23 | export const SHARED_SERVER_SETTING_KEYS = [ |
| 24 | "continueThreadsAfterServerUpdate", | |
| 24 | 25 | "sidebarAutoSettleAfterDays", |
| 25 | 26 | "sidebarAutoSettleOnMerge", |
| 26 | 27 | "defaultThreadEnvMode", |
| ... | ... | @@ -52,15 +53,27 @@ export function splitSharedServerPatch(patch: ServerSettingsPatch): { |
| 52 | 53 | }; |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | /** The shared subset of one environment's settings, as a patch that can be written elsewhere. */ | |
| 56 | export function pickSharedServerSettings(settings: ServerSettings): ServerSettingsPatch { | |
| 57 | return Struct.pick(settings, SHARED_SERVER_SETTING_KEYS); | |
| 56 | /** Omit restart recovery on servers that cannot persist its preference. */ | |
| 57 | export function filterSharedServerPatch( | |
| 58 | patch: ServerSettingsPatch, | |
| 59 | capabilities: Pick<ExecutionEnvironmentCapabilities, "threadRestartContinuation"> | undefined, | |
| 60 | ): ServerSettingsPatch { | |
| 61 | return capabilities?.threadRestartContinuation === true | |
| 62 | ? patch | |
| 63 | : Struct.omit(patch, ["continueThreadsAfterServerUpdate"]); | |
| 64 | } | |
| 65 | ||
| 66 | /** The shared subset supported by one environment. */ | |
| 67 | export function pickSharedServerSettings( | |
| 68 | settings: ServerSettings, | |
| 69 | capabilities?: Pick<ExecutionEnvironmentCapabilities, "threadRestartContinuation">, | |
| 70 | ): ServerSettingsPatch { | |
| 71 | return filterSharedServerPatch(Struct.pick(settings, SHARED_SERVER_SETTING_KEYS), capabilities); | |
| 58 | 72 | } |
| 59 | 73 | |
| 60 | 74 | /** |
| 61 | 75 | * Whether an environment can participate in shared-settings sync right now. |
| 62 | * Auto-settlement is the newest feature backed by a shared key, so a server | |
| 63 | * advertising `threadAutoSettlement` can hold every shared key. | |
| 76 | * Auto-settlement establishes baseline support; newer preferences are filtered separately. | |
| 64 | 77 | */ |
| 65 | 78 | export function supportsSharedSettingsSync(environment: { |
| 66 | 79 | readonly connection: { readonly phase: EnvironmentConnectionPhase }; |
| ... | ... | @@ -81,12 +94,15 @@ export interface SharedSettingsEnvironment { |
| 81 | 94 | readonly label: string; |
| 82 | 95 | readonly syncEligible: boolean; |
| 83 | 96 | readonly settings: ServerSettings | null; |
| 97 | readonly capabilities?: | |
| 98 | | Pick<ExecutionEnvironmentCapabilities, "threadRestartContinuation"> | |
| 99 | | undefined; | |
| 84 | 100 | } |
| 85 | 101 | |
| 86 | 102 | /** |
| 87 | 103 | * Shared-settings sync targets whose values differ from the primary |
| 88 | 104 | * environment's. Other environments are skipped: nothing can be read from or |
| 89 | * written to them, or their server cannot hold every shared key. With no | |
| 105 | * written to them, or their server lacks baseline shared-settings support. With no | |
| 90 | 106 | * primary settings loaded there is nothing to compare against, so nothing is |
| 91 | 107 | * reported. Callers must pass the real loaded settings, never a default |
| 92 | 108 | * fallback, or "apply to all" would push defaults over real values. |
| ... | ... | @@ -94,12 +110,18 @@ export interface SharedSettingsEnvironment { |
| 94 | 110 | export function findSharedSettingsMismatches(input: { |
| 95 | 111 | readonly primaryEnvironmentId: EnvironmentId | null; |
| 96 | 112 | readonly primarySettings: ServerSettings | null; |
| 113 | readonly primaryCapabilities?: | |
| 114 | | Pick<ExecutionEnvironmentCapabilities, "threadRestartContinuation"> | |
| 115 | | undefined; | |
| 97 | 116 | readonly environments: ReadonlyArray<SharedSettingsEnvironment>; |
| 98 | 117 | }): ReadonlyArray<{ readonly environmentId: EnvironmentId; readonly label: string }> { |
| 99 | 118 | if (input.primaryEnvironmentId === null || input.primarySettings === null) { |
| 100 | 119 | return []; |
| 101 | 120 | } |
| 102 | const expected = pickSharedServerSettings(input.primarySettings); | |
| 121 | const primarySettings = pickSharedServerSettings( | |
| 122 | input.primarySettings, | |
| 123 | input.primaryCapabilities, | |
| 124 | ); | |
| 103 | 125 | return input.environments.flatMap((environment) => { |
| 104 | 126 | if ( |
| 105 | 127 | environment.environmentId === input.primaryEnvironmentId || |
| ... | ... | @@ -108,7 +130,11 @@ export function findSharedSettingsMismatches(input: { |
| 108 | 130 | ) { |
| 109 | 131 | return []; |
| 110 | 132 | } |
| 111 | const actual = pickSharedServerSettings(environment.settings); | |
| 133 | const expected = filterSharedServerPatch(primarySettings, environment.capabilities); | |
| 134 | const actual = filterSharedServerPatch( | |
| 135 | pickSharedServerSettings(environment.settings, environment.capabilities), | |
| 136 | input.primaryCapabilities, | |
| 137 | ); | |
| 112 | 138 | return Equal.equals(actual, expected) |
| 113 | 139 | ? [] |
| 114 | 140 | : [{ environmentId: environment.environmentId, label: environment.label }]; |
packages/contracts/src/environment.ts+2| ... | ... | @@ -94,6 +94,8 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({ |
| 94 | 94 | threadSettlement: Schema.optionalKey(Schema.Boolean), |
| 95 | 95 | /** Server evaluates merge and inactivity settlement without a client. */ |
| 96 | 96 | threadAutoSettlement: Schema.optionalKey(Schema.Boolean), |
| 97 | /** Server persists the opt-in for continuing interrupted threads after restarts. */ | |
| 98 | threadRestartContinuation: Schema.optionalKey(Schema.Boolean), | |
| 97 | 99 | /** Server understands thread.snooze / thread.unsnooze commands. Same |
| 98 | 100 | version-skew contract as threadSettlement. */ |
| 99 | 101 | threadSnooze: Schema.optionalKey(Schema.Boolean), |