[codex] Fix graph builds on legacy ontology attributes#568
Draft
SENNGAMI wants to merge 1 commit into
Draft
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withKeyError: 'name'before the Zep ontology call.What Changed
Why This Approach
The fix normalizes ontology payloads at the service boundary instead of adding scattered defensive checks. That keeps one schema contract for:
Validation
python -m compileallset_ontology()with a stubbed client and confirmed theKeyErrorpath is goneImpact
Users can rebuild graphs from previously saved projects without having to regenerate ontology first, and new ontology payloads are normalized before they are stored.