State in dbt is the difference between two project snapshots, not a property of the warehouse. When a build runs, dbt reads every model, test, source, snapshot, seed, macro, exposure, semantic model, and metric in the project, resolves their configurations, and serializes the result into target/manifest.json. That file is the single source of truth for the project's shape at the moment of the build. The state: family of selectors works by loading a second manifest from a directory passed via --state, comparing it node by node to the manifest of the current project, and emitting the set of nodes whose definitions have changed. No warehouse query is involved in the comparison; the entire algorithm is a local set operation over two JSON documents.
The artifact itself is produced at the end of the parse phase, which means any command that goes through parse rewrites it. dbt parse, dbt compile, dbt build, dbt run, dbt test, dbt seed, dbt snapshot, dbt list, and dbt source freshness all emit a manifest, with the partial parse cache in target/partial_parse.msgpack accelerating subsequent invocations. The manifest written by dbt parse and dbt compile is complete in the sense that every node has its resolved compiled_code field. Execution-time commands additionally update run_results.json, which records the outcome of each node, but the manifest itself reflects project shape rather than execution outcome. That separation matters: the manifest answers "what does the project look like?" while run_results.json answers "how did the last invocation go?".
Inside manifest.json, the top-level keys most relevant to state comparison are nodes, sources, macros, exposures, metrics, semantic_models, parent_map, child_map, and selectors. Each entry in nodes is keyed by a fully qualified node id such as model.analytics.dim_customer or test.analytics.unique_dim_customer_customer_id, and the value carries the resolved configuration, the raw_code, the compiled_code (after compile), the depends_on graph, the checksum, the config_call_dict, and the contract specification. Sources live under sources and carry the resolved database, schema, identifier, and freshness block. The parent_map and child_map are dictionaries that pre-resolve the DAG so downstream tooling does not need to walk it from scratch. When the comparison algorithm needs to determine if model.analytics.fct_order changed, it pulls that node from both manifests and runs a structured comparison; the matched id is the join key.
The state: selector decomposes into subselectors, each pinned to a single dimension of change. state:modified.body checks the SQL body of a model by hashing the compiled or raw code; state:modified.configs checks resolved configurations, including materialization, schema, alias, tags, persist_docs, grants, and any custom + keys; state:modified.relation checks the resolved relation address (database.schema.identifier); state:modified.persisted_descriptions checks the description text that dbt would push to the warehouse via persist_docs; state:modified.macros checks for changes in macros that the node depends on; and state:modified.contract checks contract specifications, including the contract enforcement flag, the column data types, and the constraint declarations. The bare state:modified selector is the union of these subselectors. state:new returns nodes that appear in the current manifest but not the comparison manifest. state:unmodified returns the complement of state:modified and state:new.
The graph operators that combine with state selectors are the same ones that work on any selector. The trailing + operator includes descendants, so state:modified+ rebuilds modified nodes and everything downstream. The leading + includes ancestors, so +state:modified rebuilds the modified nodes and the upstream chain that feeds them. The integer-bounded variants 2+state:modified+1 limit the depth in either direction. The @ operator behaves like + plus the ancestors of the descendants, which is useful when running tests that depend on siblings of modified nodes. Selectors compose with , for intersection and for union: state:modified+ tag:nightly selects modified nodes downstream that also carry the nightly tag. The intersection rule is strict, which catches a lot of slim CI bugs in code review.
How the state diff algorithm works in practice
State comparison is more nuanced than a flat JSON diff. dbt walks every node id present in either manifest and dispatches comparison logic per node type. For models, the body comparison uses the SHA-1 hash stored in the node's checksum.checksum field, which is computed from the file's raw contents at parse time. For macros, the body is captured in the macro's macro_sql field; the comparison hashes that string and propagates a change to every node whose depends_on.macros list contains the macro. For configs, dbt rebuilds the effective configuration dictionary in both manifests, sorts keys deterministically, and compares the result. Adapter-specific configs (Snowflake cluster_by, BigQuery partition_by, Databricks liquid_clustering, Redshift dist, Postgres indexes) are part of the resolved config and contribute to state:modified.configs. The resolved relation comparison uses the post-target relation address, so flipping a schema override via dbt_project.yml triggers state:modified.relation even when the SQL body is byte-for-byte identical.
The macros dimension is the most frequent source of unexpected matches. If a project-level macro is edited, every model whose compiled output uses that macro is flagged as state:modified.macros. The dependency edges are recorded at parse time by walking the AST of every Jinja expression. A macro that is referenced inside another macro is transitively a dependency, and the propagation rule keeps walking the macro graph until it reaches a model node. Edits to deeply shared utilities such as a generate_schema_name override or a custom dispatch resolver light up most of the project, which is the correct behavior even though the team review may not have expected it. The same propagation applies to package macros; upgrading dbt_utils from one minor version to another can register dozens of state:modified.macros hits because the macro bodies inside dbt_packages/dbt_utils/ are now different strings.
Reading the manifest at the command line
The manifest is large, often several megabytes for medium projects, but it is straightforward to inspect with jq. The first thing to confirm in any state troubleshooting session is the structural integrity of both manifests; an empty nodes key or a missing parent_map usually means the comparison manifest was produced by a different dbt version and is unreadable.
# Inspect the manifest produced by the active project
jq '.metadata | {dbt_version, adapter_type, project_name, generated_at}' target/manifest.json
# Count nodes by resource type in the current manifest
jq '.nodes | to_entries | group_by(.value.resource_type) | map({type: .[0].value.resource_type, count: length})' target/manifest.json
# Inspect a single model node in detail
jq '.nodes["model.analytics.fct_order"] | {checksum, depends_on, config: .config | {materialized, schema, alias, tags}}' target/manifest.json
# Walk the macro dependencies of a model
jq '.nodes["model.analytics.fct_order"].depends_on.macros' target/manifest.json
# Compare two manifests with dbt itself; --no-write avoids touching target/
dbt ls --select state:modified+ --state ci_state --resource-type model --output name
# Decompose by subselector to identify what kind of change triggered the match
dbt ls --select state:modified.body+ --state ci_state --resource-type model
dbt ls --select state:modified.configs+ --state ci_state --resource-type model
dbt ls --select state:modified.macros+ --state ci_state --resource-type model
dbt ls --select state:modified.contract+ --state ci_state --resource-type model
dbt ls --select state:modified.relation+ --state ci_state --resource-type model
When the modified set looks larger than expected, decomposing by subselector is the diagnostic move. If state:modified.macros returns the surplus nodes, the comparison manifest predates a package upgrade. If state:modified.configs returns them, a project-level config in dbt_project.yml was edited and is propagating to many models. If state:modified.relation lights up, a schema or alias generator was changed. The discipline is to read the subselectors before accepting the slim CI plan, because the cost of an over-broad rebuild is real on production-sized projects.
Storing and refreshing the comparison manifest
The comparison manifest must come from somewhere. The conventional pattern in dbt Cloud is to publish the production manifest at the end of every successful Deploy Job and have the CI Job point --state at that published artifact. In dbt Core, teams typically push target/manifest.json to an object store (S3, GCS, Azure Blob) tagged with the commit SHA, then pull the manifest matching the current main branch tip when CI starts. The directory passed to --state is the directory that contains manifest.json, not the file itself, because dbt also reads run_results.json from the same directory when result: selectors are used.
# .github/workflows/dbt-ci.yml fragment
- name: Download production manifest
run: |
aws s3 cp s3://analytics-artifacts/main/manifest.json ci_state/manifest.json
aws s3 cp s3://analytics-artifacts/main/run_results.json ci_state/run_results.json
- name: Run slim CI build
run: |
dbt build \
--select state:modified+ \
--defer \
--state ci_state \
--target ci \
--fail-fast
The ci_state/run_results.json is downloaded alongside the manifest so a CI Job can also pivot to result:error+ workflows when the goal is to retry a failed deploy rather than build a feature branch.
💡 Exam Trap:
state:modified+does not include nodes that are merely upstream of modified nodes. The leading+versus trailing+distinction is exam-grade:+state:modifiedis parents,state:modified+is children, and the two are not interchangeable. A question that asks for "every node downstream of any change" meansstate:modified+, while a question that asks for "every node a modified node depends on" means+state:modified.
💡 Exam Trap:
state:modifiedandstate:neware disjoint. A node introduced in the feature branch isstate:new, notstate:modified. Slim CI workflows that select onlystate:modified+will silently skip newly added models. The canonical selector isstate:modified+,state:new+or the shorthandstate:modified+ state:new+(with a space for union) to pick up both.
📊 Limit: The
--stateargument accepts a directory containingmanifest.jsonand optionallyrun_results.jsonandsources.json. A manifest produced by a dbt minor version more than one step removed from the active version may fail to load. The conventional rule is to keep the CI and Deploy environments on the same dbt minor.
⚠️ Anti-Pattern: Treating
state:modifiedas a precise list of "SQL files I edited" is incorrect. The selector is a property of the resolved node, not of the file. Edits todbt_project.yml, macro files, package versions, or the contract specification all producestate:modifiedhits without any model SQL having changed. Reading the subselector decomposition is the only reliable way to tell why a node matched.
🎯 Scenario: A team upgrades
dbt_utilsfrom one minor version to the next as part of a routine package refresh. Their CI Job, configured withstate:modified+, suddenly attempts to rebuild 318 of 412 models. The on-call engineer runsdbt ls --select state:modified.macros+ --state ci_stateand sees that every model usingdbt_utils.surrogate_keyis matched. The fix is to either accept the broad rebuild (correct because the package change is meaningful) or to pre-warm the production environment with a separate manual rebuild and only then advance the comparison manifest, so the CI Job sees the new package version as the new baseline.
Decision Anchor: Choose state:modified+ when the goal is to rebuild every node affected by a change and its descendants. Choose +state:modified when the goal is to repopulate ancestors before re-running a small modified subset, typically as part of a stand-up developer environment. Choose state:modified+,state:new+ whenever the feature branch may add new models, which is the production-safe default for slim CI.
Decision Tree: Picking the right state subselector for a slim CI build
Subtleties around macro dependency tracking
A common point of confusion is the difference between a macro that is called by name and a macro that is dispatched. Calls of the form {{ my_macro() }} register a direct dependency at parse time, so editing my_macro flags every model that calls it. Calls of the form {{ dbt.something() }} route through the adapter dispatch system; editing the per-adapter implementation registers as a dependency only for projects on that adapter. Custom test macros under tests/generic/ register dependencies for the tests that invoke them, not for the models the tests cover. The state:modified.macros selector walks the macro dependency graph in both manifests and flags nodes whose macro depends-on set has either gained an entry, lost an entry, or has a downstream macro whose body changed. The propagation is transitive but bounded by the macro graph; once it reaches the macro that is referenced from a model node, the flag attaches to that model.
For very large projects, the macro propagation can produce a rebuild plan that looks alarming but is mechanically correct. The mitigation strategy is two-fold. First, isolate frequently changed macros (date math helpers, surrogate key wrappers, environment helpers) into their own subdirectory so their churn is visible at review time. Second, when a macro edit is intentional but cosmetic (renaming a variable, reformatting), advance the production manifest as a separate landed change before opening any model-level pull requests so the slim CI builds that follow can use the updated macro as the new baseline.
The role of partial_parse.msgpack
The partial parse cache lives next to manifest.json and stores a serialized representation of the parse state, keyed by file modification times and hashes. When dbt starts, it loads the cache, walks the filesystem, and reparses only files that have changed. The cache is invalidated whenever dbt_project.yml changes, whenever the dbt or adapter version changes, or whenever a package is added or removed. The cache is not the manifest; the manifest is always rewritten at the end of parse. The cache only accelerates the work that produces the manifest. Slim CI builds that compute state:modified+ benefit from the cache when the CI runner persists the target/ directory between runs, because the active project's manifest can be regenerated in a fraction of the cold-start time. The comparison manifest, fetched from the artifact store, is read directly from disk and does not interact with the cache.
