Skip to content

[codex] Fix graph builds on legacy ontology attributes#568

Draft
SENNGAMI wants to merge 1 commit into
666ghj:mainfrom
SENNGAMI:fix-ontology-attribute-normalization
Draft

[codex] Fix graph builds on legacy ontology attributes#568
SENNGAMI wants to merge 1 commit into
666ghj:mainfrom
SENNGAMI:fix-ontology-attribute-normalization

Conversation

@SENNGAMI
Copy link
Copy Markdown

Summary

This PR fixes a graph build failure caused by ontology payloads that persisted legacy attribute maps instead of normalized attribute objects.

Root Cause

GraphBuilderService.set_ontology() expected each entity and edge attribute to follow the schema:

{"name": "...", "type": "text", "description": "..."}

However, some saved ontology payloads contained legacy free-form maps such as:

{"full_name": "Founder full name", "role": "Founder title"}

When the graph build path dereferenced attr_def["name"], the request failed locally with KeyError: 'name' before the Zep ontology call.

What Changed

  • added a shared ontology schema normalizer for entity and edge attributes
  • normalize ontology output during ontology generation before it is persisted
  • normalize saved ontology again in the graph build path before sending it to Zep
  • added regression tests for legacy payload normalization and graph-builder compatibility

Why This Approach

The fix normalizes ontology payloads at the service boundary instead of adding scattered defensive checks. That keeps one schema contract for:

  • newly generated ontologies
  • already-saved legacy projects
  • downstream graph build and code generation paths

Validation

  • ran targeted backend pytest in the Docker runtime
  • compiled backend modules and tests with python -m compileall
  • replayed the original saved project payload through set_ontology() with a stubbed client and confirmed the KeyError path is gone

Impact

Users can rebuild graphs from previously saved projects without having to regenerate ontology first, and new ontology payloads are normalized before they are stored.

Legacy ontology payloads could be saved with attributes as free-form maps of attribute names to descriptions. The graph build path dereferenced attr_def["name"] directly, which raised a KeyError before the Zep ontology request. This adds a shared ontology normalizer, applies it when validating generated ontologies and when setting graph ontology, and adds regression tests for both normalization and graph-builder compatibility.

Constraint: The configured OpenAI-compatible provider guarantees valid JSON but not strict schema adherence for ontology attributes
Rejected: Guard only graph_builder.set_ontology against missing keys | would leave malformed ontologies persisted and unvalidated upstream
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep ontology payloads normalized at service boundaries so new generations and saved legacy projects share one schema contract
Tested: Targeted backend pytest for ontology normalization in the docker compose runtime
Tested: Python compileall for backend app and tests in the docker compose runtime
Tested: Reproduced the original saved project payload through graph_builder.set_ontology with a stubbed client
Not-tested: Live Zep API round-trip against the upstream service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant