Skip to content

Fixes #29826: add configurable persona AI context - #29948

Merged
harshach merged 8 commits into
mainfrom
harshach/persona-context
Jul 12, 2026
Merged

harshach merged 8 commits into
mainfrom
harshach/persona-context

Conversation

@harshach

@harshach harshach commented Jul 11, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #29826

Adds configurable Persona AI context rules, deterministic cached materialization, MCP retrieval, and an admin UI matching the supplied design so agents can consume role-specific asset and knowledge context.

Type of change:

  • New feature

High-level design:

  • Extends the Persona JSON schema with a backward-compatible contextDefinition; no relational schema migration is required because Persona JSON is already persisted in the existing entity column.
  • Adds admin rule CRUD, match preview, document preview/refresh, and authorized Persona context endpoints.
  • Materializes rules in stable priority order with global first-match-wins deduplication by entityType:FQN, a global character budget, full/compact/manifest rendering, and one shared-knowledge appendix.
  • Uses the canonical 18-type registry for both validation and materialization; fully rendered Data Products page through and render every contained asset through the same global deduplication set.
  • Adds Caffeine/Redis caching with single-flight generation and stable timestamps for cached reads, plus the get_persona_context MCP tool for paged retrieval.
  • Adds the Persona administration UI, all entity-specific options and sections, native translations in every supported locale, and design-aligned loading, empty, preview, and error states.
  • Dynamic rules were selected over manually copied context so matching remains current as metadata changes; one cached document was selected over per-rule payloads to enforce a global budget and deduplicate cross-rule knowledge.

Tests:

Use cases covered

  • Configure, preview, edit, and delete Persona rules across all 18 entity types.
  • Materialize full, compact, and manifest output without cross-rule duplicates.
  • Expand a fully rendered Data Product into all contained assets and suppress overlapping direct-asset matches.
  • Return stable cached documents and timestamps, and retrieve them through REST and MCP.

Unit tests

  • Added/updated backend, MCP, and UI unit tests.
  • Backend/MCP: 27 focused tests passed (PersonaContextBuilder, repository validation, cache, markdown, and MCP tool).
  • UI: 39 focused Jest tests passed.
  • Coverage percentage was not separately measured.

Backend integration tests

  • No new openmetadata-integration-tests test was added; the endpoints and materialized output were exercised against the local Docker stack with real PostgreSQL/OpenSearch sample data.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Added playwright/e2e/Features/PersonaAIContext.spec.ts.
  • 6/6 Chromium tests passed against the current development UI.

Manual testing performed

  1. Ran the local PostgreSQL/OpenSearch/OpenMetadata Docker stack and the UI development server.
  2. Added five ingested sample tables to a Data Product and configured a full Data Product rule followed by an overlapping table rule.
  3. Verified the Data Product rendered itself plus all five assets, the complete document contained zero duplicate entityType:FQN keys, and cached reads preserved the same generatedAt value.
  4. Verified the production UI build and the rule editor/preview flow against the supplied standalone design.

UI screen recording / screenshots:

Not attached in this draft; the UI was validated locally against the supplied standalone design and reference screenshots.

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.
  • For UI changes: I attached a screen recording and/or screenshots above.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • The issue properly describes why the new feature is needed, what's the goal, and how we are building it.
  • I have updated the documentation.
  • I have added tests around the new logic.

Greptile Summary

This PR adds configurable Persona AI context for agents. The main changes are:

  • Persona context rules and materialized documents in the backend.
  • REST and MCP endpoints for retrieving persona context.
  • Admin UI for rule CRUD, previews, cache status, and settings.
  • Schema, generated types, translations, and focused tests.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The disabled Persona AI context setting is now sent as an explicit false value when toggled off.

Important Files Changed

Filename Overview
openmetadata-ui/src/main/resources/ui/src/components/Settings/Persona/PersonaAIContext/PersonaAIContext.component.tsx Adds the Persona AI context admin panel and now preserves explicit disabled settings when saving.
openmetadata-ui/src/main/resources/ui/src/utils/PersonaAIContextUtils.ts Adds normalization helpers for persona context definitions, rules, sections, and filter summaries.
openmetadata-ui/src/main/resources/ui/src/rest/PersonaAPI.ts Adds typed REST helpers for Persona AI context settings, rules, previews, and documents.

Reviews (8): Last reviewed commit: "Fix persona Playwright CI failures" | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - openmetadata-ui-core-components/CLAUDE.md (source)
  • Context used - AGENTS.md (source)

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Jul 11, 2026
@harshach
harshach marked this pull request as ready for review July 11, 2026 01:03
@harshach
harshach requested a review from a team as a code owner July 11, 2026 01:03
Copilot AI review requested due to automatic review settings July 11, 2026 01:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

✅ TypeScript Types Auto-Updated

The generated TypeScript types have been automatically updated based on JSON schema changes in this PR.

Copilot AI review requested due to automatic review settings July 11, 2026 01:08
@harshach
harshach removed the request for review from Copilot July 11, 2026 01:08
Copilot AI review requested due to automatic review settings July 11, 2026 01:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 11, 2026 04:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 64%
64.12% (74955/116881) 47.77% (44323/92765) 48.7% (13468/27652)

@gitar-bot

gitar-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 3 resolved / 3 findings

Implements configurable Persona AI context with admin CRUD, deterministic materialization, and MCP retrieval, resolving earlier build timeout and validation issues. Comprehensive testing across backend and UI confirms stable performance.

✅ 3 resolved
✅ Performance: findRule() does O(n²) deep-Map equals during materialization

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextBuilder.java:475-476 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextBuilder.java:574-581 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextBuilder.java:781-786
In enrichAssetKnowledge, for every selected asset the code calls findRule(materializedRules, asset), which streams over all rules and calls rule.entities().contains(selectedEntity). SelectedEntity is a record whose components include the raw Map<String,Object> document (the full Elasticsearch hit) and AIContext. List.contains uses equals, so each lookup performs a deep Map.equals comparison against every other entity until it finds the match. With up to 25 rules × 1000 assets each (plus Data-Product expansions of up to 1000 members apiece), this is O(N²) deep-map comparisons on a code path that materializes the whole persona document. For a few thousand entities this becomes tens of millions of expensive map comparisons per build.

Fix: capture the owning rule while selecting entities (a single pass) instead of searching afterward — e.g. build an IdentityHashMap<SelectedEntity, ContextRule> once in selectRules/build, or store the rule reference on SelectedEntity, and look it up in constant time.

✅ Bug: getAiContextDocument validates 'format' but never uses it

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/PersonaResource.java:377-387 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/PersonaResource.java:575-579 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/PersonaResource.java:581-595
getAiContextDocument accepts a format query param (rendered/raw), validates it via validateDocumentFormat, then calls documentResponse(cached) which ignores the format entirely and always returns the same PersonaContextDocument. So requesting format=raw produces identical output to format=rendered. Either wire the format through to documentResponse (e.g. to select markdown vs. an unrendered payload) or remove the parameter and its validation to avoid advertising behavior that does not exist.

✅ Edge Case: Waiter timeout (15s) far shorter than build lease (120s) throws 500

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextCache.java:44-46 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextCache.java:137-148 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextCache.java:298-312
In PersonaContextCache.get() the single-flight waiter polls POLL_ATTEMPTS (30) * POLL_MILLIS (500ms) = 15s in waitForWinner(), but the lock holder is granted a BUILD_LEASE of 120s. If the concurrent build legitimately takes longer than 15s (materializing up to 25 rules × up to 1000 assets, each potentially loading heavy sections such as lineage and data-quality via separate AIContextBuilder search round-trips), the waiter's poll loop returns null, the follow-up provider.setIfAbsent(lockKey, lockOwner, BUILD_LEASE) fails because the original lease is still held, and the method throws IllegalStateException("Timed out waiting for persona context materialization ...").

This is a behavioral regression: before this commit, a waiter that could not get the winner simply fell through and built locally (redundant work, but no error). Now a slow-but-healthy concurrent build surfaces as a hard 500 to REST/MCP callers for the same persona. The window is realistically reachable under concurrent first-access (cache miss) for a large persona.

Suggested fix: make the poll horizon cover the build lease (e.g. poll for ~BUILD_LEASE), or on timeout fall back to building locally / returning the previous cached document (BYPASS) instead of throwing.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Copilot AI review requested due to automatic review settings July 12, 2026 04:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@harshach
harshach merged commit d560b10 into main Jul 12, 2026
97 of 106 checks passed
@harshach
harshach deleted the harshach/persona-context branch July 12, 2026 18:12
@gitar-bot

gitar-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 3 resolved / 3 findings

Adds configurable Persona AI context with rules, caching, and an admin UI, successfully resolving earlier findings regarding materialization efficiency, format validation, and waiter timeouts.

✅ 3 resolved
✅ Performance: findRule() does O(n²) deep-Map equals during materialization

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextBuilder.java:475-476 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextBuilder.java:574-581 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextBuilder.java:781-786
In enrichAssetKnowledge, for every selected asset the code calls findRule(materializedRules, asset), which streams over all rules and calls rule.entities().contains(selectedEntity). SelectedEntity is a record whose components include the raw Map<String,Object> document (the full Elasticsearch hit) and AIContext. List.contains uses equals, so each lookup performs a deep Map.equals comparison against every other entity until it finds the match. With up to 25 rules × 1000 assets each (plus Data-Product expansions of up to 1000 members apiece), this is O(N²) deep-map comparisons on a code path that materializes the whole persona document. For a few thousand entities this becomes tens of millions of expensive map comparisons per build.

Fix: capture the owning rule while selecting entities (a single pass) instead of searching afterward — e.g. build an IdentityHashMap<SelectedEntity, ContextRule> once in selectRules/build, or store the rule reference on SelectedEntity, and look it up in constant time.

✅ Bug: getAiContextDocument validates 'format' but never uses it

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/PersonaResource.java:377-387 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/PersonaResource.java:575-579 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/PersonaResource.java:581-595
getAiContextDocument accepts a format query param (rendered/raw), validates it via validateDocumentFormat, then calls documentResponse(cached) which ignores the format entirely and always returns the same PersonaContextDocument. So requesting format=raw produces identical output to format=rendered. Either wire the format through to documentResponse (e.g. to select markdown vs. an unrendered payload) or remove the parameter and its validation to avoid advertising behavior that does not exist.

✅ Edge Case: Waiter timeout (15s) far shorter than build lease (120s) throws 500

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextCache.java:44-46 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextCache.java:137-148 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PersonaContextCache.java:298-312
In PersonaContextCache.get() the single-flight waiter polls POLL_ATTEMPTS (30) * POLL_MILLIS (500ms) = 15s in waitForWinner(), but the lock holder is granted a BUILD_LEASE of 120s. If the concurrent build legitimately takes longer than 15s (materializing up to 25 rules × up to 1000 assets, each potentially loading heavy sections such as lineage and data-quality via separate AIContextBuilder search round-trips), the waiter's poll loop returns null, the follow-up provider.setIfAbsent(lockKey, lockOwner, BUILD_LEASE) fails because the original lease is still held, and the method throws IllegalStateException("Timed out waiting for persona context materialization ...").

This is a behavioral regression: before this commit, a waiter that could not get the winner simply fell through and built locally (redundant work, but no error). Now a slow-but-healthy concurrent build surfaces as a hard 500 to REST/MCP callers for the same persona. The window is realistically reachable under concurrent first-access (cache miss) for a large persona.

Suggested fix: make the poll horizon cover the build lease (e.g. poll for ~BUILD_LEASE), or on timeout fall back to building locally / returning the previous cached document (BYPASS) instead of throwing.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

This branch had an error being deployed

1 failed deployment
test — c2027596 Deployed Jul 12, 2026 by harshach via playwright-ci-postgresql (3, 7) #55966
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.

Feature: AI Context Platform for agent-ready asset retrieval

4 participants