Skip to content

feat(agent-context): return OKF document properties and add okf_* filter aliases - #21876

Open
shirshanka wants to merge 6 commits into
masterfrom
okf-agent-tools
Open

shirshanka wants to merge 6 commits into
masterfrom
okf-agent-tools

Conversation

@shirshanka

@shirshanka shirshanka commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What

Agents using the datahub-agent-context document tools now see OKF metadata and can filter on it. The same change for the standalone MCP server is in acryldata/mcp-server-datahub#301. The two keep separate copies of the tools.

  • Fields: search_documents (keyword and semantic) and get_entities on a document return okfProperties: type, status, conceptId, declaredId, description, staleAfter, bundle { location rootPath okfVersion } and frontmatter. The frontmatter comes back as a JSON object, parsed after the last response cleanup. Keyword and hybrid search therefore return the same values, including nulls and empty lists. Above OKF_FRONTMATTER_CHAR_LIMIT (4000 chars, env-configurable) it is left out and frontmatterOmitted says why. Documents without OKF get nothing extra (DocumentMapper returns null for them).
  • Filter aliases in the shared parser (metadata-ingestion/src/datahub/cli/search_filter_parser.py, which agent-context re-exports and datahub search --where also uses), all matched with IEQUAL:
    • okf_type → okfType
    • okf_status → okfStatus
    • okf_bundle → okfBundleLocation
    • okf_bundle_root → okfBundleRootPath. One repository can hold several bundles, so the descriptions show pinning a bundle with okf_bundle and okf_bundle_root together.
    • okf_id → okfConceptId OR okfDeclaredId
    • okf_stale_after → okfStaleAfter, for >/</IS NULL (epoch ms)
    • A missing status is stable, as OKF specifies. So okf_status = stable (or an IN list containing it) becomes okfStatus IEQUAL stable OR (NOT EXISTS okfStatus AND EXISTS okfConceptId). Every OKF document has a conceptId, so that term keeps non-OKF documents out. okf_status != stable (and NOT okf_status = stable) matches only OKF documents that declare a status other than stable. Other values match as written.
    • The descriptions say okf_stale_after IS NULL is not "never stale": it also matches documents whose stale_after value could not be read.
      Negation applies De Morgan recursively, so NOT okf_id = x, okf_id != x and groups such as NOT (okf_id = x OR okf_type = guide) work. Before, _Not rejected them because okf_id spans two fields. IS [NOT] NULL works on every alias.
      As a side effect, NOT (a = x OR b = y) over plain custom fields now compiles to a != x AND b != y. It used to raise "Cannot negate a filter with multiple OR clauses".
  • Docs: FILTER_DOCS and the search_documents / get_entities descriptions cover the aliases, searching by OKF id (query="guide:mau", Search V3), and that type means entity type, so document types go through subtype / okf_type.

Why it sits where it does

  • The aliases belong in the shared CLI parser. It is the one parser behind agent-context and datahub search --where, so both pick them up.
  • get_entities reads OKF with its own small GetDocumentOkfProperties query and does not add it to GetEntity. GetEntity's Document arm is a #[NEWER_GMS] block, which is off on non-Cloud servers, so OKF placed there would never reach OSS.
  • The new selections are untagged. strip_unsupported_fields=True projects them away on servers before okfProperties existed.

Testing

  • metadata-ingestion/tests/unit/cli/test_search_filter_parser.py, next to the parser: each alias, okf_id and its negation, IS [NOT] NULL, okf_stale_after comparisons, and type still meaning entity type. Every new parser line is covered.

  • New test_okf_documents.py: the gql selections, frontmatter parse and omission, and get_entities (adds OKF for documents, survives a failed lookup, skips other entities).

  • Checked by hand that the three queries validate against this branch's GraphQL schema.

  • :datahub-agent-context:lint passes, and :datahub-agent-context:testFull passes (690 passed).

  • :metadata-ingestion:testSingle on tests/unit/cli/test_search_filter_parser.py passes (31 passed).

  • :metadata-ingestion:lint: ruff passes. mypy reports errors only in azure_data_factory files this PR doesn't touch.

  • PR title follows the format

  • Tests added

  • Docs (tool descriptions) updated

  • No breaking changes


🤖 Opened with cclaude on behalf of @shirshanka

search_documents and get_entities return okfProperties for documents with OKF
frontmatter, with the frontmatter parsed and capped in size. get_entities reads
it with its own query, since GetEntity's Document arm is a NEWER_GMS block.

The shared filter parser gains okf_type, okf_status, okf_bundle and okf_id
(concept or declared id), matched with IEQUAL, plus okf_stale_after for
comparisons. FILTER_DOCS and the tool descriptions document them, searching
by OKF id, and that type means entity type.
@github-actions github-actions Bot added the ingestion PR or Issue related to the ingestion of metadata label Dec 4, 2026
@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
Agents and CLI search can work with OKF (Open Knowledge Format) document metadata end-to-end.

Responses: search_documents (keyword, semantic, hybrid) and get_entities for document URNs now surface okfProperties (typed fields, bundle info, and parsed frontmatter). cap_okf_frontmatter parses the GraphQL JSON string into an object when under OKF_FRONTMATTER_CHAR_LIMIT (default 4000); larger frontmatter is dropped with frontmatterOmitted. Hybrid search defers shaping until after merge/cleanup so nulls in frontmatter are not stripped early. Documents fetch OKF via a separate GetDocumentOkfProperties query so OSS deployments without newer GetEntity blocks still get the fields when the server supports them.

Filters: The shared search_filter_parser adds case-insensitive okf_type, okf_status, okf_bundle, okf_bundle_root, okf_id, and okf_stale_after aliases (IEQUAL / range / NULL). okf_status = stable also matches OKF docs with no declared status; negation and multi-field aliases use expanded De Morgan handling so NOT (okf_id = x OR …) compiles instead of erroring. Tool docstrings and FILTER_DOCS document OKF usage and clarify that type means entity type, not OKF document type.

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

@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!

@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: 212 of 861 tests in 1 batch, predicted longest batch ~4 min
  • Tags: compound: ingestion:connector; entity-scope: dataset; feature-dev: search-indexing, semantic-search; feature-user: analytics, documentation, search; technical-layer: cli, graphql
  • Confidence: MEDIUM (9 changed files)
  • Classifier reasoning: Changes add OKF document fields to document search, get_entities and filter parsing, touching documentation, search, and CLI filter syntax; the ingestion:connector tag is not supported by these files and should be dropped.

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

Selected scopes (47 files or classes, 212 tests)
  • tests/e2e/actions/doc_propagation/test_propagation.py
  • tests/e2e/analytics/test_analytics.py
  • tests/e2e/analytics/test_highlights.py
  • tests/e2e/assertions/dbt_test_results_test.py
  • tests/e2e/audit_events/audit_events_test.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/knowledge/test_okf_search.py
  • tests/e2e/managed_ingestion/ingestion_source_run_events_test.py
  • tests/e2e/mcp/mcp_test.py
  • tests/e2e/odcs/test_odcs_ingestion.py
  • tests/e2e/query_projection/test_query_projection_smoke.py
  • tests/e2e/read_only/test_analytics.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.

commit f315a3b · workflow run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous 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.

3 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/src/datahub_agent_context/mcp_tools/helpers.py">

<violation number="1" location="datahub-agent-context/src/datahub_agent_context/mcp_tools/helpers.py:32">
P2: The 4000-character cap applies per document only. `search_documents` can return 50 documents, so one page can carry about 200k characters of frontmatter (roughly 50k tokens) with no response-level budget. Apply a running token or character budget on the documents search path, as `_select_results_within_budget` does for lineage and incidents.</violation>
</file>

<file name="metadata-ingestion/src/datahub/cli/search_filter_parser.py">

<violation number="1" location="metadata-ingestion/src/datahub/cli/search_filter_parser.py:509">
P2: Comparison operators on `okf_type`, `okf_status`, `okf_bundle`, and `okf_id` send the raw alias name to the backend, which matches nothing. Either map these aliases in the comparison branch or reject comparisons on non-numeric OKF fields with a clear `ValueError`.</violation>
</file>

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

<violation number="1" location="datahub-agent-context/tests/unit/mcp_tools/test_search_filter_parser.py:850">
P2: Custom agent: **Enforce Pragmatic Test Coverage**

`okf_stale_after IS NULL`, `okf_stale_after >`, and `okf_id IS NOT NULL` are new parser branches that these tests don't exercise — this file is the only coverage for the OKF aliases, and the PR description promises `>`/`<`/`IS NULL` on all of them. Extend the OKF tests with assertions for `okf_stale_after > x` (GREATER_THAN), `okf_stale_after IS NULL` (NOT EXISTS okfStaleAfter), and `okf_id IS NOT NULL` (OR of EXISTS on okfConceptId/okfDeclaredId).</violation>
</file>

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

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


# Max size of an OKF document's frontmatter (as JSON) in tool responses. Above it the
# frontmatter is left out and the typed okfProperties fields remain.
OKF_FRONTMATTER_CHAR_LIMIT = int(os.getenv("OKF_FRONTMATTER_CHAR_LIMIT", "4000"))

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: The 4000-character cap applies per document only. search_documents can return 50 documents, so one page can carry about 200k characters of frontmatter (roughly 50k tokens) with no response-level budget. Apply a running token or character budget on the documents search path, as _select_results_within_budget does for lineage and incidents.

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/helpers.py, line 32:

<comment>The 4000-character cap applies per document only. `search_documents` can return 50 documents, so one page can carry about 200k characters of frontmatter (roughly 50k tokens) with no response-level budget. Apply a running token or character budget on the documents search path, as `_select_results_within_budget` does for lineage and incidents.</comment>

<file context>
@@ -26,6 +27,10 @@
 
+# Max size of an OKF document's frontmatter (as JSON) in tool responses. Above it the
+# frontmatter is left out and the typed okfProperties fields remain.
+OKF_FRONTMATTER_CHAR_LIMIT = int(os.getenv("OKF_FRONTMATTER_CHAR_LIMIT", "4000"))
+
 
</file context>

value = self._expect_condition_value().value
return F.custom_filter(field, self._COMPARISON_OPS[op_token.type], [value])
return F.custom_filter(
_resolve_range_field(field),

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: Comparison operators on okf_type, okf_status, okf_bundle, and okf_id send the raw alias name to the backend, which matches nothing. Either map these aliases in the comparison branch or reject comparisons on non-numeric OKF fields with a clear ValueError.

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 metadata-ingestion/src/datahub/cli/search_filter_parser.py, line 509:

<comment>Comparison operators on `okf_type`, `okf_status`, `okf_bundle`, and `okf_id` send the raw alias name to the backend, which matches nothing. Either map these aliases in the comparison branch or reject comparisons on non-numeric OKF fields with a clear `ValueError`.</comment>

<file context>
@@ -481,7 +505,11 @@ def _parse_condition(self) -> Filter:
             value = self._expect_condition_value().value
-            return F.custom_filter(field, self._COMPARISON_OPS[op_token.type], [value])
+            return F.custom_filter(
+                _resolve_range_field(field),
+                self._COMPARISON_OPS[op_token.type],
+                [value],
</file context>

)


def test_okf_stale_after_supports_comparisons_and_null_checks():

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: Custom agent: Enforce Pragmatic Test Coverage

okf_stale_after IS NULL, okf_stale_after >, and okf_id IS NOT NULL are new parser branches that these tests don't exercise — this file is the only coverage for the OKF aliases, and the PR description promises >/</IS NULL on all of them. Extend the OKF tests with assertions for okf_stale_after > x (GREATER_THAN), okf_stale_after IS NULL (NOT EXISTS okfStaleAfter), and okf_id IS NOT NULL (OR of EXISTS on okfConceptId/okfDeclaredId).

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_search_filter_parser.py, line 850:

<comment>`okf_stale_after IS NULL`, `okf_stale_after >`, and `okf_id IS NOT NULL` are new parser branches that these tests don't exercise — this file is the only coverage for the OKF aliases, and the PR description promises `>`/`<`/`IS NULL` on all of them. Extend the OKF tests with assertions for `okf_stale_after > x` (GREATER_THAN), `okf_stale_after IS NULL` (NOT EXISTS okfStaleAfter), and `okf_id IS NOT NULL` (OR of EXISTS on okfConceptId/okfDeclaredId).</comment>

<file context>
@@ -804,3 +804,57 @@ def test_boolean_filter_combined_with_and():
+    )
+
+
+def test_okf_stale_after_supports_comparisons_and_null_checks():
+    assert parse_filter_string("okf_stale_after < 1767225600000") == F.custom_filter(
+        "okfStaleAfter", "LESS_THAN", ["1767225600000"]
</file context>

@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.

4 issues found across 9 files

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/src/datahub_agent_context/mcp_tools/helpers.py">

<violation number="1" location="datahub-agent-context/src/datahub_agent_context/mcp_tools/helpers.py:261">
P2: Custom agent: **Enforce i18n for User-Facing Strings**

This English message is returned as `frontmatterOmitted` in the tool response, so it is user-facing text rather than a log or technical identifier. Wrap it in the project’s translation mechanism.</violation>
</file>

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

<violation number="1" location="datahub-agent-context/tests/unit/mcp_tools/test_okf_documents.py:34">
P2: Custom agent: **Enforce Strict Maintainability Standards**

`test_gql_selects_okf_properties` extracts the `okfProperties` block by counting braces and then asserts on `line.split()[0]` of every line, so a blank line or `#` comment added inside the block raises a bare `IndexError`/corrupts the depth count, and fields placed on a shared line are silently dropped from the assertion. Filter out blank and comment lines before taking the first token, and fail with a clear message when `okfProperties {` is missing.</violation>

<violation number="2" location="datahub-agent-context/tests/unit/mcp_tools/test_okf_documents.py:107">
P2: Custom agent: **Enforce Pragmatic Test Coverage**

No test covers a document whose `GetDocumentOkfProperties` lookup succeeds but returns no `okfProperties` — the common non-OKF document case the PR description calls out. The existing tests cover the OKF-present and lookup-raises paths, but not the branch where `entities.py`'s `if okf_result and okf_result.get("okfProperties")` guard is not taken. Add a test asserting `"okfProperties" not in result` after a successful-but-empty lookup, mirroring the failure test with a second response of `{"entity": {"urn": urn, "okfProperties": None}}`.</violation>
</file>

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

<violation number="1" location="datahub-agent-context/tests/unit/mcp_tools/test_search_filter_parser.py:835">
P2: Custom agent: **Enforce Pragmatic Test Coverage**

The `_negate_filter` change makes `NOT (a = x OR b = y)` over plain custom fields compile to `a != x AND b != y` instead of raising, but the new tests exercise this De Morgan branch only through the `okf_id` alias. Add a direct test for the general path, e.g. in metadata-ingestion/tests/unit/cli/test_search_filter_parser.py (untouched by this PR), asserting `parse_filter_string("NOT (a = x OR b = y)") == F.and_(F.not_(F.custom_filter("a", "EQUAL", ["x"])), F.not_(F.custom_filter("b", "EQUAL", ["y"])))` and the same via `!=`; otherwise a regression in this documented side effect ships silently.</violation>
</file>

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

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

if len(frontmatter) > OKF_FRONTMATTER_CHAR_LIMIT:
del value["frontmatter"]
value["frontmatterOmitted"] = (
f"Frontmatter is {len(frontmatter)} characters, over the "

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: Custom agent: Enforce i18n for User-Facing Strings

This English message is returned as frontmatterOmitted in the tool response, so it is user-facing text rather than a log or technical identifier. Wrap it in the project’s translation mechanism.

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/helpers.py, line 261:

<comment>This English message is returned as `frontmatterOmitted` in the tool response, so it is user-facing text rather than a log or technical identifier. Wrap it in the project’s translation mechanism.</comment>

<file context>
@@ -234,6 +239,39 @@ def _select_results_within_budget(
+                    if len(frontmatter) > OKF_FRONTMATTER_CHAR_LIMIT:
+                        del value["frontmatter"]
+                        value["frontmatterOmitted"] = (
+                            f"Frontmatter is {len(frontmatter)} characters, over the "
+                            f"{OKF_FRONTMATTER_CHAR_LIMIT}-character limit. The fields "
+                            f"above hold its main OKF keys."
</file context>

Comment on lines +34 to +41
lines = (GQL_DIR / gql_file).read_text().splitlines()
first = next(i for i, line in enumerate(lines) if "okfProperties {" in line)
block, depth = [], 0
for line in lines[first:]:
block.append(line)
depth += line.count("{") - line.count("}")
if depth == 0:
break

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: Custom agent: Enforce Strict Maintainability Standards

test_gql_selects_okf_properties extracts the okfProperties block by counting braces and then asserts on line.split()[0] of every line, so a blank line or # comment added inside the block raises a bare IndexError/corrupts the depth count, and fields placed on a shared line are silently dropped from the assertion. Filter out blank and comment lines before taking the first token, and fail with a clear message when okfProperties { is missing.

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_okf_documents.py, line 34:

<comment>`test_gql_selects_okf_properties` extracts the `okfProperties` block by counting braces and then asserts on `line.split()[0]` of every line, so a blank line or `#` comment added inside the block raises a bare `IndexError`/corrupts the depth count, and fields placed on a shared line are silently dropped from the assertion. Filter out blank and comment lines before taking the first token, and fail with a clear message when `okfProperties {` is missing.</comment>

<file context>
@@ -0,0 +1,124 @@
+    ["document_search.gql", "document_semantic_search.gql", "document_okf.gql"],
+)
+def test_gql_selects_okf_properties(gql_file):
+    lines = (GQL_DIR / gql_file).read_text().splitlines()
+    first = next(i for i, line in enumerate(lines) if "okfProperties {" in line)
+    block, depth = [], 0
</file context>
Suggested change
lines = (GQL_DIR / gql_file).read_text().splitlines()
first = next(i for i, line in enumerate(lines) if "okfProperties {" in line)
block, depth = [], 0
for line in lines[first:]:
block.append(line)
depth += line.count("{") - line.count("}")
if depth == 0:
break
def test_gql_selects_okf_properties(gql_file):
lines = (GQL_DIR / gql_file).read_text().splitlines()
start = next(
(i for i, line in enumerate(lines) if "okfProperties {" in line),
None,
)
assert start is not None, f"okfProperties block missing in {gql_file}"
block, depth = [], 0
for line in lines[start:]:
if not line.strip() or line.lstrip().startswith("#"):
continue
block.append(line)
depth += line.count("{") - line.count("}")
if depth == 0:
break
assert {line.split()[0] for line in block} >= OKF_SELECTION

[result] = get_entities([urn])

assert result["urn"] == urn
assert "okfProperties" not in result

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: Custom agent: Enforce Pragmatic Test Coverage

No test covers a document whose GetDocumentOkfProperties lookup succeeds but returns no okfProperties — the common non-OKF document case the PR description calls out. The existing tests cover the OKF-present and lookup-raises paths, but not the branch where entities.py's if okf_result and okf_result.get("okfProperties") guard is not taken. Add a test asserting "okfProperties" not in result after a successful-but-empty lookup, mirroring the failure test with a second response of {"entity": {"urn": urn, "okfProperties": None}}.

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_okf_documents.py, line 107:

<comment>No test covers a document whose `GetDocumentOkfProperties` lookup succeeds but returns no `okfProperties` — the common non-OKF document case the PR description calls out. The existing tests cover the OKF-present and lookup-raises paths, but not the branch where `entities.py`'s `if okf_result and okf_result.get("okfProperties")` guard is not taken. Add a test asserting `"okfProperties" not in result` after a successful-but-empty lookup, mirroring the failure test with a second response of `{"entity": {"urn": urn, "okfProperties": None}}`.</comment>

<file context>
@@ -0,0 +1,124 @@
+        [result] = get_entities([urn])
+
+    assert result["urn"] == urn
+    assert "okfProperties" not in result
+
+
</file context>

)


@pytest.mark.parametrize("filter_string", ["okf_id != x", "NOT okf_id = x"])

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: Custom agent: Enforce Pragmatic Test Coverage

The _negate_filter change makes NOT (a = x OR b = y) over plain custom fields compile to a != x AND b != y instead of raising, but the new tests exercise this De Morgan branch only through the okf_id alias. Add a direct test for the general path, e.g. in metadata-ingestion/tests/unit/cli/test_search_filter_parser.py (untouched by this PR), asserting parse_filter_string("NOT (a = x OR b = y)") == F.and_(F.not_(F.custom_filter("a", "EQUAL", ["x"])), F.not_(F.custom_filter("b", "EQUAL", ["y"]))) and the same via !=; otherwise a regression in this documented side effect ships silently.

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_search_filter_parser.py, line 835:

<comment>The `_negate_filter` change makes `NOT (a = x OR b = y)` over plain custom fields compile to `a != x AND b != y` instead of raising, but the new tests exercise this De Morgan branch only through the `okf_id` alias. Add a direct test for the general path, e.g. in metadata-ingestion/tests/unit/cli/test_search_filter_parser.py (untouched by this PR), asserting `parse_filter_string("NOT (a = x OR b = y)") == F.and_(F.not_(F.custom_filter("a", "EQUAL", ["x"])), F.not_(F.custom_filter("b", "EQUAL", ["y"])))` and the same via `!=`; otherwise a regression in this documented side effect ships silently.</comment>

<file context>
@@ -804,3 +804,57 @@ def test_boolean_filter_combined_with_and():
+    )
+
+
+@pytest.mark.parametrize("filter_string", ["okf_id != x", "NOT okf_id = x"])
+def test_negated_okf_id_excludes_both_fields(filter_string):
+    assert parse_filter_string(filter_string) == F.and_(
</file context>

@datahub-connector-tests

datahub-connector-tests Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Connector Tests Results

All connector tests passed for commit f315a3b

View full test logs →

To skip connector tests, add the skip-connector-tests label (org members only).

Autogenerated by the connector-tests CI pipeline.

OKF treats a missing status as stable. okf_status = stable (or an IN list
containing stable) now also matches OKF documents that declare no status,
and its negation excludes them. Tool descriptions say so, and note that
okf_stale_after IS NULL also matches unreadable values.

@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.

All reported issues were addressed across 3 files (changes from recent commits).

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

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

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

- Hybrid search shapes OKF frontmatter after its final cleanup, so it keeps
  the same nulls, empty lists and nested values as keyword search.
- Negation applies De Morgan recursively, so groups that contain okf_id
  (which spans two fields) can be negated.
- okf_status != stable matches only OKF documents that declare another
  status.
- New okf_bundle_root alias for the bundle root path, documented for use
  with okf_bundle.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f315a3b. Configure here.

return F.and_(*(_negate_filter(b) for b in branches))
if isinstance(inner, _And) and len(inner.compile()) > 1:
# NOT (A AND B) = NOT A OR NOT B, for groups _Not cannot negate.
return F.or_(*(_negate_filter(b) for b in inner.and_))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stable status negation breaks NOT

High Severity

Negating okf_status = stable adds okfStatus and okfConceptId EXISTS checks, and that narrowed result is reused as a boolean NOT. NOT (okf_status = stable OR platform = snowflake) then drops entities that are neither, and NOT NOT okf_status = stable matches nearly every non-OKF entity.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f315a3b. Configure here.

@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.

1 issue found across 4 files (changes from recent commits).

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="metadata-ingestion/src/datahub/cli/search_filter_parser.py">

<violation number="1" location="metadata-ingestion/src/datahub/cli/search_filter_parser.py:753">
P2: This OKF-only restriction breaks grouped De Morgan negation: `NOT (okf_status = stable AND type = document)` drops non-OKF documents of type `document`. Keep the narrower rule for direct `okf_status != stable`, but preserve the full complement when negating a group.</violation>
</file>

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

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

return F.and_(
*(_negate_filter(b) for b in branches),
F.custom_filter("okfStatus", "EXISTS", []),
_is_okf_document(),

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 OKF-only restriction breaks grouped De Morgan negation: NOT (okf_status = stable AND type = document) drops non-OKF documents of type document. Keep the narrower rule for direct okf_status != stable, but preserve the full complement when negating a group.

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 metadata-ingestion/src/datahub/cli/search_filter_parser.py, line 753:

<comment>This OKF-only restriction breaks grouped De Morgan negation: `NOT (okf_status = stable AND type = document)` drops non-OKF documents of type `document`. Keep the narrower rule for direct `okf_status != stable`, but preserve the full complement when negating a group.</comment>

<file context>
@@ -725,17 +737,27 @@ def _negate_filter(inner: Filter) -> Filter:
+            return F.and_(
+                *(_negate_filter(b) for b in branches),
+                F.custom_filter("okfStatus", "EXISTS", []),
+                _is_okf_document(),
+            )
+        # NOT (A OR B) = NOT A AND NOT B, applied recursively so groups that
</file context>

This branch was successfully deployed

1 active deployment
Preview — f315a3b5 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 ingestion PR or Issue related to the ingestion of metadata

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant