Skip to content

[Detail Bug] Lineage API returns wrong cached graphs when pagination or includeDeleted differs #37314

Done

Description

@detail-app

Detail Bug Report

https://app.detail.dev/org_3377c26d-da48-4ccd-b83a-22c542f4fe83/bugs/bug_f4cb4c00-1675-412c-91d4-1d12945739d9

Introduced in #24919 by @mohityadav766 on Dec 21, 2025

Summary

  • Context: GuavaLineageGraphCache caches built lineage graphs server-side (enabled by default, 5-minute TTL) so repeated /v1/lineage/getLineage calls skip expensive Elasticsearch traversal.
  • Bug: LineageCacheKey.fromRequest() builds the cache key from only a subset of SearchLineageRequest fields — it omits layerFrom, layerSize, includeDeleted and includeSourceFields, even though the graph built by ESLineageGraphBuilder/OSLineageGraphBuilder depends on all four.
  • Actual vs. expected: Two requests differing only in these fields produce identical cache keys, so the second caller is served the first caller's cached graph (e.g. within /getLineage, a from=100&size=50 request receives the graph built for from=0&size=1000; direction is keyed, so /getLineage and /getLineage/{direction} never collide with each other); expected behavior is a distinct cache entry per distinct request variant.
  • Impact: Users silently receive wrong lineage graphs — wrong pages of edges, or graphs containing (or missing) deleted entities — for up to the TTL after a variant that differs only in pagination or includeDeleted warms the cache.

Code with Bug

openmetadata-service/src/main/java/org/openmetadata/service/search/lineage/LineageCacheKey.java:

/**
 * ...
 * All fields that affect the lineage result must be included in the key.   // <-- BUG 🔴 key omits request fields that affect results
 */
public static LineageCacheKey fromRequest(SearchLineageRequest request) {
  ...
  return new LineageCacheKey(
      request.getFqn() != null ? request.getFqn() : "",
      request.getUpstreamDepth() != null ? request.getUpstreamDepth() : 0,
      request.getDownstreamDepth() != null ? request.getDownstreamDepth() : 0,
      request.getQueryFilter() != null ? request.getQueryFilter() : "",
      request.getColumnFilter() != null ? request.getColumnFilter() : "",
      request.getPreservePaths() != null ? request.getPreservePaths() : Boolean.TRUE,
      request.getDirection() != null ? request.getDirection().value() : "",
      request.getIsConnectedVia() != null ? request.getIsConnectedVia() : Boolean.FALSE,
      0,               // from            <-- BUG 🔴 hardcoded, not request.getLayerFrom()
      0,               // size            <-- BUG 🔴 hardcoded, not request.getLayerSize()
      0,
      Boolean.FALSE,
      0,
      0,
      request.getStartTime(),
      request.getendTime());           // <-- BUG 🔴 includeDeleted/includeSourceFields also not in key
}

openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ESLineageGraphBuilder.java (mirrored in OSLineageGraphBuilder.java):

List<EsLineageData> paginatedUpstreamEntities =
    paginateList(
        upStreamEntities, lineageRequest.getLayerFrom(), lineageRequest.getLayerSize());

SearchRequest searchRequest =
    EsUtils.getSearchRequest(
        lineageRequest.getDirection(),
        GLOBAL_SEARCH_ALIAS,
        lineageRequest.getQueryFilter(),
        GRAPH_AGGREGATION,
        directionKeyAndValues,
        lineageRequest.getLayerFrom(),
        lineageRequest.getLayerSize(),
        lineageRequest.getIncludeDeleted(),    // <-- BUG 🔴 affects ES query but not cache key
        ...);

Explanation

  • The server-side cache uses LineageCacheKey.fromRequest() to index cached lineage graphs.
  • ESLineageGraphBuilder/OSLineageGraphBuilder build results using layerFrom/layerSize (pagination) and includeDeleted (ES filtering); includeSourceFields affects hydration.
  • Because these fields are not incorporated into the cache key, different request variants collide and the cache can return a graph built for a different from/size/includeDeleted/includeSourceFields combination.
  • On a cache hit, the builder returns the cached result verbatim (return cached.get();) with no post-cache pagination/normalization, so incorrect results are served for up to the TTL.

Codebase Inconsistency

  • LineageCacheKey’s javadoc explicitly states: “All fields that affect the lineage result must be included in the key.”
  • The UI-side lineage scene cache (LineageSceneCache, documented in docs/perf/lineage-scale-validation.md) intentionally keys on parameters including size and includeDeleted, indicating the server-side omission is not an accepted design.

Recommended Fix

  • Include layerFrom, layerSize, and includeDeleted in LineageCacheKey and populate them from the request in fromRequest() so distinct request variants get distinct cache entries.
  • Decide how to handle includeSourceFields: either add it to the key or re-hydrate node payload post-cache if the cached graph is meant to be source-field-agnostic.
  • Update tests that currently assert fromRequest hardcodes pagination fields (e.g., testFromRequestDefaultsPaginationFields).

History

This bug was introduced in commit 9c80936 ("Lineage Improvements (#24919)", Mohit Yadav, Dec 2025). That PR introduced server-side lineage result caching (GuavaLineageGraphCache, AbstractLineageGraphBuilder.checkCache/cacheResult, enabled by default via LineageGraphConfiguration) along with LineageCacheKey.fromRequest() — and from day one the key contained only fqn, depths, queryFilter, columnFilter, preservePaths, direction and isConnectedVia, with no layerFrom/layerSize/includeDeleted/includeSourceFields fields at all, even though the surrounding code in the same commit (ESLineageGraphBuilder/OSLineageGraphBuilder) builds the cached graph from paginateList(..., getLayerFrom(), getLayerSize()) and ES queries filtered by getIncludeDeleted(), and serves cache hits verbatim.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done ✅

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions