Skip to content

Conversation

@inabao
Copy link
Collaborator

@inabao inabao commented Jan 5, 2026

cp #1431 to 0.15

@inabao inabao self-assigned this Jan 5, 2026
@inabao inabao requested a review from wxyucs as a code owner January 5, 2026 06:42
@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 and resolves a concurrency bug within the "HGraph" component, specifically during the insertion of new points. By implementing proper locking mechanisms around critical data modifications, the change ensures data integrity and prevents race conditions that could arise from simultaneous write operations.

Highlights

  • Concurrency Fix: Introduced a "std::shared_lock" to protect "InsertVector" calls for "basic_flatten_codes_" and "high_precise_codes_" within the "HGraph::add_one_point" method, resolving potential concurrency issues during graph insertion.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 fix a concurrency issue in HGraph::add_one_point by adding a std::shared_lock around vector insertion calls. While this change correctly prevents a race condition between vector insertion and resizing operations, it is part of a function with a pre-existing and more critical potential for deadlocks due to its locking strategy. The function acquires a std::unique_lock after this new block, which can lead to deadlocks if called from a context that already holds a lock on the same mutex. This is a critical issue that needs to be addressed.

Comment on lines +1006 to 1012
{
std::shared_lock add_lock(add_mutex_);
this->basic_flatten_codes_->InsertVector(data, inner_id);
if (use_reorder_) {
this->high_precise_codes_->InsertVector(data, inner_id);
}
}

Choose a reason for hiding this comment

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

critical

While adding this shared_lock correctly fixes a race condition with resize, the overall locking strategy in add_one_point is unsafe and can lead to deadlocks.

Immediately after this block, a std::unique_lock is acquired on the same add_mutex_ (line 1013). This shared_lock -> unique_lock sequence on a non-recursive mutex is dangerous:

  1. Deadlock on re-entry: If a caller already holds a unique_lock on add_mutex_ (e.g., in HGraph::Merge) and calls add_one_point, it will deadlock when this shared_lock is acquired.
  2. Deadlock on indirect recursive locking: The unique_lock on line 1013 is held during calls to other functions like graph_add_one. If any function in that call path (e.g., resize) also tries to acquire a unique_lock on add_mutex_, it will deadlock.

This indicates a larger design issue with locking in this part of the code. The function add_one_point should likely not manage locks itself. Instead, it could be refactored into unlocked helper methods, with the public API methods (Add, Merge, etc.) being responsible for acquiring locks once at a higher level.

Signed-off-by: jinjiabao.jjb <[email protected]>
@pull-request-size pull-request-size bot added size/S and removed size/XS labels Jan 5, 2026
@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             0.15    #1496      +/-   ##
==========================================
+ Coverage   90.23%   90.34%   +0.10%     
==========================================
  Files         221      218       -3     
  Lines       15097    13499    -1598     
==========================================
- Hits        13623    12195    -1428     
+ Misses       1474     1304     -170     
Flag Coverage Δ
cpp 90.34% <100.00%> (+0.10%) ⬆️

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

Components Coverage Δ
common 93.36% <100.00%> (+0.10%) ⬆️
datacell 91.73% <ø> (-0.15%) ⬇️
index 88.64% <94.11%> (+0.27%) ⬆️
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 817e681...43f8a7b. Read the comment docs.

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

inabao added 2 commits January 6, 2026 14:41
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