Skip to content

Conversation

@inabao
Copy link
Collaborator

@inabao inabao commented Dec 9, 2025

Summary by Sourcery

Relax strict result equality in the Pyramid serialization test and add a helper script for stress-running the Pyramid functional tests in parallel.

Tests:

  • Adjust the Pyramid serialization binary set test to log detailed mismatches instead of failing immediately on differing result IDs.

Chores:

  • Add a shell script to repeatedly run the Pyramid functional test suite in parallel for debugging and stress testing.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 9, 2025

Reviewer's Guide

Adds diagnostic logging to the Pyramid serialization test to debug mismatched search results, and introduces a helper shell script to run the Pyramid Serialize File tests in parallel for CI reproduction and stress testing.

File-Level Changes

Change Details Files
Relax strict ID equality assertion in TestSerializeBinarySet and add detailed per-rank debug logging when mismatches occur.
  • Replace per-rank REQUIRE equality assertion with a mismatch detection flag to avoid immediate test termination on first difference.
  • When mismatches are detected, print the query path involved in the failing test case.
  • For each rank in the top-k results, log decoded from/to IDs, their corresponding base paths, and their distances using fmt::format.
  • Keep the original dimension equality check to ensure structural consistency between results.
tests/test_index.cpp
Add a shell script to repeatedly run Pyramid Serialize File functests in parallel to reproduce CI issues.
  • Introduce a configurable CONCURRENCY parameter to control the number of parallel test processes.
  • Provide two execution modes: batch-style parallel runs and a persistent mode that maintains a fixed level of concurrency.
  • Default the script to batch_parallel mode while leaving persistent_parallel available but commented out for alternative usage.
  • Use a simple infinite loop with job control and wait to continuously stress-test the Pyramid Serialize File test target.
test.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link

Summary of Changes

Hello @inabao, 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 addresses an error in the Pyramid CI by introducing a new shell script for parallel execution of functional tests and augmenting the test_index.cpp file with comprehensive debugging information. These changes will facilitate the identification and diagnosis of issues within the Pyramid Serialize File test, ultimately helping to stabilize the CI pipeline.

Highlights

  • Parallel Test Execution Script: Added a new shell script, test.sh, to enable parallel execution of the Pyramid Serialize File functional tests. It supports both batch and persistent parallel modes for running tests concurrently.
  • Enhanced Debugging for Serialization Tests: Modified tests/test_index.cpp to include detailed logging within the TestSerializeBinarySet function. If discrepancies are found between original and serialized test results, it now prints comprehensive debug information including query paths, IDs, file paths, and distances for mismatched entries.
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

@sourcery-ai sourcery-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.

Hey there - I've reviewed your changes and found some issues that need to be addressed.

  • The added debug printing in TestSerializeBinarySet (flag pr and multiple std::cout/fmt::format calls) looks like temporary diagnostics; consider either removing it or reworking it to use the test framework’s logging facilities so test output doesn’t become noisy in normal runs.
  • The new test.sh script runs an infinite loop with hard‑coded paths and parameters; if this is meant as a local stress tool, consider moving it to a separate tooling directory, adding a way to bound the run (e.g., max iterations or duration), and avoiding hard‑coded build-release/tests/functests so it’s usable across environments.
  • In test.sh, the persistent_parallel loop checks jobs -p | wc -l in a tight loop with very short sleep; consider increasing the sleep interval or restructuring to avoid unnecessary CPU usage when processes are already at the desired concurrency.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The added debug printing in `TestSerializeBinarySet` (flag `pr` and multiple `std::cout`/`fmt::format` calls) looks like temporary diagnostics; consider either removing it or reworking it to use the test framework’s logging facilities so test output doesn’t become noisy in normal runs.
