@devries-cameron20 / t3code-1 / commits / f100356710
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(client): retain PR links while reconnect metadata changes (#17365)

Maxwell Young committed Oct 19, 2026 at 08:10 UTC f1003567108e920773c1c568e33f88933cbd4e3a
2 files changed +50 -5
packages/client-runtime/src/state/shellReducer.test.ts
+45
@@ -516,4 +516,49 @@ describe("reuseUnchangedThreadShells", () => {
516 incoming,
517 );
518 });
519 +
520 + it("retains deferred links when the only row changes status", () => {
521 + const { pullRequests: _links, ...withoutLinks } = linked;
522 + const next = reuseUnchangedThreadShells(
523 + { ...v2ShellSnapshot, threads: [linked] },
524 + {
525 + ...v2ShellSnapshot,
526 + snapshotSequence: 5,
527 + threads: [{ ...withoutLinks, status: "running" }],
528 + },
529 + );
530 + expect(next.snapshotSequence).toBe(5);
531 + expect(next.threads[0]?.status).toBe("running");
532 + expect(next.threads[0]?.pullRequests).toBe(linked.pullRequests);
533 + });
534 +
535 + it("retains deferred links on a renamed row alongside an unchanged sibling", () => {
536 + const { pullRequests: _links, ...withoutLinks } = linked;
537 + const next = reuseUnchangedThreadShells(
538 + { ...v2ShellSnapshot, threads: [linked, other] },
539 + { ...v2ShellSnapshot, threads: [{ ...withoutLinks, title: "Renamed" }, { ...other }] },
540 + );
541 + expect(next.threads[0]?.title).toBe("Renamed");
542 + expect(next.threads[0]?.pullRequests).toBe(linked.pullRequests);
543 + expect(next.threads[1]).toBe(other);
544 + });
545 +
546 + it("keeps an explicit link removal when metadata also changes", () => {
547 + const updated = { ...linked, title: "Renamed", pullRequests: [] };
548 + const incoming = { ...v2ShellSnapshot, threads: [updated] };
549 + const next = reuseUnchangedThreadShells({ ...v2ShellSnapshot, threads: [linked] }, incoming);
550 + expect(next).toBe(incoming);
551 + expect(next.threads[0]?.pullRequests).toEqual([]);
552 + });
553 +
554 + it("keeps explicitly refreshed links instead of the previous links", () => {
555 + const updated = {
556 + ...linked,
557 + pullRequests: [{ ...link, number: 4, url: "https://github.com/pingdotgg/t3code/pull/4" }],
558 + };
559 + const incoming = { ...v2ShellSnapshot, threads: [updated] };
560 + const next = reuseUnchangedThreadShells({ ...v2ShellSnapshot, threads: [linked] }, incoming);
561 + expect(next).toBe(incoming);
562 + expect(next.threads[0]?.pullRequests).toBe(updated.pullRequests);
563 + });
564 });
packages/client-runtime/src/state/shellReducer.ts
+5 -5
@@ -31,7 +31,7 @@ export function reuseUnchangedThreadShells(
31 ): OrchestrationV2ShellSnapshot {
32 if (previous === null || previous.threads.length === 0) return next;
33 const previousById = new Map(previous.threads.map((thread) => [thread.id, thread] as const));
34 - let reused = 0;
34 + let changed = false;
35 const threads = next.threads.map((thread) => {
36 const prior = previousById.get(thread.id);
37 if (prior === undefined) return thread;
@@ -39,11 +39,11 @@ export function reuseUnchangedThreadShells(
39 thread.pullRequests === undefined && prior.pullRequests !== undefined
40 ? { ...thread, pullRequests: prior.pullRequests }
41 : thread;
42 - if (!sameThreadShell(prior, candidate)) return thread;
43 - reused += 1;
44 - return prior;
42 + const retained = sameThreadShell(prior, candidate) ? prior : candidate;
43 + if (retained !== thread) changed = true;
44 + return retained;
45 });
46 - return reused === 0 ? next : { ...next, threads };
46 + return changed ? { ...next, threads } : next;
47 }
48
49 function upsertById<T extends { readonly id: unknown }>(