From f379d25b31bdb02c02d0165a74948783bc9eeba6 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 15 May 2026 04:44:24 +0100 Subject: [PATCH 1/2] fix: prevent memory pollution and API waste on automated runs --- hooks/capture.ts | 5 ++++- hooks/recall.ts | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hooks/capture.ts b/hooks/capture.ts index ea6d63f..8e5b7d7 100644 --- a/hooks/capture.ts +++ b/hooks/capture.ts @@ -34,7 +34,10 @@ export function buildCaptureHandler( `agent_end fired: provider="${ctx.messageProvider}" success=${event.success}`, ) const provider = ctx.messageProvider as string - if (SKIPPED_PROVIDERS.includes(provider)) { + const trigger = ctx.trigger as string | undefined + const isAutomatedRun = trigger && trigger !== "user" && trigger !== "manual" + + if (isAutomatedRun || SKIPPED_PROVIDERS.includes(provider)) { return } diff --git a/hooks/recall.ts b/hooks/recall.ts index d6d80c8..b9628ea 100644 --- a/hooks/recall.ts +++ b/hooks/recall.ts @@ -179,6 +179,11 @@ export function buildRecallHandler( event: Record, ctx?: Record, ) => { + const trigger = ctx?.trigger as string | undefined + if (trigger && trigger !== "user" && trigger !== "manual") { + return + } + const rawPrompt = event.prompt as string | undefined if (!rawPrompt || rawPrompt.length < 5) return From 5f67c42af9be671baca8588e5643675a6e49daf3 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 20 May 2026 21:42:29 +0100 Subject: [PATCH 2/2] fix: centralize automated run trigger guard --- hooks/capture.ts | 10 +++++++--- hooks/recall.ts | 3 ++- hooks/trigger.ts | 10 ++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 hooks/trigger.ts diff --git a/hooks/capture.ts b/hooks/capture.ts index 8e5b7d7..7db96a8 100644 --- a/hooks/capture.ts +++ b/hooks/capture.ts @@ -2,6 +2,7 @@ import type { SupermemoryClient } from "../client.ts" import type { SupermemoryConfig } from "../config.ts" import { log } from "../logger.ts" import { buildDocumentId, stripInboundMetadata } from "../memory.ts" +import { isInteractiveTrigger } from "./trigger.ts" const SKIPPED_PROVIDERS = ["exec-event", "cron-event", "heartbeat"] @@ -30,14 +31,17 @@ export function buildCaptureHandler( event: Record, ctx: Record, ) => { + const trigger = ctx.trigger as string | undefined + if (!isInteractiveTrigger(trigger)) { + return + } + log.info( `agent_end fired: provider="${ctx.messageProvider}" success=${event.success}`, ) const provider = ctx.messageProvider as string - const trigger = ctx.trigger as string | undefined - const isAutomatedRun = trigger && trigger !== "user" && trigger !== "manual" - if (isAutomatedRun || SKIPPED_PROVIDERS.includes(provider)) { + if (SKIPPED_PROVIDERS.includes(provider)) { return } diff --git a/hooks/recall.ts b/hooks/recall.ts index b9628ea..2a16fae 100644 --- a/hooks/recall.ts +++ b/hooks/recall.ts @@ -2,6 +2,7 @@ import type { ProfileSearchResult, SupermemoryClient } from "../client.ts" import type { SupermemoryConfig } from "../config.ts" import { log } from "../logger.ts" import { stripInboundMetadata } from "../memory.ts" +import { isInteractiveTrigger } from "./trigger.ts" function formatRelativeTime(isoTimestamp: string): string { try { @@ -180,7 +181,7 @@ export function buildRecallHandler( ctx?: Record, ) => { const trigger = ctx?.trigger as string | undefined - if (trigger && trigger !== "user" && trigger !== "manual") { + if (!isInteractiveTrigger(trigger)) { return } diff --git a/hooks/trigger.ts b/hooks/trigger.ts new file mode 100644 index 0000000..19e726e --- /dev/null +++ b/hooks/trigger.ts @@ -0,0 +1,10 @@ +const INTERACTIVE_TRIGGERS = new Set(["user", "manual"]) + +export function isInteractiveTrigger(trigger: string | undefined): boolean { + // Keep this allowlist in sync with OpenClaw's agent trigger values. + // "user" and "manual" are interactive; automated triggers such as + // "heartbeat", "cron", "memory", and "overflow" should skip memory hooks. + // Undefined preserves legacy behavior for OpenClaw versions that do not + // provide ctx.trigger yet. + return !trigger || INTERACTIVE_TRIGGERS.has(trigger) +}