mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
fix(server): preserve timely ACP listing errors during cleanup
A provider error returned within the listing window can still be displayed while its probe shuts down.
This commit is contained in:
@@ -2905,7 +2905,11 @@ describe("ACPAgentClient import listing deadlines", () => {
|
||||
type ListingPhase = "spawn" | "initialize" | "session/list";
|
||||
const phases: ListingPhase[] = ["initialize", "session/list"];
|
||||
|
||||
function createBlockedListing(phase: ListingPhase, terminator = new FakeTerminator()) {
|
||||
function createBlockedListing(
|
||||
phase: ListingPhase,
|
||||
terminator = new FakeTerminator(),
|
||||
listingError?: RequestError,
|
||||
) {
|
||||
const child = createProbeChildStub();
|
||||
const clientToAgent = new PassThrough();
|
||||
const agentToClient = new PassThrough();
|
||||
@@ -2939,6 +2943,7 @@ describe("ACPAgentClient import listing deadlines", () => {
|
||||
markStarted();
|
||||
await blocked;
|
||||
}
|
||||
if (listingError) throw listingError;
|
||||
return { sessions: [] };
|
||||
},
|
||||
async newSession() {
|
||||
@@ -3026,32 +3031,44 @@ describe("ACPAgentClient import listing deadlines", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("returns a timely listing while its probe is still shutting down", async () => {
|
||||
vi.useFakeTimers();
|
||||
const terminator = new FakeTerminator("deferred");
|
||||
const probe = createBlockedListing("session/list", terminator);
|
||||
const listing = listSessionsThroughManager(probe.client);
|
||||
test.each([
|
||||
{ outcome: "success", listingError: undefined, providerErrors: [] },
|
||||
{
|
||||
outcome: "provider error",
|
||||
listingError: new RequestError(-32001, "Provider rejected listing"),
|
||||
providerErrors: [
|
||||
{ provider: "test-acp", message: expect.stringContaining("Provider rejected listing") },
|
||||
],
|
||||
},
|
||||
])(
|
||||
"returns a timely $outcome while its probe is still shutting down",
|
||||
async ({ listingError, providerErrors }) => {
|
||||
vi.useFakeTimers();
|
||||
const terminator = new FakeTerminator("deferred");
|
||||
const probe = createBlockedListing("session/list", terminator, listingError);
|
||||
const listing = listSessionsThroughManager(probe.client);
|
||||
|
||||
try {
|
||||
await probe.started;
|
||||
await vi.advanceTimersByTimeAsync(88_000);
|
||||
probe.release();
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
try {
|
||||
await probe.started;
|
||||
await vi.advanceTimersByTimeAsync(88_000);
|
||||
probe.release();
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
|
||||
expect(terminator.terminated.map((child) => child.pid)).toEqual([probe.child.pid]);
|
||||
expect(probe.child.stdout.destroyed).toBe(false);
|
||||
await expect(listing).resolves.toEqual({ sessions: [], providerErrors: [] });
|
||||
terminator.releaseAll();
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
expect(probe.child.stdout.destroyed).toBe(true);
|
||||
} finally {
|
||||
probe.release();
|
||||
terminator.releaseAll();
|
||||
await listing;
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
expect(terminator.terminated.map((child) => child.pid)).toEqual([probe.child.pid]);
|
||||
expect(probe.child.stdout.destroyed).toBe(false);
|
||||
await expect(listing).resolves.toEqual({ sessions: [], providerErrors });
|
||||
terminator.releaseAll();
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
expect(probe.child.stdout.destroyed).toBe(true);
|
||||
} finally {
|
||||
probe.release();
|
||||
terminator.releaseAll();
|
||||
await listing;
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
vi.useRealTimers();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test.each(phases)("cleans up when import listing stalls in %s", async (phase) => {
|
||||
vi.useFakeTimers();
|
||||
|
||||
@@ -1363,22 +1363,21 @@ export class ACPAgentClient implements AgentClient {
|
||||
signal,
|
||||
client: this.buildProbeClient((params) => history.accept(params)),
|
||||
});
|
||||
let sessions: ImportableProviderSession[];
|
||||
try {
|
||||
sessions = await this.listImportableSessionsFromProbe(probe, history, options, signal);
|
||||
} catch (error) {
|
||||
await this.closeProbe(probe);
|
||||
throw error;
|
||||
return await this.listImportableSessionsFromProbe(probe, history, options, signal);
|
||||
} finally {
|
||||
if (signal.aborted) {
|
||||
await this.closeProbe(probe);
|
||||
} else {
|
||||
// Deliver the provider's result while its probe finishes shutting down.
|
||||
void this.closeProbe(probe).catch((error) => {
|
||||
this.logger.warn(
|
||||
{ err: error, provider: this.provider },
|
||||
"Failed to close ACP listing probe",
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// A completed listing is ready even while its probe is shutting down.
|
||||
void this.closeProbe(probe).catch((error) => {
|
||||
this.logger.warn(
|
||||
{ err: error, provider: this.provider },
|
||||
"Failed to close ACP listing probe",
|
||||
);
|
||||
});
|
||||
return sessions;
|
||||
}
|
||||
|
||||
private async listImportableSessionsFromProbe(
|
||||
|
||||
Reference in New Issue
Block a user