Skip to content

fix(hgraph): relax Tune source coverage - #2719

Open
jac0626 wants to merge 3 commits into
antgroup:mainfrom
jac0626:codex/relax-hgraph-tune-source-main
Open

fix(hgraph): relax Tune source coverage#2719
jac0626 wants to merge 3 commits into
antgroup:mainfrom
jac0626:codex/relax-hgraph-tune-source-main

Conversation

@jac0626

@jac0626 jac0626 commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Change Type

  • Bug fix
  • New feature
  • Improvement/Refactor
  • Documentation
  • CI/Build/Infra

Linked Issue

What Changed

  • Select the Tune source with direct raw, precise FP32, then base FP32 checks; only fall through when the current candidate is absent or empty.
  • Do not require the selected source to cover the published ID range.
  • Preserve the pre-fix(hgraph): tune from available fp32 codes #2466 training count and rebuild the complete published HGraph ID range.
  • Add a regression test for an Add submission failure that leaves HGraph metadata ahead of codes.

Test Evidence

  • Other (describe below)

Test details:

clang-format-15 --dry-run --Werror src/algorithm/hgraph/hgraph.cpp src/algorithm/hgraph/hgraph_add_test.cpp
git diff --check
cmake --build build --target unittests functests --parallel 6
./build/tests/unittests '[hgraph_tune_incomplete_source]' --allow-running-no-tests
./build/tests/unittests '[tune]' --allow-running-no-tests
./build/tests/functests '[tune_codes]' --allow-running-no-tests

Results: 8 regression assertions, 7 deduplicated-Tune assertions, and 8040 Tune-source assertions passed.

Compatibility Impact

  • API/ABI compatibility: none
  • Behavior changes: Tune no longer rejects an otherwise available raw/FP32 source solely because its logical count is behind the published HGraph count. Training and rebuilding retain the pre-fix(hgraph): tune from available fp32 codes #2466 ranges.

Performance and Concurrency Impact

  • Performance impact: consistent indexes are unchanged; inconsistent indexes rebuild the full published ID range, matching legacy Tune behavior.
  • Concurrency/thread-safety impact: none; Tune keeps its existing Add serialization.

Documentation Impact

  • No docs update needed
  • Updated docs:
    • README.md
    • DEVELOPMENT.md
    • CONTRIBUTING.md
    • Other:

Risk and Rollback

  • Risk level: medium
  • Residual risk: Add-state consistency and invalid individual slots remain outside this PR.
  • Rollback plan: revert these commits to restore strict source coverage rejection.

Checklist

  • I have linked the relevant issue.
  • I have added/updated tests for the bug fix.
  • I have considered API compatibility impact.
  • I have updated docs if behavior/workflow changed.
  • My commit messages follow project conventions.

Signed-off-by: jc543239 <jc543239@antgroup.com>
Assisted-by: Codex:GPT-5
Copilot AI lite review requested due to automatic review settings August 19, 2026 09:00
@vsag-bot

vsag-bot commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

/label status/waiting-for-review
/waiting-on reviewer
/request-review @jiaweizone
/request-review @wxyucs
/request-review @inabao
/request-review @LHT129

@jac0626 jac0626 added kind/bug Bug fixes, defects, or unexpected behavior 修复程序错误、缺陷或异常行为 version/1.0 labels Aug 19, 2026 — with ChatGPT Codex Connector
@mergify

mergify Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 3 merge protections satisfied — ready to merge.

Show 3 satisfied protections

🟢 Require kind label

  • label~=^kind/

🟢 Require version label

  • label~=^version/

