fix error -gpt and claude issues on prod#185
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
WalkthroughThe 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. ChangesConcentrateAI Streaming Fallback
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
apps/supercode-cli/server/package.jsonapps/supercode-cli/server/src/index.ts
| 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), | ||
| }) |
There was a problem hiding this comment.
🩺 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.
| 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.
| 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 | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Silent failure and token counter reset on fallback error.
Two issues in this block:
-
When
fbRes.okisfalse, 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. -
Lines 646-647 unconditionally set
inputTokens/outputTokenswith?? 0. If the fallback response omitsusage, 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.
| 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.
Description
Please include a summary of the change and which issue is fixed.
Fixes #(issue)
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
bun testpassesbun run typecheckpassesbun run lintpasses (if applicable)Checklist:
Summary by CodeRabbit
Bug Fixes
Chores
0.1.53.