Skip to content

Conversation

@MaslovKK
Copy link

@MaslovKK MaslovKK commented Dec 12, 2025

The presence of usage doesn't always mean it's the last chunk.


Summary by cubic

Remove special handling of usage in streaming: yield every chunk as it arrives instead of deferring usage to the end. This avoids misordering when usage appears mid-stream.

Written for commit c2ded53. Summary will update automatically on new commits.

The presence of usage doesn't always mean it's the last chunk.
@MaslovKK MaslovKK requested a review from a team as a code owner December 12, 2025 02:17
@MaslovKK MaslovKK requested review from Patrick-Erichsen and removed request for a team December 12, 2025 02:17
@continue
Copy link
Contributor

continue bot commented Dec 12, 2025

All Green - Keep your PRs mergeable

Learn more

All Green is an AI agent that automatically:

✅ Addresses code review comments

✅ Fixes failing CI checks

✅ Resolves merge conflicts

1 similar comment
@continue-development-app
Copy link

All Green - Keep your PRs mergeable

Learn more

All Green is an AI agent that automatically:

✅ Addresses code review comments

✅ Fixes failing CI checks

✅ Resolves merge conflicts

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Dec 12, 2025
@github-actions
Copy link

github-actions bot commented Dec 12, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
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.

1 issue found across 1 file

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/openai-adapters/src/apis/OpenAI.ts">

<violation number="1" location="packages/openai-adapters/src/apis/OpenAI.ts:277">
P1: `finish_reason` is not a direct property on `ChatCompletionChunk` - it&#39;s on each choice in `choices[0].finish_reason`. This condition will always be false, causing usage data to never be captured.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

for await (const result of response) {
// Check if this chunk contains usage information
if (result.usage) {
if (result.usage && result.finish_reason === "stop") {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 12, 2025

Choose a reason for hiding this comment

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

P1: finish_reason is not a direct property on ChatCompletionChunk - it's on each choice in choices[0].finish_reason. This condition will always be false, causing usage data to never be captured.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/openai-adapters/src/apis/OpenAI.ts, line 277:

<comment>`finish_reason` is not a direct property on `ChatCompletionChunk` - it&#39;s on each choice in `choices[0].finish_reason`. This condition will always be false, causing usage data to never be captured.</comment>

<file context>
@@ -274,7 +274,7 @@ export class OpenAIApi implements BaseLlmApi {
     for await (const result of response) {
       // Check if this chunk contains usage information
-      if (result.usage) {
+      if (result.usage &amp;&amp; result.finish_reason === &quot;stop&quot;) {
         // Store it to emit after all content chunks
         lastChunkWithUsage = result;
</file context>
Suggested change
if (result.usage && result.finish_reason === "stop") {
if (result.usage && result.choices?.[0]?.finish_reason === "stop") {

✅ Addressed in c2ded53

@continue
Copy link
Contributor

continue bot commented Dec 12, 2025

Bug Fix Required

cubic correctly identified an issue: finish_reason is not a direct property on ChatCompletionChunk. It's located at choices[0].finish_reason.

The current code:

if (result.usage && result.finish_reason === "stop")

Should be:

if (result.usage && result.choices?.[0]?.finish_reason === "stop")

I've created a branch with the fix: patch-1...continuedev:continue:fix-usage-finish-reason-access

You can either:

  1. Cherry-pick the commit from that branch into your PR
  2. Make the change directly in your PR

The fix aligns with how other parts of the codebase access chunk properties (e.g., line 389: chunk.choices && chunk.choices.length > 0).

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Dec 12, 2025
@MaslovKK
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant