@devries-cameron20 / t3code-1 / commits / 4b697be849
Fork 0

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

fix(web): keep deleted ACP sessions out of pending listings (#39331)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 19, 2026 at 21:39 UTC 4b697be8491ea615d198d06c67513f9dfa29b2a3
3 files changed +186 -1
apps/web/src/components/settings/AcpSessionManagementSection.browser.test.tsx
+33
@@ -186,6 +186,39 @@ it("rechecks task access after confirming deletion", async () => {
186 expect(commands.delete).not.toHaveBeenCalled();
187 });
188
189 +it("keeps a deleted ACP session out of a pending page only", async () => {
190 + setup();
191 + commands.list.mockResolvedValueOnce({
192 + _tag: "Success",
193 + value: { sessions: [session], nextCursor: "page-2" },
194 + });
195 + let finishPage!: (value: unknown) => void;
196 + commands.list.mockReturnValueOnce(
197 + new Promise((resolve) => {
198 + finishPage = resolve;
199 + }),
200 + );
201 + const otherSession = { ...session, sessionId: `${session.sessionId}0` };
202 + await using screen = await renderSection();
203 + const deletedRow = screen.getByText(session.sessionId, { exact: true });
204 + await screen.click("List sessions");
205 + await screen.click("Load more");
206 + await screen.click("Delete");
207 + await expect.element(deletedRow).not.toBeInTheDocument();
208 +
209 + await act(async () =>
210 + finishPage({
211 + _tag: "Success",
212 + value: { sessions: [session, otherSession], nextCursor: null },
213 + }),
214 + );
215 + await expect.element(screen.getByText(otherSession.sessionId, { exact: true })).toBeVisible();
216 + await expect.element(deletedRow).not.toBeInTheDocument();
217 +
218 + await screen.click("Refresh");
219 + await expect.element(deletedRow).toBeVisible();
220 +});
221 +
222 it.each(["Save", "Disable"])("keeps other provider edits through a %s refetch", async (action) => {
223 setup();
224 const providers: AcpRegistryConfigurableProvider[] = ["google", "other"].map((providerId) => ({
apps/web/src/components/settings/AcpSessionManagementSection.tsx
+11 -1
@@ -120,10 +120,12 @@ function InstanceSessionManagement(
120 const canRead = useEnvironmentScope(props.environmentId, AuthOrchestrationReadScope);
121 const { projectId } = props;
122 const projectGeneration = useRef(0);
123 + const deletionsDuringList = useRef<Set<string> | null>(null);
124 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Late continuations must not act on a replaced project scope.
125 useLayoutEffect(() => {
126 return () => {
127 projectGeneration.current += 1;
128 + deletionsDuringList.current = null;
129 };
130 // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Retiring a project invalidates its pending operations even when the instance stays mounted.
131 }, [projectId]);
@@ -191,6 +193,8 @@ function InstanceSessionManagement(
193 const loadSessions = async (cursor?: string) => {
194 const generation = projectGeneration.current;
195 if (projectId === null || loading) return;
196 + const deletedSessionIds = new Set<string>();
197 + deletionsDuringList.current = deletedSessionIds;
198 setLoading(true);
199 const result = await listSessions({
200 environmentId: props.environmentId,
@@ -201,10 +205,15 @@ function InstanceSessionManagement(
205 },
206 });
207 if (generation !== projectGeneration.current) return;
208 + deletionsDuringList.current = null;
209 setLoading(false);
210 if (result._tag === "Success") {
211 + // A pending list can return a snapshot taken before a deletion completed.
212 + const listedSessions = result.value.sessions.filter(
213 + (session) => !deletedSessionIds.has(session.sessionId),
214 + );
215 setSessions((current) =>
207 - cursor === undefined ? result.value.sessions : [...current, ...result.value.sessions],
216 + cursor === undefined ? listedSessions : [...current, ...listedSessions],
217 );
218 setNextCursor(result.value.nextCursor);
219 return;
@@ -276,6 +285,7 @@ function InstanceSessionManagement(
285 if (generation !== projectGeneration.current) return;
286 setDeletingSessionId(null);
287 if (result._tag === "Success") {
288 + deletionsDuringList.current?.add(session.sessionId);
289 setSessions((current) =>
290 current.filter((candidate) => candidate.sessionId !== session.sessionId),
291 );
scripts/scenarios/acp-refresh-keeps-deleted-session-removed.e2e.ts new
+142
@@ -0,0 +1,142 @@
1 +// @effect-diagnostics nodeBuiltinImport:off -- The scenario supplies a local ACP agent with a gated list.
2 +import * as NodeHttp from "node:http";
3 +import * as NodePath from "node:path";
4 +
5 +import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
6 +import { expect } from "e2e";
7 +import * as Effect from "effect/Effect";
8 +
9 +import { T3_HOME } from "../e2e.config.ts";
10 +import { rpcClient, runPromise, test, WEB } from "./t3.ts";
11 +
12 +const SESSION_TITLE = "Native draft to delete";
13 +const ACP = `
14 +import { createInterface } from "node:readline";
15 +
16 +const [origin] = process.argv.slice(2);
17 +const reply = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n");
18 +const handle = async ({ method, params }) => {
19 + if (method === "initialize") {
20 + return {
21 + protocolVersion: 1,
22 + agentInfo: { name: "session-scenario", version: "1.0.0" },
23 + agentCapabilities: { sessionCapabilities: { list: {}, delete: {} } },
24 + authMethods: [],
25 + };
26 + }
27 + if (method === "session/new") return { sessionId: "health-probe" };
28 + if (method === "session/list") {
29 + const response = await fetch(origin + "/list");
30 + const { present, title } = await response.json();
31 + return { sessions: present ? [{ sessionId: "native-draft", cwd: params.cwd, title }] : [] };
32 + }
33 + if (method === "session/delete") {
34 + if (params.sessionId === "native-draft") await fetch(origin + "/delete");
35 + return {};
36 + }
37 + return undefined;
38 +};
39 +// A gated session/list must not block the session/delete that arrives while it waits.
40 +createInterface({ input: process.stdin }).on("line", (line) => {
41 + const request = JSON.parse(line);
42 + if (request.id === undefined) return;
43 + void handle(request).then((result) =>
44 + reply(
45 + result === undefined
46 + ? { id: request.id, error: { code: -32601, message: "Method not found" } }
47 + : { id: request.id, result },
48 + ),
49 + );
50 +});
51 +`;
52 +
53 +test(
54 + "Refreshing native ACP sessions does not bring back a session deleted during the refresh",
55 + WEB,
56 + async ({ t3, app, screen }) => {
57 + const instanceId = ProviderInstanceId.make("scenario-session-agent");
58 + const snapshotTaken = Promise.withResolvers<void>();
59 + const releaseSnapshot = Promise.withResolvers<void>();
60 + let present = true;
61 + let holdNextList = false;
62 + const state = NodeHttp.createServer((request, response) => {
63 + if (request.url === "/list") {
64 + const snapshot = JSON.stringify({ present, title: SESSION_TITLE });
65 + const reply = () =>
66 + response.writeHead(200, { "Content-Type": "application/json" }).end(snapshot);
67 + if (holdNextList) {
68 + holdNextList = false;
69 + snapshotTaken.resolve();
70 + void releaseSnapshot.promise.then(reply);
71 + } else {
72 + reply();
73 + }
74 + } else if (request.url === "/delete") {
75 + present = false;
76 + response.writeHead(204).end();
77 + } else {
78 + response.writeHead(404).end();
79 + }
80 + });
81 +
82 + try {
83 + await new Promise<void>((resolve) => state.listen(0, "127.0.0.1", resolve));
84 + const address = state.address();
85 + if (address === null || typeof address === "string") throw new Error("No fixture port");
86 + const project = await t3.project("demo", { "session-agent.mjs": ACP });
87 + await runPromise(
88 + Effect.gen(function* () {
89 + const client = yield* rpcClient(T3_HOME, app.baseUrl ?? "");
90 + yield* client["server.updateSettings"]({
91 + patch: {},
92 + providerInstanceMutation: {
93 + operation: "upsert",
94 + instanceId,
95 + instance: {
96 + driver: ProviderDriverKind.make("acpRegistry"),
97 + displayName: "Session scenario agent",
98 + enabled: true,
99 + config: {
100 + source: "local",
101 + commandPath: process.execPath,
102 + commandArgs: [
103 + NodePath.join(project, "session-agent.mjs"),
104 + `http://127.0.0.1:${address.port}`,
105 + ],
106 + },
107 + },
108 + },
109 + });
110 + }).pipe(Effect.scoped),
111 + );
112 + await t3.open(`/settings/providers?instanceId=${instanceId}`);
113 + await screen.getByRole("button", "List sessions", { exact: true }).tap({ timeout: 60_000 });
114 + const entry = screen.getByText(SESSION_TITLE, { exact: true });
115 + await entry.waitFor();
116 +
117 + holdNextList = true;
118 + await screen.getByRole("button", "Refresh", { exact: true }).tap();
119 + await snapshotTaken.promise;
120 + const remove = screen.getByRole("button", "Delete", { exact: true });
121 + const loading = screen.getByRole("button", "Loading", { exact: true });
122 + if (!(await remove.isVisible()) || !(await remove.isEnabled())) {
123 + releaseSnapshot.resolve();
124 + await loading.waitFor({ state: "hidden" });
125 + }
126 + await remove.tap();
127 + const confirm = screen.getByRole("alertdialog");
128 + await confirm.getByRole("button", "Confirm", { exact: true }).tap();
129 + await entry.waitFor({ state: "hidden" });
130 + expect(await loading.isVisible(), "The refresh is still pending after deletion").toBe(true);
131 +
132 + releaseSnapshot.resolve();
133 + await loading.waitFor({ state: "hidden" });
134 + await app.screenshot("after-deletion-and-refresh");
135 + expect(await entry.isVisible(), "The deleted native session stays off the list").toBe(false);
136 + } finally {
137 + releaseSnapshot.resolve();
138 + state.close();
139 + state.closeAllConnections();
140 + }
141 + },
142 +);