ProtectedProviderReturns the active provider — explicit override if set, otherwise the global default.
Flatten a dependency tree into a topologically sorted list. Parents appear before their children, ensuring safe restore ordering.
Walk from a root record through its relationships, building a tree of all records that should be included in a version label.
The starting entity name
The starting record's primary key
Controls depth, filtering, etc.
Server-side user context
The root DependencyNode with all descendants populated
Walks entity relationship graphs to discover records for version labeling.
Two-direction traversal
Reverse: Uses the entity's
RelatedEntities(EntityRelationship metadata) to find child records. This is curated by CodeGen and admins — only explicitly registered One-To-Many relationships are walked.Forward: Scans the current entity's own FK fields to find records it references (e.g., AI Agent Prompt → AI Prompt via PromptID). Skips system/infrastructure fields (UserID, CreatedBy, etc.).
Discovery mode — prevents explosion from forward references
Records found via reverse walk are "owned children" and get full treatment (both reverse + forward walks). Records found via forward walk are "referenced records" and only get forward-only treatment (their own FK refs are followed, but their EntityRelationship children are NOT discovered).
This prevents the classic explosion pattern:
With discovery mode:
Ancestor stack — prevents backtracking
A set of entity names on the current path from root to the current node is maintained. When evaluating any relationship, if the target entity type is already on the ancestor stack, it is skipped. This is a secondary safety net that prevents cycles even within full-mode walks.
Filters
TrackRecordChanges === trueExcludeEntitiesandEntityFilteroptionsvisitedset for record-level cycle detection