Skip to content

Fix multi-node search inconsistency: preference + deterministic sort tiebreaker - #29503

Merged
harshach merged 4 commits into
mainfrom
harshach/multinode-search-consistency
Jun 26, 2026
Merged

harshach merged 4 commits into
mainfrom
harshach/multinode-search-consistency

Conversation

@harshach

@harshach harshach commented Jun 26, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #

On a multi-node OpenSearch/Elasticsearch cluster the same query could return reordered or different results across requests, because reads bounced between shard copies (no preference was ever set) and the default relevance sort had no total-order tiebreaker, so equal-scored docs ordered differently per replica. This PR pins each authenticated user's searches to one shard copy via a preference routing key (SearchUtils.searchPreferenceFor, threaded through OpenSearch/ElasticSearchRequestBuilder and both search managers) and always appends a deterministic name.keyword + id.keyword sort tiebreaker on every sort path (including the default and non-_score paths, where docs commonly tie). Together these make repeated/paginated searches return stable, identical ordering across replicas.

Type of change:

  • Bug fix

High-level design:

No new API surface: preference is derived from the request's SubjectContext (per-user key) so a session pins to one shard copy without changing endpoints, and the sort change reuses the existing keyword-tiebreaker logic, extending it to the previously-uncovered default/non-_score sort paths. Behavior is unchanged on a single-node/single-shard cluster.

Tests:

Use cases covered

  • Repeated identical search on a multi-node cluster returns the same result set/order (no "bouncing").
  • Read-after-write for a given user resolves to the same shard copy.
  • Default (totalVotes) and relevance (_score) sorts produce a stable total order across replicas.

Unit tests

  • Not added in this PR — change is in the request-building/sort path; covered by existing search ITs. Multi-node ordering is best validated against a replicated cluster (see manual testing).

Backend integration tests

  • Not applicable (no new/changed API endpoint; internal request-building only).

Manual testing performed

  • Compiled openmetadata-service and verified spotless is clean.
  • Recommended cluster check: with number_of_replicas >= 1, run the same query repeatedly and paginate during ingestion — ordering stays stable with preference set.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.

Greptile Summary

This PR fixes search result instability on multi-node OpenSearch/Elasticsearch clusters by (1) deriving a per-user preference routing key that pins each user's requests to one shard copy, and (2) always appending a deterministic name.keyword + id.keyword sort tiebreaker so equal-scored documents order identically across replicas.

  • SearchUtils.searchPreferenceFor computes a stable routing key from the authenticated user's name; appendPreferenceParam URL-encodes it onto raw _search endpoints, while the request-builder path sets it on the builder directly.
  • The sort-handling block in both ElasticSearchSearchManager and OpenSearchSearchManager is restructured: the outer guard is now !Boolean.TRUE.equals(isHierarchy) (null-safe), an explicit _score desc + tiebreaker is added when no sortFieldParam is supplied, and appendDeterministicTiebreak guards against duplicating the primary sort field.
  • VectorIndexService gains a backward-compatible default overload so existing callers that don't supply a preference compile without changes.

Confidence Score: 5/5

Safe to merge — all changes are internal request-building logic with no new API surface, and the null-safety regression that existed before this PR is correctly resolved with !Boolean.TRUE.equals(...).

The two mechanical changes — pinning a per-user preference key and always appending name.keyword/id.keyword tiebreakers — are narrow and well-contained. The appendDeterministicTiebreak guard logic correctly skips the field that is already the primary sort key. The VectorIndexService default overload preserves backward compatibility cleanly. No new error paths, no schema or API changes, and behavior on a single-node cluster is unchanged.

