Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/proxy/engine/proxy_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ class _ProxyIsolateHost {
details: _requestContextPayload(prompt: resolvedPrompt),
);
final payload = await _executeNonStreamRequest(resolvedPrompt, retryTracker: retryTracker);

final candidates = payload['candidates'] as List?;
if (candidates != null && candidates.isEmpty) {
return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates');
}
Comment on lines +473 to +476
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The indentation of the added lines is inconsistent with the rest of the file (which uses 2 spaces). Additionally, the check for candidates is incomplete as it doesn't account for potential nesting under a response key, which is handled elsewhere in the codebase (e.g., in OpenAiResponseMapper). Using is List instead of a cast is also safer to avoid potential TypeError if the upstream returns an unexpected type. According to the Dart style guide, indentation should be 2 spaces.

Suggested change
final candidates = payload['candidates'] as List?;
if (candidates != null && candidates.isEmpty) {
return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates');
}
final response = (payload['response'] as Map?)?.cast<String, Object?>() ?? payload;
final candidates = response['candidates'];
if (candidates is List && candidates.isEmpty) {
return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates');
}
References
  1. Dart style guide specifies using 2 spaces for indentation. (link)


await _logTrace(
category: 'chat.completions',
route: route,
Expand Down Expand Up @@ -664,6 +670,12 @@ class _ProxyIsolateHost {
}

final payload = await _executeNonStreamRequest(resolvedPrompt, retryTracker: retryTracker);

final candidates = payload['candidates'] as List?;
if (candidates != null && candidates.isEmpty) {
return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates');
}
Comment on lines +674 to +677
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The indentation of the added lines is inconsistent with the rest of the file (which uses 2 spaces). Additionally, the check for candidates is incomplete as it doesn't account for potential nesting under a response key, which is handled elsewhere in the codebase (e.g., in OpenAiResponseMapper). Using is List instead of a cast is also safer to avoid potential TypeError if the upstream returns an unexpected type. According to the Dart style guide, indentation should be 2 spaces.

Suggested change
final candidates = payload['candidates'] as List?;
if (candidates != null && candidates.isEmpty) {
return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates');
}
final response = (payload['response'] as Map?)?.cast<String, Object?>() ?? payload;
final candidates = response['candidates'];
if (candidates is List && candidates.isEmpty) {
return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates');
}
References
  1. Dart style guide specifies using 2 spaces for indentation. (link)


await _logResponsePreview(
category: 'responses',
route: route,
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy/gemini/gemini_code_assist_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const _cloudCodeDomains = <String>{
};
const defaultGeminiRequestMaxRetries = 10;
const defaultGeminiBaseRetryDelay = Duration(seconds: 1);
const defaultGeminiRequestTimeout = Duration(seconds: 90);
const defaultGeminiRequestTimeout = Duration(minutes: 5);
const _maxTransientRequestRetries = 3;
const _maxRetryable429Delay = Duration(minutes: 1);
const _maxRetryableTransientDelay = Duration(minutes: 5);
Expand Down
Loading