Skip to content

Conversation

@Aitous
Copy link

@Aitous Aitous commented Nov 24, 2025

When multiple primary vendors are configured (e.g., 'reddit,alpha_vantage'), the system now correctly stops after attempting all primary vendors instead of continuing through all fallback vendors.

Changes:

  • Track which primary vendors have been attempted in a list
  • Add stopping condition when all primary vendors are attempted
  • Preserve existing single-vendor behavior (stop after first success)

This prevents unnecessary API calls and ensures predictable behavior.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Aitous, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where, in multi-vendor configurations, the system would continue to iterate through fallback vendors even after all primary vendors had been attempted. The changes introduce a more granular tracking mechanism for primary vendors and a new stopping condition that ensures the process terminates once all primary vendors have been tried. This refinement prevents redundant API calls and establishes more predictable behavior for data routing in environments with multiple primary vendors, without altering the established single-vendor stopping logic.

Highlights

  • Vendor Tracking Enhancement: Replaced a simple boolean flag (any_primary_vendor_attempted) with a list (primary_vendors_attempted) to precisely track which primary vendors have been attempted during the routing process.
  • Multi-Vendor Stopping Condition: Implemented a new stopping condition that ensures the system halts execution once all configured primary vendors have been attempted in a multi-vendor setup, preventing unnecessary processing of fallback vendors.
  • Single-Vendor Behavior Preservation: Maintained the existing stopping logic for single-vendor configurations, where the process correctly stops after the first successful vendor.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 aims to correct the stopping logic for multi-vendor configurations, ensuring the system stops after all primary vendors are attempted. The implementation correctly introduces a list to track attempted primary vendors. However, there's a logical flaw where the stopping condition for multiple vendors is only checked upon a successful API call, which contradicts the goal of stopping even if some primary vendors fail. I've suggested a correction to move this logic. I also noted a potential edge case with duplicate vendors in the configuration that could cause premature termination.

Comment on lines 218 to 229
if vendor_results:
results.extend(vendor_results)
successful_vendor = vendor
result_summary = f"Got {len(vendor_results)} result(s)"
print(f"SUCCESS: Vendor '{vendor}' succeeded - {result_summary}")

# Stopping logic: Stop after first successful vendor for single-vendor configs
# Multiple vendor configs (comma-separated) may want to collect from multiple sources
# Stopping logic:
# - Single vendor config: Stop after first success
# - Multi-vendor config: Stop after all primary vendors attempted
if len(primary_vendors) == 1:
print(f"DEBUG: Stopping after successful vendor '{vendor}' (single-vendor config)")
break
elif set(primary_vendors_attempted) == set(primary_vendors):
print(f"DEBUG: All primary vendors attempted ({', '.join(primary_vendors_attempted)}), stopping")
break
else:
print(f"FAILED: Vendor '{vendor}' produced no results")

Choose a reason for hiding this comment

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

high

There are a couple of issues with the current stopping logic for multi-vendor configurations:

  1. The check is inside the if vendor_results: block, which means the loop only stops if the last primary vendor attempted was successful. The desired behavior is to stop after all primary vendors are attempted, regardless of success.
  2. The set(...) == set(...) comparison will not work correctly if the vendor configuration contains duplicate names (e.g., 'a,b,a'). The loop would stop prematurely because sets only contain unique elements.

The suggestion below fixes the first issue by moving the check. For the second issue, you might consider ensuring primary_vendors only contains unique entries when it's created, or using a different comparison method that handles duplicates (like collections.Counter).

Suggested change
if vendor_results:
results.extend(vendor_results)
successful_vendor = vendor
result_summary = f"Got {len(vendor_results)} result(s)"
print(f"SUCCESS: Vendor '{vendor}' succeeded - {result_summary}")
# Stopping logic: Stop after first successful vendor for single-vendor configs
# Multiple vendor configs (comma-separated) may want to collect from multiple sources
# Stopping logic:
# - Single vendor config: Stop after first success
# - Multi-vendor config: Stop after all primary vendors attempted
if len(primary_vendors) == 1:
print(f"DEBUG: Stopping after successful vendor '{vendor}' (single-vendor config)")
break
elif set(primary_vendors_attempted) == set(primary_vendors):
print(f"DEBUG: All primary vendors attempted ({', '.join(primary_vendors_attempted)}), stopping")
break
else:
print(f"FAILED: Vendor '{vendor}' produced no results")
if vendor_results:
results.extend(vendor_results)
successful_vendor = vendor
result_summary = f"Got {len(vendor_results)} result(s)"
print(f"SUCCESS: Vendor '{vendor}' succeeded - {result_summary}")
# Stopping logic:
# - Single vendor config: Stop after first success
if len(primary_vendors) == 1:
print(f"DEBUG: Stopping after successful vendor '{vendor}' (single-vendor config)")
break
else:
print(f"FAILED: Vendor '{vendor}' produced no results")
# - Multi-vendor config: Stop after all primary vendors attempted
if len(primary_vendors) > 1 and set(primary_vendors_attempted) == set(primary_vendors):
print(f"DEBUG: All primary vendors attempted ({', '.join(primary_vendors_attempted)}), stopping")
break

When multiple primary vendors are configured (e.g., 'reddit,alpha_vantage'),
the system now correctly stops after attempting all primary vendors instead
of continuing through all fallback vendors.

Changes:
- Track which primary vendors have been attempted in a list
- Add stopping condition when all primary vendors are attempted
- Preserve existing single-vendor behavior (stop after first success)

This prevents unnecessary API calls and ensures predictable behavior.
Tests verify:
- Single vendor stops after first success
- Multi-vendor stops after all primaries (even if they fail)
- Fallback vendors are not attempted when primaries are configured
- Tool-level config overrides category-level config

Tests use pytest with fixtures and mocked vendors, can run without API keys in CI/CD.

Run with: pytest tests/test_multi_vendor_routing.py -v
@Aitous Aitous force-pushed the fix/multi-vendor-stopping-logic branch from ca9b9f5 to 9080dbc Compare November 24, 2025 01:20
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