The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 10:15 UTC
fix(settings): share restart continuation across environments (#9933)
maria committed
Sep 5, 2026 at 01:33 UTC
f47a3fe90354a3dfa14276e3699541d552426276
8 files changed
+204
-42
apps/mobile/src/features/settings/SettingsRouteScreen.tsx
+16
-2
@@ -44,6 +44,7 @@ import {
44
type ServerSettingsPatch,
45
} from "@t3tools/contracts";
46
import {
47
+ filterSharedServerPatch,
48
findSharedSettingsMismatches,
49
pickSharedServerSettings,
50
supportsSharedSettingsSync,
@@ -584,11 +585,13 @@ function AutoSettleSettingsRows() {
585
const mismatches = findSharedSettingsMismatches({
586
primaryEnvironmentId: reference.environmentId,
587
primarySettings: referenceSettings,
588
+ primaryCapabilities: reference.serverConfig?.environment.capabilities,
589
environments: environments.map((environment) => ({
590
environmentId: environment.environmentId,
591
label: environment.label,
592
syncEligible: supportsSharedSettingsSync(environment),
593
settings: environment.serverConfig?.settings ?? null,
594
+ capabilities: environment.serverConfig?.environment.capabilities,
595
})),
596
});
597
@@ -652,11 +655,22 @@ function AutoSettleSettingsRows() {
655
<Pressable
656
accessibilityRole="button"
657
onPress={() => {
655
- const patch = pickSharedServerSettings(referenceSettings);
658
+ const patch = pickSharedServerSettings(
659
+ referenceSettings,
660
+ reference.serverConfig?.environment.capabilities,
661
+ );
662
for (const mismatch of mismatches) {
663
+ const target = environments.find(
664
+ (candidate) => candidate.environmentId === mismatch.environmentId,
665
+ );
666
void updateSettings({
667
environmentId: mismatch.environmentId,
659
- input: { patch },
668
+ input: {
669
+ patch: filterSharedServerPatch(
670
+ patch,
671
+ target?.serverConfig?.environment.capabilities,
672
+ ),
673
+ },
674
});
675
}
676
}}
apps/server/src/environment/ServerEnvironment.ts
+1
@@ -219,6 +219,7 @@ export const make = Effect.gen(function* () {
219
pullRequests: true,
220
threadSettlement: true,
221
threadAutoSettlement: true,
222
+ threadRestartContinuation: true,
223
threadSnooze: true,
224
environmentThemes: true,
225
usageLimitSources: true,
apps/web/src/components/settings/SettingsPanels.tsx
+1
-1
@@ -2439,7 +2439,7 @@ export function GeneralSettingsPanel() {
2439
<SettingsRow
2440
{...searchableSetting("continue-threads-after-server-update")}
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
resetAction={
2444
settings.continueThreadsAfterServerUpdate !==
2445
DEFAULT_UNIFIED_SETTINGS.continueThreadsAfterServerUpdate ? (
apps/web/src/hooks/useSettings.ts
+34
-25
@@ -26,6 +26,7 @@ import {
26
} from "@t3tools/contracts/settings";
27
import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors";
28
import {
29
+ filterSharedServerPatch,
30
findSharedSettingsMismatches,
31
pickSharedServerSettings,
32
splitSharedServerPatch,
@@ -368,18 +369,6 @@ export function usePrimarySettingsAvailable(): boolean {
369
return primaryEnvironment !== null || !isHostedStaticApp();
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
-
372
/**
373
* Returns an updater that routes each key to the correct backing store.
374
*
@@ -394,7 +383,7 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
383
serverEnvironment.updateSettings,
384
"server settings update",
385
);
397
- const sharedSettingsSyncTargetIds = useSharedSettingsSyncTargetIds();
386
+ const { environments } = useEnvironments();
387
const updateSettings = useCallback(
388
(patch: UnifiedSettingsPatch) => {
389
const { serverPatch, clientPatch } = splitPatch(patch);
@@ -402,11 +391,11 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
391
if (Object.keys(serverPatch).length > 0) {
392
const { sharedPatch, localPatch } = splitSharedServerPatch(serverPatch);
393
// Dropping the write silently leaves the control looking saved.
405
- const warnUnsaved = () =>
394
+ const warnUnsaved = (description = PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE) =>
395
toastManager.add({
396
type: "warning",
397
title: "Setting not saved",
409
- description: PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE,
398
+ description,
399
});
400
if (Object.keys(localPatch).length > 0) {
401
if (environmentId) {
@@ -419,26 +408,38 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
408
}
409
}
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
+ );
414
if (environmentId) {
415
targets.add(environmentId);
416
}
426
- if (targets.size === 0) {
427
- warnUnsaved();
428
- }
417
+ let wroteToTarget = false;
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;
426
void persistServerSettings({
427
environmentId: targetId,
432
- input: { patch: sharedPatch },
428
+ input: { patch: targetPatch },
429
});
430
}
431
+ if (!wroteToTarget) {
432
+ warnUnsaved(
433
+ targets.size > 0 ? "Update older servers to save this setting." : undefined,
434
+ );
435
+ }
436
}
437
}
438
if (Object.keys(clientPatch).length > 0) {
439
persistClientSettingsPatch(clientPatch);
440
}
441
},
441
- [environmentId, persistServerSettings, sharedSettingsSyncTargetIds],
442
+ [environmentId, environments, persistServerSettings],
443
);
444
445
return updateSettings;
@@ -453,6 +454,7 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
454
export function useSharedSettingsSync() {
455
const primaryEnvironment = usePrimaryEnvironment();
456
const primaryEnvironmentId = primaryEnvironment?.environmentId ?? null;
457
+ const primaryCapabilities = primaryEnvironment?.serverConfig?.environment.capabilities;
458
// Read the loaded config, not `primaryServerSettingsAtom`: that atom falls
459
// back to defaults while the primary is disconnected, and "apply to all"
460
// must never push defaults over real values. Same for a primary too old to
@@ -472,28 +474,35 @@ export function useSharedSettingsSync() {
474
findSharedSettingsMismatches({
475
primaryEnvironmentId,
476
primarySettings,
477
+ primaryCapabilities,
478
environments: environments.map((environment) => ({
479
environmentId: environment.environmentId,
480
label: environment.label,
481
syncEligible: supportsSharedSettingsSync(environment),
482
settings: environment.serverConfig?.settings ?? null,
483
+ capabilities: environment.serverConfig?.environment.capabilities,
484
})),
485
}),
482
- [environments, primaryEnvironmentId, primarySettings],
486
+ [environments, primaryEnvironmentId, primarySettings, primaryCapabilities],
487
);
488
489
const applyToAll = useCallback(() => {
490
if (primarySettings === null) {
491
return;
492
}
489
- const patch = pickSharedServerSettings(primarySettings);
493
+ const patch = pickSharedServerSettings(primarySettings, primaryCapabilities);
494
for (const mismatch of mismatches) {
495
+ const target = environments.find(
496
+ (candidate) => candidate.environmentId === mismatch.environmentId,
497
+ );
498
void persistServerSettings({
499
environmentId: mismatch.environmentId,
493
- input: { patch },
500
+ input: {
501
+ patch: filterSharedServerPatch(patch, target?.serverConfig?.environment.capabilities),
502
+ },
503
});
504
}
496
- }, [mismatches, persistServerSettings, primarySettings]);
505
+ }, [environments, mismatches, persistServerSettings, primarySettings, primaryCapabilities]);
506
507
return { mismatches, applyToAll };
508
}
docs/user/updating.md
+7
-4
@@ -11,12 +11,15 @@ Server updates restart the connection and can interrupt active agents and
11
terminal commands. Saved threads, settings, and project files remain.
12
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;
19
the setting does not enable automatic startup. Terminal commands may still be
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.
23
24
## Update a connected server
25
packages/client-runtime/src/state/sharedSettings.test.ts
+109
-2
@@ -2,6 +2,7 @@ import { DEFAULT_SERVER_SETTINGS, EnvironmentId } from "@t3tools/contracts";
2
import { describe, expect, it } from "@effect/vitest";
3
4
import {
5
+ filterSharedServerPatch,
6
findSharedSettingsMismatches,
7
pickSharedServerSettings,
8
splitSharedServerPatch,
@@ -11,6 +12,7 @@ import {
12
const primaryId = EnvironmentId.make("env-primary");
13
const laptopId = EnvironmentId.make("env-laptop");
14
const boxId = EnvironmentId.make("env-box");
15
+const restartCapabilities = { threadRestartContinuation: true };
16
17
describe("supportsSharedSettingsSync", () => {
18
it("accepts only connected servers that advertise the shared-settings capability", () => {
@@ -40,16 +42,24 @@ describe("splitSharedServerPatch", () => {
42
const { sharedPatch, localPatch } = splitSharedServerPatch({
43
sidebarAutoSettleAfterDays: 7,
44
sidebarAutoSettleOnMerge: false,
45
+ continueThreadsAfterServerUpdate: true,
46
enableAgentBrowserAccess: false,
47
});
45
- expect(sharedPatch).toEqual({ sidebarAutoSettleAfterDays: 7, sidebarAutoSettleOnMerge: false });
48
+ expect(sharedPatch).toEqual({
49
+ sidebarAutoSettleAfterDays: 7,
50
+ sidebarAutoSettleOnMerge: false,
51
+ continueThreadsAfterServerUpdate: true,
52
+ });
53
expect(localPatch).toEqual({ enableAgentBrowserAccess: false });
54
});
55
});
56
57
describe("pickSharedServerSettings", () => {
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",
63
"defaultThreadEnvMode",
64
"newWorktreesStartFromOrigin",
65
"sidebarAutoSettleAfterDays",
@@ -59,9 +69,106 @@ describe("pickSharedServerSettings", () => {
69
});
70
});
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
+
94
describe("findSharedSettingsMismatches", () => {
95
const primarySettings = { ...DEFAULT_SERVER_SETTINGS, sidebarAutoSettleAfterDays: 7 };
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
+
172
it("lists sync-eligible environments whose shared settings differ", () => {
173
const mismatches = findSharedSettingsMismatches({
174
primaryEnvironmentId: primaryId,
packages/client-runtime/src/state/sharedSettings.ts
+34
-8
@@ -21,6 +21,7 @@ import type { EnvironmentConnectionPhase } from "../connection/presentation.ts";
21
22
/** Server keys that hold a user preference rather than machine config. */
23
export const SHARED_SERVER_SETTING_KEYS = [
24
+ "continueThreadsAfterServerUpdate",
25
"sidebarAutoSettleAfterDays",
26
"sidebarAutoSettleOnMerge",
27
"defaultThreadEnvMode",
@@ -52,15 +53,27 @@ export function splitSharedServerPatch(patch: ServerSettingsPatch): {
53
};
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);
72
}
73
74
/**
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.
77
*/
78
export function supportsSharedSettingsSync(environment: {
79
readonly connection: { readonly phase: EnvironmentConnectionPhase };
@@ -81,12 +94,15 @@ export interface SharedSettingsEnvironment {
94
readonly label: string;
95
readonly syncEligible: boolean;
96
readonly settings: ServerSettings | null;
97
+ readonly capabilities?:
98
+ | Pick<ExecutionEnvironmentCapabilities, "threadRestartContinuation">
99
+ | undefined;
100
}
101
102
/**
103
* Shared-settings sync targets whose values differ from the primary
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
106
* primary settings loaded there is nothing to compare against, so nothing is
107
* reported. Callers must pass the real loaded settings, never a default
108
* fallback, or "apply to all" would push defaults over real values.
@@ -94,12 +110,18 @@ export interface SharedSettingsEnvironment {
110
export function findSharedSettingsMismatches(input: {
111
readonly primaryEnvironmentId: EnvironmentId | null;
112
readonly primarySettings: ServerSettings | null;
113
+ readonly primaryCapabilities?:
114
+ | Pick<ExecutionEnvironmentCapabilities, "threadRestartContinuation">
115
+ | undefined;
116
readonly environments: ReadonlyArray<SharedSettingsEnvironment>;
117
}): ReadonlyArray<{ readonly environmentId: EnvironmentId; readonly label: string }> {
118
if (input.primaryEnvironmentId === null || input.primarySettings === null) {
119
return [];
120
}
102
- const expected = pickSharedServerSettings(input.primarySettings);
121
+ const primarySettings = pickSharedServerSettings(
122
+ input.primarySettings,
123
+ input.primaryCapabilities,
124
+ );
125
return input.environments.flatMap((environment) => {
126
if (
127
environment.environmentId === input.primaryEnvironmentId ||
@@ -108,7 +130,11 @@ export function findSharedSettingsMismatches(input: {
130
) {
131
return [];
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
+ );
138
return Equal.equals(actual, expected)
139
? []
140
: [{ environmentId: environment.environmentId, label: environment.label }];
packages/contracts/src/environment.ts
+2
@@ -94,6 +94,8 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
94
threadSettlement: Schema.optionalKey(Schema.Boolean),
95
/** Server evaluates merge and inactivity settlement without a client. */
96
threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
97
+ /** Server persists the opt-in for continuing interrupted threads after restarts. */
98
+ threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
99
/** Server understands thread.snooze / thread.unsnooze commands. Same
100
version-skew contract as threadSettlement. */
101
threadSnooze: Schema.optionalKey(Schema.Boolean),