[Canon] Source-bounded concept visibility (derived-content origin gate)

Abierto
#6,724 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
20/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
sql, typescript

Línea de trabajo

Read packages/MJCoreEntities/src/graph/GraphEngine.ts and packages/MJCoreEntities/src/engines/CanonGraphEngine.ts, then compare the origin check in packages/SearchEngine/src/generic/SearchEnricher.ts with concept filtering and visibility checks. The issue calls for a batched, fail-closed source visibility gate across graph and direct reads, plus policy decisions for concepts without sources; done means concepts and suggestions cannot expose text unless the caller and all audience readers share a readable backing source.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

canon

What should Canon do that it does not do today?
Ensure every MJ: Graph Concepts record is no more visible than the source records (SourcedFrom targets: MJ: Content Item Chunks, MJ: Content Items, MJ: Content Sources, or referenced entities) from which it was derived, mirroring SearchEngine's origin-record gate on derived content (PromotedFromContentItemID).

Who needs it, and what goes wrong without it?
Today MJ: Graph Concepts carries derived text synthesized from underlying documents (Name, Synonyms, Description, Specification), while GraphEngine.FilterNodesForUser (packages/MJCoreEntities/src/graph/GraphEngine.ts) only checks whether the caller can read the MJ: Graph Concepts entity row itself — not whether the caller (or every AudienceReader) can read the underlying content items, chunks, or sources linked by SourcedFrom edges.
Concrete failure mode (seen in multi-entitlement apps like Betty):

  • An internal SOP (Staff-only ContentSource) defines a confidential escalation process or internal code name.
  • Graph synthesis (GraphStage / EntityGraphOverlayStore) extracts a Concept (Name, Synonyms, Description, Specification) linked via SourcedFrom -> MJ: Content Item Chunks / MJ: Content Items.
  • A Public or Member user (who has no read entitlement on that Staff content item) queries Canon via FindConcepts, ResolveConcepts, ExplainConcept, CanonContext, or a RunView over MJ: Graph Concepts and receives the derived concept name, synonyms, and specification verbatim — leaking restricted source content even though direct search on MJ: Content Items would deny it.
  • Conversely, until this ships, multi-entitlement apps cannot use Canon concept text in user/LLM prompts at all (they must strip concept text and pass only chunk/item IDs through their own hydration gates).

Which layer does it touch?

  • Governed data slices (alternate base views, queries)
  • Concepts and authority (graph concepts, edges, tiers)
  • Agent guardrails (canonical notes)
  • Executable procedures (skills, actions, workflows)
  • Schema (a new type, status, tier, edge type or column)

What existing work is it related to?

  • plans/canon-master-plan.md — Workstream 5 (5c)
  • packages/SearchEngine/src/generic/SearchEnricher.ts (ExcludeEntitySourcedContentItems / PromotedFromContentItemID origin-record gate — reference pattern in SearchEngine)
  • packages/MJCoreEntities/src/engines/CanonGraphEngine.ts (FindConcepts, CanonContext, ExplainConcept, scoreConcepts)
  • packages/MJCoreEntities/src/graph/GraphEngine.ts (FilterNodesForUser, Subgraph)

Rough size
Medium–Large (1–2 sprints: edge/origin index, server enforcement hook, audience-aware CanonGraphEngine + GraphEngine integration, unanchored-concept policy, tests).


Design Sketch

1. Mirror SearchEngine's Derived-Content Origin Gate

