Skip to content

Commit 9dbc3ee

Browse files
committed
🤖 fix: make temp directory cleanup non-blocking for faster stream interruption
When interrupting a stream (especially on SSH), the UI was delayed by 500ms-2s waiting for the temp directory cleanup to complete. The cleanup involved an SSH 'rm -rf' command that blocked the processingPromise resolution, which delayed the stream-abort event emission. This change makes temp directory cleanup fire-and-forget, so the stream-abort event is emitted immediately after the stream breaks out of the processing loop, providing instant UI feedback. The cleanup is still guaranteed to happen (via void promise), but it no longer blocks the critical path for UI responsiveness. _Generated with `cmux`_
1 parent 71e965c commit 9dbc3ee

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

‎src/services/streamManager.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -978,19 +978,22 @@ export class StreamManager extends EventEmitter {
978978
streamInfo.partialWriteTimer = undefined;
979979
}
980980

981-
// Clean up stream temp directory using runtime
981+
// Clean up stream temp directory using runtime (fire-and-forget)
982+
// Don't block stream completion waiting for directory deletion
983+
// This is especially important for SSH where rm -rf can take 500ms-2s
982984
if (streamInfo.runtimeTempDir) {
983-
try {
984-
const result = await streamInfo.runtime.exec(`rm -rf "${streamInfo.runtimeTempDir}"`, {
985+
void streamInfo.runtime
986+
.exec(`rm -rf "${streamInfo.runtimeTempDir}"`, {
985987
cwd: "~",
986988
timeout: 10,
989+
})
990+
.then(async (result) => {
991+
await result.exitCode;
992+
log.debug(`Cleaned up temp dir: ${streamInfo.runtimeTempDir}`);
993+
})
994+
.catch((error) => {
995+
log.error(`Failed to cleanup temp dir ${streamInfo.runtimeTempDir}:`, error);
987996
});
988-
await result.exitCode; // Wait for completion
989-
log.debug(`Cleaned up temp dir: ${streamInfo.runtimeTempDir}`);
990-
} catch (error) {
991-
log.error(`Failed to cleanup temp dir ${streamInfo.runtimeTempDir}:`, error);
992-
// Don't throw - cleanup is best-effort
993-
}
994997
}
995998

996999
this.workspaceStreams.delete(workspaceId);

0 commit comments

Comments
 (0)