Skip to content

fix(search): enforce ContextMemory shareConfig visibility in search - #29384

Merged
harshach merged 2 commits into
mainfrom
harshach/memory-pin-search-sort-api
Jun 26, 2026
Merged

harshach merged 2 commits into
mainfrom
harshach/memory-pin-search-sort-api

Conversation

@harshach

@harshach harshach commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

ContextMemory enforces its per-memory shareConfig visibility (Private = owner-only, Entity = everyone, Shared = listed principals; admins bypass) only on the REST /v1/contextCenter/memories read endpoints. Global search (/search/query on the all alias) and the search-backed listing/NLQ paths applied only domain + RBAC filters, neither of which understands shareConfig, so any user could see other users' Private/Shared memory title/question/answer in search results. This PR adds ContextMemorySearchVisibility — an engine-agnostic search filter that mirrors ContextMemoryVisibility — and ANDs it into the Elasticsearch and OpenSearch query paths for every non-admin subject, deliberately independent of the RBAC access-control toggle so disabling RBAC can never expose private memories. The filter is entityType-guarded so non-memory documents are untouched, and the index still stores every memory so owners can always find their own.

Fixes 29490

Type of change:

  • Bug fix

High-level design:

ContextMemorySearchVisibility builds a per-subject OMQueryBuilder using the same QueryBuilderFactory abstraction RBACConditionEvaluator uses, so one builder serves both engines: should[ NOT(entityType=contextMemory) , (entityType=contextMemory AND should[ visibility=Entity, nested owners.id=me, sharedWithIds ∋ {me + teams + domains} ]) ]. It is applied wherever RBAC is applied — ElasticSearchSearchManager (folded into applyRbacCondition, plus the inline direct-query and NLQ-fallback paths) and OpenSearchSearchManager (the inline listWithOffset path plus after each applyRbacQueryWithCaching call) — gated only on !isAdmin. Correctness rests on each OR-group being a should-only bool (engine default minimum_should_match=1, the same default RBACConditionEvaluator already relies on); a unit test pins that invariant so a stray must/filter can't silently turn the filter into a fail-open no-op. No DB migration or schema change (visibility data was already indexed); reindex already covers contextMemory. The AI/RAG vector-retrieval path (VectorSearchResource → OpenSearchVectorService) is a deliberate follow-up — it ignores the subject today and needs subject plumbing plus an acting-principal decision.

Tests:

Use cases covered

  • A non-admin's global search excludes other users' Private memories, keeps their own (incl. Private) and Entity-visibility memories, and shows Shared memories only to the listed user/team/domain principals.
  • Non-memory documents (tables, dashboards, etc.) are unaffected by the filter.
  • Admins and missing/unidentifiable subjects get no filter.

Unit tests

  • Added ContextMemorySearchVisibilityTest (8 tests, Elasticsearch + OpenSearch): entityType guard, the three visibility clauses, sharedWithIds = {user, teams, domains}, admin/null → no filter, and the should-only minimum_should_match=1 invariant.

Backend integration tests

  • Not applicable — no new/changed API endpoint (this is a search query-filter change). A live-engine end-to-end search IT is a planned follow-up.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  • mvn -pl openmetadata-service test -Dtest=ContextMemorySearchVisibilityTest → 8/8 green; mvn spotless:apply clean.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • 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.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. (No schema changes.)
  • For UI changes: I attached a screen recording and/or screenshots above. (No UI changes.)
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

Greptile Summary

This PR introduces ContextMemorySearchVisibility, a new engine-agnostic filter that ANDs per-memory shareConfig visibility (Private = owner-only, Entity = everyone, Shared = listed principals with a visibility=Shared guard to prevent stale-list leaks) into search query paths for non-admin subjects, independent of the RBAC toggle.

  • The filter is correctly wired into the main listing, direct-query, and NLQ-fallback paths for both Elasticsearch and OpenSearch, and the sharedWithIds branch is properly gated by visibility=Shared (addressing a prior review concern).
  • The searchWithNLQ success path in both engines (when the NLQ service returns a transformed query) executes client.search without applying either RBAC or the new visibility filter — private ContextMemory documents remain reachable via NLQ search, which is the scenario this PR specifically targets.
  • The AI/RAG vector-retrieval path is acknowledged as a deliberate follow-up.

Confidence Score: 3/5

Not safe to merge as-is — the NLQ success path in both engines executes without the visibility filter, which is the primary attack vector this PR aims to close.

