The best way to control Claude Code, Codex and more from any computer or phone
fix(server): a turn that adds a Git remote shows "Add to another machine" right away (#29947)
Julius Marminge committed
Nov 11, 2026 at 15:40 UTC
3ffd240fc75e1392734bc396dfa3643c50cb3f9e
6 files changed
+211
-2
apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
+1
@@ -143,6 +143,7 @@ const layerTest = Layer.mergeAll(
143
repositoryIdentityResolved: false,
144
}),
145
invalidate: () => Effect.void,
146
+ refreshRepositoryIdentity: () => Effect.void,
147
subscribeChanges: Effect.never,
148
}),
149
),
apps/server/src/orchestration-v2/RunFinalizationQueue.test.ts
+5
@@ -5,6 +5,8 @@ import * as Layer from "effect/Layer";
5
import * as Option from "effect/Option";
6
7
import * as SqlitePersistence from "../persistence/Sqlite.ts";
8
+import * as ProjectEnrichment from "../project/ProjectEnrichmentService.ts";
9
+import * as ProjectService from "../project/ProjectService.ts";
10
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
11
import * as ServerSettings from "../serverSettings.ts";
12
import * as VcsStatusBroadcaster from "../vcs/VcsStatusBroadcaster.ts";
@@ -43,11 +45,14 @@ it.effect.each([
45
checkpointScopes: [{ id: scopeId, runId, kind: "root_run" as const, cwd: "/repo" }],
46
checkpoints: [],
47
}),
48
+ getThreadShell: () => Effect.succeed(null),
49
});
50
const observer = RunFinalization.layerObserver.pipe(
51
Layer.provide(
52
Layer.mergeAll(
53
projections,
54
+ Layer.mock(ProjectService.ProjectService)({}),
55
+ Layer.mock(ProjectEnrichment.ProjectEnrichmentService)({}),
56
Layer.mock(WorkspaceEntries.WorkspaceEntries)({ refresh: () => Effect.void }),
57
Layer.mock(PullRequestService.PullRequestService)({ refreshAfterTurn: () => Effect.void }),
58
Layer.mock(VcsStatusBroadcaster.VcsStatusBroadcaster)({
apps/server/src/orchestration-v2/RunFinalizationService.test.ts
+155
@@ -1,17 +1,28 @@
1
+import * as NodeServices from "@effect/platform-node/NodeServices";
2
import { assert, it } from "@effect/vitest";
3
import {
4
CheckpointScopeId,
5
+ ProjectId,
6
RunId,
7
ThreadId,
8
type OrchestrationV2ThreadShell,
9
+ type Project,
10
+ type RepositoryIdentity,
11
} from "@t3tools/contracts";
12
import * as Deferred from "effect/Deferred";
13
import * as Effect from "effect/Effect";
14
import * as Fiber from "effect/Fiber";
15
+import * as FileSystem from "effect/FileSystem";
16
import * as Layer from "effect/Layer";
17
import * as Option from "effect/Option";
18
+import * as PubSub from "effect/PubSub";
19
import * as TestClock from "effect/testing/TestClock";
20
21
+import * as ProcessRunner from "../processRunner.ts";
22
+import * as ProjectEnrichment from "../project/ProjectEnrichmentService.ts";
23
+import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts";
24
+import * as ProjectService from "../project/ProjectService.ts";
25
+import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
26
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
27
import * as VcsStatusBroadcaster from "../vcs/VcsStatusBroadcaster.ts";
28
import * as WorkspaceEntries from "../workspace/WorkspaceEntries.ts";
@@ -19,6 +30,12 @@ import * as CheckpointCapture from "./CheckpointCaptureService.ts";
30
import * as ProjectionStore from "./ProjectionStore.ts";
31
import * as RunFinalization from "./RunFinalizationService.ts";
32
33
+// Without a project the observer never touches enrichment, so its methods stay unimplemented.
34
+const layerNoProject = Layer.mergeAll(
35
+ Layer.mock(ProjectService.ProjectService)({ getById: () => Effect.succeedNone }),
36
+ Layer.mock(ProjectEnrichment.ProjectEnrichmentService)({}),
37
+);
38
+
39
it.effect("completes finalization when the post-checkpoint workspace refresh fails", () => {
40
const threadId = ThreadId.make("thread_refresh_failure");
41
const runId = RunId.make("run_refresh_failure");
@@ -103,6 +120,7 @@ it.effect.each(
120
const layer = RunFinalization.layerObserver.pipe(
121
Layer.provide(
122
Layer.mergeAll(
123
+ layerNoProject,
124
Layer.mock(WorkspaceEntries.WorkspaceEntries)({ refresh: () => Effect.void }),
125
Layer.mock(PullRequestService.PullRequestService)({
126
refreshAfterTurn: () => Effect.void,
@@ -150,6 +168,7 @@ it.effect("returns from the post-turn refresh without waiting for the PR lookup"
168
const layer = RunFinalization.layerObserver.pipe(
169
Layer.provide(
170
Layer.mergeAll(
171
+ layerNoProject,
172
Layer.mock(WorkspaceEntries.WorkspaceEntries)({ refresh: () => Effect.void }),
173
Layer.mock(PullRequestService.PullRequestService)({
174
refreshAfterTurn: () => Effect.void,
@@ -200,6 +219,7 @@ it.effect("replaces a still-running PR lookup when a newer turn finishes", () =>
219
const layer = RunFinalization.layerObserver.pipe(
220
Layer.provide(
221
Layer.mergeAll(
222
+ layerNoProject,
223
Layer.mock(WorkspaceEntries.WorkspaceEntries)({ refresh: () => Effect.void }),
224
Layer.mock(PullRequestService.PullRequestService)({
225
refreshAfterTurn: () => Effect.void,
@@ -241,3 +261,138 @@ it.effect("replaces a still-running PR lookup when a newer turn finishes", () =>
261
assert.strictEqual(lookups, 2);
262
}).pipe(Effect.provide(layer));
263
});
264
+
265
+const identityProjectId = ProjectId.make("project-identity-refresh");
266
+const identityThreadId = ThreadId.make("thread-identity-refresh");
267
+const identityRunId = RunId.make("completed-run");
268
+
269
+const layerIdentityRefresh = <R>(
270
+ workspaceRoot: string,
271
+ resolver: Layer.Layer<RepositoryIdentityResolver.RepositoryIdentityResolver, never, R>,
272
+) =>
273
+ RunFinalization.layerObserver.pipe(
274
+ Layer.provideMerge(
275
+ Layer.mergeAll(
276
+ Layer.effect(ProjectEnrichment.ProjectEnrichmentService, ProjectEnrichment.make()).pipe(
277
+ Layer.provide(
278
+ Layer.mergeAll(
279
+ resolver,
280
+ Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
281
+ invalidate: () => Effect.void,
282
+ resolvePath: () => Effect.succeed(null),
283
+ }),
284
+ ),
285
+ ),
286
+ ),
287
+ Layer.mock(WorkspaceEntries.WorkspaceEntries)({ refresh: () => Effect.void }),
288
+ Layer.mock(PullRequestService.PullRequestService)({ refreshAfterTurn: () => Effect.void }),
289
+ Layer.mock(VcsStatusBroadcaster.VcsStatusBroadcaster)({
290
+ refreshLocalStatus: () =>
291
+ Effect.succeed({
292
+ isRepo: true,
293
+ hasPrimaryRemote: true,
294
+ isDefaultRef: true,
295
+ refName: "main",
296
+ hasWorkingTreeChanges: false,
297
+ workingTree: { files: [], insertions: 0, deletions: 0 },
298
+ }),
299
+ }),
300
+ Layer.mock(ProjectionStore.ProjectionStoreV2)({
301
+ getThreadShell: () =>
302
+ Effect.succeed({
303
+ id: identityThreadId,
304
+ projectId: identityProjectId,
305
+ branch: "main",
306
+ activeRunId: null,
307
+ } as OrchestrationV2ThreadShell),
308
+ }),
309
+ Layer.mock(ProjectService.ProjectService)({
310
+ getById: () => Effect.succeedSome({ id: identityProjectId, workspaceRoot } as Project),
311
+ }),
312
+ ),
313
+ ),
314
+ );
315
+
316
+it.effect("resolves the identity of a project whose remote was added during the turn", () =>
317
+ Effect.gen(function* () {
318
+ const fileSystem = yield* FileSystem.FileSystem;
319
+ const processRunner = yield* ProcessRunner.ProcessRunner;
320
+ const workspaceRoot = yield* fileSystem.makeTempDirectoryScoped({
321
+ prefix: "t3-run-finalization-identity-test-",
322
+ });
323
+ const git = (args: ReadonlyArray<string>) =>
324
+ processRunner.run({ command: "git", args: ["-C", workspaceRoot, ...args] });
325
+ yield* git(["init"]);
326
+
327
+ yield* Effect.gen(function* () {
328
+ const enrichment = yield* ProjectEnrichment.ProjectEnrichmentService;
329
+ // A shell read before the turn caches the folder as having no repository.
330
+ assert.isNull(yield* enrichment.readRepositoryIdentity(workspaceRoot));
331
+
332
+ yield* git(["remote", "add", "origin", "https://github.com/t3-triage/example-29929.git"]);
333
+ const changes = yield* enrichment.subscribeChanges;
334
+ const observer = yield* RunFinalization.RunFinalizationObserver;
335
+ yield* observer.refresh({
336
+ cwd: workspaceRoot,
337
+ threadId: identityThreadId,
338
+ runId: identityRunId,
339
+ });
340
+
341
+ const change = yield* PubSub.take(changes);
342
+ assert.strictEqual(
343
+ change.enrichment.repositoryIdentity?.locator.remoteUrl,
344
+ "https://github.com/t3-triage/example-29929.git",
345
+ "the project's repository identity is still null after the turn added a remote",
346
+ );
347
+ }).pipe(
348
+ Effect.scoped,
349
+ Effect.provide(layerIdentityRefresh(workspaceRoot, RepositoryIdentityResolver.layer)),
350
+ );
351
+ }).pipe(
352
+ Effect.scoped,
353
+ Effect.provide(ProcessRunner.layer.pipe(Layer.provideMerge(NodeServices.layer))),
354
+ ),
355
+);
356
+
357
+it.effect("returns from the post-turn refresh while the identity resolver is still running", () => {
358
+ const workspaceRoot = "/repo-stubbed-identity";
359
+ const identity: RepositoryIdentity = {
360
+ canonicalKey: "example.test/stubbed-identity",
361
+ locator: {
362
+ source: "git-remote",
363
+ remoteName: "origin",
364
+ remoteUrl: "https://example.test/stubbed-identity.git",
365
+ },
366
+ };
367
+ const releaseResolver = Deferred.makeUnsafe<void>();
368
+ let remoteAdded = false;
369
+ const resolver = Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
370
+ resolve: (_cwd, options) =>
371
+ options?.refresh
372
+ ? Deferred.await(releaseResolver).pipe(
373
+ Effect.map(() => {
374
+ remoteAdded = true;
375
+ return identity;
376
+ }),
377
+ )
378
+ : Effect.sync(() => (remoteAdded ? identity : null)),
379
+ });
380
+ return Effect.gen(function* () {
381
+ const enrichment = yield* ProjectEnrichment.ProjectEnrichmentService;
382
+ assert.isNull(yield* enrichment.readRepositoryIdentity(workspaceRoot));
383
+ const changes = yield* enrichment.subscribeChanges;
384
+ const observer = yield* RunFinalization.RunFinalizationObserver;
385
+ const refresh = yield* observer
386
+ .refresh({ cwd: workspaceRoot, threadId: identityThreadId, runId: identityRunId })
387
+ .pipe(Effect.timeoutOption("1 minute"), Effect.forkChild({ startImmediately: true }));
388
+ yield* TestClock.adjust("1 minute");
389
+ assert.isTrue(
390
+ Option.isSome(yield* Fiber.join(refresh)),
391
+ "turn finalization waited on the identity resolver, blocking the thread's next turn",
392
+ );
393
+
394
+ yield* Deferred.succeed(releaseResolver, undefined);
395
+ const change = yield* PubSub.take(changes);
396
+ assert.strictEqual(change.enrichment.repositoryIdentity?.canonicalKey, identity.canonicalKey);
397
+ }).pipe(Effect.scoped, Effect.provide(layerIdentityRefresh(workspaceRoot, resolver)));
398
+});
apps/server/src/orchestration-v2/RunFinalizationService.ts
+35
-2
@@ -3,8 +3,11 @@ import * as Context from "effect/Context";
3
import * as Effect from "effect/Effect";
4
import * as FiberMap from "effect/FiberMap";
5
import * as Layer from "effect/Layer";
6
+import * as Option from "effect/Option";
7
import * as Schema from "effect/Schema";
8
9
+import * as ProjectEnrichment from "../project/ProjectEnrichmentService.ts";
10
+import * as ProjectService from "../project/ProjectService.ts";
11
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
12
import * as VcsStatusBroadcaster from "../vcs/VcsStatusBroadcaster.ts";
13
import * as WorkspaceEntries from "../workspace/WorkspaceEntries.ts";
@@ -97,7 +100,32 @@ export const layerObserver = Layer.effect(
100
const vcsStatus = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
101
const projections = yield* ProjectionStore.ProjectionStoreV2;
102
const pullRequests = yield* PullRequestService.PullRequestService;
103
+ const projects = yield* ProjectService.ProjectService;
104
+ const enrichment = yield* ProjectEnrichment.ProjectEnrichmentService;
105
const pullRequestLookups = yield* FiberMap.make<string>();
106
+ const identityRefreshes = yield* FiberMap.make<ProjectId>();
107
+ // A turn can add the first remote (`git remote add`, `gh repo create --push`), which the
108
+ // enrichment and resolver caches would otherwise keep reporting as missing for a minute.
109
+ const refreshMissingRepositoryIdentity = Effect.fn(
110
+ "RunFinalizationService.refreshMissingRepositoryIdentity",
111
+ )(
112
+ function* (projectId: ProjectId) {
113
+ const project = yield* projects.getById(projectId);
114
+ if (Option.isNone(project)) return;
115
+ const { workspaceRoot } = project.value;
116
+ if ((yield* enrichment.readRepositoryIdentity(workspaceRoot)) !== null) return;
117
+ yield* enrichment.refreshRepositoryIdentity(workspaceRoot);
118
+ },
119
+ (effect, projectId) =>
120
+ effect.pipe(
121
+ Effect.catch((error) =>
122
+ Effect.logWarning("failed to refresh repository identity after run completion", {
123
+ projectId,
124
+ detail: error.message,
125
+ }),
126
+ ),
127
+ ),
128
+ );
129
return {
130
refreshAfterTurn: pullRequests.refreshAfterTurn,
131
refresh: Effect.fn("RunFinalizationService.refresh")(
@@ -106,9 +134,14 @@ export const layerObserver = Layer.effect(
134
[workspaceEntries.refresh(cwd), vcsStatus.refreshLocalStatus(cwd)],
135
{ concurrency: "unbounded" },
136
);
109
- if (local.refName === null || local.isDefaultRef) return;
137
const thread = yield* projections.getThreadShell(threadId);
111
- if (!thread || thread.branch !== local.refName) return;
138
+ if (!thread) return;
139
+ // Forge discovery probes can take seconds; like the PR lookup, the next turn must not wait.
140
+ yield* refreshMissingRepositoryIdentity(thread.projectId).pipe(
141
+ FiberMap.run(identityRefreshes, thread.projectId),
142
+ );
143
+ if (local.refName === null || local.isDefaultRef) return;
144
+ if (thread.branch !== local.refName) return;
145
if (thread.activeRunId !== null && thread.activeRunId !== runId) return;
146
// The forge CLI can take minutes, so the next turn must not wait for it. A newer
147
// turn's lookup replaces a running one instead of queueing behind the cwd's lock.
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+1
@@ -999,6 +999,7 @@ const layerSharedApplicationDataPlaneTest = Layer.mergeAll(
999
repositoryIdentityResolved: false,
1000
}),
1001
invalidate: () => Effect.void,
1002
+ refreshRepositoryIdentity: () => Effect.void,
1003
subscribeChanges: Effect.never,
1004
}),
1005
),
apps/server/src/project/ProjectEnrichmentService.ts
+14
@@ -51,6 +51,8 @@ export class ProjectEnrichmentService extends Context.Service<
51
workspaceRoot: string,
52
) => Effect.Effect<RepositoryIdentity | null>;
53
readonly invalidate: (workspaceRoots: Iterable<string>) => Effect.Effect<void>;
54
+ /** Re-resolves past both identity caches and publishes a found identity, leaving the favicon alone. */
55
+ readonly refreshRepositoryIdentity: (workspaceRoot: string) => Effect.Effect<void>;
56
readonly subscribeChanges: Effect.Effect<
57
PubSub.Subscription<ProjectEnrichmentChange>,
58
never,
@@ -340,12 +342,24 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* (
342
);
343
});
344
345
+ const refreshRepositoryIdentity: ProjectEnrichmentService["Service"]["refreshRepositoryIdentity"] =
346
+ Effect.fn("ProjectEnrichmentService.refreshRepositoryIdentity")(function* (workspaceRoot) {
347
+ // Remote-less folders hit this after every turn; publishing their unchanged null would
348
+ // push a shell frame to every subscriber.
349
+ if ((yield* repositoryIdentityResolver.resolve(workspaceRoot, { refresh: true })) === null) {
350
+ return;
351
+ }
352
+ yield* Cache.invalidate(repositoryIdentityCache, workspaceRoot);
353
+ yield* resolveRepositoryIdentity(workspaceRoot);
354
+ });
355
+
356
return ProjectEnrichmentService.of({
357
peek,
358
request,
359
getAvailable,
360
readRepositoryIdentity,
361
invalidate,
362
+ refreshRepositoryIdentity,
363
subscribeChanges: PubSub.subscribe(changes),
364
});
365
});