fix: use cached raw user message as auto-recall query#579
Merged
rwmjhb merged 1 commit intoCortexReach:masterfrom Apr 11, 2026
Merged
fix: use cached raw user message as auto-recall query#579rwmjhb merged 1 commit intoCortexReach:masterfrom
rwmjhb merged 1 commit intoCortexReach:masterfrom
Conversation
…l metadata noise 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
recallQueryusesevent.promptdirectly, which on Slack includes Conversation info JSON metadata (message_id, sender_id, conversation_label, etc.) prepended by the platform adapterlastRawUserMessage.get(cacheKey) || event.prompt— the same pattern already applied togatingText(line 2245) — so the retrieval query uses clean user text instead of the noisy assembled promptContext
The
gatingTextvariable (used for short-message skip and greeting detection) was already correctly patched to preferlastRawUserMessage. However, the actualrecallQuerypassed toretrieveWithRetry()was missed, so retrieval itself was still affected.The
lastRawUserMessageMap is populated in themessage_receivedhook (line 2211–2219), which strips bot mentions and caches clean user text keyed bychannelId. Thebefore_prompt_buildhook shares the samecacheKeyderivation, so the cached value is always available when needed.Reproduction
event.promptinbefore_prompt_buildcontainsConversation info: {"message_id":"...","sender_id":"...","conversation_label":"..."}prefixTest plan
event.prompt)gatingTextandrecallQuerynow use the same source for consistency🤖 Generated with Claude Code