The filter implementation and wiring are correct for listing, direct-query, and fallback paths, but both ElasticSearchSearchManager.searchWithNLQ and OpenSearchSearchManager.searchWithNLQ execute the engine query directly when the NLQ service returns a transformed query, skipping both RBAC and the new visibility filter. A non-admin user with NLQ access can retrieve private ContextMemory documents owned by others — the exact exposure the PR describes fixing.

ElasticSearchSearchManager.java and OpenSearchSearchManager.java — specifically the searchWithNLQ success branch in each file (the block between requestBuilder.query(nlqQuery) and client.search).

Security Review

  • Missing visibility filter on NLQ success path (ES + OS): ElasticSearchSearchManager.searchWithNLQ and OpenSearchSearchManager.searchWithNLQ both skip applyContextMemoryVisibility (and RBAC) when the NLQ service successfully transforms a query. A non-admin user can retrieve private ContextMemory documents owned by other users via the NLQ search endpoint whenever the NLQ service is configured and returns results.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/search/security/ContextMemorySearchVisibility.java New filter class that correctly enforces ContextMemory shareConfig visibility (Entity/owner-nested/Shared-gated) using engine-agnostic QueryBuilderFactory; the sharedWithIds branch is properly gated by visibility=Shared, addressing the stale-list leak from the prior thread.
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java Correctly adds applyContextMemoryVisibility to applyRbacCondition, searchWithDirectQuery, and fallbackToBasicSearch, but the searchWithNLQ success path (when transformedQuery is non-null) executes without RBAC or the visibility filter, leaving private memories exposed via NLQ.
openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java Correctly adds applyContextMemoryVisibility after each applyRbacQueryWithCaching call and in listWithOffset, but searchWithNLQ success path has the same gap as ElasticSearch — neither RBAC nor the visibility filter is applied before client.search.
openmetadata-service/src/test/java/org/openmetadata/service/search/security/ContextMemorySearchVisibilityTest.java Comprehensive unit tests covering entityType guard, three visibility clauses, sharedWithIds gating by visibility=Shared, principal ID composition, the should-only minimum_should_match invariant, admin/null bypass, and OpenSearch equivalence; does not cover the NLQ integration paths.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Search Request] --> B{Search Path}
    B --> C[listWithOffset]
    B --> D[searchWithDirectQuery]
    B --> E[searchWithNLQ]
    B --> F[main search / buildSearchRequestBuilder]
    C --> C1[applyRbacCondition] --> C2[applyContextMemoryVisibility ✅] --> C3[Execute]
    D --> D1[inline RBAC] --> D2[applyContextMemoryVisibility ✅] --> D3[Execute]
    E --> E1{NLQ transform}
    E1 -->|success| E2[Execute query - NO RBAC - NO visibility filter ❌]
    E1 -->|failure/null| E3[fallbackToBasicSearch]
    E3 --> E4[inline RBAC] --> E5[applyContextMemoryVisibility ✅] --> E6[Execute]
    F --> F1[applyRbacQueryWithCaching] --> F2[applyContextMemoryVisibility ✅] --> F3[Execute]
    style E2 fill:#ff6b6b,color:#fff
    style C2 fill:#51cf66,color:#fff
    style D2 fill:#51cf66,color:#fff
    style E5 fill:#51cf66,color:#fff
    style F2 fill:#51cf66,color:#fff
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"}}}%%
flowchart TD
    A[Search Request] --> B{Search Path}
    B --> C[listWithOffset]
    B --> D[searchWithDirectQuery]
    B --> E[searchWithNLQ]
    B --> F[main search / buildSearchRequestBuilder]
    C --> C1[applyRbacCondition] --> C2[applyContextMemoryVisibility ✅] --> C3[Execute]
    D --> D1[inline RBAC] --> D2[applyContextMemoryVisibility ✅] --> D3[Execute]
    E --> E1{NLQ transform}
    E1 -->|success| E2[Execute query - NO RBAC - NO visibility filter ❌]
    E1 -->|failure/null| E3[fallbackToBasicSearch]
    E3 --> E4[inline RBAC] --> E5[applyContextMemoryVisibility ✅] --> E6[Execute]
    F --> F1[applyRbacQueryWithCaching] --> F2[applyContextMemoryVisibility ✅] --> F3[Execute]
    style E2 fill:#ff6b6b,color:#fff
    style C2 fill:#51cf66,color:#fff
    style D2 fill:#51cf66,color:#fff
    style E5 fill:#51cf66,color:#fff
    style F2 fill:#51cf66,color:#fff
Loading

Comments Outside Diff (2)

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

    P1 security NLQ success path bypasses context-memory visibility filter

    When the NLQ service is configured and transformNaturalLanguageQuery returns a non-null result, the query is executed directly (lines 595–612) without going through either RBAC or applyContextMemoryVisibility. Only the fallbackToBasicSearch path has the filter applied. A non-admin user can issue an NLQ query, receive a transformed ES query, and get back private ContextMemory documents belonging to other users — the exact leak this PR is meant to close. The fix is to call applyContextMemoryVisibility(subjectContext, requestBuilder) (and RBAC, which is also absent here) before client.search(...) in the success branch. The same gap exists in the OpenSearch searchWithNLQ success path for the same reason.

  2. openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java, line 558-602 (link)

    P1 security NLQ success path bypasses context-memory visibility filter (OpenSearch)

    Same gap as the Elasticsearch counterpart: when nlqService.transformNaturalLanguageQuery returns a non-null result, the code sets the query, adds aggregations, and calls client.search without calling applyRbacQueryWithCaching or applyContextMemoryVisibility. Only the fallbackToBasicSearch paths carry the filter. applyRbacQueryWithCaching(subjectContext, requestBuilder) and applyContextMemoryVisibility(subjectContext, requestBuilder) should both be called after requestBuilder.query(nlqQuery) and before client.search(...).

Reviews (2): Last reviewed commit: "fix(search): gate ContextMemory sharedWi..." | Re-trigger Greptile

Private/Shared context memories were filtered only on the REST /v1/contextCenter/memories read endpoints, so global search and search-backed listings returned other users' memory content. Add ContextMemorySearchVisibility (mirroring ContextMemoryVisibility) and AND it into the Elasticsearch and OpenSearch query paths for every non-admin subject, independent of the RBAC access-control toggle. Covered by ContextMemorySearchVisibilityTest (8 ES+OS unit tests).

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

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Jun 24, 2026
@harshach harshach added the skip-pr-checks Bypass PR metadata validation check label Jun 24, 2026
@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Playwright Results — 2 failure(s), 16 flaky

✅ 4378 passed · ❌ 2 failed · 🟡 16 flaky · ⏭️ 88 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 1 323 0 2 4
✅ Shard 2 824 0 0 9
🔴 Shard 3 819 1 2 8
🔴 Shard 4 875 1 5 12
🟡 Shard 5 744 0 1 47
🟡 Shard 6 793 0 6 8

Genuine Failures (failed on all attempts)

