Skip to content

fix: should not mark as completed if upstream error, close #1444#1488

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
Apr 25, 2026
Merged

fix: should not mark as completed if upstream error, close #1444#1488
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented Apr 25, 2026

Copy link
Copy Markdown
Owner

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request improves the handling of incomplete streams by refining the criteria for a completed aggregated response and ensuring that streams ending without a terminal event are correctly marked as failed. Feedback suggests improving observability by logging aggregation errors and reporting the specific error cause when updating the request status.

Comment thread internal/server/orchestrator/inbound.go Outdated
Comment on lines 142 to 145
if aggErr == nil && meta.ID != "" && len(responseBody) > 0 && isCompletedAggregatedOutboundResponse(meta) {
log.Debug(ctx, "Stream has valid complete response without terminal event, treating as completed")
ts.state.StreamCompleted = true
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If AggregateStreamChunks fails, the error aggErr is currently ignored without any logging. Adding a debug log here would help diagnose why a stream couldn't be treated as completed via aggregation. Also, note that the function name isCompletedAggregatedOutboundResponse is slightly confusing for an inbound stream; consider a more generic name like isCompletedAggregatedResponse in a future refactor.

		if aggErr != nil {
			log.Debug(ctx, "Failed to aggregate stream chunks", log.Cause(aggErr))
		} else if meta.ID != "" && len(responseBody) > 0 && isCompletedAggregatedOutboundResponse(meta) {
			log.Debug(ctx, "Stream has valid complete response without terminal event, treating as completed")
			ts.state.StreamCompleted = true
		}

if ts.request != nil {
persistCtx := context.WithoutCancel(ctx)

errToReport := errors.New("stream ended without terminal event or completed response")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

When the stream ends without a terminal event, it is more informative to report the actual aggregation error (aggErr) if it exists, rather than a generic error message. This ensures that if the stream was corrupted or malformed, the specific error is captured in the request status.

            errToReport := aggErr
            if errToReport == nil {
                errToReport = errors.New("stream ended without terminal event or completed response")
            }

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@looplj looplj merged commit 0618993 into unstable Apr 25, 2026
5 checks passed
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