Skip to content

algo.* procedures silently coerce an unrecognised direction to BOTH instead of rejecting it #6976

Closed

Description

@robfrank

Problem

GraphEngine.parseDirection coerces any unrecognised direction string to BOTH:

public static Vertex.DIRECTION parseDirection(final String dir) {
  if (dir == null)
    return Vertex.DIRECTION.BOTH;
  return switch (dir.toUpperCase()) {
    case "OUT" -> Vertex.DIRECTION.OUT;
    case "IN"  -> Vertex.DIRECTION.IN;
    default    -> Vertex.DIRECTION.BOTH;   // <-- 'INCOMING', 'outgoing', 'nope', ''
  };
}

So CALL algo.bfs(startNode, 3, 'INCOMING') traverses both directions and returns a plausible-looking result. The caller asked one question and got the answer to a different one, with nothing to indicate the substitution. A typo in a direction is silently a semantic change, not an error.

This affects roughly 23 algo.*/path procedures that route their direction argument through the shared helper, including algo.bfs, algo.dfs, algo.degree, algo.closeness, algo.harmonic, algo.eccentricity, algo.eigenvector, algo.jaccard, algo.commonNeighbors, algo.adamicAdar, algo.resourceAllocation, algo.preferentialAttachment, algo.totalNeighbors, algo.knn, algo.randomWalk, algo.node2vec, algo.fastrp, algo.hashgnn, algo.graphsage, algo.maxkcut, algo.labelPropagation, algo.dijkstra, algo.dijkstraSingleSource. AlgoLabelPropagation also carries its own local copy of the same pattern.

Why now

This is longstanding and was low-impact for as long as the direction values were near-interchangeable in practice. #6956 changed that for PageRank: direction: 'IN' had been returning OUT's scores on one of the two execution paths, and once fixed the three values demonstrably produce different answers. The same PR added rejection locally in AlgoPageRank rather than tightening the shared helper, precisely because the shared change reaches ~23 other procedures and deserved its own issue. That is this issue.

The wider lesson from #6956 is the relevant one: a direction that silently degrades to something plausible is exactly how a direction bug survives unnoticed for a long time.

Proposed fix

Reject unrecognised values by name instead of coercing:

throw new IllegalArgumentException("unknown direction '" + dir + "', expected one of OUT, IN or BOTH");

matching the IllegalArgumentException style AbstractAlgoProcedure already uses for its other config knobs, and the "reject, do not silently clamp — there is no correct value to fall back to" precedent set for the numeric bounds in #6065.

Things to settle before implementing

  1. Keep null meaning BOTH. Every current caller relies on an absent argument defaulting through this helper, so null must stay a legal "use the default". Only a present but unrecognised value should be rejected. Note the default here is BOTH, whereas AlgoPageRank's own default is OUT — do not unify those two without checking each procedure, they are separately meaningful.
  2. parseDirection is public API on GraphEngine. Check for callers outside the procedure package before changing its contract.
  3. AlgoLabelPropagation's local copy needs the same treatment, or should be routed through the shared helper.
  4. It is a behaviour change. Anything today passing a malformed direction and quietly getting BOTH starts getting an error. That is the point, but it belongs in the release notes.
  5. Test coverage. AlgoPageRankTest.pageRankRejectsAnUnrecognisedDirection (added in fix(pagerank): honor IN direction in OLTP and CSR paths #6956) is a usable template — it pins both the rejected shapes ('INCOMING', 'OUTGOING', trailing whitespace, empty string, a non-string) and that all three valid values in either case still work.

Related

Activity

  1. added
    engine
    on Sep 1, 2026
  2. added this to the 26.9.1 milestone on Sep 1, 2026
  3. added
    in progress
    on Sep 1, 2026
  4. self-assigned this
    on Sep 1, 2026
  5. added 2 commits that reference this issue on Sep 1, 2026
  6. lvca commented on Sep 2, 2026

    @lvca
    Member

    Fixed in #7001.

    algo.* procedures and path functions used to accept any direction string and silently fall back to BOTH when they didn't recognise it. So a typo like direction: 'INCOMING' instead of 'IN' gave you a plausible-looking answer to a question you never asked, with no error to hint at it.

    They now reject anything that isn't OUT, IN or BOTH (case doesn't matter):

    CALL algo.bfs(start, 'ROAD', 'INCOMING', 3)
    -> unknown direction 'INCOMING', expected one of OUT, IN or BOTH
    

    Omitting the direction still works as before and uses each procedure's own default.

    Two other places carried the same bug and are fixed too: the bellmanFord() SQL function, and node.degree() / node.relationship.exists() / node.relationship.types().

    Heads up: this is a behaviour change. If a query of yours passes a malformed direction today, it has been quietly running with BOTH and will now fail instead. That is the point of the fix, but it's worth checking your saved queries.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 2, 2026
  8. added a commit that references this issue on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengineopencypher

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions