Skip to content

Surface schema field/relationship/schema-level descriptions in schema_metadata - #2706

Merged
mstomar125 merged 1 commit into
mainfrom
issue-2653-schema-descriptions
Sep 17, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-2653-schema-descriptions

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

  • EntityFieldDescriptor now carries each field's description (was read from SchemaField and silently dropped before serialization).
  • New EntityRelationshipDescriptor (on a new EntityTypeDescriptor.relationships field) carries each relationship's description plus its shape (target_type, direction, cardinality, reverse_name, reverse_cardinality) — SchemaRelationship wasn't represented in EntityTypeDescriptor at all before this.
  • find_skills now fetches each candidate schema's own description subtree (markdown children under the schema node) and attaches it as a sibling description key on that schema's schema_metadata entry, reusing the existing shared subtree-render utility (flatten_subtree_content, ADR-057) rather than a third independent implementation. Fetches are cached per call since the same schema can appear in metadata for multiple matched skills.

Deliberately unchanged

  • The compact EXISTING SCHEMAS prompt line (EntityTypeDescriptor::render_line) is untouched — none of the new description content is rendered into it. It still shows only type id / display name / field shape / title_template, exactly as before. Description content reaches the model only through schema_metadata's JSON (to_json/from_json), delivered alongside a matched find_skills skill result.
  • find_skills's "skill"-only search scope and the "EXISTING SCHEMAS" prompt-injection mechanism itself (packages/agent/src/local_agent/tools.rs/agent_loop.rs) are untouched — out of scope for this issue.

Incidental fix required

EntityFieldDescriptor/EntityTypeDescriptor gained new struct fields. packages/agent's own test fixtures (local_agent/tools.rs, local_agent/routing.rs) construct these structs via exhaustive literals, which no longer compiled. Updated those literals with the new fields' inert defaults (None / vec![]) — no agent behavior, logic, or test assertions changed, purely mechanical to keep the workspace compiling.

Testing

  • New unit tests in entity_types_block.rs: field/relationship descriptions survive the to_json/from_json round trip, and are confirmed absent from render_line()'s output.
  • New integration test packages/core/tests/find_skills_schema_metadata_test.rs: a fixture schema authored with a field description, a relationship description, and a markdown schema-level description, associated with a skill scoped to it via node_types, embedded with the real embedding model, and retrieved through a live find_skills() call — asserts all three description sources are present in the returned schema_metadata, not dropped.
  • bun run test:all and the full pre-push gate (including cargo test -p nodespace-app --test "*" and bun run test:e2e) pass clean.
  • bun run quality:fix (cargo fmt + cargo clippy --all-targets -- -D warnings -D clippy::unused-async) clean across the whole workspace.

Test plan

  • bun run test:all passes
  • bun run quality:fix clean
  • New fixture-schema test proves find_skills's schema_metadata carries field, relationship, and schema-level descriptions
  • Existing entity_types_block.rs/skill_ops.rs test suites pass unchanged in shape

closes #2653

🤖 Generated with Claude Code

…_metadata (closes #2653)

EntityFieldDescriptor now carries each field's description, and a new
EntityRelationshipDescriptor carries each relationship's description plus
enough shape (target_type, direction, cardinality, reverse_name,
reverse_cardinality) to identify it — EntityTypeDescriptor previously
represented no relationship data at all. Both flow through
EntityTypeDescriptor::from_schema/to_json/from_json, so schema_metadata
(the find_skills sidecar) stops dropping them.

find_skills also fetches each candidate schema's own description subtree
(reusing flatten_subtree_content, the shared ADR-057 subtree-render
utility already used for skill instructions) and attaches it as a sibling
description key on the schema_metadata entry, cached per call since the
same schema can appear in metadata for multiple matched skills.

The compact EXISTING SCHEMAS prompt line (render_line) is deliberately
unchanged — descriptions reach the model only via schema_metadata JSON,
not the deterministic prompt-injection block.

EntityFieldDescriptor/EntityTypeDescriptor gained new struct fields, which
broke exhaustive struct literals in packages/agent's own test fixtures
(tools.rs, routing.rs) — updated those literals with the new fields' inert
defaults (None/empty vec) to keep the workspace compiling; no agent
behavior changed.

Added an integration test with a fixture schema carrying rich field,
relationship, and schema-level descriptions, verifying all three reach a
live find_skills() call's schema_metadata end to end.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Independent scoped review (dispatched per issue #2653's process note) — verdict: APPROVE

Reviewed structurally and by running the tests directly (not just reading the diff): cargo test -p nodespace-core --lib entity_types_block:: (15/15), cargo test -p nodespace-core --lib skill_ops:: (26/26), cargo test -p nodespace-core --test find_skills_schema_metadata_test --features nlp (1/1, real GGUF-backed end-to-end), plus a clean cargo build -p nodespace-agent --tests / cargo build -p nodespace-app --tests.

1. EntityRelationshipDescriptor shape — maps 1:1 to SchemaRelationship's fields minus required/edge_fields. edge_fields omission is a documented, reasonable scope call (a different consumer, rel_ops.rs's RelationshipGroup, already surfaces edge fields for instance viewers — this issue is about description content, not edge-attribute shape). to_json/from_json round-trips correctly, snake_case keys match EntityFieldDescriptor's established convention, malformed-entry skip behavior matches the existing fields decode pattern.

2. Subtree-render reuse — confirmed genuine reuse, not a reimplementation: the new render_node_subtree helper is a faithful, behavior-preserving refactor calling the same get_subtree_data + flatten_subtree_content (ADR-057's shared utility, services/node_service/hierarchy.rs:1101) that render_skill_instructions already used; render_skill_instructions/render_schema_description are now thin wrappers over it.

3. Fixture test — exercises the real find_skills() op end-to-end (real SqliteStore, real handle_create_schema writing the schema-level description subtree, real embedding model). Three distinct, non-trivial description strings, each asserted independently. Not vacuous: node_types: ["invoice"] scoping bypasses the retrieval heuristics entirely (deterministic which schema is returned), and every assertion traces back through code that would leave the corresponding JSON key Null/absent if any one of the three fixes were reverted — confirmed by reading the threading through to_json/skill_ops's merge step. Real-embedding-model dependency mirrors the existing embedding_service_test.rs convention (#![cfg(feature = "nlp")]), not a new burden.

Mechanical agent-crate diff (local_agent/tools.rs, local_agent/routing.rs) — read both hunks in full; every added line is description: None, or relationships: vec![], inside a pre-existing test-fixture struct literal, matching the file-level diff stats exactly. No behavior/assertions touched.

No blocking findings. One non-blocking note: if a future recipe needs the agent to set an edge-field value when creating a relationship (e.g. a role on a membership edge), that's a legitimate follow-up in the same spirit as this issue — not a gap in this PR's scope.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Automated independent review: APPROVE (posted as a comment — GitHub blocks self-approval on this self-authored PR). Full findings in the review comment above.

@mstomar125
mstomar125 merged commit 512cb9b into main Sep 17, 2026
@mstomar125
mstomar125 deleted the issue-2653-schema-descriptions branch September 17, 2026 09:00
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.

Surface schema field/relationship descriptions and schema-level guidance to the agent (EntityTypeDescriptor drops them today)

1 participant