fix(active-memory): anchor dreaming-narrative key guard to canonical key shapes

This commit is contained in:
xialonglee
2026-06-20 07:48:28 +08:00
committed by Vincent Koc
parent 9ac1b5cd5a
commit 3d222677ce
2 changed files with 29 additions and 3 deletions
+19
View File
@@ -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-<phase>-<hash> 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: [] },
+10 -3
View File
@@ -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-<phase>-<hash>" or
// "agent:<agentId>:dreaming-narrative-<phase>-<hash>".
// 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) {