diff --git a/src/tools/memory.ts b/src/tools/memory.ts index a93ffb4..ca0c527 100644 --- a/src/tools/memory.ts +++ b/src/tools/memory.ts @@ -118,7 +118,10 @@ export function createMemoryTools(state: ToolRuntimeState) { if (results.length === 0) return "No relevant memory found."; for (const result of results) { - state.store.updateMemoryUsage(result.record.id, activeScope, scopes).catch(() => {}); + try { + await state.store.updateMemoryUsage(result.record.id, activeScope, scopes); + } catch { + } } return results diff --git a/test/regression/plugin.test.ts b/test/regression/plugin.test.ts index 4f7d37c..d7a02ce 100644 --- a/test/regression/plugin.test.ts +++ b/test/regression/plugin.test.ts @@ -247,23 +247,18 @@ async function retryWithDelay( delayMs = 100, shouldRetry?: (result: T) => boolean, ): Promise { - let lastError: unknown; + let lastResult: T | undefined; for (let attempt = 0; attempt < maxAttempts; attempt++) { if (attempt > 0) { await new Promise((resolve) => setTimeout(resolve, delayMs * attempt)); } - try { - const result = await fn(); - if (!shouldRetry || !shouldRetry(result)) { - return result; - } - lastError = new Error(`Attempt ${attempt + 1} returned result that needs retry`); - } catch (e) { - lastError = e; - if (attempt === maxAttempts - 1) throw e; + const result = await fn(); + lastResult = result; + if (!shouldRetry || !shouldRetry(result)) { + return result; } } - throw lastError; + return lastResult as T; } test("auto-capture stores qualifying output with decision category and skips short output", async () => { @@ -463,15 +458,8 @@ test("memory_delete and memory_clear reject destructive operations without confi try { await harness.capture("Resolved successfully after rotating the stale token and reloading the API gateway config."); - // Use retryWithDelay to handle async write delay - search might not find immediately after capture - const searchOutput = await retryWithDelay( - () => - withPatchedFetch(() => - harness.toolHooks.memory_search.execute({ query: "stale token API gateway", limit: 5 }, harness.context), - ), - 3, - 100, - (result) => result === "No relevant memory found." || !result.match(/\[([^\]]+)\]/), + const searchOutput = await withPatchedFetch(() => + harness.toolHooks.memory_search.execute({ query: "stale token API gateway", limit: 5 }, harness.context), ); const recordId = searchOutput.match(/\[([^\]]+)\]/)?.[1]; assert.ok(recordId, `Expected recordId in searchOutput, got: ${searchOutput}`);