Skip to content

fix(agent-context): send Document fields to OSS servers; keep semantic search score Cloud-only - #21879

Open
shirshanka wants to merge 3 commits into
masterfrom
fix/agent-context-oss-document-fields
Open

shirshanka wants to merge 3 commits into
masterfrom
fix/agent-context-oss-document-fields

Conversation

@shirshanka

@shirshanka shirshanka commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two fixes to how the agent tools in datahub-agent-context send tagged GraphQL fields to OSS servers.

  1. get_entities sent no Document fields to OSS servers. Fields that arrived after older GMS releases are tagged #[NEWER_GMS] in the .gql files. That includes every ... on Document arm in entity_details.gql. execute_graphql only turned those fields on for Cloud. OSS servers never got them, so a document came back without its title, contents, owners, tags or domain. That is true even on OSS releases that have had Document since v1.4.0.
    execute_graphql now sends tagged fields to every server and, on a schema error, retries without them. The fallback is cached per graph and query, so one query that needs the fallback no longer turns tagged fields off for every other tool on that server. This is the same logic mcp-server-datahub already uses (graphql_helpers.execute_graphql).

  2. Semantic document search asked for score, which the OSS schema doesn't have. SearchResult.score is only in the Cloud schema. It is now tagged #[CLOUD] #[NEWER_GMS], like incidentStatus in entity_details.gql. CLOUD filtering comments it out for OSS before the tagged-field check runs, so it can't make OSS queries fail and fall back. Cloud still requests it and still falls back if a server lacks it.

  3. Fallbacks are keyed on the graph object, not id(graph). CPython reuses a freed object's id(), so a new DataHubGraph could inherit an earlier graph's cached fallbacks and leave out newer fields its server supports. The cache is now a weakref.WeakKeyDictionary keyed on the graph, and its entries go away with the graph.

Fields that only exist on Cloud stay tagged #[CLOUD]. With these two changes, every .gql file in the package validates against the OSS schema in datahub-graphql-core on master. That holds for both the first query and the fallback. Before, document_semantic_search.gql failed on score.

Behaviour on other servers

  • OSS before v1.4.0 (no Document type): GetEntity now fails once on each server and falls back to the query without tagged fields. That fallback is what those servers ran before, and it is cached for the query, so later calls go straight to it.
  • Cloud: the first attempt is unchanged. A fallback is now remembered per query, not for every query on that server.
  • DISABLE_NEWER_GMS_FIELD_DETECTION=true still turns tagged fields off everywhere.

Overlap with open PRs

#21876 adds OKF fields to document_search.gql and document_semantic_search.gql. With this change, OSS servers get those fields on the first try. The only overlap is the score line in document_semantic_search.gql, which is a separate hunk. No conflict is expected.

Testing

New regression tests. Each one fails on master and passes with this change:

  • tests/unit/mcp_tools/test_newer_gms_fields.py::test_get_entities_sends_document_fields_to_oss: on an OSS graph, get_entities on a document sends a query with an active ... on Document arm, including contents and ownership. Fails on master.
  • tests/unit/mcp_tools/test_gql_schema_compat.py::test_full_query_validates_against_oss_schema[document_semantic_search.gql]: validates each .gql file with graphql-core against datahub-graphql-core/src/main/resources/**/*.graphql, as an OSS server receives it (CLOUD lines stripped). It checks the full query and the fallback. Fails on master with Cannot query field 'score' on type 'SearchResult'.
  • test_newer_gms_fields.py::test_fallback_is_cached_per_query: a fallback in one query doesn't drop tagged fields from another. Fails on master.
  • test_newer_gms_fields.py::test_fallback_is_not_shared_by_graphs_with_the_same_id: two graphs that report the same id() don't share fallbacks. Fails before the cache fix (the new graph inherits the old one's fallback).
  • test_newer_gms_fields.py::test_fallbacks_are_dropped_with_their_graph: a freed graph's fallbacks are removed from the cache.
  • Also added: OSS semantic search runs once and doesn't request score; Cloud still requests score; after a failed fallback, the next call sends the full query again.

Checks run:

  • pytest tests: 705 passed, 3 xfailed.
  • ruff check, ruff format --check and mypy pass.
  • graphql-core is added to the dev extra for the schema test.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (PR title format)
  • Tests for the changes have been added
  • Docs: n/a
  • Breaking changes: n/a

🤖 Opened with cclaude on behalf of @shirshanka

…loud-only

get_entities never sent #[NEWER_GMS] fields to OSS servers, so Document
lookups came back without title, contents or owners. Probe tagged fields on
every server and cache the fallback per graph and query, as
mcp-server-datahub does. Tag SearchResult.score #[CLOUD] as well, since the
OSS schema does not have it, so OSS semantic document search is valid on the
first try.
@cclaude-datahub-project cclaude-datahub-project Bot added the cclaude Opened from a cclaude box label Dec 4, 2026
@cursor

cursor Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
execute_graphql no longer treats #[NEWER_GMS] as Cloud-only. OSS agents now attempt queries with those fields enabled, retry without them on schema validation errors, and remember fallbacks per graph and query via a weakref cache (only after a successful retry). That fixes get_entities on OSS so Document fragments (title, contents, ownership, etc.) are actually requested instead of being stripped up front.

document_semantic_search.gql tags SearchResult.score with #[CLOUD] #[NEWER_GMS] so OSS strips score before the newer-GMS probe, avoiding spurious fallbacks while Cloud still requests it.

Adds graphql-core to dev deps and new tests that validate all MCP .gql files against the repo OSS schema (full query and fallback), plus unit tests for per-query fallback caching, Cloud-only score, and graph lifecycle on the fallback cache.

Reviewed by Cursor Bugbot for commit 70d9076. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Smart test selection

pytest smoke tests

Mode: active. Only the selection below runs for the pytest smoke tests on this PR (applied: smart).

  • Selection: smart: tests for the tagged features, plus always-run modules, this PR's changed tests, and the plumbing sample if the PR changes the pytest harness
  • Size: 188 of 859 tests in 1 batch, predicted longest batch ~3 min
  • Tags: change-type: build; entity-scope: dataset; feature-dev: semantic-search; feature-user: documentation, search; technical-layer: graphql
  • Confidence: MEDIUM (6 changed files)
  • Classifier reasoning: Changes adjust GraphQL newer-GMS field fallback logic in agent tools (affecting document semantic search and incidents queries), add a graphql-core test dependency, and add schema-compat tests; product code is touched so feature tags apply, while setup.py is a build-level change.

Medium confidence: a wrong tag means tests are skipped, so check the tags above against what this PR touches.

Selected scopes (40 files or classes, 188 tests)
  • tests/e2e/actions/doc_propagation/test_propagation.py
  • tests/e2e/authorization/test_self_entity_auth.py
  • tests/e2e/browse/browse_test.py
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchBasic
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchDiagnose
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchDryRun
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchErrorHandling
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFilterCombinations
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFiltersByEntityType
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFiltersByPlatform
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchPagination
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchProjectionLive
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchWhereFilter
  • tests/e2e/delete/delete_assertion_cascade_test.py
  • tests/e2e/frontend/test_static_asset_encodings.py
  • tests/e2e/institutional_memory/institutional_memory_test.py
  • tests/e2e/knowledge/document_change_history_test.py
  • tests/e2e/knowledge/document_search_filter_test.py
  • tests/e2e/knowledge/test_document_crud.py::TestDocumentCrudAndMutations
  • tests/e2e/knowledge/test_document_hierarchy_settings.py::TestDocumentHierarchyAndSettings
  • tests/e2e/knowledge/test_document_search_history.py::TestDocumentSearchAndHistory
  • tests/e2e/knowledge/test_okf_reimport.py
  • tests/e2e/managed_ingestion/ingestion_source_run_events_test.py
  • tests/e2e/mcp/mcp_test.py
  • tests/e2e/query_projection/test_query_projection_smoke.py
  • tests/e2e/read_only/test_search.py
  • tests/e2e/read_only/test_services_up.py
  • tests/e2e/search/test_lineage_search_index_fields.py
  • tests/e2e/search/test_search_projection.py::TestSearchProjection
  • tests/e2e/semantic/test_classical_embedding_provider.py::TestClassicalEmbeddingProvider
  • tests/e2e/semantic/test_config_fingerprint.py::TestConfigFingerprint
  • tests/e2e/semantic/test_current_offset_api.py
  • tests/e2e/semantic/test_event_driven_docs.py::TestEventDrivenDocumentIngestion
  • tests/e2e/semantic/test_event_mode_fallback.py::TestEventModeFallback
  • tests/e2e/semantic/test_local_embedding_provider.py::TestLocalEmbeddingProvider
  • tests/e2e/semantic/test_semantic_search.py::TestSemanticSearchWithIngestion
  • tests/e2e/semantic/test_source_type_filtering.py::TestSourceTypeFiltering
  • tests/e2e/semantic/test_stateful_ingestion.py::TestStatefulIngestion
  • tests/e2e/siblings/siblings_search_batching_test.py
  • tests/e2e/test_e2e.py

Add the run-all-tests:pytest label to run the full pytest suite on this PR.

Playwright E2E tests

This run: smart

  • Selection: smart: specs tagged documentation, search, semantic-search plus the tests the change affects
  • Size: 87 tests in 18 spec files, ~19 min predicted on 3 shard(s)
