mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-30 19:59:35 +00:00
fix(active-memory): exclude dreaming-narrative session keys from eligibility gate (#95721)
Merged via squash.
Prepared head SHA: fc8717e8f4
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Reviewed-by: @vincentkoc
This commit is contained in:
@@ -844,6 +844,79 @@ describe("active-memory plugin", () => {
|
||||
expect(runEmbeddedAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not run for dreaming-narrative cron session keys", async () => {
|
||||
const result = await hooks.before_prompt_build(
|
||||
{ prompt: "what wings should i order?", messages: [] },
|
||||
{
|
||||
agentId: "main",
|
||||
trigger: "user",
|
||||
sessionKey: "agent:main:dreaming-narrative-light-abc123",
|
||||
messageProvider: "webchat",
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(runEmbeddedAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not run when a session id resolves to a dreaming-narrative cron session key", async () => {
|
||||
hoisted.sessionStore["agent:main:dreaming-narrative-light-abc123"] = {
|
||||
sessionId: "dreaming-session",
|
||||
updatedAt: 1,
|
||||
};
|
||||
|
||||
const result = await hooks.before_prompt_build(
|
||||
{ prompt: "what wings should i order?", messages: [] },
|
||||
{
|
||||
agentId: "main",
|
||||
trigger: "user",
|
||||
sessionId: "dreaming-session",
|
||||
messageProvider: "webchat",
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(runEmbeddedAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("allows non-canonical session keys that merely contain the dreaming-narrative substring", 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-room",
|
||||
messageProvider: "webchat",
|
||||
},
|
||||
);
|
||||
|
||||
// Real session keys that happen to contain "dreaming-narrative" in a
|
||||
// non-canonical way (not {light|rem|deep} phase suffix) must remain eligible.
|
||||
// The session key "agent:main:webchat:dreaming-narrative-room" is a real chat
|
||||
// whose topic happens to contain the string — not a dreaming cron key.
|
||||
expect(runEmbeddedAgent).toHaveBeenCalledTimes(1);
|
||||
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: [] },
|
||||
|
||||
@@ -1155,6 +1155,19 @@ function isEligibleInteractiveSession(ctx: {
|
||||
if (ctx.trigger !== "user") {
|
||||
return false;
|
||||
}
|
||||
// Exclude only canonical dreaming-narrative session keys (bare or agent-prefixed).
|
||||
// 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) {
|
||||
return false;
|
||||
}
|
||||
@@ -3617,7 +3630,12 @@ export default definePluginEntry({
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
if (!isEligibleInteractiveSession(ctx)) {
|
||||
if (
|
||||
!isEligibleInteractiveSession({
|
||||
...ctx,
|
||||
sessionKey: resolvedSessionKey ?? ctx.sessionKey,
|
||||
})
|
||||
) {
|
||||
await persistPluginStatusLines({
|
||||
api,
|
||||
agentId: effectiveAgentId,
|
||||
|
||||
Reference in New Issue
Block a user