From 3d222677ce1158ccefddb2fd4a0848b0bee08d0b Mon Sep 17 00:00:00 2001 From: xialonglee Date: Sat, 20 Jun 2026 07:48:28 +0800 Subject: [PATCH] fix(active-memory): anchor dreaming-narrative key guard to canonical key shapes --- extensions/active-memory/index.test.ts | 19 +++++++++++++++++++ extensions/active-memory/index.ts | 13 ++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/extensions/active-memory/index.test.ts b/extensions/active-memory/index.test.ts index 7dde8c557a41..7ce61dc3c5f6 100644 --- a/extensions/active-memory/index.test.ts +++ b/extensions/active-memory/index.test.ts @@ -878,6 +878,25 @@ describe("active-memory plugin", () => { expect(result).not.toBeUndefined(); }); + it("allows real webchat session keys whose peer id starts with a phased dreaming-narrative prefix", async () => { + const result = await hooks.before_prompt_build( + { prompt: "what wings should i order?", messages: [] }, + { + agentId: "main", + trigger: "user", + sessionKey: "agent:main:webchat:dreaming-narrative-light-room", + messageProvider: "webchat", + }, + ); + + // A real webchat session key whose peer id begins with a phased dreaming-narrative + // phrase must not be excluded. Only the canonical bare or agent-prefixed key + // shape (dreaming-narrative-- directly after agentId or bare) should + // be rejected — not the same phrase appearing deeper in the key as a peer id. + expect(runEmbeddedAgent).toHaveBeenCalledTimes(1); + expect(result).not.toBeUndefined(); + }); + it("defaults to direct-style sessions only", async () => { const result = await hooks.before_prompt_build( { prompt: "what wings should we order?", messages: [] }, diff --git a/extensions/active-memory/index.ts b/extensions/active-memory/index.ts index ec2bdb8d703b..2911cc03e359 100644 --- a/extensions/active-memory/index.ts +++ b/extensions/active-memory/index.ts @@ -1156,9 +1156,16 @@ function isEligibleInteractiveSession(ctx: { return false; } // Exclude only canonical dreaming-narrative session keys (bare or agent-prefixed). - // Broad substring match would also exclude real chat session ids that happen to - // contain the phrase (e.g. telegram:group:dreaming-narrative-room). - if (/(?:^|:)dreaming-narrative-(?:light|rem|deep)-/i.test(ctx.sessionKey ?? "")) { + // Canonical forms: "dreaming-narrative--" or + // "agent::dreaming-narrative--". + // A colon-delimited match would also exclude real chat session ids whose peer id + // begins with a phased dreaming-narrative phrase (e.g. + // "agent:main:feishu:group:dreaming-narrative-light-room"). + const sessionKey = ctx.sessionKey ?? ""; + if ( + /^dreaming-narrative-(light|rem|deep)-/i.test(sessionKey) || + /^agent:[^:]+:dreaming-narrative-(light|rem|deep)-/i.test(sessionKey) + ) { return false; } if (!ctx.sessionKey && !ctx.sessionId) {