Skip to content

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

Merged
cramforce merged 2 commits intoslack-at-mentions-from-markdownfrom
fix/slack-mention-review-fixes
Mar 13, 2026
Merged

fix(slack): use replace offset for duplicate mentions, invalidate cache on user_change#236
cramforce merged 2 commits intoslack-at-mentions-from-markdownfrom
fix/slack-mention-review-fixes

Conversation

@matchai
Copy link
Member

@matchai matchai commented Mar 13, 2026

Fixes issues found during review of #230.

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, every match gets its < prefix check evaluated against the first occurrence's 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 doesn't learn the new name.

Subscribes to Slack's user_change event and deletes the cached entry so the next lookupUser call hits the API and picks up the new profile. The stale reverse index entry is left to expire naturally via TTL — it's harmless since <@USER_ID> renders as the user's current display name in Slack regardless.

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:49am
chat-sdk-nextjs-chat Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 5:49am

@cramforce cramforce merged commit 792229a into slack-at-mentions-from-markdown Mar 13, 2026
4 checks passed
@cramforce cramforce deleted the fix/slack-mention-review-fixes branch March 13, 2026 12:47
cramforce added a commit that referenced this pull request Mar 13, 2026
…messages (#230)

* feat(slack): resolve @DisplayName mentions to <@USER_ID> in outgoing messages

Build a reverse index from display name → user IDs during lookupUser(),
track thread participants on incoming messages, and resolve @name mentions
to Slack's <@USER_ID> format before sending. Disambiguates using thread
participants when multiple users share a display name. Also increases
user/channel cache TTLs to 8 days.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

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

* Revert "fix(slack): use replace offset for duplicate mentions, invalidate cache on user_change"

This reverts commit 8cb0d90.

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

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

* style: align handleUserChange to async/await, expand changeset

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Matan Kushner <hello@matchai.dev>
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.

2 participants