Skip to content

[Detail Bug] Search Reindex: live edits can lose updated vector chunks during staged chunk index promotion (multi-node) #35100

Closed

Description

@detail-app

Detail Bug Report

https://app.detail.dev/org_3377c26d-da48-4ccd-b83a-22c542f4fe83/bugs/bug_0ae28d4c-b854-42d2-af41-630ee3c3d175

Introduced in #34647 by @pmbrull on Oct 5, 2026

Summary

  • Context: OpenSearchVectorService runs a "staged" chunk-index recreate during a full reindex: it writes new chunk documents into a bare next-generation index (G1) and only atomically promotes it (alias swap + remove_index of the old target L0) once every vector-indexable entity type finalizes. While the recreate is in flight, live entity edits are routed through updateEntityEmbeddings, which writes the new chunks to the live alias (which during a recreate points at L0) and is supposed to mirror the same write into G1 so the edit survives promotion.
  • Bug: The live-edit mirror write goes through resolveChunkSinkTarget(), a discovery helper backed by a 15-second JVM-local cache that can hold null. On every JVM except the one running the reindex job, the in-JVM stagedChunkIndex field is null, so the mirror relies entirely on this cache. When the cache holds a stale null — because it was populated before the coordinator created G1 (including by a pre-recreate probe whose TTL hasn't expired) or because a transient cluster-state probe failed — mirrorToStagedGeneration silently no-ops, and the live edit is written only to L0, which promotion then remove_indexes.
  • Actual vs. expected: A live entity edit committed during a full reindex should still be present in the chunk index after the reindex promotes; instead its post-edit chunks are absent from G1, and semantic/vector search (searchChunksByParent) serves the pre-edit passages for that entity until the entity is edited again or the next full reindex runs.
  • Impact: Stale semantic/searchChunksByParent results for the affected entity. Keyword and entity-document search are unaffected (the entity doc carries its own post-edit embedding via partialUpdateEntity). The entity remains searchable with valid — but stale — passages, not missing entirely. The symptom self-heals on the next edit to that entity; for rarely-edited entities the stale window can persist until the next full reindex.

Code with Bug

In openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:

      if (refresh != ChunkRefresh.NONE) {
        replaceChunks(chunkIndexName, parentId, chunkDocs, previousCount(header));   // writes to the live alias, which points at OLD generation L0 during a recreate
        mirrorToStagedGeneration(parentId, chunkDocs);                               // <-- BUG 🔴 mirror can silently no-op when discovery cache returns stale null
      }
  private void mirrorToStagedGeneration(String parentId, List<Map<String, Object>> chunkDocs) {
    String staged = resolveChunkSinkTarget();
    if (staged != null) {
      try {
        replaceChunks(staged, parentId, chunkDocs, previousCount(getChunkHeader(staged, parentId)));
      } catch (IOException | RuntimeException e) {
        LOG.warn("Failed to mirror chunks for {} into staged {}: {}", parentId, staged, e.getMessage());
      }
    }                                  // <-- BUG 🔴 staged==null is silently skipped; live edit remains only in L0 and can be deleted on promotion
  }
  private static final long SINK_TARGET_CACHE_MS = 15_000;
  ...
  private String resolveChunkSinkTarget() {
    String target = stagedChunkIndex;                       // null on every non-coordinator JVM
    if (target == null) {
      long now = System.currentTimeMillis();
      if (now - cachedSinkTargetAt > SINK_TARGET_CACHE_MS) {
        cachedSinkTarget = findActiveStagedGeneration();    // returns null when no un-promoted *_g* index exists, or on a transient probe failure (caught at :693, logged only at DEBUG)
        cachedSinkTargetAt = now;
      }
      target = cachedSinkTarget;                            // <-- BUG 🔴 returns cached null for up to 15s, preventing mirroring during recreate
    }
    return target;
  }

Explanation

During a staged chunk-index recreate in a multi-node deployment, user edits may be handled by JVMs that are not running the reindex job. On those JVMs, stagedChunkIndex is unset, so mirrorToStagedGeneration() depends on resolveChunkSinkTarget().

resolveChunkSinkTarget() can return a cached null for up to 15 seconds (either because it cached null before G1 existed, or because findActiveStagedGeneration() transiently failed and returned null). When this happens, the mirror write is skipped without any warning.

Meanwhile updateEntityEmbeddings() still writes the updated chunks to the live alias, which during recreate points at the old generation (L0). When the recreate is promoted, the promotion action removes L0 (remove_index). If the reindex sink already streamed that entity (pre-edit) into G1, the post-edit chunks are never present in G1 after promotion, producing stale searchChunksByParent results until the next edit or full reindex.

Codebase Inconsistency

  • Reindex sink writes (writeEntityChunks / backfillEntityChunks) receive the run-scoped staged target explicitly via ReindexContext.getStagedChunkIndex() and do not use discovery.
  • Live-edit mirroring (mirrorToStagedGeneration) uses resolveChunkSinkTarget() (the lossy discovery + null cache path).
  • resolveChunkSinkTarget’s javadoc states it “only serves deletes,” indicating the helper was not intended for write-path correctness after the mirror call site was added.

Recommended Fix

Latch the run-scoped staged chunk index from the participant’s ReindexContext into a JVM-local field used by resolveChunkSinkTarget() (e.g., set cachedSinkTarget / cachedSinkTargetAt) for the duration of the run, so live-edit mirroring does not depend on best-effort cluster discovery.

Constraint: do not set stagedChunkIndex on participants, because that field is used to gate promotion (markEntityTypeReindexed) and is coordinator-only.

As a stopgap, add a WARN log when mirrorToStagedGeneration cannot resolve a staged target (today it silently skips).

History

This bug was introduced in commit fd05475. PR #34647 ("Fixes #34394: Add memory lifecycle and status filtering") added the mirrorToStagedGeneration method and its call site at OpenSearchVectorService.java:330 to prevent live edits from being stranded in the old generation during a staged chunk recreate. The change routed the mirror write through the existing resolveChunkSinkTarget() discovery helper — a 15-second JVM-local null cache designed only for the delete path (deleteEntityChunks, where a null is harmless) — instead of threading the run-scoped staged target from ReindexContext the way sink writes already did. The silent if (staged != null) skip with no else branch or log meant that when the cache held a stale null on a non-coordinator JVM, the mirror would no-op without any signal, leaving the live edit stranded in the soon-to-be-remove_indexed old generation. The PR also did not update the resolveChunkSinkTarget javadoc, which still reads "this only serves deletes," masking the new write-path call site from anyone reading the code.

Activity

  1. added a commit that references this issue on Oct 11, 2026
    15da1d6
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