Skip to content

fix: make channels.close idempotent to prevent error toast on already…#38844

Open
sriramsowmithri9807 wants to merge 3 commits into
RocketChat:developfrom
sriramsowmithri9807:fix/hide-room-idempotent-close
Open

fix: make channels.close idempotent to prevent error toast on already…#38844
sriramsowmithri9807 wants to merge 3 commits into
RocketChat:developfrom
sriramsowmithri9807:fix/hide-room-idempotent-close

Conversation

@sriramsowmithri9807
Copy link
Copy Markdown

@sriramsowmithri9807 sriramsowmithri9807 commented Feb 20, 2026

Fix the channels.close API endpoint to make the Hide channel action idempotent and prevent unnecessary error responses when the channel is already hidden.


Proposed Changes

This PR introduces a one-line change in the channels.close endpoint so that attempting to hide an already-hidden channel returns a successful response instead of an error.

Before

  • If subscription.open === false, the API returned:

    API.v1.failure("The channel, [name], is already closed to the sender")
    
  • This produced an error toast in the UI when users attempted to hide a channel that was already hidden.

After

  • The endpoint now returns:

    API.v1.success()
    
  • The operation becomes a silent no-op, matching expected UX behaviour and making the endpoint idempotent.


Changed File

apps/meteor/app/api/server/v1/channels.ts  (around line 605)
if (!sub.open) {
-    return API.v1.failure(`The channel, ${findResult.name}, is already closed to the sender`);
+    return API.v1.success();
}

Issue Addressed

Previously, hiding a channel could trigger an error under the following scenario:

  1. Hide a channel from the sidebar
  2. Reopen it using global search (Ctrl + K)
  3. Attempt to hide it again

Because opening via search does not call openRoom(), the subscription’s open flag remains false.
The API then incorrectly reports the channel as “already closed”, causing an unnecessary UI error toast.

This PR ensures the hide action behaves consistently regardless of how the room was reopened.


Steps to Reproduce

  1. Open any channel (example: #newone)
  2. Click the Info (ⓘ) icon
  3. Click Hide → channel disappears from sidebar
  4. Reopen the channel via Ctrl + K search
  5. Click Info → Hide again

Before this fix

  • Error toast:
    "The channel, newone, is already closed to the sender"

After this fix

  • Channel hides silently (expected behaviour)

Impact

  • Improves UX consistency
  • Prevents misleading API errors
  • Makes channels.close idempotent
  • Aligns backend behaviour with frontend expectations

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the channel close operation to return success instead of an error when the channel is not open.

…-hidden channels

Previously, clicking Hide on an already-hidden channel returned an API
failure with 'The channel is already closed to the sender', which
surfaced as an error toast in the UI. This changes the endpoint to
return success silently, making the hide action idempotent.
@sriramsowmithri9807 sriramsowmithri9807 requested a review from a team as a code owner February 20, 2026 15:09
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Feb 20, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 20, 2026

⚠️ No Changeset found

Latest commit: 0d74753

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 20, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 20, 2026

Walkthrough

The channels.close API endpoint behavior was modified to return success instead of failure when a user attempts to close an already-closed channel. Additionally, package.json was updated with a one-line modification.

Changes

Cohort / File(s) Summary
Channels API Endpoint
apps/meteor/app/api/server/v1/channels.ts
Modified channels.close to return success when the channel is already closed, changing from the previous failure response.
Package Manifest
package.json
Minor version or dependency update with one line added and one line removed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐰 A channel already closed with care,
Now whispers "success" through the air,
No more frowns when twice we shut the door,
Just quiet peace—what could be more? ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: making channels.close idempotent to prevent error toast on already-hidden channels, which matches the primary objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

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

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/meteor/app/api/server/v1/channels.ts (1)

369-371: Consider making channels.open symmetric.

channels.close is now idempotent, but its counterpart still returns a 400-level failure when sub.open is already true. The same UX / API-consistency argument applies in both directions.

♻️ Proposed change to make `channels.open` consistent
-			if (sub.open) {
-				return API.v1.failure(`The channel, ${findResult.name}, is already open to the sender`);
-			}
+			if (sub.open) {
+				return API.v1.success();
+			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/api/server/v1/channels.ts` around lines 369 - 371, The
channels.open handler currently returns API.v1.failure when sub.open is already
true, making open non-idempotent and inconsistent with channels.close; update
the logic in the channels.open flow (the branch that checks sub.open and builds
the response referencing findResult.name) to treat an already-open subscription
as a successful no-op instead of a 400-level failure—return the same success
shape used for a fresh open (or API.v1.success) and ensure no duplicate state
changes are attempted so the operation becomes symmetric with channels.close.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ebeaa7 and eedd470.

📒 Files selected for processing (1)
  • apps/meteor/app/api/server/v1/channels.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/api/server/v1/channels.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (1)
apps/meteor/app/api/server/v1/channels.ts (1)

604-606: LGTM — correct idempotent behavior.

Returning API.v1.success() when !sub.open is the right choice. The subscription is already in the desired state, so the operation is a no-op; making the endpoint idempotent is well-aligned with REST API design principles and directly eliminates the spurious error toast described in the PR.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/meteor/app/api/server/v1/channels.ts`:
- Around line 369-371: The channels.open handler currently returns
API.v1.failure when sub.open is already true, making open non-idempotent and
inconsistent with channels.close; update the logic in the channels.open flow
(the branch that checks sub.open and builds the response referencing
findResult.name) to treat an already-open subscription as a successful no-op
instead of a 400-level failure—return the same success shape used for a fresh
open (or API.v1.success) and ensure no duplicate state changes are attempted so
the operation becomes symmetric with channels.close.

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