Skip to content

fix error -gpt and claude issues on prod#185

Merged
yashdev9274 merged 1 commit into
mainfrom
supercode-cli
Jul 8, 2026
Merged

fix error -gpt and claude issues on prod#185
yashdev9274 merged 1 commit into
mainfrom
supercode-cli

Conversation

@yashdev9274

@yashdev9274 yashdev9274 commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Description

Please include a summary of the change and which issue is fixed.

Fixes #(issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

  • bun test passes
  • bun run typecheck passes
  • bun run lint passes (if applicable)

Checklist:

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Summary by CodeRabbit

  • Bug Fixes

    • Improved AI chat streaming reliability by automatically retrying when a streamed response returns no text and no tool calls, helping ensure a reply is still delivered.
    • Preserved streamed output more consistently and updated usage counts when the fallback response is used.
  • Chores

    • Bumped the CLI package version to 0.1.53.

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
supercli Ready Ready Preview, Comment Jul 8, 2026 11:35am
supercli-client Ready Ready Preview, Comment Jul 8, 2026 11:35am
supercli-docs Ready Ready Preview, Comment Jul 8, 2026 11:35am

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The concentrateai streaming handler in /api/ai/chat now accumulates streamed content and tracks tool call occurrence. If no text or tool calls are seen during streaming, it retries with a non-streaming request, writes the returned content to the response, and updates token counters. The CLI package version was also bumped.

Changes

ConcentrateAI Streaming Fallback

Layer / File(s) Summary
Track content/tool calls and add fallback retry
apps/supercode-cli/server/src/index.ts
Adds fullContent and sawToolCalls tracking during streaming, then retries with a non-streaming request and writes fallback content/token counts when no streamed output was captured.
Package version bump
apps/supercode-cli/server/package.json
Bumps CLI package version from 0.1.52 to 0.1.53.

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

Possibly related PRs

  • yashdev9274/supercli#117: Adds the original ConcentrateAI provider streaming logic that this PR's buffering and fallback modify.
  • yashdev9274/supercli#129: Also modifies concentrateai streaming tool_calls/content handling in the same endpoint.
  • yashdev9274/supercli#142: Adjusts concentrateai message formatting for tool call metadata in the same streaming flow.

Poem

A rabbit hops through streams of text,
Catching content, tool calls next,
If silence falls, no words in sight,
I fetch a fallback, set it right! 🐇
Version bumped, one hop ahead—
Hoppy code, well fed! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is related to the bug fix and mentions the affected GPT/Claude production issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch supercode-cli

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@yashdev9274 yashdev9274 merged commit 89da516 into main Jul 8, 2026
4 of 8 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/supercode-cli/server/src/index.ts`:
- Around line 635-639: The fallback fetch in the server request flow can hang
indefinitely because it bypasses the timeout/retry behavior used by
nonStreamingRequest in concentrate-service.ts. Update the fallback path around
the fbRes fetch call to use the same fetchWithRetry wrapper and apply an
AbortSignal.timeout(60_000) so the Express request cannot մնain open forever.
Keep the fix localized to the fallback handling in index.ts and preserve the
existing fbBody/apiKey request construction.
- Around line 640-648: The fallback handling in the streaming response block is
silently swallowing failures and resetting token counts. Update the fbRes.ok
branch in index.ts to explicitly handle the non-OK case by logging the error and
writing an error event to the NDJSON stream, using the existing fallback
response flow symbols around fbRes and res.write. Also change the
inputTokens/outputTokens assignment so it only overwrites the existing counters
when fbData.usage is present, preserving any partial counts from the streaming
phase instead of defaulting to zero.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 33ef5b2b-055d-4734-a918-8d6ceb75bc7f

📥 Commits

Reviewing files that changed from the base of the PR and between a6e4ca3 and 3dcdfc0.

📒 Files selected for processing (2)
  • apps/supercode-cli/server/package.json
  • apps/supercode-cli/server/src/index.ts

Comment on lines +635 to +639
const fbRes = await fetch("https://api.concentrate.ai/v1/chat/completions", {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify(fbBody),
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Fallback fetch lacks a timeout and retry — can hang the request thread indefinitely.

The upstream nonStreamingRequest in concentrate-service.ts uses fetchWithRetry with AbortSignal.timeout(60_000). The fallback fetch here has neither, so a slow or unresponsive ConcentrateAI gateway will hold the Express request thread open with no upper bound.

🔒️ Proposed fix: add timeout to fallback fetch
-          const fbRes = await fetch("https://api.concentrate.ai/v1/chat/completions", {
-            method: "POST",
-            headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
-            body: JSON.stringify(fbBody),
-          })
+          const fbRes = await fetch("https://api.concentrate.ai/v1/chat/completions", {
+            method: "POST",
+            headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
+            body: JSON.stringify(fbBody),
+            signal: AbortSignal.timeout(60_000),
+          })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const fbRes = await fetch("https://api.concentrate.ai/v1/chat/completions", {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify(fbBody),
})
const fbRes = await fetch("https://api.concentrate.ai/v1/chat/completions", {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify(fbBody),
signal: AbortSignal.timeout(60_000),
})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/supercode-cli/server/src/index.ts` around lines 635 - 639, The fallback
fetch in the server request flow can hang indefinitely because it bypasses the
timeout/retry behavior used by nonStreamingRequest in concentrate-service.ts.
Update the fallback path around the fbRes fetch call to use the same
fetchWithRetry wrapper and apply an AbortSignal.timeout(60_000) so the Express
request cannot մնain open forever. Keep the fix localized to the fallback
handling in index.ts and preserve the existing fbBody/apiKey request
construction.

