Skip to content

Commit 6bd4b57

Browse files
raw34claude
andauthored
fix: use cached raw user message as auto-recall query to avoid channel metadata noise (#579)
On Slack, `event.prompt` in the `before_prompt_build` hook includes Conversation info JSON metadata (message_id, sender_id, conversation_label, etc.) prepended by the platform adapter. This metadata pollutes the embedding vector, causing irrelevant memories to score higher during auto-recall. The `gatingText` variable (used for skip/greeting detection) was already correctly using `lastRawUserMessage.get(cacheKey)` — the clean user text cached during `message_received`. However, the actual `recallQuery` passed to `retrieveWithRetry()` still used `event.prompt` directly, so the retrieval itself was still affected by the noise. This fix applies the same pattern to `recallQuery`: prefer the cached raw user message, falling back to `event.prompt` for non-channel triggers or when no cached message is available. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c035e98 commit 6bd4b57

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,10 +2263,15 @@ const memoryLanceDBProPlugin = {
22632263
const agentId = resolveHookAgentId(ctx?.agentId, (event as any).sessionKey);
22642264
const accessibleScopes = resolveScopeFilter(scopeManager, agentId);
22652265

2266+
// Use cached raw user message for the recall query to avoid channel
2267+
// metadata noise (e.g. Slack's Conversation info JSON with message_id,
2268+
// sender_id, conversation_label) that pollutes the embedding vector and
2269+
// causes irrelevant memories to rank higher. Fall back to event.prompt
2270+
// for non-channel triggers or when no cached message is available.
22662271
// FR-04: Truncate long prompts (e.g. file attachments) before embedding.
22672272
// Auto-recall only needs the user's intent, not full attachment text.
22682273
const MAX_RECALL_QUERY_LENGTH = config.autoRecallMaxQueryLength ?? 2_000;
2269-
let recallQuery = event.prompt;
2274+
let recallQuery = lastRawUserMessage.get(cacheKey) || event.prompt;
22702275
if (recallQuery.length > MAX_RECALL_QUERY_LENGTH) {
22712276
const originalLength = recallQuery.length;
22722277
recallQuery = recallQuery.slice(0, MAX_RECALL_QUERY_LENGTH);

0 commit comments

Comments
 (0)