❌ Features/LineageExportPNGSnapshot.spec.ts › exported PNG includes edge lines between nodes (shard 3)
Error: �[2mexpect(�[22m�[31mBuffer�[39m�[2m).�[22mtoMatchSnapshot�[2m(�[22m�[32mexpected�[39m�[2m)�[22m failed

  Expected an image 4986px by 2697px, received 4986px by 2805px. 

  Snapshot: lineage-export-with-edges.png

❌ Pages/Domains.spec.ts › Create DataProducts and add remove assets (shard 4)
�[31mTest timeout of 540000ms exceeded.�[39m
🟡 16 flaky test(s) (passed on retry)
  • Pages/AISettings.spec.ts › persists MCP Server configuration after save (shard 1, 1 retry)
  • Flow/SearchRBAC.spec.ts › the browse tree only shows the asset-type categories a user can access (shard 1, 1 retry)
  • Features/KnowledgeCenterTextEditor.spec.ts › Rich Text Editor - Text Formatting (shard 3, 1 retry)
  • Features/Table.spec.ts › Table pagination with sorting should works (shard 3, 1 retry)
  • Flow/PersonaFlow.spec.ts › Set default persona for team should work properly (shard 4, 1 retry)
  • Pages/CustomProperties.spec.ts › Duration: advanced search equalTo and Contains operators (shard 4, 1 retry)
  • Pages/CustomProperties.spec.ts › Timestamp (shard 4, 1 retry)
  • Pages/DataContracts.spec.ts › Create Data Contract and validate for Database Schema (shard 4, 1 retry)
  • Pages/DataContractsSemanticRules.spec.ts › Validate Description Rule Is_Set (shard 4, 1 retry)
  • Pages/EntityDataSteward.spec.ts › Tier Add, Update and Remove (shard 5, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • Pages/Lineage/LineageRightPanel.spec.ts › Verify custom properties tab IS visible for supported type: searchIndex (shard 6, 1 retry)
  • Pages/Lineage/PlatformLineage.spec.ts › Verify domain platform view (shard 6, 1 retry)
  • Pages/Login.spec.ts › Refresh should work (shard 6, 1 retry)
  • Pages/ServiceEntity.spec.ts › Inactive Announcement create & delete (shard 6, 1 retry)
  • Pages/UserDetails.spec.ts › My Data Tab - AssetsTabs search functionality (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

@Rohit0301 Rohit0301 removed the skip-pr-checks Bypass PR metadata validation check label Jun 25, 2026
Address PR review (greptile P1): the sharedWithIds clause matched regardless of the stored visibility, so a Private memory carrying a stale sharedWithIds (e.g. flipped Shared->Private without clearing the list) would leak to those principals via search, while the REST guard ContextMemoryVisibility.isInSharedWithList consults sharedWith only when visibility==SHARED. AND the sharedWithIds match with visibility=Shared and add a regression test asserting sharedWithIds is never a bare (ungated) should clause.

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

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 62%
62.67% (67386/107521) 44.75% (38109/85150) 45.79% (11377/24843)

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@harshach
harshach merged commit 06909bc into main Jun 26, 2026
59 of 69 checks passed
@harshach
harshach deleted the harshach/memory-pin-search-sort-api branch June 26, 2026 04:56
@gitar-bot

gitar-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown
Code Review 🚫 Blocked 0 resolved / 1 findings

Introduces ContextMemorySearchVisibility to enforce privacy filters in search queries, but changes are requested due to an information disclosure risk where Private memories could remain visible to previously shared principals, and a bypass exists in the main NLQ path.

🚨 Security: NLQ main success path bypasses ContextMemory visibility filter

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:588-602 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:576-590

The whole point of this PR is to AND the ContextMemorySearchVisibility filter into every non-admin search path that can return contextMemory documents. However, the successful NLQ path is not covered in either engine — the filter is only applied in the NLQ fallback path.

Elasticsearch (ElasticSearchSearchManager.searchWithNLQ, lines 588-623): when nlqService.transformNaturalLanguageQuery(...) returns a non-null transformed query, the code builds requestBuilder from the raw NLQ query (line 596), adds aggregations, and executes the search (line 607) without ever calling applyContextMemoryVisibility. The visibility filter is only added in fallbackToBasicSearch (line 1591) and searchWithDirectQuery (line 685).

OpenSearch (OpenSearchSearchManager.searchWithNLQ, lines 576-602): identical gap — the transformed-query branch executes client.search(...) (line 588) with no applyContextMemoryVisibility call; only the fallback (line 1624) and direct-query (line 639) paths apply it.

Impact: a non-admin user issuing an NLQ search (/search/... NLQ endpoint) against the all alias or the contextMemory index will, whenever the NLQ transform succeeds, receive other users' Private/Shared ContextMemory title/question/answer — exactly the leak this PR claims to close. The PR description acknowledges only the "NLQ-fallback" path was wired up; the primary NLQ path was missed. Because this is the privacy guarantee the PR is built to enforce, treat it as a data-exposure regression rather than a no-op.

Fix: call applyContextMemoryVisibility(subjectContext, requestBuilder) right after building the request and before executing the search in both searchWithNLQ success branches (after line 596 in ES, after line 579 in OS). Add a regression test exercising the NLQ success path.

ES: apply the visibility filter on the NLQ success path before executing. Mirror the same addition in OpenSearchSearchManager.searchWithNLQ after requestBuilder.query(nlqQuery).
ElasticSearchRequestBuilder requestBuilder = new ElasticSearchRequestBuilder();
String queryToProcess = EsUtils.parseJsonQuery(transformedQuery);
Query nlqQuery = Query.of(q -> q.withJson(new StringReader(queryToProcess)));
requestBuilder.query(nlqQuery);

applyContextMemoryVisibility(subjectContext, requestBuilder);

requestBuilder.from(request.getFrom());
requestBuilder.size(request.getSize());
🤖 Prompt for agents
Code Review: Introduces `ContextMemorySearchVisibility` to enforce privacy filters in search queries, but changes are requested due to an information disclosure risk where Private memories could remain visible to previously shared principals, and a bypass exists in the main NLQ path.

1. 🚨 Security: NLQ main success path bypasses ContextMemory visibility filter
   Files: openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:588-602, openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:576-590

   The whole point of this PR is to AND the `ContextMemorySearchVisibility` filter into every non-admin search path that can return `contextMemory` documents. However, the **successful** NLQ path is not covered in either engine — the filter is only applied in the NLQ *fallback* path.
   
   Elasticsearch (`ElasticSearchSearchManager.searchWithNLQ`, lines 588-623): when `nlqService.transformNaturalLanguageQuery(...)` returns a non-null transformed query, the code builds `requestBuilder` from the raw NLQ query (line 596), adds aggregations, and executes the search (line 607) without ever calling `applyContextMemoryVisibility`. The visibility filter is only added in `fallbackToBasicSearch` (line 1591) and `searchWithDirectQuery` (line 685).
   
   OpenSearch (`OpenSearchSearchManager.searchWithNLQ`, lines 576-602): identical gap — the transformed-query branch executes `client.search(...)` (line 588) with no `applyContextMemoryVisibility` call; only the fallback (line 1624) and direct-query (line 639) paths apply it.
   
   Impact: a non-admin user issuing an NLQ search (`/search/...` NLQ endpoint) against the `all` alias or the contextMemory index will, whenever the NLQ transform succeeds, receive other users' Private/Shared `ContextMemory` `title`/`question`/`answer` — exactly the leak this PR claims to close. The PR description acknowledges only the "NLQ-fallback" path was wired up; the primary NLQ path was missed. Because this is the privacy guarantee the PR is built to enforce, treat it as a data-exposure regression rather than a no-op.
   
   Fix: call `applyContextMemoryVisibility(subjectContext, requestBuilder)` right after building the request and before executing the search in both `searchWithNLQ` success branches (after line 596 in ES, after line 579 in OS). Add a regression test exercising the NLQ success path.

   Fix (ES: apply the visibility filter on the NLQ success path before executing. Mirror the same addition in OpenSearchSearchManager.searchWithNLQ after requestBuilder.query(nlqQuery).):
   ElasticSearchRequestBuilder requestBuilder = new ElasticSearchRequestBuilder();
   String queryToProcess = EsUtils.parseJsonQuery(transformedQuery);
   Query nlqQuery = Query.of(q -> q.withJson(new StringReader(queryToProcess)));
   requestBuilder.query(nlqQuery);
   
   applyContextMemoryVisibility(subjectContext, requestBuilder);
   
   requestBuilder.from(request.getFrom());
   requestBuilder.size(request.getSize());

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

harshach added a commit that referenced this pull request Jul 3, 2026
…pagination

Review (lautel): filtering the search-backed contextMemory list in Java and
falling back to new ResultList<>(visible) whenever an item was dropped loses
the engine's paging metadata (total, cursors) and truncates the page below
the requested limit, so a client paging by offset silently stops short of the
real result set.

The post-filter was also redundant: ContextMemory shareConfig visibility is
already enforced at query time by ContextMemorySearchVisibility (#29384),
applied in both search managers on the listWithOffset path the search-backed
listing uses. So the search already excludes memories the caller may not see.
Remove the post-filter and return the search result as-is, restoring correct
offset pagination while keeping the visibility guarantee.

Verified: ContextMemoryIT 189/189.

Co-Authored-By: Claude Fable 5 <[email protected]>
pmbrull pushed a commit that referenced this pull request Jul 27, 2026
…query (#29541)

* fix(search): enforce ContextMemory visibility at index time, not per-query

Private/Shared ContextMemory could leak through search paths the per-query applyContextMemoryVisibility filter (#29384) did not cover. Instead of filtering on every search path, only org-wide (ENTITY) memories are written to the index: ContextMemoryRepository.isSearchIndexable gates the live create/update/embedding paths and getReindexFilter applies the same rule to the bulk reindex reader and counts (so partition totals stay balanced and the staged index promotes). Removes the applyContextMemoryVisibility apparatus from both search managers.

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

* fix(search): gate bulk live-index paths on isSearchIndexable too

createEntitiesIndex and updateEntitiesIndex (the bulk live paths reached via SearchIndexHandler.onEntitiesCreated/onEntitiesUpdated) bypassed the isSearchIndexable gate, so a PRIVATE/SHARED ContextMemory created or updated through a bulk lifecycle dispatch (import/batch extraction) could still be indexed. Apply the same gate: skip non-indexable entities on bulk create; on bulk update drop them and delete their stale docs, mirroring updateEntityIndex's ENTITY->PRIVATE flip handling.

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

* fix(search): make isSearchIndexable safe for repository-less types

checkIfIndexingIsSupported gates on the index mapping, not repository existence, so an indexable but repository-less type (e.g. an index-only/time-series sub-entity) reaching createEntityIndex/updateEntityIndex would throw EntityNotFoundException at the getEntityRepository().isSearchIndexable call added in the prior commits. Route all live index-path gates through a new Entity.isSearchIndexable facade that defaults to indexable when no repository is registered, so the rule still lives in ContextMemoryRepository but repository-less types index exactly as before.

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

* docs(search): document reindex-only scope of MEMORY_SEARCH_VISIBILITY_PARAM

Warn that the filter param is set only by ContextMemoryRepository.getReindexFilter and must not be applied to the REST /contextCenter/memories listing (owners must still read their own PRIVATE/SHARED memories there).

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

* fix(search): clean up hidden memory vector chunks

* fix(search): handle time-series indexability

* fix(search): derive memory visibility bind parameter

* fix(ci): address reindex and Playwright failures

* test(search): use context memory table name

* test(search): stabilize term boost previews

* test(incidents): isolate pagination fixtures

* fix(search): harden indexability handling

* fix(search): preserve visibility defense in depth

* fix(search): purge stale non-indexable documents

* fix(search): align distributed cursor filters

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Mohit Yadav <[email protected]>
pmbrull pushed a commit that referenced this pull request Jul 27, 2026
…query (#29541)

* fix(search): enforce ContextMemory visibility at index time, not per-query

Private/Shared ContextMemory could leak through search paths the per-query applyContextMemoryVisibility filter (#29384) did not cover. Instead of filtering on every search path, only org-wide (ENTITY) memories are written to the index: ContextMemoryRepository.isSearchIndexable gates the live create/update/embedding paths and getReindexFilter applies the same rule to the bulk reindex reader and counts (so partition totals stay balanced and the staged index promotes). Removes the applyContextMemoryVisibility apparatus from both search managers.

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

* fix(search): gate bulk live-index paths on isSearchIndexable too

createEntitiesIndex and updateEntitiesIndex (the bulk live paths reached via SearchIndexHandler.onEntitiesCreated/onEntitiesUpdated) bypassed the isSearchIndexable gate, so a PRIVATE/SHARED ContextMemory created or updated through a bulk lifecycle dispatch (import/batch extraction) could still be indexed. Apply the same gate: skip non-indexable entities on bulk create; on bulk update drop them and delete their stale docs, mirroring updateEntityIndex's ENTITY->PRIVATE flip handling.

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

* fix(search): make isSearchIndexable safe for repository-less types

checkIfIndexingIsSupported gates on the index mapping, not repository existence, so an indexable but repository-less type (e.g. an index-only/time-series sub-entity) reaching createEntityIndex/updateEntityIndex would throw EntityNotFoundException at the getEntityRepository().isSearchIndexable call added in the prior commits. Route all live index-path gates through a new Entity.isSearchIndexable facade that defaults to indexable when no repository is registered, so the rule still lives in ContextMemoryRepository but repository-less types index exactly as before.

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

* docs(search): document reindex-only scope of MEMORY_SEARCH_VISIBILITY_PARAM

Warn that the filter param is set only by ContextMemoryRepository.getReindexFilter and must not be applied to the REST /contextCenter/memories listing (owners must still read their own PRIVATE/SHARED memories there).

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

* fix(search): clean up hidden memory vector chunks

* fix(search): handle time-series indexability

* fix(search): derive memory visibility bind parameter

* fix(ci): address reindex and Playwright failures

* test(search): use context memory table name

* test(search): stabilize term boost previews

* test(incidents): isolate pagination fixtures

* fix(search): harden indexability handling

* fix(search): preserve visibility defense in depth

* fix(search): purge stale non-indexable documents

* fix(search): align distributed cursor filters

---------

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

This branch was previously deployed

1 inactive deployment
test — b0efa965 Deployed Jun 26, 2026 by harshach via playwright-ci-postgresql (5, 6) #53240
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.

fix(search): enforce ContextMemory shareConfig visibility in global search and NLQ paths

2 participants