Repository navigation
fix(chat): create community channels on demand from channel search - #1989
Conversation
Bootstrap now auto-joins only a user's first subscribed communities, so other community channels may not exist yet and could not be found from search (the only way to reach them on mobile). Search now also looks the query up on Hive (community id, or title for 3+ characters, top 3) and ensures those communities have a channel, appending any the Mattermost search did not return. Lookup failures never fail the search. Closes #1988
Channel search can now ask Hive and create channels, so the web hook waits 350ms for typing to pause (same as mobile), and the route keeps short per-process caches of Hive matches (60s) and community channel ids (5 min).
Hive helpers turn errors into an empty result, so caching empties could hide communities for a minute after a blip. Channel id cache drops to 60s.
|
ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 2 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoCreate missing community channels from chat search
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1.
|
[Medium impact] The PR appears safe to merge, with a non-blocking edge case that can leave a user's search creation budget stuck.
|
Search now only uses communities that clearly match (exact id, or a title containing the query) and creating a missing channel spends a per-user hourly budget (10, Redis, fails closed). Existing channels are always returned. Drops the channel id cache, logs community channels that could not be provided, and hides the previous term's results while a new search is pending on web.
Set the counter with its expiry before counting, so a Redis failure between calls cannot leave a key that never expires. A budgeted create only follows a clear not-found, so a Mattermost outage cannot spend the budget. The search hook returns only the fields its consumers use, and expected refusals are not logged.
| await redis.set(key, 0, "PX", CHANNEL_CREATE_WINDOW_MS, "NX"); | ||
| const count = await redis.incr(key); | ||
| // The key can expire between the two calls, and INCR then recreates it | ||
| // without a TTL. Re-arm it; a no-op whenever SET already set one. | ||
| // PEXPIRE ... NX needs Redis 7+ (the stacks run redis:7-alpine). | ||
| if (count === 1) await redis.pexpire(key, CHANNEL_CREATE_WINDOW_MS, "NX"); |
There was a problem hiding this comment.
If the old key expires between set and incr, incr recreates it without an expiry. If pexpire then fails, the catch returns false but leaves the key behind. Later calls cannot repair it: set with NX does nothing, and the count is greater than one.
After ten attempts, the user can no longer create channels from search, even after waiting an hour. This is a non-blocking edge case; make the increment and expiry atomic so the budget always resets.
Since #1987, chat bootstrap only auto-joins a user's first 10 subscribed communities, so other community channels may not exist yet. Channel search only returned existing channels, and on mobile search is the only way to reach a community chat.
hive-NNNNNNid directly, or (for 3+ characters) communities whose title contains the query, top 3.ensureChannelForCommunity, real Hive communities only). Creating spends a per-user budget of 10 per hour (Redis, fails closed); finding an existing channel is free, and a budgeted create only follows a clear not-found from Mattermost.No mobile change needed: mobile already lists search results and joins by channel id (it cannot join a not-yet-created channel, which is why creation happens at search time rather than on join).
Known limits, intentionally out of scope:
community) still creates that channel without the budget; that user is joining it.Test plan
mattermost-channel-search-communities.spec.ts: creation and append, title narrowing, id lookup, cap, skip conditions, budget spend/refusal, single caller lookup, failures, caching, non-array passthrough.chat-channel-create-budget.spec.ts: cap per user, fail closed, expiry always set even when Redis fails midway.mattermost-ensure-user.spec.ts:allowCreateonly asked after Hive validation and a clear not-found.channel-search-debounce.spec.tsx: one request per typing pause; stale results hidden until the new term settles.pnpm test src/specs/api/ src/specs/features/chat/: 1182 passed.Closes #1988