- The new `test.sh` script runs an infinite loop with hard‑coded paths and parameters; if this is meant as a local stress tool, consider moving it to a separate tooling directory, adding a way to bound the run (e.g., max iterations or duration), and avoiding hard‑coded `build-release/tests/functests` so it’s usable across environments.
- In `test.sh`, the `persistent_parallel` loop checks `jobs -p | wc -l` in a tight loop with very short sleep; consider increasing the sleep interval or restructuring to avoid unnecessary CPU usage when processes are already at the desired concurrency.

## Individual Comments

### Comment 1
<location> `tests/test_index.cpp:989-998` </location>
<code_context>
+        bool pr = false;
</code_context>

<issue_to_address>
**issue (testing):** The original assertion comparing result IDs has been removed, so this test no longer verifies the expected behavior.

This change removes the core correctness check (`res_to.value()->GetIds()[j] == res_from.value()->GetIds()[j]`) and replaces it with a flag/logging path that never fails the test, so regressions could pass unnoticed. Please restore an assertion on the IDs (e.g., `REQUIRE`/`CHECK`) and keep the logging as a supplement. If ID equality is no longer required, update the test name and add assertions that clearly express the new expected behavior instead.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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 introduces a shell script for running tests in parallel and modifies a test case, likely to debug a CI failure. My review focuses on improving the robustness of the shell script and fixing a critical issue in the modified C++ test case where an assertion was removed, effectively disabling the test. I've provided suggestions to handle test failures correctly in the script and to restore the test's assertion while keeping the intended debug logging.

Comment on lines 989 to 1049
bool pr = false;
for (auto j = 0; j < topk; ++j) {
REQUIRE(res_to.value()->GetIds()[j] == res_from.value()->GetIds()[j]);
if (res_to.value()->GetIds()[j] != res_from.value()->GetIds()[j]) {
pr = true;
}
}
if (pr) {
auto query_path = dataset->query_->GetPaths()[i];
std::cout << "query path: " << query_path << std::endl;
for (auto j = 0; j < topk; ++j) {
auto from_id = res_from.value()->GetIds()[j] >> 16;
auto to_id = res_to.value()->GetIds()[j] >> 16;
auto from_path = dataset->base_->GetPaths()[from_id];
auto to_path = dataset->base_->GetPaths()[to_id];
auto from_distance = res_from.value()->GetDistances()[j];
auto to_distance = res_to.value()->GetDistances()[j];
std::cout << fmt::format("rank {}: from_id {}, from_path {}, from_distance {:.6f} | to_id {}, to_path {}, to_distance {:.6f}",
j, from_id, from_path, from_distance, to_id, to_path, to_distance) << std::endl;
}
std::cout << std::endl;
}

Choose a reason for hiding this comment

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

critical

The original REQUIRE assertion has been removed and replaced with logging. This is a critical issue as it means the test will no longer fail if there is a mismatch, potentially hiding bugs. While the detailed logging is useful for debugging, the test must still fail.

The current implementation is also inefficient as it iterates through all topk results to check for a mismatch, even after one has been found.

I suggest refactoring this to first check for a mismatch, and if one is found, print the detailed debug information and then explicitly fail the test using REQUIRE(false). This restores the test's correctness while keeping the valuable debug output.

        bool mismatch = false;
        for (auto j = 0; j < topk; ++j) {
            if (res_to.value()->GetIds()[j] != res_from.value()->GetIds()[j]) {
                mismatch = true;
                break;
            }
        }

        if (mismatch) {
            auto query_path = dataset->query_->GetPaths()[i];
            std::cout << "Mismatch in TestSerializeBinarySet for query path: " << query_path << std::endl;
            for (auto j = 0; j < topk; ++j) {
                auto from_id_full = res_from.value()->GetIds()[j];
                auto to_id_full = res_to.value()->GetIds()[j];
                auto from_id = from_id_full >> 16;
                auto to_id = to_id_full >> 16;
                auto from_path = dataset->base_->GetPaths()[from_id];
                auto to_path = dataset->base_->GetPaths()[to_id];
                auto from_distance = res_from.value()->GetDistances()[j];
                auto to_distance =  res_to.value()->GetDistances()[j];
                std::cout << fmt::format("rank {}: from_id {}, from_path {}, from_distance {:.6f} | to_id {}, to_path {}, to_distance {:.6f}{}",
                                         j, from_id, from_path, from_distance, to_id, to_path, to_distance,
                                         (from_id_full != to_id_full ? "  <-- MISMATCH" : "")) << std::endl;
            }
            std::cout << std::endl;
            REQUIRE(false); // Fail test to make CI failure visible
        }

