Skip to content

fix(slack): use replace offset for duplicate mentions, invalidate cache on user_change#233

Closed
matchai wants to merge 3 commits intofeat/state-remove-from-listfrom
fix/slack-mention-offset-and-user-change
Closed

fix(slack): use replace offset for duplicate mentions, invalidate cache on user_change#233
matchai wants to merge 3 commits intofeat/state-remove-from-listfrom
fix/slack-mention-offset-and-user-change

Conversation

@matchai
Copy link
Member

@matchai matchai commented Mar 13, 2026

Fixes three issues found during review of #230. Stacks on #234.

Duplicate mention bug

resolveOutgoingMentions used text.indexOf(match) inside the .replace() callback, which always returns the index of the first occurrence. When the same @name appears multiple times, subsequent matches get their < prefix check evaluated against the wrong position. Uses the offset parameter that .replace() already provides.

Stale user cache on name changes

The user cache (slack:user:{userId}) has an 8-day TTL. When a Slack user changes their display name, the cache serves stale data until expiry — incoming messages show the old name and the reverse index never learns the new name.

Subscribes to Slack's user_change event and:

  1. Reads the old cached display name
  2. Removes the user ID from the old name's reverse index (via removeFromList from feat(state): add removeFromList to StateAdapter #234)
  3. Deletes the user cache entry

The next lookupUser call hits the Slack API and picks up the new profile. Requires adding user_change to bot_events in the Slack app manifest (users:read scope is already present).

Test comment

Fixed misleading "fire-and-forget" comment — the code actually awaits participant tracking.

@vercel
Copy link
Contributor

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 5:21am
chat-sdk-nextjs-chat Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 5:21am

@matchai matchai marked this pull request as draft March 13, 2026 04:58
@matchai matchai force-pushed the fix/slack-mention-offset-and-user-change branch from 618a5a0 to fa14617 Compare March 13, 2026 05:10
@matchai matchai changed the base branch from slack-at-mentions-from-markdown to feat/state-remove-from-list March 13, 2026 05:10
@matchai matchai marked this pull request as ready for review March 13, 2026 05:13
@matchai matchai changed the title Fix duplicate mention resolution and invalidate cache on user_change fix(slack): use replace offset for duplicate mentions, invalidate cache on user_change Mar 13, 2026
@matchai
Copy link
Member Author

matchai commented Mar 13, 2026

Superseded by combined PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant