The best way to control Claude Code, Codex and more from any computer or phone
fix(shared): saving one source control token no longer drops the other hosts' tokens (#29554)
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Yordis Prieto committed
Nov 3, 2026 at 14:31 UTC
bff68fb6b6f86346f780024db62ba75873f70854
4 files changed
+50
-6
apps/web/src/components/settings/SourceControlAppSignInSettings.tsx
+1
-1
@@ -171,7 +171,7 @@ export function SourceControlAppSignInSettings({
171
/>
172
</span>
173
) : tokenOverrides ? (
174
- "Signed in, but the token saved below is used until you remove it."
174
+ "Signed in, but the token saved below is used while it can be read."
175
) : (
176
"Signed in"
177
);
packages/contracts/src/settings.ts
+1
-1
@@ -1696,7 +1696,7 @@ export const ServerSettingsPatch = Schema.Struct({
1696
otlpLogsUrl: Schema.optionalKey(TrimmedString),
1697
}),
1698
),
1699
- /** Merges per host, replacing patched fields whole; redaction markers retain secrets, empty or omitted secrets remove them. */
1699
+ /** Merges per host, replacing patched fields whole; redaction markers retain secrets, empty secrets remove them. A non-empty token map keeps the saved tokens of hosts it omits; an empty map clears them all. */
1700
sourceControlHosts: Schema.optionalKey(Schema.Record(Schema.String, SourceControlHostSettings)),
1701
// Replace whole maps to avoid half-merged driver configs.
1702
providerInstances: Schema.optionalKey(Schema.Record(ProviderInstanceId, ProviderInstanceConfig)),
packages/shared/src/serverSettings.test.ts
+18
@@ -127,6 +127,24 @@ describe("serverSettings helpers", () => {
127
});
128
});
129
130
+ it("keeps a source control host's saved tokens when a patch sets another host's token", () => {
131
+ const reference = { provider: "vault", reference: "github/token" };
132
+ const saved = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
133
+ sourceControlHosts: { github: { tokens: { "github.com": reference } } },
134
+ });
135
+ const patched = applyServerSettingsPatch(saved, {
136
+ sourceControlHosts: { github: { tokens: { "ghe.example": "x" } } },
137
+ });
138
+ expect(patched.sourceControlHosts.github?.tokens).toEqual({
139
+ "github.com": reference,
140
+ "ghe.example": "x",
141
+ });
142
+ const recased = applyServerSettingsPatch(saved, {
143
+ sourceControlHosts: { github: { tokens: { " GitHub.com ": "ghp_new" } } },
144
+ });
145
+ expect(recased.sourceControlHosts.github?.tokens).toEqual({ "github.com": "ghp_new" });
146
+ });
147
+
148
it("inherits actions, preserves existing actions, and supports empty overrides and reset", () => {
149
const project = { id: ProjectId.make("project-actions"), scripts: [] };
150
const action = {
packages/shared/src/serverSettings.ts
+30
-4
@@ -23,6 +23,7 @@ import {
23
withIdleCompaction,
24
} from "@t3tools/contracts";
25
import * as Option from "effect/Option";
26
+import * as Predicate from "effect/Predicate";
27
import * as Schema from "effect/Schema";
28
import { deepMerge } from "./Struct.ts";
29
import { fromLenientJson } from "./schemaJson.ts";
@@ -226,6 +227,15 @@ function mergeSettingsEntries<Value>(
227
return Object.fromEntries(next);
228
}
229
230
+// Secret persistence keys tokens by trimmed, lowercased host, so merge on the same key.
231
+const byHost = (tokens: unknown) =>
232
+ Object.fromEntries(
233
+ Object.entries(Predicate.isObject(tokens) ? tokens : {}).map(([host, token]) => [
234
+ host.trim().toLowerCase(),
235
+ token,
236
+ ]),
237
+ );
238
+
239
const knownProjectOverrideKeys = new Set(Object.keys(ProjectSettingsOverrides.fields));
240
241
function pickOverrideKeys(entry: ProjectSettingsOverrides | undefined, known: boolean) {
@@ -530,10 +540,26 @@ export function applyServerSettingsPatch(
540
sourceControlHosts: {
541
...current.sourceControlHosts,
542
...Object.fromEntries(
533
- Object.entries(sourceControlHostsPatch).map(([kind, fields]) => [
534
- kind,
535
- { ...current.sourceControlHosts[kind], ...fields },
536
- ]),
543
+ Object.entries(sourceControlHostsPatch).map(([kind, fields]) => {
544
+ const saved = current.sourceControlHosts[kind];
545
+ return [
546
+ kind,
547
+ {
548
+ ...saved,
549
+ ...fields,
550
+ // Older clients send the whole token map; a host missing from it keeps its saved
551
+ // token. An empty map still clears them all.
552
+ ...(Predicate.isObject(fields.tokens) && Object.keys(fields.tokens).length > 0
553
+ ? {
554
+ tokens: {
555
+ ...byHost(saved?.tokens),
556
+ ...byHost(fields.tokens),
557
+ },
558
+ }
559
+ : {}),
560
+ },
561
+ ];
562
+ }),
563
),
564
},
565
}