Skip to content

fix(apps): handle multiple results returned from /apps/installed endpoint#39554

Open
gauravsingh001-cyber wants to merge 1 commit into
RocketChat:developfrom
gauravsingh001-cyber:fix/handle-multiple-apps-response
Open

fix(apps): handle multiple results returned from /apps/installed endpoint#39554
gauravsingh001-cyber wants to merge 1 commit into
RocketChat:developfrom
gauravsingh001-cyber:fix/handle-multiple-apps-response

Conversation

@gauravsingh001-cyber
Copy link
Copy Markdown
Contributor

@gauravsingh001-cyber gauravsingh001-cyber commented Mar 12, 2026

Description

The /apps/installed endpoint may return multiple results when includeClusterStatus=true, particularly in clustered environments.

The current implementation assumes that the response always contains a single object with an apps property. However, if the API returns multiple results (for example, responses from different nodes in a cluster), the existing logic may fail and throw an error.

This change ensures that when the response is an array, the client safely uses the first result to retrieve the list of installed apps.

Changes

  • Added handling for array responses returned by /apps/installed
  • Ensured the client works with both single-node and clustered responses
  • Prevented potential runtime errors caused by unexpected response formats

Notes

This change addresses the TODO comment in orchestrator.ts regarding multiple results returned from the /apps/installed API.

Summary by CodeRabbit

Bug Fixes

  • Fixed app loading to handle different API response formats, ensuring installed apps display correctly in all scenarios.

@gauravsingh001-cyber gauravsingh001-cyber requested a review from a team as a code owner March 12, 2026 04:25
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Mar 12, 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 Mar 12, 2026

⚠️ No Changeset found

Latest commit: 4e9fbbf

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

Walkthrough

Adds handling in getInstalledApps for API responses that are arrays. If the result is an array, the function extracts apps from the first element; otherwise, it uses the existing object-based extraction. Maintains backward compatibility with 3 new lines added.

Changes

Cohort / File(s) Summary
API Response Handling
apps/meteor/client/apps/orchestrator.ts
Added conditional logic to support array-shaped API responses in getInstalledApps, extracting apps from the first array element while preserving existing object-based extraction behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'fix(apps): handle multiple results returned from /apps/installed endpoint' directly and accurately summarizes the main change: adding handling for array-shaped API responses in the getInstalledApps function to support clustered environments.

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


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.

@gauravsingh001-cyber gauravsingh001-cyber changed the title fix:handle multiple results from /apps/installed API fix(apps): handle multiple results returned from /apps/installed endpoint Mar 12, 2026
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 (2)
apps/meteor/client/apps/orchestrator.ts (2)

52-52: Minor: Missing space after if keyword.

For consistency with the rest of the codebase (see line 55, 75, etc.), add a space between if and (.

✏️ Formatting fix
-		if(Array.isArray(result)){
+		if (Array.isArray(result)) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/client/apps/orchestrator.ts` at line 52, The if statement uses no
space after the keyword ("if(Array.isArray(result))"); update it to match
project style by adding a space after if so it reads like "if
(Array.isArray(result))", keeping the same condition and surrounding logic that
references result and Array.isArray.

55-58: Stale TODO comment should be removed or updated.

Lines 52-54 now handle the "multiple results" case by extracting result[0]?.apps from array responses. The TODO at line 56 describing this exact scenario appears to be addressed by this change and should be removed for clarity.

🧹 Proposed cleanup
 		if ('apps' in result) {
-			// TODO: chapter day: multiple results are returned, but we only need one
 			return result.apps as App[];
 		}

As per coding guidelines: "Avoid code comments in the implementation" for TypeScript files.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/client/apps/orchestrator.ts` around lines 55 - 58, Remove the
stale TODO comment about "multiple results" in the block that checks "if ('apps'
in result)" since the array-response case is already handled elsewhere by using
result[0]?.apps; update or delete the comment to avoid confusion and comply with
the guideline to avoid inline implementation comments in TypeScript files (refer
to the result variable and the result[0]?.apps extraction when locating the
related logic in orchestrator.ts).
🤖 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/client/apps/orchestrator.ts`:
- Line 52: The if statement uses no space after the keyword
("if(Array.isArray(result))"); update it to match project style by adding a
space after if so it reads like "if (Array.isArray(result))", keeping the same
condition and surrounding logic that references result and Array.isArray.
- Around line 55-58: Remove the stale TODO comment about "multiple results" in
the block that checks "if ('apps' in result)" since the array-response case is
already handled elsewhere by using result[0]?.apps; update or delete the comment
to avoid confusion and comply with the guideline to avoid inline implementation
comments in TypeScript files (refer to the result variable and the
result[0]?.apps extraction when locating the related logic in orchestrator.ts).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ed98dc90-5fd7-44c0-952b-b149bf082627

📥 Commits

Reviewing files that changed from the base of the PR and between 7485960 and 4e9fbbf.

📒 Files selected for processing (1)
  • apps/meteor/client/apps/orchestrator.ts
📜 Review details
⏰ 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 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/client/apps/orchestrator.ts
🧠 Learnings (3)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/apps/orchestrator.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/apps/orchestrator.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/apps/orchestrator.ts
🔇 Additional comments (1)
apps/meteor/client/apps/orchestrator.ts (1)

52-54: Type mismatch: REST typings don't include array response.

The REST type definition at packages/rest-typings/src/apps/index.ts:189-191 declares /apps/installed returns { success: true; apps: App[] } | { success: false; error: string }, not an array. This runtime handling contradicts the typed contract.

Consider updating the REST typings to reflect the actual clustered response shape, or add a type assertion with a comment explaining the discrepancy. Without updating types, TypeScript may flag Array.isArray(result) as always false.

[raise_major_issue, request_verification]

#!/bin/bash
# Verify REST typing for /apps/installed endpoint
rg -n "'/apps/installed'" --type ts -A 3

@gauravsingh001-cyber
Copy link
Copy Markdown
Contributor Author

Hi @dougfabris, could you please take a look at this PR when you have time? I’d really appreciate your review. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant