fix: serialize session lifecycle transitions

This commit is contained in:
User
2026-07-15 01:37:42 +02:00
parent 08b1f4909e
commit 6747f6f8a0
10 changed files with 1402 additions and 101 deletions
+11 -4
View File
@@ -174,9 +174,16 @@ export class PiProcessManager {
teardown(id: string): void {
const rt = this.runtimes.get(id);
if (rt) {
rt.child.kill();
this.runtimes.delete(id);
}
if (rt) this.teardownIfCurrent(id, rt);
}
/** Remove only the runtime identity the caller observed. */
teardownIfCurrent(id: string, expected: SessionRuntime): boolean {
if (this.runtimes.get(id) !== expected) return false;
// Delete before signalling the child so its asynchronous exit cannot be mistaken for a
// crash, and so a replacement installed by a later lifecycle operation is never targeted.
this.runtimes.delete(id);
expected.child.kill();
return true;
}
}