Compare commits

..
7 changed files with 12 additions and 284 deletions
@@ -291,7 +291,6 @@ async function listSessions(
input: Extract<ProviderInput, { type: "sessions" }>,
state: AcpConnectionState,
): Promise<void> {
const extraScanDeadline = performance.now() + EXTRA_SESSION_SCAN_BUDGET_MS;
const runtime = await AcpRuntime.start({
options: state.options,
launch: state.launch,
@@ -300,11 +299,7 @@ async function listSessions(
emit: state.emit,
});
try {
const selected = await runtime.listSessions({
cwd: input.cwd,
limit: input.limit,
extraScanDeadline,
});
const selected = await runtime.listSessions({ cwd: input.cwd, limit: input.limit });
state.emit({
type: "sessions",
requestId: input.requestId,
@@ -320,10 +315,6 @@ async function listSessions(
}
}
function sessionUpdatedAt(session: SessionInfo): number {
return Date.parse(session.updatedAt ?? "") || 0;
}
function retireSession(state: AcpConnectionState, sessionId: string): void {
if (state.sessions.delete(sessionId)) {
state.emit({ type: "session.closed", sessionId });
@@ -420,7 +411,6 @@ interface ActivePrompt {
const DEFAULT_DEFERRED_SETTLE_DELAY_MS = 500;
const SESSION_SCAN_LIMIT = 500;
const EXTRA_SESSION_SCAN_BUDGET_MS = 2_000;
// COMPAT(acpAutoAccept): added in v0.17.4, remove after 2027-05-23. The generic ACP adapter saves
// its Auto Accept toggle as this setting on agents that later moved to a bundled ACP provider.
const LEGACY_AUTO_ACCEPT_SETTING = "auto_accept";
@@ -928,38 +918,17 @@ class AcpRuntime {
return true;
}
/** Selects the most recent sessions from a bounded scan of the provider's pages. */
async listSessions({
cwd,
limit,
extraScanDeadline,
}: {
cwd?: string;
limit?: number;
extraScanDeadline: number;
}): Promise<SessionInfo[]> {
/** Follows `nextCursor` until `limit` sessions, the last page, or the scan cap. */
async listSessions({ cwd, limit }: { cwd?: string; limit?: number }): Promise<SessionInfo[]> {
const wanted = Math.min(limit ?? SESSION_SCAN_LIMIT, SESSION_SCAN_LIMIT);
const sessions: SessionInfo[] = [];
let cursor: string | undefined;
// ACP does not guarantee that sessions arrive in recency order.
for (let pages = 0; pages < SESSION_SCAN_LIMIT; pages += 1) {
// Once we have enough rows, pages can improve the order only within the original budget.
const remainingMs =
cursor && sessions.length >= wanted ? extraScanDeadline - performance.now() : undefined;
if (remainingMs !== undefined && remainingMs <= 0) break;
const request = this.call(this.connection.listSessions({ cwd, cursor }));
const page =
remainingMs === undefined
? await request
: await withTimeout(request, remainingMs, "ACP listing scan budget expired").catch(
() => undefined,
);
if (!page) break;
sessions.push(...page.sessions.slice(0, SESSION_SCAN_LIMIT - sessions.length));
do {
const page = await this.call(this.connection.listSessions({ cwd, cursor }));
sessions.push(...page.sessions);
cursor = page.nextCursor ?? undefined;
if (!cursor || sessions.length === SESSION_SCAN_LIMIT) break;
}
return sessions.sort((a, b) => sessionUpdatedAt(b) - sessionUpdatedAt(a)).slice(0, wanted);
} while (cursor && sessions.length < wanted);
return sessions.slice(0, wanted);
}
async drainNotifications(): Promise<void> {
-36
View File
@@ -7038,42 +7038,6 @@ describe("ACP tool call rows", () => {
}
});
it("returns enough sessions and closes the connection when another page stalls", async () => {
const harness = connectorHarness({
capabilities: { sessionCapabilities: { list: {} } },
handleRequest(runtime, request) {
if (request.method !== "session/list") return false;
const { cursor } = request.params as { cursor?: string };
if (!cursor) {
runtime.respond(request, {
sessions: [{ sessionId: "s1", cwd: "/repo", title: "First page" }],
nextCursor: "stalled",
});
}
return true;
},
});
const connection = await runAcpProvider({
id: "stalled-listing",
label: "Stalled listing",
connector: harness.connector,
}).connect({ versions: [1], capabilities: ["prompt.message", "session.list"] });
const events: ProviderEvent[] = [];
connection.onEvent((event) => events.push(event));
try {
await connection.send({ type: "sessions", requestId: "list", limit: 1 });
await expect.poll(() => countRequests(harness.instances[1], "session/list")).toBe(2);
const listed = await waitForEvent(events, (event) => event.type === "sessions");
expect(listed).toMatchObject({ sessions: [{ title: "First page" }] });
await expect.poll(() => harness.instances[1].readsCanceled).toBe(true);
expect(harness.instances[1].writesClosed).toBe(true);
} finally {
const listing = harness.instances[1];
if (listing && !listing.readsCanceled) listing.closeFromAgent();
await connection.close();
}
});
it("resumes the generic ACP adapter's saved Auto Accept toggle in the unattended mode", async () => {
const harness = connectorHarness({
configOptions: [
@@ -1,68 +0,0 @@
// An ACP peer that returns sessions in storage order, with an optional page boundary.
const readline = require("node:readline");
const { existsSync, renameSync, writeFileSync } = require("node:fs");
const path = require("node:path");
const stalledListing = process.argv.indexOf("--stall-after-first-page");
const controlDir = stalledListing === -1 ? null : process.argv[stalledListing + 1];
if (process.argv.includes("--version")) {
process.stdout.write("1.5.13\n");
process.exit(0);
}
const sessions = Array.from({ length: 317 }, (_, index) => ({
sessionId: `session-${index}`,
cwd: process.cwd(),
title: `September session ${index}`,
updatedAt: "2026-09-08T11:36:19Z",
}));
sessions[42] = {
...sessions[42],
title: "Latest November session",
updatedAt: "2026-11-23T04:07:46Z",
};
readline.createInterface({ input: process.stdin }).on("line", (line) => {
const { id, method, params } = JSON.parse(line);
if (id === undefined) return;
let response;
if (method === "initialize") {
response = {
result: { protocolVersion: 1, agentCapabilities: { sessionCapabilities: { list: {} } } },
};
} else if (method === "session/list") {
if (controlDir) {
if (params.cursor) {
writeFileSync(path.join(controlDir, "second-page"), "");
return;
}
const marker = path.join(controlDir, "first-page");
writeFileSync(marker + ".tmp", String(process.pid));
renameSync(marker + ".tmp", marker);
const gate = setInterval(() => {
if (!existsSync(path.join(controlDir, "release-first-page"))) return;
clearInterval(gate);
process.stdout.write(
JSON.stringify({
jsonrpc: "2.0",
id,
result: { sessions: sessions.slice(0, 42), nextCursor: "next" },
}) + "\n",
);
}, 10);
return;
}
const pageSize = process.argv.includes("--paginated") ? 42 : sessions.length;
response = {
result: params.cursor
? { sessions: sessions.slice(pageSize) }
: {
sessions: sessions.slice(0, pageSize),
nextCursor: pageSize < sessions.length ? "next" : null,
},
};
} else {
response = { error: { code: -32601, message: `Unsupported method ${method}` } };
}
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, ...response }) + "\n");
});
@@ -314,8 +314,6 @@ test("streams whole-file batches and answers a same-socket ping before the revis
).join("\n") + "\n";
writeFileSync(join(cwd, `${file}.ts`), content);
}
// Stage the fixture so Git reads the added files in bulk. They are still new relative to HEAD.
git(cwd, "add", ".");
expect(ctx.client.getLastServerInfoMessage()).toMatchObject({
features: { diffSubscription: true },
});
@@ -1,7 +1,5 @@
import { describe, test, expect, vi } from "vitest";
import { describe, test, expect } from "vitest";
import { mkdtemp, rm, readFile, writeFile } from "node:fs/promises";
import { existsSync } from "node:fs";
import { setTimeout as delay } from "node:timers/promises";
import os from "node:os";
import path from "node:path";
import { loadConfig } from "../config.js";
@@ -167,122 +165,6 @@ test("Antigravity creates an agent and answers a prompt with real agy", async ({
}
}, 120000);
test.each(["one page", "two pages"])(
"Antigravity lists the latest importable sessions from %s in storage order",
async (pages) => {
const command = [
process.execPath,
path.resolve(import.meta.dirname, "antigravity-session-list-fixture.cjs"),
];
if (pages === "two pages") command.push("--paginated");
const daemon = await createTestPaseoDaemon({
agentClients: {},
mcpEnabled: false,
builtinPlugins: new BuiltinPluginLoader(undefined, ["antigravity-provider"]),
providerOverrides: { antigravity: { command, paseoTools: { enabled: false } } },
});
const client = new DaemonClient({
url: `ws://127.0.0.1:${daemon.port}/ws`,
appVersion: "0.17.3",
});
const providers = ["antigravity"];
try {
await client.connect();
await client.refreshProvidersSnapshot({ cwd: daemon.paseoHome, providers });
const search = await client.fetchRecentProviderSessions({
providers,
limit: 5,
query: "November",
});
expect(search.entries.map((session) => session.title)).toEqual(["Latest November session"]);
const wide = await client.fetchRecentProviderSessions({ providers, limit: 100 });
expect(wide.entries[0]?.title).toBe("Latest November session");
const recent = await client.fetchRecentProviderSessions({ providers });
expect(recent.entries).toHaveLength(20);
expect(recent.entries[0]?.title).toBe("Latest November session");
} finally {
await client.close();
await daemon.close();
}
},
30_000,
);
test("Antigravity returns a late full page before Import Session times out", async () => {
const controlDir = await mkdtemp(path.join(os.tmpdir(), "paseo-antigravity-listing-"));
const command = [
process.execPath,
path.resolve(import.meta.dirname, "antigravity-session-list-fixture.cjs"),
"--stall-after-first-page",
controlDir,
];
const daemon = await createTestPaseoDaemon({
agentClients: {},
mcpEnabled: false,
builtinPlugins: new BuiltinPluginLoader(undefined, ["antigravity-provider"]),
providerOverrides: { antigravity: { command, paseoTools: { enabled: false } } },
});
const client = new DaemonClient({
url: `ws://127.0.0.1:${daemon.port}/ws`,
appVersion: "0.17.3",
});
const providers = ["antigravity"];
try {
await client.connect();
await client.refreshProvidersSnapshot({ cwd: daemon.paseoHome, providers });
vi.useFakeTimers({ toFake: ["performance", "setTimeout", "clearTimeout"] });
const result = client.fetchRecentProviderSessions({ providers });
let returned = false;
const markReturned = () => {
returned = true;
};
void result.then(markReturned, markReturned);
const firstPage = path.join(controlDir, "first-page");
await waitForFixture(() => existsSync(firstPage), "first page requested");
const pid = Number(await readFile(firstPage, "utf8"));
await vi.advanceTimersByTimeAsync(59_000);
await writeFile(path.join(controlDir, "release-first-page"), "");
// Let real I/O deliver the page before advancing to the client deadline.
// The provider signals a second request but never answers it.
const secondPage = path.join(controlDir, "second-page");
await waitForFixture(() => returned || existsSync(secondPage), "result or second page request");
await vi.advanceTimersByTimeAsync(1_000);
const recent = await result;
expect(recent.entries.map((session) => session.title)).toEqual(
Array.from({ length: 20 }, (_, index) => `September session ${index}`),
);
await waitForFixture(() => {
try {
process.kill(pid, 0);
return false;
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ESRCH") return true;
throw error;
}
}, "listing process exited");
} finally {
if (vi.isFakeTimers()) {
await vi.advanceTimersByTimeAsync(2_000);
vi.useRealTimers();
}
await client.close();
await daemon.close();
await rm(controlDir, { recursive: true, force: true });
}
});
async function waitForFixture(condition: () => boolean, description: string): Promise<void> {
// Use real timers for subprocess I/O while the RPC clock is paused.
const deadline = Date.now() + 10_000;
while (!condition()) {
if (Date.now() >= deadline) throw new Error(`Timed out waiting for ${description}`);
await delay(10);
}
}
test("bundled fx requires a config entry and lists models instead of its providers", async () => {
const root = await mkdtemp(path.join(os.tmpdir(), "paseo-fx-optin-"));
const record = path.join(root, "launches.txt");
@@ -194,14 +194,12 @@ test("classifies a removed file as deleted", async () => {
const root = await createRoot();
const target = join(root, "removed.txt");
await writeFile(target, "before");
const canary = createWatcherLivenessCanary(root);
const events: FileChange[] = [];
const subscription = await subscribeToFileChanges(root, (error, batch) => {
expect(error).toBeNull();
events.push(...canary.filterEvents(batch));
events.push(...batch);
});
await canary.verify();
await rm(target);
// macOS FSEvents can replay the write above as a create after the subscription starts,
// so the delete is the latest event for the path, not the first. Native recursive delivery
+2 -17
View File
@@ -177,7 +177,7 @@ test("filters by search and clears to all plugins", async ({ page }) => {
test("keeps the directory's ranking window when searching", async ({ page }) => {
await page.goto("/plugins?window=month");
await submitSearch(page, "graphite");
await expectDirectorySearch(page, "graphite", "month");
await expect(page).toHaveURL(/\/plugins\/all\?q=graphite&window=month$/);
await expect(page.getByRole("link", { name: "This month" })).toHaveAttribute(
"aria-current",
"true",
@@ -358,16 +358,10 @@ test.describe("search engine visits without JavaScript", () => {
});
test("renders search results and submits the search form", async ({ page }) => {
await page.goto("/plugins?window=month");
await submitSearch(page, "graphite");
await expectDirectorySearch(page, "graphite", "month");
await page.goto("/plugins/all?q=graphite");
await expect(
page.getByRole("heading", { level: 1, name: /^Results for “graphite”/ }),
).toBeVisible();
await expect(page.getByRole("link", { name: "This month" })).toHaveAttribute(
"aria-current",
"true",
);
await expect(page.getByRole("main").getByRole("link", { name: /Graphite/ })).toBeVisible();
await expect(page.getByRole("link", { name: /Dracula/ })).toHaveCount(0);
@@ -465,15 +459,6 @@ async function submitSearch(page: Page, term: string) {
await page.keyboard.press("Enter");
}
async function expectDirectorySearch(page: Page, term: string, window: string) {
await expect(page).toHaveURL(
(url) =>
url.pathname === "/plugins/all" &&
url.searchParams.get("q") === term &&
url.searchParams.get("window") === window,
);
}
async function typeSearch(page: Page, term: string) {
await page.getByRole("searchbox", { name: "Search plugins" }).pressSequentially(term);
}