In SearchEngine, a derived document promoted to an origin record (PromotedFromContentItemID in packages/SearchEngine/src/generic/SearchEnricher.ts:242-245) cannot rely on the index provider's read check; the engine verifies the origin entity record directly as the caller. Apply the exact same rule to MJ: Graph Concepts:

  • A synthesized MJ: Graph Concepts row is derived content whenever it has one or more SourcedFrom edges (GraphEdgeType.Name = 'SourcedFrom', SourceEntityID = 'MJ: Graph Concepts').
  • A concept with backing sources is readable to principal set P = [caller, ...AudienceReaders] if and only if P has at least one shared readable backing source (every u in P passes CanRead / RLS on the same backing source record). Requiring a shared readable source prevents intersection leaks in rooms (e.g., if Concept C came from Doc A readable only by Alice and Doc B readable only by Bob, neither alone proves both may discuss Doc A's text).
2. Resolution Pipeline (Batched, Fail-Closed)

Add a server-side/engine origin verifier (e.g., ConceptSourceVisibilityGate invoked inside GraphEngine.FilterNodesForUser for 'MJ: Graph Concepts' and any CanonGraphEngine concept lookup):

  1. Batch-load SourcedFrom edges (SourceEntityID = 'MJ: Graph Concepts', SourceRecordID IN (...), Status IN ('Approved', ...proposedWhenRequested)). Never load SourcedFrom row-by-row inside a loop.
  2. Normalize backing targets by entity type:
    • 'MJ: Content Item Chunks': optionally verify chunk read directly AND resolve ContentItemID / ContentSourceID (important when RLS lives on MJ: Content Items or a host ISA view like betty.vwContentItems, or when chunks are deleted/re-created on re-ingest).
    • 'MJ: Content Items', 'MJ: Content Sources', or any other entity (e.g., MJ: Entities, MJ: Conversations, MJ: AI Agent Notes): group target IDs by TargetEntityID and verify via one batched RunViews call per entity (passing each principal u in P, honoring entity RLS and server PreRunView middleware such as tenant/entitlement hooks).
  3. Evaluate visibility:
    • If the concept has >= 1 SourcedFrom target: keep the concept only if at least one target ID survives across every principal in P. Cache the check per (conceptID, UserScopedCacheKey(user)) or compute per traversal step cleanly; fail closed on any query failure or unknown target entity.
    • What if a concept has 0 SourcedFrom edges? (Human-authored canonical term vs orphaned synthesized concept):
      • Add explicit graph configuration on MJ: Graphs (or GraphType): UnanchoredConceptPolicy = 'GraphReaders' | 'StewardsOnly' | 'Deny':
        • 'GraphReaders' (reasonable default for "MJ Canon" metadata/business glossary graphs authored directly by stewards without chunks);
        • 'StewardsOnly' (recommended default for ContentSource-fed multi-entitlement graphs so a synthesized concept whose chunks were purged/unlinked never silently opens up to everyone).
  4. Also gate direct CRUD / RunView reads on MJ: Graph Concepts:
    • Going only through CanonGraphEngine / GraphEngine would leave RunView({ EntityName: 'MJ: Graph Concepts' }) or mj_GraphConcept GraphQL queries open (note UI currently has CanRead = 1). Pair with 5b + a server-side PostRunView / PreRunView security hook or entity-server read filter for multi-entitlement graphs so unentitled callers cannot read derived concept fields over raw GraphQL RunView either.
3. Lexical Matching & Cache Safety (CanonGraphEngine)

Notice CanonGraphEngine.scoreConcepts (CanonGraphEngine.ts:285-320) currently scores candidate Name / Synonyms in memory before calling FilterNodesForUser:

  • Keep checking IsFieldReadableByAll(conceptEntity, 'Name' | 'Synonyms', principals) first (FLS), AND run FilterNodesForUser (including the 5c origin gate) before surfacing any concept name, synonym, description, specification, "Did you mean..." suggestion, or ambiguity list (AMBIGUOUS_CONCEPT must not enumerate concepts from hidden sources — NO_MATCH vs AMBIGUOUS must leak zero names the caller cannot read!).
4. Re-ingest / Chunk Churn Resilience

As noted in MJ#6675 review, MJ: Content Item Chunks rows can be marked DeleteStatus = 'Pending'/'Deleted' or recreated during re-ingest. Encourage anchoring durable SourcedFrom / Supersedes edges on MJ: Content Items or MJ: Content Sources (or having the pipeline maintain/re-link SourcedFrom onto parent ContentItem in addition to chunk IDs) so source visibility stays stable across chunk re-embedding.

5. Open Questions for Dec 3 Canon Review
  1. Should EntityGraphOverlayStore automatically write a companion SourcedFrom edge to the parent MJ: Content Items (and/or MJ: Content Sources) alongside chunk-level SourcedFrom, so re-chunking never temporarily unlinks a concept from its source entitlement?
  2. For concepts grounded in two documents (Doc A Public and Doc B Staff), is "readable if the caller can read at least one backing source" sufficient (assuming concept text should summarize the shared concept, not verbatim Staff secrets), or should synthesis carry a RequiredAllSources / ceiling sensitivity mode?
  3. What UnanchoredConceptPolicy default should "MJ Canon" vs new tenant Canon graphs use?
Lenguaje dominante
TSQL
Estrellas
32
Forks
7
Merge medio
1 d 16 h
PR fusionados (30 d)
504

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MemberJunction/MJ

Todos los issues de MemberJunction/MJ

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.