From 0a3ce2479720d841b277ae700ccd1ddae27483f7 Mon Sep 17 00:00:00 2001 From: cynarAI <155274210+cynarAI@users.noreply.github.com> Date: Tue, 22 Sep 2026 10:57:40 +0200 Subject: [PATCH] fix(api): pass actor identity when purging memory after thread clear (#62) threads/clear called memoryProviders.resolve with a bare spaceId string. The resolver destructures { spaceId, userId }, so both were undefined and purgeHistory was silently skipped after every clear. Co-authored-by: Cursor Agent Co-authored-by: cynarAI --- .../src/memory-provider-router-wiring.test.ts | 16 ++++++++++++---- apps/api/src/router.ts | 7 ++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/api/src/memory-provider-router-wiring.test.ts b/apps/api/src/memory-provider-router-wiring.test.ts index cf738ce..a185097 100644 --- a/apps/api/src/memory-provider-router-wiring.test.ts +++ b/apps/api/src/memory-provider-router-wiring.test.ts @@ -4,12 +4,20 @@ import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; describe("memory provider config router wiring", () => { + const routerSource = readFileSync( + resolve(dirname(fileURLToPath(import.meta.url)), "router.ts"), + "utf8", + ); + it("routes providerConfig through owner-gated getMemoryProviderConfig", () => { - const routerSource = readFileSync( - resolve(dirname(fileURLToPath(import.meta.url)), "router.ts"), - "utf8", - ); expect(routerSource).toContain("getMemoryProviderConfig(deps, context.actor)"); expect(routerSource).not.toMatch(/providerConfig:[\s\S]{0,240}findSpaceMemoryConfig/); }); + + it("passes actor space and user when resolving memory after thread clear", () => { + expect(routerSource).not.toMatch(/memoryProviders\.resolve\(context\.actor\.spaceId\)/); + expect(routerSource).toMatch( + /memoryProviders[\s\S]{0,120}\.resolve\(\{[\s\S]{0,120}spaceId: context\.actor\.spaceId[\s\S]{0,120}userId: context\.actor\.userId/, + ); + }); }); diff --git a/apps/api/src/router.ts b/apps/api/src/router.ts index 0040536..47dec1f 100644 --- a/apps/api/src/router.ts +++ b/apps/api/src/router.ts @@ -1484,7 +1484,12 @@ export function createRouter(deps: RouterDeps) { }); const [configuredMemory] = await Promise.all([ target.kind === "bot" - ? deps.memoryProviders.resolve(context.actor.spaceId).catch((error) => { + ? deps.memoryProviders + .resolve({ + spaceId: context.actor.spaceId, + userId: context.actor.userId, + }) + .catch((error) => { getLogger().error("semantic memory resolution after thread clear failed", error); return null; })