Specs selected because of this PR (18)
Spec Tests Why
autocomplete-v2/autocomplete.spec.ts 2/2 tagged search
browse-v2/browse-v2.spec.ts 10/10 tagged search
documents/document-import.spec.ts 3/3 tagged documentation
documents/document-management.spec.ts 11/11 tagged documentation
documents/document-tree-expand.spec.ts 2/2 tagged documentation
documents/external-document-profile.spec.ts 1/1 tagged documentation
entity-pages/summary-tab/v2-dataset-summary-about-section.spec.ts 2/2 tagged documentation
entity-pages/summary-tab/v2-summary-tab-about-section.spec.ts 2/2 tagged documentation
logical-models/physical-children-view.spec.ts 2/2 tagged search
mutations-v2/v2-edit-documentation.spec.ts 7/7 tagged documentation
mutations/edit-documentation.spec.ts 1/1 tagged documentation
schema-scale/schema-scale.spec.ts 2/2 tagged documentation
search/query-and-filter-search.spec.ts 10/10 tagged search
search/search-filters.spec.ts 5/5 tagged search
search/search-within-operator.spec.ts 1/1 tagged search
search/search.spec.ts 7/7 tagged search
search/searchv2.spec.ts 15/15 tagged search
upload-files/upload-files.spec.ts 4/4 tagged documentation

Add the run-all-tests:playwright label to run the full Playwright suite on this PR.

commit 70d9076 · workflow run

@cubic-dev-ai cubic-dev-ai Bot 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.

2 issues found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="datahub-agent-context/tests/unit/mcp_tools/test_newer_gms_fields.py">

<violation number="1" location="datahub-agent-context/tests/unit/mcp_tools/test_newer_gms_fields.py:66">
P2: This query-wide assertion does not verify that the Document selection requests ownership. Scope the check to the tagged `... on Document` block so this regression test fails when that field is removed.</violation>
</file>

<file name="datahub-agent-context/src/datahub_agent_context/mcp_tools/base.py">

<violation number="1" location="datahub-agent-context/src/datahub_agent_context/mcp_tools/base.py:16">
P3: This module-global cache now retains every distinct graph/query pair forever, including the full query text, with no eviction or size bound. Use a bounded cache so dynamically generated queries or repeatedly recreated graph clients cannot grow process memory indefinitely.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

query = sent["GetEntity"]
assert _selects(query, r"\.\.\. on Document \{")
assert _selects(query, r"^\s*contents \{")
assert _selects(query, r"^\s*ownership \{")

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.

P2: This query-wide assertion does not verify that the Document selection requests ownership. Scope the check to the tagged ... on Document block so this regression test fails when that field is removed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At datahub-agent-context/tests/unit/mcp_tools/test_newer_gms_fields.py, line 66:

<comment>This query-wide assertion does not verify that the Document selection requests ownership. Scope the check to the tagged `... on Document` block so this regression test fails when that field is removed.</comment>

<file context>
@@ -0,0 +1,138 @@
+    query = sent["GetEntity"]
+    assert _selects(query, r"\.\.\. on Document \{")
+    assert _selects(query, r"^\s*contents \{")
+    assert _selects(query, r"^\s*ownership \{")
+    assert result["info"]["contents"]["text"] == "How to count MAU"
+
</file context>
Suggested change
assert _selects(query, r"^\s*ownership \{")
assert re.search(
r"^\s*ownership \{.*#\[NEWER_GMS\]",
query.rsplit("... on Document {", 1)[1],
re.MULTILINE,
)

# one operation does not imply that every newer field is unavailable: an OSS server
# that has Document but lacks some other tagged field must still get Document fields.
# Key: (id(graph), query), Value: False once the query only worked without newer fields.
_newer_gms_fields_support_cache: dict[tuple[int, str], bool] = {}

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.

P3: This module-global cache now retains every distinct graph/query pair forever, including the full query text, with no eviction or size bound. Use a bounded cache so dynamically generated queries or repeatedly recreated graph clients cannot grow process memory indefinitely.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At datahub-agent-context/src/datahub_agent_context/mcp_tools/base.py, line 16:

<comment>This module-global cache now retains every distinct graph/query pair forever, including the full query text, with no eviction or size bound. Use a bounded cache so dynamically generated queries or repeatedly recreated graph clients cannot grow process memory indefinitely.</comment>

<file context>
@@ -9,9 +9,11 @@
+# one operation does not imply that every newer field is unavailable: an OSS server
+# that has Document but lacks some other tagged field must still get Document fields.
+# Key: (id(graph), query), Value: False once the query only worked without newer fields.
+_newer_gms_fields_support_cache: dict[tuple[int, str], bool] = {}
 
 # Default view configuration
</file context>
Suggested change
_newer_gms_fields_support_cache: dict[tuple[int, str], bool] = {}
_newer_gms_fields_support_cache: cachetools.LRUCache = cachetools.LRUCache(maxsize=128)

…id(graph)

A freed graph's id() can be reused by a new graph, which then inherited the
old graph's fallbacks. Keep them in a WeakKeyDictionary keyed on the graph
object, so they go away with it.
@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

This branch was successfully deployed

1 active deployment
Preview — 70d90760 Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cclaude Opened from a cclaude box

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant