Skip to content

fix(chat): cap bootstrap community auto-join at 10 - #1987

Merged
feruzm merged 2 commits into
developfrom
fix/chat-bootstrap-cap-communities
Oct 24, 2026
Merged

feruzm merged 2 commits into
developfrom
fix/chat-bootstrap-cap-communities

Conversation

@feruzm

@feruzm feruzm commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Chat bootstrap ensured a channel and membership for every subscribed community, in sequential batches. Accounts following hundreds of communities never finished before the bootstrap deadline, so /chats never loaded for them.

  • Bootstrap now auto-joins at most 10 subscribed communities (pickAutoJoinCommunities), keeping Hive's order (role holders first, then community rank).
  • Duplicates and channels the user left are skipped before counting, so they don't use up the cap.
  • Explicit community joins (community in the body, used by the community chat page) are unchanged.
  • Existing memberships are untouched.

Follow-up: community channels beyond the cap are no longer created during bootstrap, so channel search should create them on demand (tracked separately).

Test plan

  • New spec mattermost-auto-join-communities.spec.ts (cap, order, duplicates, left channels, case); fails when the cap is removed.
  • pnpm test src/specs/api/: 931 passed.

Closes #1986

Summary by CodeRabbit

  • New Features
    • Community channel auto-join now selects up to 10 subscribed communities, preserving their subscription order.
    • Communities you’ve manually left are excluded, and duplicate communities are counted only once.

Bootstrap ensured a channel and membership for every subscribed community,
so accounts following hundreds of communities never finished before the
deadline and chat never loaded. Auto-join now takes the first 10
subscriptions (Hive order, left channels skipped before counting).
Explicit community joins are unchanged.

Closes #1986
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T18:42:52.171498Z 6f7f167 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Cap chat bootstrap auto-joins at 10 communities

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Limit bootstrap auto-joins to 10 subscribed communities to keep large accounts within the request
 deadline.
• Preserve Hive order while excluding duplicates and manually left channels before applying the cap.
• Keep explicit community joins unchanged and add selection tests; channels beyond the cap need
 on-demand creation.
Diagram

graph TD
  A["Bootstrap request"] --> B["Hive subscriptions"] --> D{"Auto-join selection"} --> E["Batched joins"] --> F["Explicit join"] --> G["Chat response"]
  A --> C["Left channels"] --> D
  A -->|"Optional community"| F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Create and join community channels on demand
  • ➕ Removes subscription-count-dependent channel work from bootstrap.
  • ➕ Avoids provisioning channels the user never opens.
  • ➖ Channel search and navigation must create missing channels before use.
  • ➖ Requires a broader change than the immediate timeout fix.

Recommendation: Use the cap as a focused fix for long bootstraps while preserving explicit joins. Pursue on-demand channel creation separately so communities beyond the cap remain discoverable through search.

Files changed (3) +84 / -15

Bug fix (2) +29 / -15
route.tsLimit bootstrap membership work to selected communities +7/-15

Limit bootstrap membership work to selected communities

• Uses the new selector before batching subscribed-community joins, so duplicates and manually left channels do not consume the 10-community allowance. Explicit community joins remain separate and unchanged.

apps/web/src/app/api/mattermost/bootstrap/route.ts

mattermost.tsAdd ordered, capped auto-join selection +22/-0

Add ordered, capped auto-join selection

• Defines the 10-community limit and a helper that preserves subscription order and first-occurrence titles while skipping duplicates and manually left channels.

apps/web/src/server/mattermost.ts

Tests (1) +55 / -0
mattermost-auto-join-communities.spec.tsTest auto-join cap and exclusions +55/-0

Test auto-join cap and exclusions

• Covers the cap on a large subscription list, ordering, duplicate handling, left-channel exclusion and case matching, and lists below the cap.

apps/web/src/specs/api/mattermost-auto-join-communities.spec.ts

@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the new bootstrap test addresses the previous coverage gap.

Summary

Bootstrap now auto-joins up to 10 subscribed communities, preserving their order and skipping duplicates and channels the user left.

  • Chat bootstrap joins no more than 10 subscribed communities automatically.

Reviews (2) · Last reviewed commit: "test(chat): cover bootstrap auto-join ca..." · Reviewed by Greptile

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. New test helpers omit return types ✓ Resolved
Description
loadModule and subs rely on inferred return types instead of declaring them explicitly. Later
changes can alter these helper contracts without an explicit type review, making the new test code
less maintainable.
Code

apps/web/src/specs/api/mattermost-auto-join-communities.spec.ts[R7-15]

+async function loadModule() {
+  process.env.MATTERMOST_BASE_URL = "https://chat.test/api/v4";
+  process.env.MATTERMOST_ADMIN_TOKEN = "admin-token";
+  process.env.MATTERMOST_TEAM_ID = "team-1";
+  return await import("@/server/mattermost");
+}
+
+const subs = (n: number) =>
+  Array.from({ length: n }, (_, i) => ({ id: `hive-${100000 + i}`, title: `C${i}` }));
Evidence
The changed TypeScript spec defines loadModule and subs without return type annotations. The
checklist requires explicit annotations for function return types in newly added or modified
TypeScript code.

Rule 2668119: Disallow implicit and any types in new TypeScript code
apps/web/src/specs/api/mattermost-auto-join-communities.spec.ts[7-15]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new test helpers `loadModule` and `subs` omit explicit return type annotations, contrary to the TypeScript typing requirement.
## Fix Focus Areas
- apps/web/src/specs/api/mattermost-auto-join-communities.spec.ts[7-15]
## Recommended Fix
Add an explicit `Promise<...>` return type to `loadModule` and an explicit array return type to `subs`, using the precise imported module and subscription shapes where practical.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Some communities vanish from chat search 🐞 Bug ≡ Correctness
Description
pickAutoJoinCommunities stops bootstrap from calling ensureCommunityChannelMembership for
subscriptions beyond the first ten, so bootstrap no longer creates those channels. When an omitted
community has no existing Mattermost channel, the New chat search queries only existing channels and
offers no result to join, although opening the community page can still create it.
Code

apps/web/src/app/api/mattermost/bootstrap/route.ts[243]

+    const uniqueCommunityIds = pickAutoJoinCommunities(communityIds, leftChannels);
Evidence
The new selection limits which subscriptions reach channel creation. The search endpoint queries
Mattermost channels only, and the New chat modal renders join actions only for channels returned by
that search.

apps/web/src/app/api/mattermost/bootstrap/route.ts[238-260]
apps/web/src/server/mattermost.ts[313-378]
apps/web/src/app/api/mattermost/channels/search/route.ts[42-69]
apps/web/src/app/chats/_components/chats-client.tsx[801-824]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Communities omitted by the bootstrap cap may have no Mattermost channel, so the New chat search cannot find them.
## Fix Focus Areas
- apps/web/src/app/api/mattermost/bootstrap/route.ts[238-260]
- apps/web/src/app/api/mattermost/channels/search/route.ts[42-69]
- apps/web/src/app/chats/_components/chats-client.tsx[801-824]
## Recommended Fix
Add an on-demand path for community search results without existing channels. Validate matches against Hive, then let the user explicitly create and join the selected community channel; do not create channels for every search result.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can choose which labels appear on a finding, and whether they show icons or text

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

const BATCH_SIZE = 5;

const leftChannels = getUserLeftChannels(userWithProps);
const uniqueCommunityIds = pickAutoJoinCommunities(communityIds, leftChannels);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Some communities vanish from chat search 🐞 Bug ≡ Correctness

pickAutoJoinCommunities stops bootstrap from calling ensureCommunityChannelMembership for
subscriptions beyond the first ten, so bootstrap no longer creates those channels. When an omitted
community has no existing Mattermost channel, the New chat search queries only existing channels and
offers no result to join, although opening the community page can still create it.
Agent Prompt
## Issue description
Communities omitted by the bootstrap cap may have no Mattermost channel, so the New chat search cannot find them.

## Fix Focus Areas
- apps/web/src/app/api/mattermost/bootstrap/route.ts[238-260]
- apps/web/src/app/api/mattermost/channels/search/route.ts[42-69]
- apps/web/src/app/chats/_components/chats-client.tsx[801-824]

## Recommended Fix
Add an on-demand path for community search results without existing channels. Validate matches against Hive, then let the user explicitly create and join the selected community channel; do not create channels for every search result.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You'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 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e077cb33-94b4-4052-b9a7-90a554148018
Commits

Reviewing files that changed from the base of the PR and between 6f7f167 and 59aeee6.

Files selected for processing: 1
  • apps/web/src/specs/api/mattermost-auto-join-communities.spec.ts
Walkthrough

The Mattermost bootstrap now selects up to 10 subscribed communities in subscription order. It skips duplicate IDs and channels the user has left before ensuring membership.

