From f1d3ce6d4ba3c966aaf718dd0c47564191ffdab8 Mon Sep 17 00:00:00 2001 From: Junebugg1214 <82672745+Junebugg1214@users.noreply.github.com> Date: Fri, 13 Mar 2026 13:08:24 -0400 Subject: [PATCH] fix: queue targeted memory sync requests --- src/memory/manager.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/memory/manager.ts b/src/memory/manager.ts index 60db6b5d57a..e32e8f66c27 100644 --- a/src/memory/manager.ts +++ b/src/memory/manager.ts @@ -122,6 +122,12 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem >(); private sessionWarm = new Set(); private syncing: Promise | null = null; + private queuedSyncParams: { + reason?: string; + force?: boolean; + sessionFiles?: string[]; + progress?: (update: MemorySyncProgressUpdate) => void; + } | null = null; private readonlyRecoveryAttempts = 0; private readonlyRecoverySuccesses = 0; private readonlyRecoveryFailures = 0; @@ -456,10 +462,33 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem return; } if (this.syncing) { + const queued = this.queuedSyncParams; + this.queuedSyncParams = { + reason: params?.reason ?? queued?.reason, + force: params?.force || queued?.force, + sessionFiles: Array.from( + new Set([ + ...(queued?.sessionFiles ?? []), + ...(params?.sessionFiles?.filter((sessionFile) => sessionFile.trim().length > 0) ?? []), + ]), + ), + progress: params?.progress ?? queued?.progress, + }; return this.syncing; } - this.syncing = this.runSyncWithReadonlyRecovery(params).finally(() => { + this.syncing = (async () => { + let nextParams = params; + while (!this.closed) { + this.queuedSyncParams = null; + await this.runSyncWithReadonlyRecovery(nextParams); + if (!this.queuedSyncParams) { + break; + } + nextParams = this.queuedSyncParams; + } + })().finally(() => { this.syncing = null; + this.queuedSyncParams = null; }); return this.syncing ?? Promise.resolve(); }