fix: prevent memory pollution and API waste on automated runs (Resolves #20)#52
fix: prevent memory pollution and API waste on automated runs (Resolves #20)#52franksde wants to merge 2 commits into
Conversation
|
@Dhravya mind taking a look when you have a moment? Happy to adjust if the approach doesn't fit. |
| 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" |
There was a problem hiding this comment.
The log.info fires before this guard (line 33), so automated runs still produce log noise. Move the trigger check above the log.info call.
There was a problem hiding this comment.
Moved the trigger guard above the capture log now, so automated runs return before agent_end fired gets emitted.
| ctx?: Record<string, unknown>, | ||
| ) => { | ||
| const trigger = ctx?.trigger as string | undefined | ||
| if (trigger && trigger !== "user" && trigger !== "manual") { |
There was a problem hiding this comment.
The trigger check is duplicated verbatim in both files. Extract it to a shared helper, e.g. isInteractiveTrigger(trigger: string | undefined): boolean in a utils file, to avoid drift if the allowed values ever change.
There was a problem hiding this comment.
Pulled this into hooks/trigger.ts and reused it from both hooks. That keeps the allowlist in one place if OpenClaw adds or renames trigger values later.
| 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" |
There was a problem hiding this comment.
The allowlist ("user" | "manual") is implicit — if openclaw ever ships a new interactive trigger type (e.g. "api" or "webhook"), it will be silently blocked without any obvious failure. A comment noting where these values come from (openclaw trigger enum) would help future maintainers.
There was a problem hiding this comment.
Added a short note next to the shared helper explaining that user and manual are the interactive OpenClaw triggers, while undefined stays allowed for older OpenClaw versions.
|
@franksde can you pls have a look at the suggestions |
|
Pushed an update for the review suggestions. The trigger check now happens before capture logging, and the interactive trigger allowlist lives in a shared helper with a short note about the OpenClaw trigger values and legacy undefined behavior. |
Summary
Currently, Supermemory executes
recallandcapturehooks on all agent turns, including automated background tasks likeheartbeatandcron. This leads to significant token waste and pollutes the memory database with irrelevant background logs.While there is an existing
SKIPPED_PROVIDERSarray incapture.ts, it is insufficient because automated triggers often lack a distinctmessageProvider.Now that the OpenClaw SDK exposes the
triggerfield in the hook context (merged in openclaw/openclaw#24585), we can accurately identify and skip non-interactive automated runs.Key Changes
ctx.trigger. If the trigger exists and is NOT"user"or"manual", it skips the memory recall process entirely.SKIPPED_PROVIDERScheck.Compatibility
This change is 100% backward compatible. If a user is on an older version of OpenClaw where
ctx.triggerisundefined, the logic safely bypasses the guard and falls back to the legacy behavior.Resolves #20