Repository navigation
fix(agent-context): send Document fields to OSS servers; keep semantic search score Cloud-only - #21879
fix(agent-context): send Document fields to OSS servers; keep semantic search score Cloud-only#21879shirshanka wants to merge 3 commits into
Conversation
…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.
PR SummaryOverview
Adds Reviewed by Cursor Bugbot for commit 70d9076. Bugbot is set up for automated code reviews on this repo. Configure here. |
Smart test selectionpytest smoke testsMode: active. Only the selection below runs for the pytest smoke tests on this PR (applied:
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)
Add the Playwright E2E testsThis run:
Specs selected because of this PR (18)
Add the commit |
There was a problem hiding this comment.
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 \{") |
There was a problem hiding this comment.
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>
| 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] = {} |
There was a problem hiding this comment.
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>
| _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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Two fixes to how the agent tools in
datahub-agent-contextsend tagged GraphQL fields to OSS servers.get_entitiessent no Document fields to OSS servers. Fields that arrived after older GMS releases are tagged#[NEWER_GMS]in the.gqlfiles. That includes every... on Documentarm inentity_details.gql.execute_graphqlonly 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 hadDocumentsince v1.4.0.execute_graphqlnow 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 logicmcp-server-datahubalready uses (graphql_helpers.execute_graphql).Semantic document search asked for
score, which the OSS schema doesn't have.SearchResult.scoreis only in the Cloud schema. It is now tagged#[CLOUD] #[NEWER_GMS], likeincidentStatusinentity_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.Fallbacks are keyed on the graph object, not
id(graph). CPython reuses a freed object'sid(), so a newDataHubGraphcould inherit an earlier graph's cached fallbacks and leave out newer fields its server supports. The cache is now aweakref.WeakKeyDictionarykeyed 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.gqlfile in the package validates against the OSS schema indatahub-graphql-coreon master. That holds for both the first query and the fallback. Before,document_semantic_search.gqlfailed onscore.Behaviour on other servers
Documenttype):GetEntitynow 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.DISABLE_NEWER_GMS_FIELD_DETECTION=truestill turns tagged fields off everywhere.Overlap with open PRs
#21876 adds OKF fields to
document_search.gqlanddocument_semantic_search.gql. With this change, OSS servers get those fields on the first try. The only overlap is thescoreline indocument_semantic_search.gql, which is a separate hunk. No conflict is expected.Testing
New regression tests. Each one fails on
masterand 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_entitieson a document sends a query with an active... on Documentarm, includingcontentsandownership. 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.gqlfile with graphql-core againstdatahub-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 withCannot 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 sameid()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.score; Cloud still requestsscore; after a failed fallback, the next call sends the full query again.Checks run:
pytest tests: 705 passed, 3 xfailed.ruff check,ruff format --checkandmypypass.graphql-coreis added to thedevextra for the schema test.Checklist
🤖 Opened with cclaude on behalf of @shirshanka