Skip to content

Backport 2.0: AI context trust signals (#32261) + prerequisite MCP context-memory visibility (#32465) - #32973

Merged
pmbrull merged 2 commits into
2.0from
pmbrull/cherry-pick-32261-2.0
Sep 8, 2026
Merged

pmbrull merged 2 commits into
2.0from
pmbrull/cherry-pick-32261-2.0

Conversation

@pmbrull

@pmbrull pmbrull commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Two backports to 2.0, cherry-picked in dependency order:

# Upstream SHA Why
1 #32261 — trust signals for AI context (Fixes #32260) c3d6c03 The backport that was asked for
2 #32465 — Apply context memory visibility rules on MCP entity reads d3ab545 Prerequisite. 2.0 did not compile without it — see below

Why #32465 is in this PR

2.0 was broken at HEAD before this branch. 1f7813f0b0 (the 2.0 backport of #32858, fix(context): hydrate owners for memory reads) added two call sites of ContextMemoryVisibility.guardFields(entityType, fieldsParam) in ContextMemoryResource.java (lines 400 and 438), but #32465 — the PR that defines guardFields on ContextMemoryVisibility — was never backported:

[ERROR] .../resources/context/ContextMemoryResource.java:[400,36] cannot find symbol
[ERROR]   symbol:   method guardFields(java.lang.String,java.lang.String)
[ERROR]   location: class org.openmetadata.service.resources.context.ContextMemoryVisibility

Nothing on push-to-2.0 compiles Java (only CodeQL runs), which is why this went unnoticed. Picking #32465 here both restores the branch and lets this PR's CI actually validate the #32261 backport instead of failing on a pre-existing break.

What #32261 does

Knowledge pills (ContextMemory items) attached to an asset flowed into AI context bundles (get_asset_context, persona documents) regardless of lifecycle state, and the bundle never told an agent whether the knowledge it received was still current.

  1. Active-only pill gating — toPillKnowledgeItem mirrors the glossary path's approval gating: pills in Draft or Archived state with a live APPLIED_TO edge are no longer served to agents as current context. Pre-lifecycle memories (no status) remain visible, matching how isApproved treats a missing glossary review status.

  2. Read-time staleness stamping — KnowledgeItem gains additive stale + staleReasons fields, stamped by AIContextBuilder from two deterministic, pure-function signals:

    • assetUpdatedAfterKnowledge — the attached asset's updatedAt is newer than the knowledge item's last update;
    • dataQualityFailing / upstreamDataQualityFailing — the asset's (or a direct upstream's, capped at 3 edges, gated behind VIEW_TESTS and memoized per bundle) data-quality tests are failing.

    Stamping is informational only — items are never removed, so agents can weigh the signal instead of silently losing context.

  3. Compact Markdown trust cue — stale items render a one-line cue naming the reasons, only when stale; the cue's exact rendered length is charged to the existing knowledge budget (fitItem) so it can never push a bundle past the caller's budget.

No new status vocabulary, no new provenance model, no relational migration (additive fields on the KnowledgeItem JSON type; ContextMemory schema untouched).

What #32465 does

Applies the per-entity ContextMemory visibility rules on MCP entity reads: CommonUtils.readEntityForCaller / enforceEntityVisibility, wired into GetEntityTool, PatchEntityTool and CompanyContextTool, plus the guardFields / hasVisibilityRules helpers on ContextMemoryVisibility that merge owners into the caller's field selection (a read that omits owners hands the guard an ownerless memory and denies the owner their own private memory).

Type of change:

  • Bug fix
  • Improvement

Backport fidelity:

Both picks were diffed line-by-line against their upstream commits, comparing only added/removed content lines (ignoring blob hashes and hunk offsets):

Also checked: ContextMemoryStatus (Draft/Active/Archived) exists on 2.0 with the same vocabulary, so the pill gate keeps its meaning.

Tests:

Use cases covered

  • Archived/Draft pill attached to a table is excluded from get_asset_context output
  • Pill on an asset updated after the pill's last update is flagged stale with assetUpdatedAfterKnowledge
  • Pill on an asset (or upstream) with failing DQ tests is flagged with the corresponding reason
  • Fresh pill on a healthy asset carries no stale flag or reasons
  • A stale item's markdown excerpt shrinks so cue + excerpt fit the caller's knowledge budget
  • Trust cue renders in Compact Markdown exactly once, only for stale items
  • MCP get_entity / patch_entity / company-context reads honour ContextMemory visibility; guardFields merges owners into the caller's field selection

Unit tests

Both upstream test suites come across with the picks. Green on this branch:

Tests run: 46, Failures: 0, Errors: 0, Skipped: 0 -- AIContextBuilderTest
Tests run: 17, Failures: 0, Errors: 0, Skipped: 0 -- ContextMemoryVisibilityTest
Tests run: 16, Failures: 0, Errors: 0, Skipped: 0 -- CompanyContextToolTest
Tests run: 29, Failures: 0, Errors: 0, Skipped: 0 -- GetEntityToolTest
Tests run: 17, Failures: 0, Errors: 0, Skipped: 0 -- PatchEntityToolTest

Backend integration tests

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI behavior change; generated TS types only).

Manual testing performed

mvn -pl openmetadata-service,openmetadata-mcp,openmetadata-integration-tests -am install -DskipTests   -> BUILD SUCCESS
mvn -pl openmetadata-service,openmetadata-mcp,openmetadata-integration-tests spotless:check            -> BUILD SUCCESS

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR is linked to the original PRs and issue above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: additive JSON-type fields only; entity JSON column storage means no migration is required.
  • For UI changes: N/A — generated types only.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

…ad-time staleness stamping (#32261)

* Fixes #32260: trust signals for AI context — gate pills on Active, read-time staleness stamping

* Fixes #32260: address review — exact cue budget sizing, upstream DQ authorization gate, log placeholder

* Fixes #32260: charge stale cue to the shared budget pool; count ellipsis inside the excerpt limit

* Fixes #32260: guard excerpt against non-positive limits (zero-allowance structural preview)

* Fixes #32260: gate upstream DQ behind VIEW_TESTS, bound structural preview to the excerpt limit

* Fixes #32260: suppress caller-relative upstream DQ signal when no caller context exists (persona materialization)

(cherry picked from commit c3d6c03)
@pmbrull
pmbrull requested review from a team as code owners September 8, 2026 15:47
@github-actions

github-actions Bot commented Sep 8, 2026

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 Ingestion safe to test Add this label to run secure Github workflows on PRs labels Sep 8, 2026
"default": false
},
"staleReasons": {
"description": "Machine-readable reasons for the stale flag (e.g. assetUpdated, dataQualityFailing).",

@gitar-bot gitar-bot Bot Sep 8, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: staleReasons schema example doesn't match emitted value

The staleReasons description in aiContext.json lists the example reason assetUpdated, but stampStaleness actually emits assetUpdatedAfterKnowledge (alongside dataQualityFailing and upstreamDataQualityFailing). This schema field is consumer-facing for agents, so the mismatched example is misleading. Update the example to the real reason strings.

Align the schema example with the reason strings the builder emits.:

"description": "Machine-readable reasons for the stale flag (e.g. assetUpdatedAfterKnowledge, dataQualityFailing, upstreamDataQualityFailing).",

Was this helpful? React with 👍 / 👎

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Playwright Results — workflow failed

Validated commit f81ecf50f09c359877134c3271e3e425d330c745 in Playwright run 34250390678, attempt 1.

✅ 0 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

⚙️ No test failures. This run failed in CI infrastructure or reporting (see Pipeline and setup failures), not because of your changes — no test action needed from you.

Pipeline and setup failures (26)

  • Seeded fixture preparation finished with status failure.
  • The Playwright shard matrix was unexpectedly skipped.
  • Shard chromium-01 did not upload a usable Playwright results artifact.
  • Shard chromium-02 did not upload a usable Playwright results artifact.
  • Shard chromium-03 did not upload a usable Playwright results artifact.
  • Shard chromium-04 did not upload a usable Playwright results artifact.
  • Shard chromium-05 did not upload a usable Playwright results artifact.
  • Shard data-asset-rules-01 did not upload a usable Playwright results artifact.
  • Shard domain-isolation-01 did not upload a usable Playwright results artifact.
  • Shard global-state-01 did not upload a usable Playwright results artifact.
  • Shard ingestion-01 did not upload a usable Playwright results artifact.
  • Shard reindex-01 did not upload a usable Playwright results artifact.
  • Shard search-01 did not upload a usable Playwright results artifact.
  • Shard search-rbac-01 did not upload a usable Playwright results artifact.
  • Shard chromium-01 did not upload its execution status.
  • Shard chromium-02 did not upload its execution status.
  • Shard chromium-03 did not upload its execution status.
  • Shard chromium-04 did not upload its execution status.
  • Shard chromium-05 did not upload its execution status.
  • Shard data-asset-rules-01 did not upload its execution status.
  • Shard domain-isolation-01 did not upload its execution status.
  • Shard global-state-01 did not upload its execution status.
  • Shard ingestion-01 did not upload its execution status.
  • Shard reindex-01 did not upload its execution status.
  • Shard search-01 did not upload its execution status.
  • Shard search-rbac-01 did not upload its execution status.

Performance

⚪ Performance metrics unavailable; see the CI and reporting failures above.

Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
⛔ Shard chromium-01 — — — — — —
⛔ Shard chromium-02 — — — — — —
⛔ Shard chromium-03 — — — — — —
⛔ Shard chromium-04 — — — — — —
⛔ Shard chromium-05 — — — — — —
⛔ Shard data-asset-rules-01 — — — — — —
⛔ Shard domain-isolation-01 — — — — — —
⛔ Shard global-state-01 — — — — — —
⛔ Shard ingestion-01 — — — — — —
⛔ Shard reindex-01 — — — — — —
⛔ Shard search-01 — — — — — —
⛔ Shard search-rbac-01 — — — — — —

📦 Download artifacts

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

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 67%
67.17% (80747/120206) 51.8% (49681/95903) 52.57% (14759/28072)

* fix(mcp): apply per-entity visibility rules on direct entity reads

* test(mcp): cover the shared-pill lookup and state the rule in comments

* review: exercise the sharedWith path, cover the admin branch, correct the scope note

(cherry picked from commit d3ab545)
@pmbrull pmbrull changed the title Backport 2.0: trust signals for AI context — gate pills on Active, read-time staleness stamping (#32261) Backport 2.0: AI context trust signals (#32261) + prerequisite MCP context-memory visibility (#32465) Sep 8, 2026
@gitar-bot

gitar-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Backports AI context trust signals (#32261) and prerequisite MCP context-memory visibility (#32465) to 2.0. Pills now gate on Active lifecycle state, knowledge items are stamped with staleness signals (asset updates, failing data-quality tests), and MCP entity reads honour ContextMemory visibility rules. All unit tests pass. Minor: the staleReasons schema example lists assetUpdated, but the code emits assetUpdatedAfterKnowledge—update the example to match the actual reason strings.

💡 Quality: staleReasons schema example doesn't match emitted value

📄 openmetadata-spec/src/main/resources/json/schema/type/aiContext.json:47 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/AIContextBuilder.java:601-607

The staleReasons description in aiContext.json lists the example reason assetUpdated, but stampStaleness actually emits assetUpdatedAfterKnowledge (alongside dataQualityFailing and upstreamDataQualityFailing). This schema field is consumer-facing for agents, so the mismatched example is misleading. Update the example to the real reason strings.

Align the schema example with the reason strings the builder emits.
"description": "Machine-readable reasons for the stale flag (e.g. assetUpdatedAfterKnowledge, dataQualityFailing, upstreamDataQualityFailing).",
🤖 Prompt for agents
Code Review: Backports AI context trust signals (#32261) and prerequisite MCP context-memory visibility (#32465) to `2.0`. Pills now gate on Active lifecycle state, knowledge items are stamped with staleness signals (asset updates, failing data-quality tests), and MCP entity reads honour ContextMemory visibility rules. All unit tests pass. Minor: the `staleReasons` schema example lists `assetUpdated`, but the code emits `assetUpdatedAfterKnowledge`—update the example to match the actual reason strings.

1. 💡 Quality: staleReasons schema example doesn't match emitted value
   Files: openmetadata-spec/src/main/resources/json/schema/type/aiContext.json:47, openmetadata-service/src/main/java/org/openmetadata/service/aicontext/AIContextBuilder.java:601-607

   The `staleReasons` description in aiContext.json lists the example reason `assetUpdated`, but `stampStaleness` actually emits `assetUpdatedAfterKnowledge` (alongside `dataQualityFailing` and `upstreamDataQualityFailing`). This schema field is consumer-facing for agents, so the mismatched example is misleading. Update the example to the real reason strings.

   Fix (Align the schema example with the reason strings the builder emits.):
   "description": "Machine-readable reasons for the stale flag (e.g. assetUpdatedAfterKnowledge, dataQualityFailing, upstreamDataQualityFailing).",

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 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

@pmbrull
pmbrull merged commit 32eb245 into 2.0 Sep 8, 2026
112 of 122 checks passed
@pmbrull
pmbrull deleted the pmbrull/cherry-pick-32261-2.0 branch September 8, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion 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