🟢 Require linked issue for feature/bug PRs

  • body~=(?im)(?:^|[\s\-\*])(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s*:?\s+(?:#\d+|[\w.\-]+/[\w.\-]+#\d+|https?://github\.com/[\w.\-]+/[\w.\-]+/issues/\d+)

Copilot AI 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.

Pull request overview

This PR addresses an HGraph Tune failure mode where total_count_ (and ID metadata) can be ahead of the available FP32/raw codes after a failed Add, and Tune should still proceed by rebuilding only the readable prefix.

Changes:

  • Adjust Tune’s source selection to pick the available raw/FP32 source with the largest available prefix.
  • Bound Tune training and code rebuilding by the selected source’s available count (rather than the published HGraph count).
  • Add a regression test covering Add submission failure leaving HGraph metadata ahead of codes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/algorithm/hgraph/hgraph.cpp Relaxes Tune’s source selection and limits rebuild/training to the selected source’s available count.
src/algorithm/hgraph/hgraph_add_test.cpp Adds a regression test using a rejecting thread pool to reproduce Add failure followed by a successful Tune.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/algorithm/hgraph/hgraph_add_test.cpp
Comment thread src/algorithm/hgraph/hgraph.cpp Outdated
@jac0626
jac0626 marked this pull request as ready for review August 20, 2026 06:22
@jac0626

jac0626 commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

/retest

Prefer complete raw or FP32 Tune sources when available, then fall back without rejecting incomplete sources. Preserve the pre-coverage training and full published-ID rebuild ranges.

Signed-off-by: jc543239 <jc543239@antgroup.com>
Assisted-by: Codex:GPT-5
Copilot AI review requested due to automatic review settings August 20, 2026 07:05

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/algorithm/hgraph/hgraph_add_test.cpp:60

  • ArmableRejectingThreadPool::Enqueue returns a default-constructed std::future<void>, which is invalid. If any code path calls Enqueue directly and later waits/gets on the returned future, this will throw std::future_error. Return a ready future instead to satisfy the ThreadPool contract.
        if (reject_submissions_.load(std::memory_order_acquire)) {
            throw std::bad_alloc();
        }
        task();
        return {};

src/algorithm/hgraph/hgraph.cpp:214

  • The fallback tune-source selection (second pass with require_coverage=false) always picks the first available source (raw/high_precise/basic) rather than the one with the largest readable prefix. This contradicts the PR/issue requirement to choose the available raw/FP32 source with the largest readable prefix, and can also pick a shorter source even when a longer FP32 source is available.
        auto select_tune_source = [&](bool require_coverage) {
            auto select = [&](const FlattenInterfacePtr& codes, bool require_fp32) {
                if (tune_source != nullptr or codes == nullptr or
                    (require_fp32 and codes->GetQuantizerName() != QUANTIZATION_TYPE_VALUE_FP32) or
                    (require_coverage and not covers_active_ids(codes))) {

src/algorithm/hgraph/hgraph.cpp:274

  • current_count is loaded from total_count_ (the published HGraph count), but when Tune falls back to an incomplete source, decode_tune_source(i, ...) will still be called for i >= tune_source->TotalCount() during both training (for i < train_count) and rebuilding (for i < current_count). In the Add-failure scenario this PR targets, GetCodesById can return nullptr and Tune will throw an INTERNAL_ERROR instead of rebuilding the readable prefix. Tune should bound both the training sample loop and the rebuild loop by min(published_count, tune_source->TotalCount()).
            for (int64_t i = 0; i < current_count; ++i) {
                decode_tune_source(i, insert_buffer.data());
                new_code->InsertVector(static_cast<const void*>(insert_buffer.data()), i);
            }

Keep raw-first source selection explicit, falling back to precise or base FP32 codes only when the earlier source is unavailable or empty.

Assisted-by: Codex:GPT-5
Signed-off-by: jc543239 <jc543239@antgroup.com>
Copilot AI review requested due to automatic review settings August 20, 2026 08:25

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

src/algorithm/hgraph/hgraph.cpp:270

  • Rebuild currently iterates [0, current_count) even when the chosen tune_source is a fallback that may only have a shorter readable prefix. For FlattenDataCell + MemoryIO, GetCodesById reads from the resized buffer without validating writes, so this can decode uninitialized memory and silently rebuild corrupted vectors.

When using an incomplete source, cap the rebuild loop to the source’s readable count (e.g., TotalCount()).

            Vector<float> insert_buffer(dim_, 0, allocator_);
            for (int64_t i = 0; i < current_count; ++i) {
                decode_tune_source(i, insert_buffer.data());
                new_code->InsertVector(static_cast<const void*>(insert_buffer.data()), i);
            }

Comment on lines 199 to +203
if (is_tune_base_code or is_tune_precise_code or is_tune_raw_code) {
if (covers_active_ids(raw_vector_)) {
tune_source = raw_vector_;
} else if (covers_active_ids(high_precise_codes_) and
high_precise_codes_->GetQuantizerName() == QUANTIZATION_TYPE_VALUE_FP32) {
tune_source = raw_vector_;
if ((tune_source == nullptr or tune_source->TotalCount() == 0) and
high_precise_codes_ != nullptr and
high_precise_codes_->GetQuantizerName() == QUANTIZATION_TYPE_VALUE_FP32) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Bug fixes, defects, or unexpected behavior 修复程序错误、缺陷或异常行为 size/L version/1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug](hgraph): allow Tune to use incomplete FP32 sources

4 participants