The best way to control Claude Code, Codex and more from any computer or phone
fix(web): show an error when merge-back or disconnect fails (#23753)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
Victor Vogel committed
Oct 30, 2026 at 15:59 UTC
fd78ea42fcce187fc4622885f2b982823a569121
2 files changed
+152
-3
apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx
new
+126
@@ -0,0 +1,126 @@
1
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
+import * as Cause from "effect/Cause";
3
+import { AsyncResult } from "effect/reactivity";
4
+import { expect, it, vi } from "vite-plus/test";
5
+import { page } from "vite-plus/test/browser";
6
+
7
+const state = vi.hoisted(() => ({ projection: null as unknown, commandSucceeds: false }));
8
+
9
+vi.mock(import("@effect/atom-react"), async (original) => ({
10
+ ...(await original()),
11
+ useAtomValue: (() => false) as never,
12
+}));
13
+
14
+vi.mock(import("../../state/entities"), () => ({
15
+ useQuietThreadShell: (() => null) as never,
16
+ useThreadProjection: ((ref: unknown) =>
17
+ ref === null ? null : { projection: state.projection }) as never,
18
+ useThreadRelationshipShells: (() =>
19
+ state.projection === null ? [] : [(state.projection as { thread: unknown }).thread]) as never,
20
+ useProjects: (() => []) as never,
21
+}));
22
+vi.mock(import("../../state/environments"), () => ({
23
+ useEnvironment: (() => null) as never,
24
+ useEnvironmentProviders: (() => new Map()) as never,
25
+}));
26
+vi.mock(import("../../lib/archivedThreadsState"), () => ({
27
+ useArchivedThreadSnapshots: (() => ({ snapshots: [] })) as never,
28
+}));
29
+vi.mock(import("../../state/use-atom-command"), () => ({
30
+ useAtomCommand: (() => async () =>
31
+ state.commandSucceeds
32
+ ? AsyncResult.success(undefined)
33
+ : AsyncResult.failure(Cause.fail(new Error("Connection lost")))) as never,
34
+}));
35
+
36
+import { render } from "../../../test/render";
37
+import { ToastProvider } from "../ui/toast";
38
+import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
39
+
40
+const environmentId = EnvironmentId.make("environment");
41
+const threadId = ThreadId.make("fork");
42
+
43
+function setup() {
44
+ state.commandSucceeds = false;
45
+ state.projection = {
46
+ thread: {
47
+ id: threadId,
48
+ title: "Fork",
49
+ activeProviderThreadId: null,
50
+ lineage: { parentThreadId: ThreadId.make("source"), relationshipToParent: "fork" },
51
+ forkedFrom: null,
52
+ },
53
+ runs: [{ id: "run", ordinal: 1, status: "completed" }],
54
+ subagents: [],
55
+ contextTransfers: [],
56
+ providerThreads: [],
57
+ providerSessions: [{ id: "session", status: "ready" }],
58
+ };
59
+}
60
+
61
+it.each([
62
+ ["merge", "Could not merge back"],
63
+ ["disconnect", "Could not disconnect agent session"],
64
+])("reports a rejected %s command and clears the busy state", async (action, title) => {
65
+ setup();
66
+ await using screen = await render(
67
+ <ToastProvider timeout={0}>
68
+ <ThreadRelationshipsPanel environmentId={environmentId} threadId={threadId} />
69
+ </ToastProvider>,
70
+ );
71
+
72
+ if (action === "merge") {
73
+ await screen.getByRole("button", { name: "Merge back to source conversation" }).click();
74
+ } else {
75
+ await screen.getByRole("button", { name: "More thread actions" }).click();
76
+ await page.getByRole("menuitem", { name: "Disconnect agent session" }).click();
77
+ }
78
+
79
+ await expect.element(page.getByText(title, { exact: true })).toBeVisible();
80
+ await expect
81
+ .element(
82
+ screen.getByRole("button", {
83
+ name: action === "merge" ? "Merge back to source conversation" : "More thread actions",
84
+ }),
85
+ )
86
+ .toBeEnabled();
87
+});
88
+
89
+it.each([
90
+ ["merge", "Could not merge back"],
91
+ ["disconnect", "Could not disconnect agent session"],
92
+])("clears the previous %s error after a successful retry", async (action, title) => {
93
+ setup();
94
+ await using screen = await render(
95
+ <ToastProvider timeout={0}>
96
+ <ThreadRelationshipsPanel environmentId={environmentId} threadId={threadId} />
97
+ </ToastProvider>,
98
+ { router: "/environment/fork" },
99
+ );
100
+
101
+ const runAction = async () => {
102
+ if (action === "merge") {
103
+ await screen.getByRole("button", { name: "Merge back to source conversation" }).click();
104
+ } else {
105
+ await screen.getByRole("button", { name: "More thread actions" }).click();
106
+ await page.getByRole("menuitem", { name: "Disconnect agent session" }).click();
107
+ }
108
+ };
109
+
110
+ await runAction();
111
+ await expect.element(page.getByText(title, { exact: true })).toBeVisible();
112
+ expect(screen.router?.state.location.pathname).toBe("/environment/fork");
113
+
114
+ state.commandSucceeds = true;
115
+ await runAction();
116
+
117
+ await expect.element(page.getByText(title, { exact: true })).not.toBeInTheDocument();
118
+ await vi.waitFor(() => {
119
+ expect(screen.router?.state.location.pathname).toBe(
120
+ action === "merge" ? "/environment/source" : "/environment/fork",
121
+ );
122
+ });
123
+ if (action === "disconnect") {
124
+ await expect.element(screen.getByRole("button", { name: "More thread actions" })).toBeEnabled();
125
+ }
126
+});
apps/web/src/components/chat/ThreadRelationshipsControl.tsx
+26
-3
@@ -54,7 +54,7 @@ import {
54
SquareIcon,
55
UnplugIcon,
56
} from "lucide-react";
57
-import { useState, type ReactNode } from "react";
57
+import { useRef, useState, type ReactNode } from "react";
58
59
import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
60
import { buildThreadRouteParams } from "../../threadRoutes";
@@ -385,6 +385,8 @@ export function ThreadRelationshipsPanel(props: {
385
orchestrationEnvironment.stopWorkflow.permissionAtom(props.environmentId),
386
);
387
const [busyAction, setBusyAction] = useState<"merge" | "detach" | null>(null);
388
+ const mergeErrorToastId = useRef<string | null>(null);
389
+ const detachErrorToastId = useRef<string | null>(null);
390
const [stoppingId, setStoppingId] = useState<string | null>(null);
391
// Derive graphs after hooks to preserve their compiler cache.
392
const providers = providersByEnvironment.get(props.environmentId);
@@ -492,6 +494,10 @@ export function ThreadRelationshipsPanel(props: {
494
495
const merge = async () => {
496
if (!latestMergeBackRun || mergeTargetThreadId === null || busyAction !== null) return;
497
+ if (mergeErrorToastId.current !== null) {
498
+ toastManager.close(mergeErrorToastId.current);
499
+ mergeErrorToastId.current = null;
500
+ }
501
setBusyAction("merge");
502
const result = await mergeBack({
503
environmentId: props.environmentId,
@@ -502,17 +508,34 @@ export function ThreadRelationshipsPanel(props: {
508
},
509
});
510
setBusyAction(null);
505
- if (result._tag === "Success") openThread(mergeTargetThreadId);
511
+ if (result._tag === "Failure") {
512
+ mergeErrorToastId.current = toastManager.add({
513
+ type: "error",
514
+ title: "Could not merge back",
515
+ });
516
+ return;
517
+ }
518
+ openThread(mergeTargetThreadId);
519
};
520
521
const detach = async () => {
522
if (!canDetach || busyAction !== null) return;
523
+ if (detachErrorToastId.current !== null) {
524
+ toastManager.close(detachErrorToastId.current);
525
+ detachErrorToastId.current = null;
526
+ }
527
setBusyAction("detach");
511
- await stopSession({
528
+ const result = await stopSession({
529
environmentId: props.environmentId,
530
input: { threadId: props.threadId },
531
});
532
setBusyAction(null);
533
+ if (result._tag === "Failure") {
534
+ detachErrorToastId.current = toastManager.add({
535
+ type: "error",
536
+ title: "Could not disconnect agent session",
537
+ });
538
+ }
539
};
540
541
const stopSubagent = async (