Skip to content

fix(hnsw): stop NewHnswSync orphaning model files and spill to the resolved dir (#29253) - #29334

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
cpegeric:bug_29253
Sep 24, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
cpegeric:bug_29253

Conversation

@cpegeric

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #29253

What this PR does / why we need it:

DownloadAll loads each metadata model with view=false, which KEEPS the committed local file. Two problems on the ISCP CDC sync path (SqlContext, nil Proc):

  1. Orphan on error. If a later model's LoadIndex/Unload failed after earlier models committed their files, NewHnswSync did return nil, err without Destroy. runHnsw only Destroys a non-nil sync, so the earlier committed files leaked -- one FileSize file per ISCP retry of an index with two or more model rows. Call sync.Destroy() on the DownloadAll error branch before returning.

  2. Wrong directory. LoadMetadata builds models with an empty TmpDir and DownloadAll never copied sync.tmpDir onto them, so hnswSpillDir -- which returns "" for a nil Proc -- left os.CreateTemp using os.TempDir(). Those files sit outside the tree HostSpillDir.sweepOnce reclaims, and on the success path park there for the whole consumer lifetime. Set m.TmpDir = s.tmpDir before LoadIndex so spills land in the directory the ISCP writer already resolved (NewSync -> syncSpillDir).

Tests (CGo, real usearch load over the 2-model resource fixtures):

  • TestDownloadAllPlacesModelsInResolvedSpillDir: both models spill into the resolved dir (2 files), Destroy clears them. Fails without fix 2 (0 files -> os.TempDir).
  • TestNewHnswSyncRemovesCommittedFilesOnDownloadAllError: model abc-0 commits, abc-1's stream fails; the resolved dir is clean afterward. Fails without fix 1 (1 orphan).

The setupModel dropped-error path noted in the issue is a separate concern and not the orphan source; left out of scope.

…solved dir (matrixorigin#29253)

DownloadAll loads each metadata model with view=false, which KEEPS the committed local
file. Two problems on the ISCP CDC sync path (SqlContext, nil Proc):

1. Orphan on error. If a later model's LoadIndex/Unload failed after earlier models
   committed their files, NewHnswSync did `return nil, err` without Destroy. runHnsw
   only Destroys a non-nil sync, so the earlier committed files leaked -- one FileSize
   file per ISCP retry of an index with two or more model rows. Call sync.Destroy() on
   the DownloadAll error branch before returning.

2. Wrong directory. LoadMetadata builds models with an empty TmpDir and DownloadAll
   never copied sync.tmpDir onto them, so hnswSpillDir -- which returns "" for a nil
   Proc -- left os.CreateTemp using os.TempDir(). Those files sit outside the tree
   HostSpillDir.sweepOnce reclaims, and on the success path park there for the whole
   consumer lifetime. Set m.TmpDir = s.tmpDir before LoadIndex so spills land in the
   directory the ISCP writer already resolved (NewSync -> syncSpillDir).

Tests (CGo, real usearch load over the 2-model resource fixtures):
- TestDownloadAllPlacesModelsInResolvedSpillDir: both models spill into the resolved
  dir (2 files), Destroy clears them. Fails without fix 2 (0 files -> os.TempDir).
- TestNewHnswSyncRemovesCommittedFilesOnDownloadAllError: model abc-0 commits, abc-1's
  stream fails; the resolved dir is clean afterward. Fails without fix 1 (1 orphan).

The setupModel dropped-error path noted in the issue is a separate concern and not the
orphan source; left out of scope.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH 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.

GPT-6 high review — APPROVE at exact head 77a9300.

Reviewed both changed paths and their lifecycle: DownloadAll now routes temporary model files through the resolved spill directory, and NewHnswSync destroys already-committed files when a later model load fails. The added tests cover both the spill-location and partial-download cleanup cases; exact-head CI/UT/BVT evidence is green. No blocking findings.

@mergify mergify Bot added the queued label Sep 24, 2026
@mergify

mergify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-24 09:39 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-24 09:59 UTC · at 536e2d37e08bbc6fa38a90bd44075fdded61fd70

This pull request spent 20 minutes 10 seconds in the queue, with no time running CI.

Reason

Pull request #29334 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

> The author needs to enable ["Allow edits from maintainers"](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants