fix(agent-context): send Document fields to OSS servers; keep semantic search score Cloud-only
Summary
Two fixes to how the agent tools in datahub-agent-context send 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 .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
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. - 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=truestill 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_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.- Also added: OSS semantic search runs once and doesn't request
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
- 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