Area: Ingestion Issues
Sub-Area: Stateful Ingestion
Applies to: OSS + Cloud
Issue
An ingestion run finishes with a failure titled Skipping stateful ingestion / stale entity removal. The run did not soft-delete any stale entities. The message reads:
Entity difference exceeds fail_safe_threshold; skipping stale entity removal. To update, set stateful_ingestion.fail_safe_threshold in your recipe.- Context:
previous_run=X entities, current_run=Y entities, change=Z%, threshold=75.0
You Might Be Asking
- Why is my ingestion skipping stale entity removal even though my source did not lose assets?
- How do I raise fail_safe_threshold so the removal goes through?
- Why does the check fire when my entity count stayed the same or grew?
Cause
fail_safe_threshold is a safety check on stale entity removal. It is a number from 0 to 100, and the default is 75.0.
The check does not compare total entity counts. It measures the percentage of the previous run's entities that are missing from the current run: (1 - overlap / previous entity count) * 100. If that percentage is above the threshold, DataHub skips the removal.
So a run with the same or a higher entity count can still trip the check when URNs change. Common causes:
- You added or changed
platform_instanceorenv. Dataset URNs are built from platform, name, platform_instance and env, so these changes produce new URNs. The old URNs are missing from the new run. - Name casing changed, so URNs changed.
- You switched a dbt Cloud recipe from
auto_discovery(all production jobs) to explicit mode (onejob_id). Models that only the other jobs produced are now missing. If they were more than the threshold percentage of the previous run, the check trips. - The source returned much less data, for example because of filter changes, permission changes or connection problems.
When the check trips, nothing is soft-deleted. DataHub copies the previous run's URNs into the new state, so the stale entities are removed on the next successful run.
Stale entity removal is also skipped in two other cases, under the same title:
- The source already reported a failure. A warning reads
The soft-deletion of stale entities will be skipped because the source reported a failure. - The source produced no events. A failure reads
The source did not produce any metadata. Despite stateful ingestion being enabled, we will not delete any metadata. This is a fail-safe mechanism to prevent the accidental deletion of all entities.
Solution
Step 1: Find out why entities went missing
- Read the full run log for errors before the
Skipping stateful ingestionmessage. A source failure or zero output is a different cause than the threshold. - Check whether the recipe changed
platform_instance,env, or anything that changes URNs. - Check whether the recipe changed filter patterns or discovery settings.
- For dbt Cloud, check whether you switched between auto-discovery and explicit mode. A dbt Cloud recipe needs
token,account_idandproject_id. Explicit mode also needsjob_id:
# Auto-discovery: all production jobs of the project, latest run of each
source:
type: dbt-cloud
config:
token: ${DBT_CLOUD_TOKEN}
account_id: <account id>
project_id: <project id>
auto_discovery:
enabled: true
# Explicit mode: one job only
source:
type: dbt-cloud
config:
token: ${DBT_CLOUD_TOKEN}
account_id: <account id>
project_id: <project id>
job_id: <job id>
If auto_discovery is not enabled and job_id is missing, the recipe fails with job_id is required in explicit mode. Either provide job_id or enable auto_discovery mode. See dbt Cloud module.
Step 2: If the removal is intended, raise the threshold for one run
If you confirmed that the missing entities should be removed, set a higher fail_safe_threshold under source.config.stateful_ingestion. Values must be 100 or lower. A value of exactly 100.0 disables the check.
pipeline_name: my_pipeline # unique to this source and stable across runs
source:
type: <your source>
config:
stateful_ingestion:
enabled: true
remove_stale_metadata: true
fail_safe_threshold: 90.0 # set above the change=Z% value from the log
Run the ingestion once. After it succeeds, set the value back to the default of 75.0 or remove the key. Raising the threshold lets the soft-deletion of the missing entities go through, so confirm the list first.
Stateful ingestion needs a top-level pipeline_name that is unique to the source configuration and stable across runs. CLI runs without it fail with pipeline_name must be set when stateful ingestion is enabled. UI-managed sources get one injected automatically. If you change pipeline_name, the next run has no previous state. See Stateful ingestion and pipeline_name.
Step 3: Fix the underlying cause if the drop is not intended
- If you want all jobs again, return the dbt Cloud recipe to auto-discovery mode.
- If you changed
platform_instanceorenvby mistake, change it back so URNs match the previous run. See Platform instances. - Fix any source connection or permission problems from Step 1.
- Do not raise the threshold to hide a source failure. Raising it can soft-delete valid entities.