Changes: Subscribed community auto-join

Layer / File(s) Summary
Select eligible communities
apps/web/src/server/mattermost.ts, apps/web/src/specs/api/mattermost-auto-join-communities.spec.ts
Adds pickAutoJoinCommunities with a default limit of 10. Tests cover order, duplicate IDs, left-channel filtering, retained titles, and inputs below the limit.
Use selected communities during bootstrap
apps/web/src/app/api/mattermost/bootstrap/route.ts
The bootstrap uses the helper’s results and passes true to membership ensuring for each selected community. The timeout comment now refers to chained Mattermost calls.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant BootstrapRoute
  participant pickAutoJoinCommunities
  participant ensureCommunityChannelMembership
  BootstrapRoute->>pickAutoJoinCommunities: subscriptions and left channels
  pickAutoJoinCommunities-->>BootstrapRoute: selected community IDs and titles
  BootstrapRoute->>ensureCommunityChannelMembership: selected community with auto-join true
Loading
Merge Risk: Minimal · up to 6f7f1

The cap does not prevent users from opening other communities’ chats from their community pages. No established merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(chat): cap bootstrap community auto-join at 10" matches the main change. The PR adds pickAutoJoinCommunities, which caps bootstrap auto-joins at 10 subscribed communities in Hive order,…
Linked Issues check Passed The implementation meets issue #1986. pickAutoJoinCommunities selects at most 10 entries, preserves subscription order, skips duplicate IDs, and skips left-channel IDs after normalization. The boots…
Out of Scope Changes check Passed The changed files support issue #1986. The route applies the selection, mattermost.ts provides the cap and filtering logic, and the new spec tests that logic. The supplied changes show no unrelated …
Full details: Title check

Explanation

The title "fix(chat): cap bootstrap community auto-join at 10" matches the main change. The PR adds pickAutoJoinCommunities, which caps bootstrap auto-joins at 10 subscribed communities in Hive order, skips duplicates and left channels before counting toward the cap, and adds Vitest coverage for these rules. The title is specific and concise, uses a conventional commit prefix, and names the primary behavior change.

Full details: Linked Issues check

Explanation

The implementation meets issue #1986. pickAutoJoinCommunities selects at most 10 entries, preserves subscription order, skips duplicate IDs, and skips left-channel IDs after normalization. The bootstrap route uses this selection for automatic joins in batches. The explicit community join remains outside the cap and still calls ensureCommunityChannelMembership with auto-join enabled. The new spec covers the cap, order, duplicate handling, left-channel handling, case handling, and shorter lists.

Full details: Out of Scope Changes check

Explanation

The changed files support issue #1986. The route applies the selection, mattermost.ts provides the cap and filtering logic, and the new spec tests that logic. The supplied changes show no unrelated product behavior or unrelated tests. The follow-up for on-demand channel creation is explicitly not included.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

A rabbit counts the channels in a row
Ten hops mark the limit for the show
Left-behind paths quietly pass by
Duplicate names do not multiply
The first title stays beside its friend
Then membership calls begin their end

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔇 Additional comments: 3
apps/web/src/specs/api/mattermost-auto-join-communities.spec.ts: 1

1-55: LGTM!

apps/web/src/app/api/mattermost/bootstrap/route.ts: 1

15-15: LGTM!

Also applies to: 22-24, 238-238, 243-243, 260-260

apps/web/src/server/mattermost.ts-1280-1280: 1

1280-1280: Minor · Functional Correctness · Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Deduplicate community IDs using the normalized ID.

If subscriptions contain hive-100000 and Hive-100000, picked.has(id) treats them as different communities. Both use a slot, so the cap can exclude another community. Track normalized IDs for duplicate checks, while keeping the first ID and title for the membership call.


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bc929fad-6788-4541-be04-637f0a1a181d
Commits

Reviewing files that changed from the base of the PR and between f853c6d and 6f7f167.

Files selected for processing: 3
  • apps/web/src/app/api/mattermost/bootstrap/route.ts
  • apps/web/src/server/mattermost.ts
  • apps/web/src/specs/api/mattermost-auto-join-communities.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@feruzm
feruzm merged commit 2ced2a3 into develop Oct 24, 2026
9 checks passed
@feruzm
feruzm deleted the fix/chat-bootstrap-cap-communities branch October 24, 2026 18:57
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.

Chat bootstrap times out for users with many community subscriptions

1 participant