Skip to content

Fix/candidate pool empty array - #3871

Merged
diegosouzapw merged 4 commits into
cheaper-inference:release/v3.8.26from
YunyunZhai:fix/candidate-pool-empty-array
Jun 15, 2026
Merged

diegosouzapw merged 4 commits into
cheaper-inference:release/v3.8.26from
YunyunZhai:fix/candidate-pool-empty-array

Conversation

@YunyunZhai

Copy link
Copy Markdown
Contributor

Summary

  • fix(combo): skip early return when candidatePool is an empty array

Related Issues

  • Closes #
  • Related to #

Validation

  • [ √] npm run lint
  • [ √] npm run test:unit
  • npm run test:coverage
  • Coverage is still >= 60% for statements, lines, functions, and branches
  • SonarQube PR analysis is green or any remaining issues are explicitly documented below

Tests Added Or Updated

  • tests/unit/combo-auto-candidate-expansion.test.ts

Coverage Notes

  • added expandAutoComboCandidatePool falls through to active connections when candidatePool is an empty array

Reviewer Notes

  • Call out any risky areas, migrations, feature flags, or manual validation that reviewers should know about.

zhaiyunyun added 2 commits June 15, 2026 09:12
expandAutoComboCandidatePool() returned early when candidatePool was an
array, but an empty array meant the candidate pool stayed empty — no
targets were ever broadened. Only return early when candidatePool has
at least one entry.
@YunyunZhai
YunyunZhai requested a review from diegosouzapw as a code owner June 15, 2026 01:33

@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 modifies expandAutoComboCandidatePool to ensure that an empty candidatePool array does not trigger an early return, allowing the function to fall back to active connections. A corresponding unit test has been added to verify this behavior. The reviewer pointed out a potential TypeScript compiler error when accessing .length on an unknown type property and suggested extracting candidatePool to a local variable for proper type narrowing. Additionally, the reviewer identified a similar check on line 3264 that should be updated as well.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +2910 to +2911
if (Array.isArray(localAutoConfig?.candidatePool) && localAutoConfig.candidatePool.length > 0)
return eligibleTargets;

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.

high

While this change correctly prevents an early return when candidatePool is an empty array, accessing localAutoConfig.candidatePool.length directly might trigger TypeScript compiler errors (e.g., Object is of type 'unknown' or Property 'length' does not exist on type 'unknown') because localAutoConfig is typed as Record<string, unknown>.

Extracting candidatePool to a local variable allows TypeScript's Array.isArray type guard to correctly narrow its type to any[], ensuring type-safe access to .length.

Additionally, please note that there is a similar check on line 3264:

const candidatePool = Array.isArray(autoConfigSource.candidatePool)
  ? autoConfigSource.candidatePool
  : [...new Set(eligibleTargets.map((target) => target.provider))];

If autoConfigSource.candidatePool is an empty array [], it will bypass the fallback and pass [] to selectAutoProvider, which will fail to select any candidates. You should also update line 3264 to check for length > 0 so it correctly falls back to the active connections' providers.

Suggested change
if (Array.isArray(localAutoConfig?.candidatePool) && localAutoConfig.candidatePool.length > 0)
return eligibleTargets;
const candidatePool = localAutoConfig?.candidatePool;
if (Array.isArray(candidatePool) && candidatePool.length > 0)
return eligibleTargets;

@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.8.26 June 15, 2026 07:23
diegosouzapw and others added 2 commits June 15, 2026 12:22
PR cheaper-inference#3871 own growth: combo.ts 5203->5204 (+1). Updates the frozen
file-size baseline so Fast Quality Gates pass on release/v3.8.26.

Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks, @YunyunZhai! 🙏 Sharp catch — expandAutoComboCandidatePool was early-returning on any array, so an empty candidatePool: [] blocked expansion from active connections. Your && length > 0 guard is exactly right, and the TDD regression nails it (4/4 green locally). I added a tiny file-size baseline bump (combo.ts +1) so Fast Quality Gates pass. Merging into release/v3.8.26. 🚀

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.

2 participants