mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-25 01:35:31 +00:00
fix(server): keep the full Import Session deadline
Start ACP probe cleanup when the agent manager stops waiting. Keep the 90-second window for listings that still have time to finish. Co-authored-by: Chirag Singhal <76880977+chirag127@users.noreply.github.com>
This commit is contained in:
co-authored by
Chirag Singhal
parent
0d0aa27584
commit
b8516bb2c1
@@ -317,7 +317,7 @@ interface HydrateTimelineOptions {
|
||||
broadcastTimeline?: boolean;
|
||||
}
|
||||
|
||||
export type ImportablePersistedAgentQueryOptions = ListImportableSessionsOptions & {
|
||||
export type ImportablePersistedAgentQueryOptions = Omit<ListImportableSessionsOptions, "signal"> & {
|
||||
/**
|
||||
* When set, only providers in this set are scanned, in addition to the
|
||||
* built-in importable allowlist + enabled + non-derived rules.
|
||||
@@ -1296,9 +1296,11 @@ export class AgentManager {
|
||||
);
|
||||
const providerResults = await Promise.all(
|
||||
providerEntries.map(async ([provider, client]) => {
|
||||
const cancellation = new AbortController();
|
||||
try {
|
||||
const sessions = await withTimeout(
|
||||
client.listImportableSessions!({
|
||||
signal: cancellation.signal,
|
||||
limit: options?.limit,
|
||||
query: options?.query,
|
||||
scanLimit: options?.scanLimit,
|
||||
@@ -1314,6 +1316,7 @@ export class AgentManager {
|
||||
error: null,
|
||||
};
|
||||
} catch (error) {
|
||||
cancellation.abort(error);
|
||||
this.logger.warn(
|
||||
{ err: error, provider },
|
||||
"Failed to list importable sessions for provider",
|
||||
|
||||
@@ -586,6 +586,8 @@ export interface AgentSlashCommand {
|
||||
}
|
||||
|
||||
export interface ListImportableSessionsOptions {
|
||||
/** Aborts provider work when the caller stops waiting for a listing. */
|
||||
signal?: AbortSignal;
|
||||
providerOptions?: ProviderOptions;
|
||||
limit?: number;
|
||||
/** Optional case-insensitive descriptor search text. */
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
summarizeACPRequestError,
|
||||
} from "./acp-agent.js";
|
||||
import { createIdleRuntimeCleanup } from "../idle-runtime-cleanup/index.js";
|
||||
import { AgentManager } from "../agent-manager.js";
|
||||
import type { ProcessTerminator, TreeKillTarget } from "../../../utils/tree-kill.js";
|
||||
import {
|
||||
COPILOT_AGENT_FEATURE_OPTION,
|
||||
@@ -2999,22 +3000,52 @@ describe("ACPAgentClient import listing deadlines", () => {
|
||||
return { client, child, agentConnection, terminator, started, release, operations };
|
||||
}
|
||||
|
||||
function listSessionsThroughManager(client: ACPAgentClient) {
|
||||
return new AgentManager({
|
||||
clients: { [client.provider]: client },
|
||||
logger: createTestLogger(),
|
||||
}).listImportableSessions({ limit: 1 });
|
||||
}
|
||||
|
||||
test("accepts a listing that finishes within the daemon's provider deadline", async () => {
|
||||
vi.useFakeTimers();
|
||||
const probe = createBlockedListing("session/list");
|
||||
const listing = listSessionsThroughManager(probe.client);
|
||||
|
||||
try {
|
||||
await probe.started;
|
||||
await vi.advanceTimersByTimeAsync(88_000);
|
||||
probe.release();
|
||||
|
||||
await expect(listing).resolves.toEqual({ sessions: [], providerErrors: [] });
|
||||
expect(probe.terminator.terminated).toEqual([probe.child]);
|
||||
} finally {
|
||||
probe.release();
|
||||
await listing;
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
test.each(phases)("cleans up when import listing stalls in %s", async (phase) => {
|
||||
vi.useFakeTimers();
|
||||
const probe = createBlockedListing(phase);
|
||||
const errors: unknown[] = [];
|
||||
const listing = probe.client.listImportableSessions({ limit: 1 }).catch((error: unknown) => {
|
||||
errors.push(error);
|
||||
return [];
|
||||
});
|
||||
const listing = listSessionsThroughManager(probe.client);
|
||||
|
||||
try {
|
||||
await probe.started;
|
||||
await vi.advanceTimersByTimeAsync(89_999);
|
||||
expect(probe.terminator.terminated).toEqual([]);
|
||||
|
||||
expect(errors).toEqual([
|
||||
expect.objectContaining({ message: expect.stringMatching(/timed out/i) }),
|
||||
]);
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
await expect(listing).resolves.toEqual({
|
||||
sessions: [],
|
||||
providerErrors: [
|
||||
{
|
||||
provider: "test-acp",
|
||||
message: "Timed out listing importable sessions for provider 'test-acp' after 90000ms",
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(probe.terminator.terminated).toEqual([probe.child]);
|
||||
expect(probe.child.stdin.destroyed).toBe(true);
|
||||
expect(probe.child.stdout.destroyed).toBe(true);
|
||||
|
||||
@@ -343,8 +343,6 @@ const ACP_CLOSE_REQUEST_TIMEOUT_MS = 2_000;
|
||||
const ACP_DISCONNECT_EXIT_GRACE_MS = 1_000;
|
||||
const ACP_IMPORT_HISTORY_LOAD_TIMEOUT_MS = 30_000;
|
||||
const ACP_IMPORT_HISTORY_BUDGET_MS = 60_000;
|
||||
// Reserve time for process-tree cleanup before the manager's 90s listing deadline.
|
||||
const ACP_IMPORT_LIST_TIMEOUT_MS = 85_000;
|
||||
|
||||
/**
|
||||
* An ACP agent publishes its slash-command inventory incrementally. Wait this
|
||||
@@ -1356,20 +1354,10 @@ export class ACPAgentClient implements AgentClient {
|
||||
}
|
||||
|
||||
async listImportableSessions(
|
||||
options?: ListImportableSessionsOptions & { signal?: AbortSignal },
|
||||
options?: ListImportableSessionsOptions,
|
||||
): Promise<ImportableProviderSession[]> {
|
||||
const history = new ACPImportHistoryCollector();
|
||||
const deadline = new AbortController();
|
||||
const timeout = setTimeout(
|
||||
() =>
|
||||
deadline.abort(
|
||||
new Error(`ACP import listing timed out after ${ACP_IMPORT_LIST_TIMEOUT_MS}ms`),
|
||||
),
|
||||
ACP_IMPORT_LIST_TIMEOUT_MS,
|
||||
);
|
||||
const signal = options?.signal
|
||||
? AbortSignal.any([deadline.signal, options.signal])
|
||||
: deadline.signal;
|
||||
const signal = options?.signal ?? new AbortController().signal;
|
||||
let probe: SpawnedACPProcess | undefined;
|
||||
try {
|
||||
signal.throwIfAborted();
|
||||
@@ -1419,7 +1407,6 @@ export class ACPAgentClient implements AgentClient {
|
||||
signal.throwIfAborted();
|
||||
return sessions;
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
if (probe) await this.closeProbe(probe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1827,7 +1827,7 @@ export class ClaudeAgentClient implements AgentClient {
|
||||
}
|
||||
|
||||
async listImportableSessions(
|
||||
options?: ListImportableSessionsOptions & { signal?: AbortSignal },
|
||||
options?: ListImportableSessionsOptions,
|
||||
): Promise<ImportableProviderSession[]> {
|
||||
// Leave time to deliver the provider error before the client RPC expires at 60 seconds.
|
||||
const deadline = AbortSignal.timeout(45_000);
|
||||
|
||||
Reference in New Issue
Block a user