No files require special attention; the most complex logic is in the two search manager files and the appendDeterministicTiebreak helper, both of which read correctly.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/search/SearchUtils.java Adds searchPreferenceFor (returns user's display name) and appendPreferenceParam (URL-encodes preference onto raw endpoints). Both methods are null-safe and straightforward.
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java Restructures sort handling to always apply deterministic tiebreaker; outer hierarchy guard changed to null-safe !Boolean.TRUE.equals(...); isExport dead parameter removed; preference wired in.
openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java Mirrors the ElasticSearch manager changes: null-safe hierarchy guard, always-applied tiebreaker via appendDeterministicTiebreak, preference set on builder.
openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorIndexService.java Adds a default overload without preference for backward compatibility, while the new abstract method requires String preference — clean interface evolution.
openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java Accepts preference parameter and routes it through appendPreferenceParam to the raw _search endpoint URL.
openmetadata-service/src/main/java/org/openmetadata/service/resources/search/VectorSearchResource.java Captures subjectContext (previously discarded) and passes searchPreferenceFor(subjectContext) to the vector search call.
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchRequestBuilder.java Adds preference field with fluent setter/getter and wires it into the SearchRequest builder with a null/empty guard.
openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchRequestBuilder.java Same as the ES counterpart — adds preference field with fluent API, applied in build() only when non-null/non-empty.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Client
    participant SearchResource
    participant SearchManager as OpenSearch/ElasticSearch SearchManager
    participant RequestBuilder as Request Builder
    participant Cluster as ES/OpenSearch Cluster

    Client->>SearchResource: "GET /search?q=..."
    SearchResource->>SearchResource: getSubjectContext(securityContext)
    SearchResource->>SearchManager: search(request, subjectContext)
    SearchManager->>SearchManager: SearchUtils.searchPreferenceFor(subjectContext) → user.getName()
    SearchManager->>RequestBuilder: requestBuilder.preference(userName)
    SearchManager->>RequestBuilder: appendDeterministicTiebreak(sortField)
    RequestBuilder->>Cluster: "SearchRequest{preference=userName, sort=[...tiebreaker]}"
    Note over Cluster: preference pins request to one shard copy per user
    Cluster-->>Client: Stable, deterministic results

    participant VectorResource
    participant VectorService as OpenSearchVectorService
    Client->>VectorResource: POST /search/vector
    VectorResource->>VectorResource: getSubjectContext(securityContext)
    VectorResource->>VectorService: search(..., searchPreferenceFor(ctx))
    VectorService->>VectorService: appendPreferenceParam(endpoint, preference)
    VectorService->>Cluster: "POST /_search?preference=user"
    Cluster-->>Client: Stable results
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Client
    participant SearchResource
    participant SearchManager as OpenSearch/ElasticSearch SearchManager
    participant RequestBuilder as Request Builder
    participant Cluster as ES/OpenSearch Cluster

    Client->>SearchResource: "GET /search?q=..."
    SearchResource->>SearchResource: getSubjectContext(securityContext)
    SearchResource->>SearchManager: search(request, subjectContext)
    SearchManager->>SearchManager: SearchUtils.searchPreferenceFor(subjectContext) → user.getName()
    SearchManager->>RequestBuilder: requestBuilder.preference(userName)
    SearchManager->>RequestBuilder: appendDeterministicTiebreak(sortField)
    RequestBuilder->>Cluster: "SearchRequest{preference=userName, sort=[...tiebreaker]}"
    Note over Cluster: preference pins request to one shard copy per user
    Cluster-->>Client: Stable, deterministic results

    participant VectorResource
    participant VectorService as OpenSearchVectorService
    Client->>VectorResource: POST /search/vector
    VectorResource->>VectorResource: getSubjectContext(securityContext)
    VectorResource->>VectorService: search(..., searchPreferenceFor(ctx))
    VectorService->>VectorService: appendPreferenceParam(endpoint, preference)
    VectorService->>Cluster: "POST /_search?preference=user"
    Cluster-->>Client: Stable results
Loading

Comments Outside Diff (1)

  1. openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java, line 1081-1086 (link)

    P2 Unused isExport parameter

    isExport was previously used in the || isExport tiebreaker condition that this PR removed. It no longer appears anywhere in the method body, making it a dead parameter. The OpenSearchSearchManager counterpart has the same issue (line 1127).

Reviews (4): Last reviewed commit: "Merge branch 'main' into harshach/multin..." | Re-trigger Greptile

… tiebreaker

On a multi-node OpenSearch/Elasticsearch cluster the same query could return
reordered or different results across requests: reads bounced between shard
copies (no `preference`) and the default relevance sort had no total-order
tiebreaker, so equal-scored docs ordered differently per replica.

- Add `preference` to OpenSearch/ElasticSearchRequestBuilder and set it per
  authenticated user (SearchUtils.searchPreferenceFor) so each user's queries
  pin to the same shard copy and stop bouncing across replicas.
- Always append a name.keyword + id.keyword sort tiebreaker on every sort path
  (including the default and non-_score paths, where docs commonly tie), giving
  a deterministic total order identical across shards/replicas.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 63%
63.42% (70688/111446) 45.9% (40625/88504) 47.81% (12369/25866)

The /search/vector/query path (used by the askCollate getCompanyContext tool)
ran raw approximate-kNN with no `preference`, so its results bounced across
replicas on a multi-node cluster the same way the main and hybrid search did.

- Add a `preference` param to VectorIndexService.search (a default 6-arg
  overload delegates with null) and emit it on the OpenSearchVectorService
  _search request via SearchUtils.appendPreferenceParam.
- Derive the routing key from the request principal in VectorSearchResource
  through SearchUtils.searchPreferenceFor.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…dead isExport

- ElasticSearchSearchManager: use Boolean.TRUE.equals(getIsHierarchy()) in the
  sort guard. The B2 refactor lifted the check out of the `&&` short-circuit, so
  an unboxed null Boolean could NPE on every non-sorted search — matches the
  null-safe OpenSearch side.
- appendDeterministicTiebreak (both engines): guard id.keyword the same way as
  name.keyword, so a primary sort on id.keyword no longer adds a duplicate clause.
- Drop the now-unused isExport parameter from buildSearchRequestBuilder in both
  managers and update call sites; the tiebreaker is applied unconditionally so
  export still gets it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Playwright Results — 1 failure(s), 18 flaky

✅ 4456 passed · ❌ 1 failed · 🟡 18 flaky · ⏭️ 38 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 1 324 0 1 4
🔴 Shard 2 821 1 7 9
🟡 Shard 3 827 0 2 7
✅ Shard 4 831 0 0 10
🟡 Shard 5 872 0 1 0
🟡 Shard 6 781 0 7 8

Genuine Failures (failed on all attempts)

❌ Features/BulkImport.spec.ts › Database Schema (shard 2)
Error: �[2mexpect(�[22m�[31mlocator�[39m�[2m).�[22mtoContainText�[2m(�[22m�[32mexpected�[39m�[2m)�[22m failed

Locator: locator('.rdg-cell-details')
Timeout: 15000ms
�[32m- Expected  - 1�[39m
�[31m+ Received  + 1�[39m

�[2m  Array [�[22m
�[31m+   "#FIELD_REQUIRED: Field 1 is required;#FIELD_REQUIRED: Field 13 is required",�[39m
�[2m    "Entity created",�[22m
�[2m    "Entity updated",�[22m
�[32m-   "Entity created",�[39m
�[2m    "Entity updated",�[22m
�[2m  ]�[22m

Call log:
�[2m  - Expect "toContainText" with timeout 15000ms�[22m
�[2m  - waiting for locator('.rdg-cell-details')�[22m
�[2m    6 × locator resolved to 0 elements�[22m
�[2m    13 × locator resolved to 4 elements�[22m

🟡 18 flaky test(s) (passed on retry)
  • Flow/SearchRBAC.spec.ts › a fully denied user sees neither asset type when browsing (shard 1, 2 retries)
  • Features/BulkEditEntity.spec.ts › Database service (shard 2, 1 retry)
  • Features/BulkEditEntity.spec.ts › Database (shard 2, 1 retry)
  • Features/BulkImport.spec.ts › Database service (shard 2, 1 retry)
  • Features/BulkImport.spec.ts › Database (shard 2, 1 retry)
  • Features/BulkImport.spec.ts › Table (shard 2, 1 retry)
  • Features/DataQuality/DataQualityDashboard.spec.ts › Entity Health pie chart segment click redirects to Test Cases with correct status (shard 2, 1 retry)
  • Features/DataQuality/TestCaseImportExportE2eFlow.spec.ts › Admin: Complete export-import-validate flow (shard 2, 1 retry)
  • Features/SearchExport.spec.ts › Export queues a background job and downloads from the jobs tray (shard 3, 1 retry)
  • Features/Tasks/TaskNavigation.spec.ts › navigating to /table/TASK-XXXXX should show 404 (invalid URL pattern) (shard 3, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard 5, 1 retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should allow Data Steward to edit tier for container (shard 6, 1 retry)
  • Pages/Glossary.spec.ts › Column dropdown drag-and-drop functionality for Glossary Terms table (shard 6, 1 retry)
  • Pages/GlossaryImportExport.spec.ts › Glossary Bulk Import Export (shard 6, 1 retry)
  • Pages/GlossaryImportExport.spec.ts › Import partial success - some terms pass, some fail (shard 6, 1 retry)
  • Pages/InputOutputPorts.spec.ts › Output ports section collapse/expand (shard 6, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • Pages/Lineage/PlatformLineage.spec.ts › Verify domain platform view (shard 6, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@sonarqubecloud

Copy link
Copy Markdown

@harshach
harshach merged commit d52cc19 into main Jun 26, 2026
65 of 70 checks passed
@harshach
harshach deleted the harshach/multinode-search-consistency branch June 26, 2026 16:38
@gitar-bot

gitar-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 3 resolved / 5 findings

Pins search queries to specific shards using a user-based preference key and enforces deterministic ordering with keyword tiebreakers to prevent multi-node result instability. The changes address the null-safe hierarchy guard, remove the unused isExport parameter, and resolve identified sorting inconsistencies.

⚠️ Security: ContextMemory visibility filter missing on several search paths

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:148-162 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:431-445 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:165-179 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:418-432

This commit introduces applyContextMemoryVisibility to keep private ContextMemory documents out of non-admin search results, and wires it into the main doSearch/buildSearchRequestBuilder, searchWithDirectQuery, the SubjectContext listWithOffset, and fallbackToBasicSearch paths. However, ContextMemory entities are indexed into the global all alias (ContextMemoryIndex → GLOBAL_SEARCH_ALIAS), and several other public query entry points that hit that alias do NOT apply the filter: listWithDeepPagination, searchByField, and searchBySourceUrl (in both the ES and OS managers). These methods build and execute a request without RBAC or the new visibility clause, so a non-admin querying through them can retrieve private memories that the new control is meant to hide — an inconsistent/incomplete security boundary.

Note that these methods currently do not even receive a SubjectContext, so closing the gap requires threading the subject through (as was done for listWithOffset) or otherwise enforcing visibility. At minimum, confirm whether any of these paths can target the ContextMemory index/global alias; if so, apply applyContextMemoryVisibility there too. If they are provably never used for memory-bearing indices, document that assumption.

Thread SubjectContext into the uncovered list/search paths and apply the visibility filter before executing, mirroring the listWithOffset(SubjectContext) variant.
// e.g. in listWithDeepPagination / searchByField / searchBySourceUrl
// after building requestBuilder and before build()/execute:
applyContextMemoryVisibility(subjectContext, requestBuilder);
💡 Quality: Asymmetric placement of visibility call between ES and OS managers

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:375-389 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:413 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:1193-1194

The two managers enforce the same guarantee in structurally different ways: ES invokes applyContextMemoryVisibility from inside applyRbacCondition (so every caller of that helper gets it for free), while OpenSearch calls applyRbacQueryWithCaching and then a separate applyContextMemoryVisibility at each call site. Both are correct today and apply the filter exactly once per path, but the asymmetry makes it easy to forget the second call when adding a new OpenSearch search path (and is part of why the gap in the previous finding is easy to introduce). Consider centralizing the visibility call inside the RBAC helper on both sides so coverage is consistent and harder to omit.

Call applyContextMemoryVisibility from within applyRbacQueryWithCaching in OpenSearchSearchManager so it is applied uniformly, then drop the separate call sites.
private void applyRbacQueryWithCaching(SubjectContext subjectContext, OpenSearchRequestBuilder requestBuilder) {
  // ... existing RBAC logic ...
  applyContextMemoryVisibility(subjectContext, requestBuilder);
}
✅ 3 resolved
✅ Performance: Per-user preference key can create hot shards / skewed load

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchUtils.java:68-74
SearchUtils.searchPreferenceFor derives the OpenSearch/Elasticsearch preference routing key from subjectContext.user().getName(), pinning all of a user's searches to a single shard copy. This achieves the intended read consistency, but it also defeats the cluster's round-robin replica load balancing for that user. For workloads dominated by a small number of heavy callers (e.g., a bot/service account or an automated ingestion user running large/paginated searches), all read traffic will be funneled to one replica, producing a hot shard and uneven CPU/IO across nodes. Consider whether bots/service accounts should be excluded from preference pinning, or document this trade-off. Also note that when subjectContext or user() is null the method returns null and pinning is skipped, so anonymous/unauthenticated reads still bounce between replicas — the consistency guarantee in the PR description only holds for authenticated users.

✅ Quality: isExport parameter is now dead after sort refactor

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:1127 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:1081
In both OpenSearchSearchManager.buildSearchRequestBuilder and ElasticSearchSearchManager.buildSearchRequestBuilder, the isExport parameter was previously used to decide whether to append the name.keyword/id.keyword tiebreaker (if (sortField.equalsIgnoreCase(SORT_FIELD_SCORE) || isExport)). After this change the tiebreaker is applied unconditionally via appendDeterministicTiebreak(...), so isExport is no longer referenced anywhere in either method body — it is only declared as a parameter. This is dead state that callers still compute and pass, and it obscures the fact that export no longer has special sort handling. Either remove the parameter (and update call sites) or add a comment if it is intentionally retained for future use.

✅ Bug: ES sort guard unboxes getIsHierarchy() without null check

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:1212 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:1255
ElasticSearchSearchManager now guards the sort block with if (!request.getIsHierarchy()) (line ~1212). Previously this was if (!nullOrEmpty(request.getSortFieldParam()) && !request.getIsHierarchy()), where the && short-circuited so getIsHierarchy() was only unboxed when a sort param was present. With the refactor getIsHierarchy() is now evaluated on every search request, so a null Boolean would throw a NullPointerException. The schema declares default: false, so this is unlikely in practice, but note the OpenSearch counterpart deliberately uses the null-safe !Boolean.TRUE.equals(request.getIsHierarchy()) (OpenSearchSearchManager:1255). For consistency and safety, use Boolean.TRUE.equals(...) in the ES manager as well.

🤖 Prompt for agents
Code Review: Pins search queries to specific shards using a user-based preference key and enforces deterministic ordering with keyword tiebreakers to prevent multi-node result instability. The changes address the null-safe hierarchy guard, remove the unused isExport parameter, and resolve identified sorting inconsistencies.

1. ⚠️ Security: ContextMemory visibility filter missing on several search paths
   Files: openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:148-162, openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:431-445, openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:165-179, openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:418-432

   This commit introduces `applyContextMemoryVisibility` to keep private ContextMemory documents out of non-admin search results, and wires it into the main `doSearch`/`buildSearchRequestBuilder`, `searchWithDirectQuery`, the `SubjectContext` `listWithOffset`, and `fallbackToBasicSearch` paths. However, ContextMemory entities are indexed into the global `all` alias (ContextMemoryIndex → GLOBAL_SEARCH_ALIAS), and several other public query entry points that hit that alias do NOT apply the filter: `listWithDeepPagination`, `searchByField`, and `searchBySourceUrl` (in both the ES and OS managers). These methods build and execute a request without RBAC or the new visibility clause, so a non-admin querying through them can retrieve private memories that the new control is meant to hide — an inconsistent/incomplete security boundary.
   
   Note that these methods currently do not even receive a `SubjectContext`, so closing the gap requires threading the subject through (as was done for `listWithOffset`) or otherwise enforcing visibility. At minimum, confirm whether any of these paths can target the ContextMemory index/global alias; if so, apply `applyContextMemoryVisibility` there too. If they are provably never used for memory-bearing indices, document that assumption.

   Fix (Thread SubjectContext into the uncovered list/search paths and apply the visibility filter before executing, mirroring the listWithOffset(SubjectContext) variant.):
   // e.g. in listWithDeepPagination / searchByField / searchBySourceUrl
   // after building requestBuilder and before build()/execute:
   applyContextMemoryVisibility(subjectContext, requestBuilder);

2. 💡 Quality: Asymmetric placement of visibility call between ES and OS managers
   Files: openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:375-389, openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:413, openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:1193-1194

   The two managers enforce the same guarantee in structurally different ways: ES invokes `applyContextMemoryVisibility` from inside `applyRbacCondition` (so every caller of that helper gets it for free), while OpenSearch calls `applyRbacQueryWithCaching` and then a separate `applyContextMemoryVisibility` at each call site. Both are correct today and apply the filter exactly once per path, but the asymmetry makes it easy to forget the second call when adding a new OpenSearch search path (and is part of why the gap in the previous finding is easy to introduce). Consider centralizing the visibility call inside the RBAC helper on both sides so coverage is consistent and harder to omit.

   Fix (Call applyContextMemoryVisibility from within applyRbacQueryWithCaching in OpenSearchSearchManager so it is applied uniformly, then drop the separate call sites.):
   private void applyRbacQueryWithCaching(SubjectContext subjectContext, OpenSearchRequestBuilder requestBuilder) {
     // ... existing RBAC logic ...
     applyContextMemoryVisibility(subjectContext, requestBuilder);
   }

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

pmbrull pushed a commit that referenced this pull request Jul 9, 2026
…4789) (#29850)

Backport the multi-chunk embedding fix from #29678 to 1.13, vector-pipeline
only. Excludes the AI Context Platform (REST /context, MCP tools,
AIContextBuilder, metric assets), which depends on 2.0-only server features
(Context Center, metric->asset edge).

VectorDocBuilder previously embedded only chunk 0 (~380 words) of an entity's
body, so long Knowledge Articles were not semantically retrievable past their
opening. VectorDocBuilder.fromEntity now emits one embedding document per body
chunk into a dedicated data_asset_embeddings_chunks index (deterministic
{parentId}_{chunkIndex} ids), dual-writing chunk 0 to the legacy entity-doc
embedding so hybrid search is unchanged and there is no migration cliff. Stale
chunks are cleaned on hard/soft delete, restore, and body shrink; a reindex
backfills existing entities (missing chunk header -> re-embed, fingerprint-skip
on subsequent runs).

The read side (RagHitProcessor top-N chunk merge in ai-platform) already ships
on 1.13 and lights up once the chunk index is populated.

VectorIndexService intentionally diverges from upstream by one method: the
preference/7-arg search overload (from #29503) is omitted because #29503 is not
on 1.13; only the #4789 chunk methods are added.

Fixes: open-metadata/openmetadata-collate#4789

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>

This branch had an error being deployed

1 failed deployment
test — 88b772d4 Deployed Jun 26, 2026 by Vishnuujain via playwright-ci-postgresql (2, 6) #53389
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants