fix: guard terminal handler tracking cleanup

This commit is contained in:
Eva
2026-05-01 20:51:09 +07:00
committed by Josh Lehman
parent e45121f3c5
commit f9da78ba4b
2 changed files with 5 additions and 2 deletions

View File

@@ -489,7 +489,7 @@ describe("plugin run context lifecycle", () => {
});
await vi.advanceTimersByTimeAsync(0);
expect(cleanup).toHaveBeenCalledTimes(1);
await vi.advanceTimersByTimeAsync(5_000);
await vi.advanceTimersByTimeAsync(PLUGIN_HOST_CLEANUP_TIMEOUT_MS);
await expect(resultPromise).resolves.toMatchObject({
failures: [
{

View File

@@ -98,7 +98,10 @@ function trackAgentEventHandler(runId: string, pending: Promise<void>): void {
state.pendingAgentEventHandlersByRunId.set(runId, handlers);
void pending.finally(() => {
handlers.delete(pending);
if (handlers.size === 0) {
if (
handlers.size === 0 &&
getPluginHostRuntimeState().pendingAgentEventHandlersByRunId.get(runId) === handlers
) {
state.pendingAgentEventHandlersByRunId.delete(runId);
}
});