Skip to content

fix(perplexity): handle missing group in API response#462

Open
malhobayyeb wants to merge 2 commits into
robinebers:mainfrom
malhobayyeb:fix-perplexity-api-change
Open

fix(perplexity): handle missing group in API response#462
malhobayyeb wants to merge 2 commits into
robinebers:mainfrom
malhobayyeb:fix-perplexity-api-change

Conversation

@malhobayyeb
Copy link
Copy Markdown

@malhobayyeb malhobayyeb commented May 11, 2026

Fixes #278.

Perplexity changed their API to return an empty list from the /groups endpoint for regular PRO users. This fix modifies the plugin to fetch the user plan from the /api/user endpoint instead, preventing a total connection failure, and allows the flow to proceed without a group object if rate limit data is available.

Visual Verification:
A screenshot demonstrating the successful fix (showing the rate limit details without the 'Unable to connect' error) has been provided and verified locally.

🤖 Generated with Gemini CLI


Summary by cubic

Handle empty /groups responses for Perplexity PRO users by reading the plan from /api/user (with a trailing-slash fallback) and continuing when rate-limit data exists without a group. Adds tests to cover this flow.

  • Bug Fixes
    • Fetch user from /api/user or /api/user/ and use subscription_tier in detectPlanLabel as a fallback.
    • Only fetch group details and usage analytics when a groupId exists.
    • Relax connection check to proceed if user or rateLimits are present when group is missing.
    • Guard balance and usage reads when group is null.

Written for commit f5707e7. Summary will update on new commits.

Perplexity changed their API to return an empty list from the /groups endpoint for regular PRO users. This fix modifies the plugin to fetch the user plan from the /api/user endpoint instead, preventing a total connection failure, and allows the flow to proceed without a group object if rate limit data is available.
Copilot AI review requested due to automatic review settings May 11, 2026 04:31
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

@malhobayyeb
Copy link
Copy Markdown
Author

CleanShot 2026-05-11 at 07 32 48

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Perplexity plugin to tolerate Perplexity’s API change where /groups may return an empty list for regular PRO users, by fetching plan details from /api/user and allowing the probe flow to proceed when group data is missing but rate-limit data is available.

Changes:

  • Extend plan detection to fall back to /api/user when group customerInfo is unavailable.
  • Make group and usage-analytics fetching conditional on the presence of a group id instead of hard-failing.
  • Relax the “Unable to connect” guard so the plugin can still render rate-limit lines without a group object.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/perplexity/plugin.js Outdated
const authToken = session && session.authToken
if (!authToken) return null
const restHeaders = makeRestHeaderOverrides(session)
const user = fetchJsonOptional(ctx, LOCAL_USER_ENDPOINT, authToken, restHeaders)
Comment on lines 395 to +402
const restState = fetchRestState(ctx, session)
if (!restState || !restState.group) throw "Unable to connect. Try again later."
if (!restState || (!restState.group && !restState.user && !restState.rateLimits)) throw "Unable to connect. Try again later."

const customerInfo = restState.group && restState.group.customerInfo
const plan = detectPlanLabel(customerInfo)
const plan = detectPlanLabel(customerInfo, restState.user)

const dollarLines = []
const balanceUsd = readBalanceUsd(restState.group)
const balanceUsd = restState.group ? readBalanceUsd(restState.group) : null
@validatedev
Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@malhobayyeb
Copy link
Copy Markdown
Author

@copilot review

Addressed the two open Copilot threads:

  • Added /api/user/ fallback after the exact /api/user request.
  • Added a regression test for empty /groups plus /api/user/ plan fallback and rate-limit rendering.
  • Verified no group detail or usage analytics request is made when groups are empty.

Verification:

  • bun run test plugins/perplexity/plugin.test.js --run
  • bun run test --run
  • git diff --check origin/main...HEAD

@malhobayyeb
Copy link
Copy Markdown
Author

@copilot review
@codex review

Update after final quality gating:

  • Pushed branch head is current: f5707e7 (fix-perplexity-api-change).
  • PR diff remains limited to plugins/perplexity/plugin.js and plugins/perplexity/plugin.test.js.
  • JS/CI gates pass:
    • bun install --frozen-lockfile
    • bun run build
    • bunx tsc --noEmit
    • bun run test --run (60 files, 1077 tests)
    • git diff --check origin/main...HEAD
  • Rust gates still fail, but I verified the same failures reproduce on origin/main (de22ad6) in a detached worktree, so they are not introduced by this PR:
    • cargo fmt --manifest-path src-tauri/Cargo.toml -- --check
    • cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings
    • cargo test --manifest-path src-tauri/Cargo.toml fails on plugin_engine::host_api::tests::ccusage_timeout_kills_descendant_and_closes_pipes

cubic previously reported no issues on the earlier PR revision. This comment asks Copilot and Codex for a follow-up review of the current head.

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@validatedev validatedev requested a review from Copilot May 14, 2026 21:15
@validatedev
Copy link
Copy Markdown
Collaborator

@codex review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Collaborator

@validatedev validatedev left a comment

Choose a reason for hiding this comment

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

Looks good and clean to me. Approved, thanks!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perplexity not showing

3 participants