Skip to content

fix(engine): a dangling vertex reference is a not-found, not a conflict to retry (#6572) - #6576

Merged
lvca merged 1 commit into
mainfrom
fix/6572-dangling-vertex-reference
Aug 22, 2026
Merged

lvca merged 1 commit into
mainfrom
fix/6572-dangling-vertex-reference

Conversation

@lvca

@lvca lvca commented Aug 22, 2026

Copy link
Copy Markdown
Member

Fixes #6572.

The problem

GraphEngine.getEdgeHeadChunkForWrite wrapped every RecordNotFoundException from its lazy vertex load into the retryable ConcurrentModificationException that #5670 invented for a head chunk a concurrent commit has not published yet. The reported failure named the same RID in both halves:

ConcurrentModificationException: Edge list OUT of vertex #98:4138 is not fully visible yet
(concurrent commit in flight): Record #98:4138 not found. If it persists once the retries are
spent the list is genuinely broken: run `CHECK DATABASE RECORD #98:4138 FIX` to rebuild its
edge list from the surviving edge records, then retry the delete

Single-threaded job, nothing else writing. The vertex was reached through a dangling adjacency entry - one whose target record was removed without the entry being disconnected, the documented legacy of a pre-#5670 best-effort edge delete. Two things were wrong at once, and both hurt a batch job:

  • the type said "retry me" for a record that is gone, so every attempt failed identically, the retry budget was spent on a foregone conclusion, and the whole transaction rolled back with no work committed - one stale reference killing a nightly sweep, permanently;
  • the advice said CHECK DATABASE RECORD <rid> FIX, which rebuilds the edge list of that record from the surviving edges, while that record is precisely the one that no longer exists.

The fix

The evidence separating the two cases was already on the exception: the RID it names. A missing head chunk, mid-chain chunk or stripe head really can be the publication window; the vertex the caller asked to modify cannot.

When the cause names the vertex's own RID, the read now raises the new VertexNotFoundException - a RecordNotFoundException, deliberately not a NeedRetryException:

Vertex #98:4138 does not exist, so its OUT edge list cannot be modified: it was reached through
a reference to a record that is gone (a stale edge entry, or a RID held past the delete).
Retrying cannot make it exist: run `CHECK DATABASE FIX` to drop the adjacency entries that still
point at it - the RECORD scope cannot help here, since the edge list it would rebuild belongs to
the record that is gone, and the entry to drop lives on the vertex at the other end, which only
a sweep can find

Everything else keeps the #5670 conflict and the #5764 scoped advice, unchanged.

Two deliberate details:

  • The RECORD scope is ruled out in words, not rendered as a command. An operator who met the old message has to be told it was the wrong tool, but a message that spells the command out with the RID substituted in is one a hurried reader (or a log grep) pastes into a console anyway. Same line Follow-ups from #5680: point the repair advice at CHECK DATABASE RECORD, keep the conflict's cause, and two checker asymmetries #5764's danglingRepairAdvice already draws.
  • The referrer cannot be named at the throw site. A vertex handle carries no back-pointer to the list it was read from, and no index maps a vertex back to the lists that name it. That is exactly why the repair has to be a sweep.

Deleting a missing vertex stays an error

Asked in the issue, answered here rather than silently: it stays an error, not a tolerated no-op. bucket.deleteRecord raises not-found for every other record shape - and for this vertex a few steps further down the very same delete - so tolerating it in the graph path alone would relocate the asymmetry while hiding the one thing the caller needs to know. deleteEdge's ALREADY DELETED: IGNORE IT arm is narrower than it reads: it covers only the final physical removal, after both disconnections are done, because a self-loop is walked from both of the vertex's lists and reaches it twice.

What changes is that the failure says what is wrong, and that a caller walking possibly-stale references can now tell "this will never work" from "try again" by catching RecordNotFoundException, and skip the entry instead of losing the batch.

One tolerance moves with it: disconnectEndpoint catches the new exception and treats it as "nothing to disconnect on that side" - the same answer resolveEndpointToDisconnect's existsRecord probe already gives. The probe and the head-pointer read are two reads with a gap, so the same fact can surface between them. The probe stays: a handle materialised earlier in the transaction answers its head pointer from its own buffer and raises nothing at all, so neither check replaces the other.

Verification

Issue6572DanglingVertexReferenceTest (5 tests):

  • the reported repro, with no concurrency: type, RID, cause chain and advice;
  • the retry budget is counted, not inferred - the block runs exactly 1 of the 3 attempts offered;
  • the advice is executed, not asserted: the test runs CHECK DATABASE FIX, then the delete that could not proceed completes and check database reports clean;
  • two guards so the fix cannot creep: an unreadable chunk on a vertex that exists keeps its retryable conflict and its CHECK DATABASE RECORD <vertex> FIX, and an edge whose endpoint vertex is gone still deletes.

Confirmed non-vacuous: 3 of the 5 fail against the unmodified engine.

Issue5670EdgeDeleteDanglingBackRefTest.headChunkForWriteRaisesRetryableConflictWhenTheVertexItselfVanishes pinned the old contract and is corrected in place (renamed to ...RaisesANonRetryableNotFound...), with the reasoning that led to it rewritten rather than deleted.

Green: 326 graph tests (including the slow-tagged concurrent #5670 rounds), 2946 database + SQL, 4934 openCypher, 186 root-package, full-project compile.

Issue6301AlgoSteinerTreeWeightAlignmentTest.anActiveOverlayDoesNotLendItsWeightsToTheWrongEdges fails on this branch and fails identically on main with this change stashed - pre-existing and unrelated.

Wire-visible consequence

ErrorCategory for this case moves from RETRY to NOT_FOUND, so HTTP answers 404 instead of a conflict, and every other protocol its not-found vocabulary. That is the intended verdict: the record does not exist.

…ct to retry (#6572)

getEdgeHeadChunkForWrite wrapped EVERY RecordNotFoundException from its lazy
vertex load into the retryable ConcurrentModificationException #5670 invented
for a head chunk a concurrent commit has not published yet. When the missing
record was the VERTEX itself - reached through an adjacency entry whose target
was removed without the entry being disconnected, the documented legacy of a
pre-#5670 best-effort edge delete - that was wrong twice over: the type said
"retry me" for a record that is gone, so every attempt failed identically and
the whole transaction rolled back with no work committed, and the advice named
`CHECK DATABASE RECORD <rid> FIX`, whose job is to rebuild the edge list OF the
record that no longer exists.

The evidence separating the two cases was already on the exception: the RID it
names. A missing chunk (or stripe head) really can be the publication window;
the vertex the caller asked to modify cannot. When the cause names the vertex's
own RID the read now raises VertexNotFoundException - a RecordNotFoundException,
deliberately not a NeedRetryException - saying the vertex does not exist and
pointing at `CHECK DATABASE FIX`, which sweeps and drops the entries pointing at
missing records. The RECORD scope is ruled out in words rather than rendered as
a runnable command: the entry to drop lives on the vertex at the other end, and
a message that spells out a command with the RID substituted in is one a hurried
reader pastes into a console anyway. Everything else keeps the #5670 conflict and
the #5764 scoped advice unchanged.

Deleting a vertex whose record is already gone therefore stays an ERROR rather
than becoming a silent no-op: bucket.deleteRecord answers exactly that for every
other record shape, and for this vertex a few steps further down the same delete,
so tolerating it here would only hide the corruption. What changes is that the
error says what is wrong, and that a caller can tell "this will never work" from
"try again" by catching RecordNotFoundException.

disconnectEndpoint tolerates the new exception the same way resolveEndpointToDisconnect
already tolerates an endpoint that is gone: its existsRecord probe and the
head-pointer read are two reads with a gap, so the fact can surface between them.
The probe stays - a handle materialised earlier in the transaction answers its head
from its own buffer and raises nothing at all - and neither replaces the other.

Tests: Issue6572DanglingVertexReferenceTest pins the reported repro, counts that
the retry budget is not spent (1 attempt of 3 offered), and RUNS `CHECK DATABASE
FIX` to prove the advertised repair is the one that works. The two guard tests
keep the chunk case retryable with its scoped advice, and an edge whose endpoint
vertex is gone still deletes. Issue5670EdgeDeleteDanglingBackRefTest's
headChunkForWrite test pinned the old contract and is corrected in place.
@codacy-production

codacy-production Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity

Metric Results
Complexity 5

View in Codacy

🟢 Coverage 64.29% diff coverage · -6.54% coverage variation

Metric Results
Coverage variation ✅ -6.54% coverage variation
Diff coverage ✅ 64.29% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (17baebd) 164623 131671 79.98%
Head commit (63ca390) 197022 (+32399) 144690 (+13019) 73.44% (-6.54%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6576) 14 9 64.29%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

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.

@mergify

mergify Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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

  • Queue this pull request

@claude

claude Bot commented Aug 22, 2026

Copy link
Copy Markdown

Review

I traced this fix through the full call graph (getEdgeHeadChunkForWrite -> disconnectEndpoint/deleteEdgesOf/deleteVertex -> ErrorCategory/HTTP handler) and it holds together well. Summary below.

Correctness

  • The RID-equality discriminator in getEdgeHeadChunkForWrite (vertexRID != null && vertexRID.equals(e.getRID())) is the right piece of evidence, and it's used safely: RID.equals(null) returns false, so a cause with no RID correctly falls through to the existing ConcurrentModificationException arm rather than NPE'ing.
  • VertexNotFoundException deliberately is not caught by deleteEdgesOf's catch (NeedRetryException e) (it only extends RecordNotFoundException), so it correctly propagates out of deleteVertex uncaught - matching the "stays an error, including under force" design called out in the PR body. Confirmed against tolerateUnreadableEdgeList's updated javadoc, which states this explicitly.
  • disconnectEndpoint's new catch (VertexNotFoundException e) is scoped narrowly to the getEdgeHeadChunkForWrite call, so a RecordNotFoundException raised elsewhere in that block (e.g. a genuinely unreadable chunk of a list that does exist) still surfaces as the retryable conflict - the catch doesn't over-widen.
  • ErrorCategory.of() needed no changes for the wire-visible 404: NeedRetryException is checked before RecordNotFoundException in the CauseChain-based classification, and CauseChain.contains uses isInstance (not exact-class), so VertexNotFoundException correctly falls through to NOT_FOUND automatically. Same story in AbstractServerHttpHandler.sendMappedErrorResponse - the NeedRetryException arm precedes the RecordNotFoundException arm there too, so no wire-layer edit was needed. Nice that the type hierarchy alone does the right thing across both classification paths.
  • The self-loop interaction in deleteEdgesOf/deleteEdgeOfDeletedVertex looks correctly kept apart: a self-loop edge is walked from both of the vertex's lists, and the second pass's plain "already deleted" RecordNotFoundException isn't conflated with this new type anywhere I could find.

Test coverage

Issue6572DanglingVertexReferenceTest is thorough: it pins the reported repro (type/RID/cause chain/advice), counts that the retry budget is not spent (asserts exactly 1 of 3 offered attempts), actually runs CHECK DATABASE FIX and confirms the delete then succeeds (rather than just asserting the advice string), and includes two guard tests so the fix can't creep into the legitimate chunk-unreadable/retryable case or the already-tolerated endpoint-gone edge delete. That guard pair is exactly the right regression insurance for a change this close to #5670/#5764. The correction to Issue5670EdgeDeleteDanglingBackRefTest (renamed rather than deleted, with the old reasoning preserved in a comment explaining why it was wrong) is a good way to keep the history of why the contract changed.

Minor / non-blocking

  • missingVertexRepairAdvice() and danglingRepairAdvice() both point at whole-database CHECK DATABASE FIX for two different underlying reasons (edge survives past a refused delete vs. vertex itself is gone). Not a functional problem - the messages are worded differently and dedicated tests distinguish them - just flagging that a reader skimming only the advice strings could conflate the two scenarios. The surrounding javadoc already covers this well, so no action needed.
  • The new VertexNotFoundException class is minimal and matches the existing exception style in the package (same constructor shape as RecordNotFoundException).

Nothing else found

No security concerns (purely internal exception classification), no performance concerns (same number of reads on the hot path, only the exception type differs on an already-exceptional branch), and no dependency/license changes.

Well-scoped fix with strong regression coverage - the PR description's engineering rationale checks out against the actual diff.

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.27%. Comparing base (17baebd) to head (63ca390).

Files with missing lines Patch % Lines
.../src/main/java/com/arcadedb/graph/GraphEngine.java 50.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6576      +/-   ##
==========================================
- Coverage   71.29%   71.27%   -0.02%     
==========================================
  Files        1867     1868       +1     
  Lines      164623   164635      +12     
  Branches    34794    34795       +1     
==========================================
- Hits       117372   117349      -23     
- Misses      32993    33031      +38     
+ Partials    14258    14255       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lvca lvca self-assigned this Aug 22, 2026
@lvca lvca added this to the 26.9.1 milestone Aug 22, 2026
@lvca
lvca merged commit c6e06de into main Aug 22, 2026
30 of 33 checks passed
@lvca
lvca deleted the fix/6572-dangling-vertex-reference branch August 22, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GraphEngine.getEdgeHeadChunkForWrite reports a dangling vertex reference as a retryable conflict, with repair advice aimed at the record that is gone

1 participant