From 691b9faa62f07a8d4c183369b57b600377a6111f Mon Sep 17 00:00:00 2001 From: siddseethepalli Date: Tue, 24 Feb 2026 22:36:20 +0000 Subject: [PATCH] fix: clean up settled surface mutex entries to prevent memory leak Co-Authored-By: Claude --- assistant/src/daemon/session-surfaces.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/assistant/src/daemon/session-surfaces.ts b/assistant/src/daemon/session-surfaces.ts index 69adbf85749..262cbb5ed13 100644 --- a/assistant/src/daemon/session-surfaces.ts +++ b/assistant/src/daemon/session-surfaces.ts @@ -140,7 +140,14 @@ export function createSurfaceMutex(): (surfaceId: string, fn: () => T | Promi const prev = chains.get(surfaceId) ?? Promise.resolve(); const next = prev.then(fn, fn); // Keep the chain alive but swallow errors so one failure doesn't block subsequent ops - chains.set(surfaceId, next.then(() => {}, () => {})); + const tail = next.then(() => {}, () => {}); + chains.set(surfaceId, tail); + // Clean up the map entry once the queue settles to prevent unbounded growth + tail.then(() => { + if (chains.get(surfaceId) === tail) { + chains.delete(surfaceId); + } + }); return next; }; }