fix: release finalized Pi runtimes

This commit is contained in:
2026-07-21 15:39:34 +02:00
parent 4c9424f1e3
commit 019f6b282e
2 changed files with 56 additions and 7 deletions
+15 -7
View File
@@ -111,13 +111,21 @@ export function sessionRoutes(
}
}
d.hub.publish(id, e.type, e);
if (
e.type === "system_event"
&& e.event === "agent_end"
&& d.mgr.get(id) !== rt
&& boundRuntimes.get(id) === rt
) {
boundRuntimes.delete(id);
if (e.type === "system_event" && e.event === "agent_end") {
if (d.mgr.get(id) !== rt && boundRuntimes.get(id) === rt) {
boundRuntimes.delete(id);
} else if (typeof runner.sessionShow === "function") {
void withSessionLifecycle(id, async () => {
if (d.mgr.get(id) !== rt || boundRuntimes.get(id) !== rt) return;
const manifest = await runner.sessionShow(id, workspace);
if (manifest?.status !== "finalized") return;
if (d.mgr.teardownIfCurrent(id, rt) && boundRuntimes.get(id) === rt) {
boundRuntimes.delete(id);
}
}).catch((error: unknown) => {
console.error(`[session:${id}] terminal runtime cleanup failed:`, error);
});
}
}
});
} catch (error) {