GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): keep deleted ACP sessions out of pending listings (#39331) · AIdoesmyjob/t3code@eba469a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/settings
    • AcpSessionManagementSection.browser.test.tsx
    • AcpSessionManagementSection.tsx
  • scripts/scenarios
    • acp-refresh-keeps-deleted-session-removed.e2e.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/settings/AcpSessionManagementSection.browser.test.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/settings/AcpSessionManagementSection.browser.test.tsx
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,39 @@ it("rechecks task access after confirming deletion", async () => {
186186
expect(commands.delete).not.toHaveBeenCalled();
187187
});
188188

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+
189222
it.each(["Save", "Disable"])("keeps other provider edits through a %s refetch", async (action) => {
190223
setup();
191224
const providers: AcpRegistryConfigurableProvider[] = ["google", "other"].map((providerId) => ({
Collapse file

‎apps/web/src/components/settings/AcpSessionManagementSection.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/settings/AcpSessionManagementSection.tsx
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ function InstanceSessionManagement(
120120
const canRead = useEnvironmentScope(props.environmentId, AuthOrchestrationReadScope);
121121
const { projectId } = props;
122122
const projectGeneration = useRef(0);
123+
const deletionsDuringList = useRef<Set<string> | null>(null);
123124
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Late continuations must not act on a replaced project scope.
124125
useLayoutEffect(() => {
125126
return () => {
126127
projectGeneration.current += 1;
128+
deletionsDuringList.current = null;
127129
};
128130
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Retiring a project invalidates its pending operations even when the instance stays mounted.
129131
}, [projectId]);
@@ -191,6 +193,8 @@ function InstanceSessionManagement(
191193
const loadSessions = async (cursor?: string) => {
192194
const generation = projectGeneration.current;
193195
if (projectId === null || loading) return;
196+
const deletedSessionIds = new Set<string>();
197+
deletionsDuringList.current = deletedSessionIds;
194198
setLoading(true);
195199
const result = await listSessions({
196200
environmentId: props.environmentId,
@@ -201,10 +205,15 @@ function InstanceSessionManagement(
201205
},
202206
});
203207
if (generation !== projectGeneration.current) return;
208+
deletionsDuringList.current = null;
204209
setLoading(false);
205210
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+
);
206215
setSessions((current) =>
207-
cursor === undefined ? result.value.sessions : [...current, ...result.value.sessions],
216+
cursor === undefined ? listedSessions : [...current, ...listedSessions],
208217
);
209218
setNextCursor(result.value.nextCursor);
210219
return;
@@ -276,6 +285,7 @@ function InstanceSessionManagement(
276285
if (generation !== projectGeneration.current) return;
277286
setDeletingSessionId(null);
278287
if (result._tag === "Success") {
288+
deletionsDuringList.current?.add(session.sessionId);
279289
setSessions((current) =>
280290
current.filter((candidate) => candidate.sessionId !== session.sessionId),
281291
);
Collapse file

‎scripts/scenarios/acp-refresh-keeps-deleted-session-removed.e2e.ts‎

Copy file name to clipboard
+142Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.