Skip to content

[ADR-008] Query Layer Contract #319

@ohdearquant

Description

@ohdearquant

Summary

Remove storage-layer leakage from khive-query, add ADR-required query shape support, fail invalid traversal depth, and project event-observation joins after event provenance exists.

Source ADRs

  • F045 ADR-008 (CRIT): khive-query depends on khive-storage; SQL compilation imports khive_storage::types::SqlValue (from audit-foundation/e4/ADR-008.md)
  • F047 ADR-008 (MAJ): GQL WHERE parses only repeated scalar Condition entries joined by AND (from audit-foundation/e4/ADR-008.md)
  • F048 ADR-008 (CRIT): max_hops > MAX_DEPTH is clamped to 10 and returned as a warning. (from audit-foundation/e4/ADR-008.md)
  • F218 ADR-041 (MAJ): The GQL compiler's edge path builds joins over node aliases and edge aliases, with no observed_as_* or event_observations handling found. (from audit-rest/r6/ADR-041.md)

Files affected

  • crates/khive-query/Cargo.toml (18 sampled LOC)
  • crates/khive-query/src/parsers/gql.rs (570 sampled LOC)
  • crates/khive-query/src/validate.rs (458 sampled LOC)
  • crates/khive-query/src/compilers/sql.rs (1061 sampled LOC)
  • crates/khive-query/src/ast.rs (105 sampled LOC)
  • crates/khive-runtime/src/operations.rs (3728 sampled LOC)

Acceptance criteria

  • All source findings listed above are addressed exactly once in this cluster.
  • Public types, handlers, schema, and docs touched by the affected files agree on the ADR contract.
  • Regression tests cover happy path and edge cases for the changed public APIs or schema behavior.
  • cargo test -p khive-query -p khive-runtime passes.
  • cargo clippy --workspace -- -D warnings passes.
  • make ci passes.

Dependencies

  • Depends on: #[ADR-001] Entity Kind and Type Contract
  • Depends on: #[ADR-002] Edge Ontology, Lifecycle, and Bulk Link Semantics
  • Depends on: #[ADR-004] Note Kind, Storage, and Curation Operations
  • Depends on: #[ADR-005] Storage Capabilities, Sparse Store, and Vector Contract
  • Depends on: #[ADR-004] Event Observable and Provenance Model
  • Depends on: #[ADR-007] Namespace Token and Runtime API Migration
  • Depends on: #[ADR-003] Runtime Backend and Substrate Coordinator
  • Blocks: #[ADR-016] Request Execution Modes and Presentation Envelope

LOC estimate

~150 lines added/50 removed; 6 existing affected file(s) sampled at 5940 current LOC via wc -l, plus 0 new/planned path(s).

Risk notes

  • Same-file dependencies must merge first; dependency list includes the exact overlapping paths.
  • Contains CRIT findings; do not defer without owner approval.

Auto-generated by ADR alignment triage

Metadata

Metadata

Assignees

No one assigned

    Labels

    adr-alignmentADR v1 series alignment workadvancedAdvanced layer (ADR-031..046)foundationFoundation layer (ADR-001..015)

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions