Skip to content

Every step ArcadeTraversalStrategy swaps in is added without the replaced step's labels, so an as() on a rewritten step disappears and the select() that reads it yields nothing #8258

Closed

Description

@ruispereira

Summary

ArcadeTraversalStrategy replaces steps in five places, and every one of them uses the same two-call
idiom:

    traversal.removeStep(i);
    traversal.addStep(i, newStep);

A TinkerPop step carries its as() labels in Step.getLabels(), and removeStep takes them away
with the step. The standard idiom for exactly this situation is
TraversalHelper.copyLabels(oldStep, newStep, false), which this module never calls. So a label
attached to a replaced step is gone from the compiled traversal, and the select(), path() or
where() that names it later finds nothing - as an empty result, not as an error, because
SelectOneStep simply produces no traverser for a label no step declares.

The five sites are the type filter, the index filter, the count step, the GAV vertex step and the GAV
fused step. Which of them is observable depends on where TinkerPop has settled the label by the time
this strategy runs (it is a ProviderOptimizationStrategy, so it runs last): a label on a GraphStep
often ends up on the surviving HasStep instead and is therefore safe. The count rewrite has no such
escape - it deletes the CountGlobalStep the label is attached to.

Where (HEAD 6fefb26)

gremlin/src/main/java/com/arcadedb/gremlin/ArcadeTraversalStrategy.java:175, the count arm, which
removes three steps including the labelled one:

              if (((HasStep<?>) step).getHasContainers().isEmpty() &&
                  i + 1 < steps.size() && steps.get(i + 1) instanceof CountGlobalStep) {
                traversal.removeStep(i - 1);
                traversal.removeStep(i - 1);
                replaceWith = new ArcadeCountGlobalStep(step.getTraversal(), prevStepGraph.getReturnClass(), typeNameToMatch);

and line 188, the shared tail:

            if (replaceWith != null) {
              traversal.removeStep(i - 1);
              traversal.addStep(i - 1, replaceWith);
            }

The same pattern at ArcadeTraversalStrategy.java:229 (ArcadeGAVVertexStep), :255 (the fused
step, which removes a whole chain) and :321 (ArcadeEdgeCountFilterStep).

Repro

Embedded graph on HEAD, one vertex type Person with two vertices. Behaviour:

g.V().hasLabel('Person').count()                     -> 2
g.V().hasLabel('Person').count().as('c').select('c') -> java.util.NoSuchElementException
g.V().count().as('c').select('c')  [no hasLabel]     -> 2

and the compiled traversals, printed after applyStrategies(), show exactly where the label went:

STEPS [ArcadeCountGlobalStep(vertex), SelectOneStep(last,c,null)]   labels=[[], []]
STEPS [GraphStep(vertex,[]), CountGlobalStep@[c], SelectOneStep(last,c,null)]   labels=[[], [c]]

The second line is the un-rewritten traversal, with CountGlobalStep@[c]; the first is the rewritten
one, where ArcadeCountGlobalStep carries no label at all and select('c') consequently has nothing
to select.

Tried to refute it. (a) Maybe select() after count() is simply not a legal shape: the control
line shows it returning 2 when the strategy does not fire, and the only difference between the two is
the hasLabel. (b) Maybe TinkerPop re-attaches a lost label somewhere: the printed labels=[[], []]
says it does not, and the case where a GraphStep label survives is one where TinkerPop had ALREADY
moved it onto the HasStep before this strategy ran - printed as HasStep@[a] - not one where it is
recovered afterwards. (c) Maybe the empty result is the exception being swallowed elsewhere: the
NoSuchElementException is next() on an empty result; toList() on the same traversal returns an
empty list.

Suggested fix

Call TraversalHelper.copyLabels(oldStep, newStep, false) at each of the five replacement sites
before dropping the old step; for the fused step, the labels of every step in the chain have to be
merged onto the fused one, or - better - the chain must not be fused at all when any step but the
last one carries a label, since a fused chain cannot produce the intermediate traversers that a label
on an intermediate hop promises. path() over a fused chain has the same problem for the same
reason and deserves the same guard.

Scope / confidence

The count case is reproduced. The other four sites are the identical idiom and are reported from the
code rather than from a run: the GAV pair additionally needs a registered graph analytical view, and
the edge-count arm is documented in the class as currently unreachable. Silent in all cases - an
empty result or a short path, never an error naming the label.


Activity

  1. added
    severity:major
    on Sep 23, 2026
  2. added this to the 26.10.1 milestone on Sep 23, 2026
  3. added
    in progress
    on Sep 24, 2026
  4. self-assigned this
    on Sep 24, 2026
  5. added 3 commits that reference this issue on Sep 24, 2026
  6. lvca commented on Sep 25, 2026

    @lvca
    Member

    Fixed in #8309, available in 26.10.1.

    An as() label on a step that ArcadeDB's Gremlin optimizer rewrites is now kept, so select(), path() and where() find it again (e.g. g.V().hasLabel('Person').count().as('c').select('c') returns the count).

    The optimizer also no longer merges several hops into one step when an intermediate hop is labelled or when the query asks for path(), including when those hops are inside local(), since the merged step cannot produce those intermediate results.

    As in standard TinkerPop, a label placed before count() does not survive the count.


    ❤️ 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 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buggremlinseverity:major

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions