fix: preserve dependencies across runtime branches - #185
Merged
Conversation
eitsupi
marked this pull request as draft
August 30, 2026 03:34
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
MiniJinja can render a dbt model successfully with dlin's placeholder runtime values while selecting only one side of a runtime-dependent branch. Render completion therefore does not imply that the selected branch is semantically representative of dbt parse, compile, and run contexts.
This change separates render completion from semantic certainty and conservatively recovers literal
ref()andsource()dependencies from runtime-dependent branches.What changes
env_var(), unresolvedvar()calls without a default,run_query(),statement(), and placeholder runtime object attribute/item access such astarget.*.execute,dbt_version,invocation_id, andrun_started_at) retain their existing placeholder values, but their use no longer makes branch selection semantically certain.The implementation remains conservative rather than attempting symbolic Jinja execution. When runtime reachability cannot be established by the implemented analysis, recovery falls back to broader source scanning rather than risking a false negative.
Correctness coverage
Regression tests cover runtime branches in model SQL, called and transitive local macros, aliases and higher-order calls, project macro chains, local-to-project and project-to-local transitions, duplicate definitions, unused macro exclusion, comments/raw blocks/string literals, shadowing, and conservative analysis-failure behavior.
Three deterministic runtime-macro workloads exercise sparse local reachability, dense local reachability, and a large project macro prefix. CI validates exact graph counts, direct dependency distance, complete downstream sets, expected runtime branch refs/sources, and exclusion of 250 unused project-macro dependency literals.
Performance
Release binaries were compared with
summary --no-cacheover 120 randomized rounds per profile and binary, with 5 warmups (seed 20260830). Times below are medians; lower is better.The normal small path is noise-equivalent and the large project-macro paths are faster because prepared prefix analysis is shared and lazy. The adversarial local profiles deliberately place 128 macro definitions in every model; their added cost is approximately 0.36-0.47 ms per model while recovering one previously omitted dependency per model. Further reducing that cost would require sharing compiled model templates/free-symbol analysis across models or replacing MiniJinja parsing with a custom parser, which is not justified for this fix.
Validation
cargo test --workspace --lockedcargo fmt --all --checkcargo clippy --workspace --all-targets --all-features --locked -- -D warnings