Kimi K3.1 Pro · Heavy
fix-proper-handling-of-group-memberships-discourse-cursor
Discourse · Ruby · L · 300–799 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.
- Gold bugs found
- 6 of 10
- Comments published
- 11
- Comments matching a bug
- 6
- Comments not matching
- 5
- Cost of this PR
- $2.535
Published comments (11)
Omitting offset in members raises NoMethodError — Requests that omit `offset` now call `to_i` on `nil`, raising `NoMethodError` instead of returning the first page as the endpoint previously did. Restore the zero fallback with `(params[:offset] || 0).to_i`.
Adding an existing group member violates the unique membership index — Adding a username that is already in the group blindly pushes another join row, violating the unique `group_users(group_id,user_id)` index and returning a 500; the unchanged selector makes clicking Add twice a direct trigger. Make insertion idempotent by ignoring duplicate input and existing memberships before calling `group.add`.
Removing a group member leaves the cached user count stale — Deleting through `group.users` removes the join row without running `GroupUser`’s destroy callbacks, so its `counter_cache: "user_count"` is not decremented and serialized group counts remain stale after a refresh. Destroy the join record through `Group#remove` or explicitly reset the group’s `group_users` counter after deletion.
Bulk member addition runs an unbounded series of user lookups — Bulk-adding N members performs N separate `User.find_by_username` queries in series, with no bound on the comma-separated input, replacing the previous bulk username lookup. Split the names once, fetch all matching users with a single `User.where(username: names)` query, and iterate over that result.
Remove-member links are shown for automatic groups — The item view's context is each `member`, and `GroupUserSerializer` does not expose `automatic`, so this `unless` renders removal links even for automatic groups. Bind the condition to the parent group controller's `automatic` flag so the action is hidden when membership changes are forbidden.
Unbounded members limit can load and serialize an entire large group — The action passes an arbitrary `params[:limit]` directly to ActiveRecord and serializes the result, allowing one request to load an entire large visible group's membership; the rewrite newly exposes this behavior for non-automatic groups too. Clamp `limit` to a reasonable maximum before querying.
Automatic-group removal spec uses PUT instead of DELETE — The automatic-removal test uses `xhr :put`, but `remove_member` is exposed as `DELETE members`; PUT is the `add_members` route. It therefore does not exercise the HTTP operation used to remove members and can pass despite a regression in DELETE removal handling.
totalPages adds an extra page when user_count is a multiple of limit — `totalPages` is one too high whenever `user_count` is a positive exact multiple of `limit`. For example, 100 users with a limit of 50 produces 3 pages instead of 2; Next from page 2 then sets `offset` to 100 and displays an empty third page.
Every `findMembers` response unconditionally replaces the member list and pagination state, while… — Sequence the requests and ignore obsolete responses, or prevent another page load until the current one completes.
The offset is clamped using the cached `user_count` before the request, so a reload after removal… — With 51 users on the page at offset 50, removing its sole member leaves 50 users, but this still requests offset 50; the server returns `total: 50` with no members and the model stores that out-of-range offset, leaving an empty page. Reconcile the offset with the refreshed total (and refetch a valid page when necessary) instead of relying only on the stale count. **Also found in:** - `app/assets/javascripts/discourse/models/group.js:45-48`
Default limit truncates public non-automatic group member lists — The new 50-member default also truncates the public group-members page, whose route calls `findMembers` only once and whose template has no pagination controls; groups that previously displayed more than 50 non-automatic members now hide the rest. Add pagination or continued loading to the public members route, or preserve the prior retrieval behavior for that caller.