Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/tools/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 8 additions & 20 deletions test/regression/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,18 @@ async function retryWithDelay<T>(
delayMs = 100,
shouldRetry?: (result: T) => boolean,
): Promise<T> {
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 () => {
Expand Down Expand Up @@ -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}`);
Expand Down