Comment on lines +7 to +15
batch_parallel() {
while true; do
echo "启动 $CONCURRENCY 个并行测试进程..."
for ((i=1; i<=$CONCURRENCY; i++)); do
./build-release/tests/functests "Pyramid Serialize File" &
done
wait # 等待本批次所有进程完成
done
}

Choose a reason for hiding this comment

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

medium

The wait command on its own will return the exit status of the last background job to finish. If any other job fails, its failure will not be caught, and the script will continue to run. To make this script robust for CI, you should wait for each job individually and exit if any of them fails.

Suggested change
batch_parallel() {
while true; do
echo "启动 $CONCURRENCY 个并行测试进程..."
for ((i=1; i<=$CONCURRENCY; i++)); do
./build-release/tests/functests "Pyramid Serialize File" &
done
wait # 等待本批次所有进程完成
done
}
batch_parallel() {
while true; do
echo "启动 $CONCURRENCY 个并行测试进程..."
for ((i=1; i<=$CONCURRENCY; i++)); do
./build-release/tests/functests "Pyramid Serialize File" &
done
for job in $(jobs -p); do
wait "$job" || exit $?
done
done
}

Comment on lines +18 to +27
persistent_parallel() {
while true; do
jobs_count=$(jobs -p | wc -l)
if [ $jobs_count -lt $CONCURRENCY ]; then
./build-release/tests/functests "Pyramid Serialize File" &
else
sleep 0.1 # 避免CPU占用过高
fi
done
}

Choose a reason for hiding this comment

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

medium

The current implementation of persistent_parallel uses a polling mechanism with sleep, which is inefficient and can lead to unnecessary CPU usage. A more efficient and modern approach is to use wait -n (available in Bash 4.3+), which waits for the next background job to terminate. This avoids polling and also allows for checking the exit status of each job as it completes.

Suggested change
persistent_parallel() {
while true; do
jobs_count=$(jobs -p | wc -l)
if [ $jobs_count -lt $CONCURRENCY ]; then
./build-release/tests/functests "Pyramid Serialize File" &
else
sleep 0.1 # 避免CPU占用过高
fi
done
}
persistent_parallel() {
for ((i=1; i<=$CONCURRENCY; i++)); do
./build-release/tests/functests "Pyramid Serialize File" &
done
# Requires bash 4.3+
while true; do
wait -n || exit $?
./build-release/tests/functests "Pyramid Serialize File" &
done
}

@pull-request-size pull-request-size bot added size/L and removed size/M labels Dec 9, 2025
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             main    #1408      +/-   ##
==========================================
+ Coverage   91.81%   91.82%   +0.01%     
==========================================
  Files         323      323              
  Lines       18439    18439              
==========================================
+ Hits        16930    16932       +2     
+ Misses       1509     1507       -2     
Flag Coverage Δ
cpp 91.82% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 85.64% <ø> (ø)
datacell 93.68% <ø> (+0.39%) ⬆️
index 90.89% <ø> (-0.11%) ⬇️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 684e18e...03d4668. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wxyucs
Copy link
Collaborator

wxyucs commented Dec 15, 2025

unused

@wxyucs wxyucs closed this Dec 15, 2025
Signed-off-by: jinjiabao.jjb <[email protected]>
Signed-off-by: jinjiabao.jjb <[email protected]>
Signed-off-by: jinjiabao.jjb <[email protected]>
Signed-off-by: jinjiabao.jjb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants