Skip to content

fix(#11962): a vector graph build keeps in the delta the live vectors it could not read (commit in flight on a Raft leader) - #11969

Merged
robfrank merged 3 commits into
ArcadeData:mainfrom
shaunpatterson:fix/11962-vector-build-keeps-in-flight
Nov 17, 2026
Merged

robfrank merged 3 commits into
ArcadeData:mainfrom
shaunpatterson:fix/11962-vector-build-keeps-in-flight

Conversation

@shaunpatterson

@shaunpatterson shaunpatterson commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11962 (the "committed vectors missing from searches" half).

Problem

A commit replays its vectors into the index's location index and delta buffer during phase 1. Its pages and records are published only in phase 2, which on a Raft leader comes after the quorum round trip. A graph build in that window cannot read those vectors, so validation drops them like deleted ones, and two things then lost them:

  1. The post-build trim kept only the delta entries at or past the build's snapshot id. The dropped vector was then in neither the graph nor the delta once its commit completed, and no search found it until some later rebuild.
  2. On a sparse index (fewer page vectors than 80% of the bucket's records, so the build cross-checks with a document scan), the recovery from the in-memory locations was skipped after the scan. The scan cannot see the in-flight record either, so the build published a location index without the in-flight vector at all.

On a 3-node cluster with 4 writers and 2 searchers this left 1 to 10 committed vectors out of a k=all search for 15 to 30 s after the writers stopped. During the application's ingests the leader logged the matching pattern (Recovered N vectors from in-memory index (page-parsed: 0 ...), Page id ... does not exist, Filtered out N vectors with deleted/invalid documents).

Change

  • The post-build trim also keeps the delta entries before the snapshot that the build did not incorporate and that are still live in the location index. A delete tombstones the location and removes the delta entry, and an aborted replay takes the entry out of both (undoReplay), so what survives is exactly a vector whose commit was in flight. It stays in the delta, where searches score it, and keeps the index MUTABLE so the next build incorporates it. The vector ids of the build are already sorted ascending (the build checks it), so the lookup is a binary search per delta entry.
  • The in-memory recovery (the "tertiary defense" of Missing images when vector neighbors query #3722) runs after a document scan too. It only adds live locations whose RID neither the pages nor the scan produced, so after a scan that is the in-flight commits. When the in-memory index holds no more entries than the build found, it still costs nothing.

This PR does not address the other half of the issue: a search during the window can still answer the in-flight record as an empty row.

Test

Issue11962VectorBuildDuringCommitIT (ha-raft, 3 nodes) runs a full graph build from RaftReplicatedDatabase.TEST_PRE_DISPATCH_HOOK, on another thread, while a commit of one new vector is between its replay and its dispatch to Raft. Once the commit completes, the vector must be the top-1 of a search by its own value. There are two variants: a dense index, and a sparse one (30 vectors among 90 records).

dense sparse
main fails: answers [#28:29], not [#28:30] not run separately
trim change only passes fails: answers [#28:29], not [#28:90]
this PR passes passes

The related engine suites pass too, 564 tests in 53 classes. They include all of com.arcadedb.index.vector that covers the delta, the rebuild and the #3722 recovery: VectorTransactionSearchTest, LSMVectorIndexRebuildRacingWritesTest, VectorRebuildLifecycleTest, LSMVectorIndexRecoveryTest, VectorGraphStalenessTest, GroupedVectorSearchTest, VectorPrefilterTest, DeltaScanVectorSearchTest, VectorDeltaScanTest, LSMVectorIndexRebuildTest, LSMVectorIndexCompactionTest, LSMVectorIndexGraph{Connectivity,FileVisibility,Manifest,Storage}Test, VectorGraphPersistTest, VectorIndexRebuildsOnEveryCloseTest, VectorLocationIndexTest, GraphSearcherPoolStaleGraphTest, CompactIndexKeepsGraphReusableTest, PqCodesStaleForRebuiltGraphTest and Issue11805GraphRebuildSyncsOnlyItsFileTest, plus the sparse-vector suites.

Follow-up (0526b8b): the first version also kept the delta entries of vectors that the build leaves out because of their value, such as an all-zero placeholder under COSINE or a norm the float cosine cannot hold. Those are live in the location index too, and the delta scan then scored them as NaN. CI caught it in CosineUnscorableMagnitudeIssue11635Test, ProductQuantizationTest, VectorSearchCorrectnessTest and LSMVectorIndexTest. The trim now applies the build's own value checks (dimensions, isUnscorable) before it keeps an unread entry. Those four classes plus VectorTransactionSearchTest, LSMVectorIndexRebuildRacingWritesTest, VectorRebuildLifecycleTest, LSMVectorIndexRecoveryTest and DeltaScanVectorSearchTest pass (236 tests).

…ve vectors it could not read

- A commit replays its vectors into the location index and the delta before its pages and records are published
  (on a Raft leader, the whole quorum round trip). A build in that window dropped them like deleted vectors and the
  post-build trim removed their delta entries, so once the commit completed no search found them until a later rebuild.
- The trim now also keeps the entries before the snapshot that the build did not incorporate and that are still live.
- Issue11962VectorBuildDuringCommitIT runs a build from TEST_PRE_DISPATCH_HOOK inside a leader commit.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d74afaad-6ce2-4aa1-9b4a-81fd36e3b0fe
Commits

Reviewing files that changed from the base of the PR and between 2eb615c and 0526b8b.

Files selected for processing: 2

  • engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java
  • ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue11962VectorBuildDuringCommitIT.java
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mergify

mergify Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

… document scan too

- On a sparse index the build cross-checks with a document scan and then skipped the recovery from the in-memory
  locations. The scan cannot see a commit in flight either, so the build published a location index without its
  vector, and the trim then dropped its delta entry as not live.
- Issue11962VectorBuildDuringCommitIT gains the sparse variant (30 vectors among 90 records).
… could not read

- A vector the build leaves out by its value (an all-zero COSINE placeholder, a norm the float cosine cannot hold)
  is live in the location index too, and keeping its delta entry made the delta scan score it as NaN (CI:
  CosineUnscorableMagnitudeIssue11635Test, ProductQuantizationTest, VectorSearchCorrectnessTest, LSMVectorIndexTest).
- The trim now applies the build's own value checks (dimensions, isUnscorable) before keeping an unread entry.
@shaunpatterson

Copy link
Copy Markdown
Contributor Author

On the CI failure of ecdcf2b88e (run 43753852032, job unit-tests (engine, engine, 2)):

  • CosineUnscorableMagnitudeIssue11635Test (2 failures): cosine([1.0, 1.0, 0.0, 0.0], [1.0E-25, 1.0E-25, 0.0, 0.0]) = Infinity
  • ProductQuantizationTest.anAllZeroVectorIsLeftOutOfTheGraphLikeBefore: jvector cosine assertion against an all-zero vector
  • VectorSearchCorrectnessTest.cosineKeepsAcceptingZeroPlaceholderVectors: cosine([0.01, 0.01], [0.0, 0.0]) = NaN

Each failure is jvector's VectorUtil.cosine assertion, reached from LSMVectorIndex$1.delta through mergeWithDeltaScan. Every build leaves unscorable vectors out of the graph on purpose (isUnscorable, #11635), and the post-build trim on ecdcf2b88e kept them in the delta, so the delta scan scored them. None of the three classes fails on main: locally on origin/main 2eb615cd26 they pass (5, 73 and 25 tests), and they fail on ecdcf2b88e with the same messages as in CI.

0526b8b makes the trim apply the build's own checks (dimensions and isUnscorable) before it keeps an unread entry. I checked that commit locally:

  • CosineUnscorable*, ProductQuantizationTest, VectorSearchCorrectnessTest and LSMVector*: 47 classes, 368 tests, 0 failures.
  • Issue11962VectorBuildDuringCommitIT (ha-raft, -Pintegration): 2 tests, 0 failures. That run was on the same trim with the isUnscorable check only, without the dimension check.

@shaunpatterson

Copy link
Copy Markdown
Contributor Author

Validated with the issue's vector_commit_window_build.py on the leader of a 3-node cluster. The image is 26.12.1-SNAPSHOT (main 04efccfcd3) plus this PR's engine change as of 0526b8b, together with #11939, #11977, #11987 and #11995. Each run is 60 s with 4 writers and 2 searchers on 16 buckets, INT8. The stock row is the one from the issue:

rows without a record, during the run k=all once a second for 30 s after the writers stopped
stock leader 213 of 47,122 19,755 → 19,757, never the 19,758 committed
patched leader, run 1 4 of 61,560 22,246 every second (22,246 committed)
patched leader, run 2 9 of 107,680 27,207 every second (27,207 committed)

Committed vectors are no longer missing. The rows without a record are the half of #11962 this PR does not address: a search during the commit window can still answer an in-flight record. The same cluster also passed three 18-minute application runs on this image, one plain, one with a leadership transfer and one with a leader SIGKILL. In each, the cross-node check converged and a deep check of 120 vector/full-text probes found 0 differences.

@shaunpatterson

Copy link
Copy Markdown
Contributor Author

Follow-up: #12087 builds on this PR and fixes the remaining half of #11962. Searches no longer answer, or miss, a vector whose commit is in flight.

@github-actions github-actions Bot added engine Core engine: document/schema API ha High availability / replication (Raft) has-issue The PR links an issue it resolves severity:major A feature is broken or returns wrong results, with no practical workaround triage:lgtm PR triage: nothing blocking, ready for a maintainer vector Vector index and embedding search labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Triage: triage:lgtm · severity:major · areas: vector, engine, ha · has-issue

Triage of #11969 (fixes the "committed vectors missing from searches" half of #11962).

What the change does

  • The post-build delta trim in LSMVectorIndex now also keeps delta entries from before the snapshot. An entry is kept when the build did not incorporate it, it is still live in the location index, and it passes the build's own value checks (dimensions and isUnscorable). This is what stops a vector from being lost when a graph build runs while a Raft commit is in flight.
  • The in-memory recovery (the Missing images when vector neighbors query #3722 "tertiary defense") now also runs after a document scan. It only adds live locations whose RID is not already in the set, so the extra cost is small.
  • Issue11962VectorBuildDuringCommitIT covers a dense and a sparse index. It runs a build from TEST_PRE_DISPATCH_HOOK and checks that the vector is found once the commit completes.

Review

  • Correctness: The logic is sound and well documented. The Arrays import is already present, and VectorLocationIndex.isLive exists. Arrays.binarySearch on finalActiveVectorIds depends on that array being sorted. The PR description says the build checks this, but I only saw the assignment at line 4138 and did not confirm the ordering. If the filtering step (filteredVectorIds) can reorder the ids, the trim would keep or drop the wrong entries. A one-line comment or assertion at the trim site would protect against that.
  • Tests: The new IT reproduces the race deterministically and has a regression variant for each fix. The PR reports the related engine suites passing. A fast engine-level unit test of the trim would also help. The IT needs a 3-node Raft cluster, so it is the only thing that guards this behaviour.
  • Security: Nothing concerning. The change is internal to the vector index and a test. The contributor is external, and I found nothing suspicious in the diff.
  • Performance: The extra work is a binary search plus an isLive lookup per delta entry, and only on the trim after a build. This is acceptable.
  • Conventions: The code and test follow the CLAUDE.md style (assertThat, final usage, no System.out). The test class is named *IT, which matches the other ha-raft ITs.

The PR deliberately leaves the other half of the issue open, where a search in the window can return an empty row. So #11962 should stay open, or be tracked separately. If the PR body contains Fixes #11962, GitHub will close the issue on merge. Consider changing it to Refs #11962.

@robfrank robfrank added the pr_approved review-pr: CI LGTM + clean triage + green sandbox tests on the reviewed head label Nov 16, 2026
@robfrank

Copy link
Copy Markdown
Collaborator

Automated review: approved

GitHub triage LGTM, triage clean, sandbox build and tests green. Merge is a maintainer decision.

Step Result
Triage clean
GitHub triage LGTM
Sandbox build and tests on 0526b8bb646a1ab36a769108f06fcde48cc0e48f green
Fix commits pushed none

@robfrank
robfrank merged commit ccf6bd4 into ArcadeData:main Nov 17, 2026
27 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Core engine: document/schema API ha High availability / replication (Raft) has-issue The PR links an issue it resolves pr_approved review-pr: CI LGTM + clean triage + green sandbox tests on the reviewed head severity:major A feature is broken or returns wrong results, with no practical workaround triage:lgtm PR triage: nothing blocking, ready for a maintainer vector Vector index and embedding search

Projects

None yet

2 participants