Comment on lines +640 to +648
if (fbRes.ok) {
const fbData: any = await fbRes.json()
const fbContent = fbData?.choices?.[0]?.message?.content ?? ""
if (fbContent) {
res.write(JSON.stringify({ type: "text", content: fbContent }) + "\n")
}
inputTokens = fbData?.usage?.prompt_tokens ?? 0
outputTokens = fbData?.usage?.completion_tokens ?? 0
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Silent failure and token counter reset on fallback error.

Two issues in this block:

  1. When fbRes.ok is false, the error is silently swallowed — no log, no error event written to the NDJSON stream. The client receives an empty response with no indication of what went wrong.

  2. Lines 646-647 unconditionally set inputTokens/outputTokens with ?? 0. If the fallback response omits usage, any partial token counts from the streaming phase are overwritten with zeros.

🛡️ Proposed fix: handle non-OK and guard token overwrite
           if (fbRes.ok) {
             const fbData: any = await fbRes.json()
             const fbContent = fbData?.choices?.[0]?.message?.content ?? ""
             if (fbContent) {
               res.write(JSON.stringify({ type: "text", content: fbContent }) + "\n")
             }
-            inputTokens = fbData?.usage?.prompt_tokens ?? 0
-            outputTokens = fbData?.usage?.completion_tokens ?? 0
+            if (fbData?.usage) {
+              inputTokens = fbData.usage.prompt_tokens ?? inputTokens
+              outputTokens = fbData.usage.completion_tokens ?? outputTokens
+            }
+          } else {
+            console.error(`ConcentrateAI fallback failed: ${fbRes.status}`)
           }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (fbRes.ok) {
const fbData: any = await fbRes.json()
const fbContent = fbData?.choices?.[0]?.message?.content ?? ""
if (fbContent) {
res.write(JSON.stringify({ type: "text", content: fbContent }) + "\n")
}
inputTokens = fbData?.usage?.prompt_tokens ?? 0
outputTokens = fbData?.usage?.completion_tokens ?? 0
}
if (fbRes.ok) {
const fbData: any = await fbRes.json()
const fbContent = fbData?.choices?.[0]?.message?.content ?? ""
if (fbContent) {
res.write(JSON.stringify({ type: "text", content: fbContent }) + "\n")
}
if (fbData?.usage) {
inputTokens = fbData.usage.prompt_tokens ?? inputTokens
outputTokens = fbData.usage.completion_tokens ?? outputTokens
}
} else {
console.error(`ConcentrateAI fallback failed: ${fbRes.status}`)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/supercode-cli/server/src/index.ts` around lines 640 - 648, The fallback
handling in the streaming response block is silently swallowing failures and
resetting token counts. Update the fbRes.ok branch in index.ts to explicitly
handle the non-OK case by logging the error and writing an error event to the
NDJSON stream, using the existing fallback response flow symbols around fbRes
and res.write. Also change the inputTokens/outputTokens assignment so it only
overwrites the existing counters when fbData.usage is present, preserving any
partial counts from the streaming phase instead of defaulting to zero.

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.

1 participant