#6849·keep

[ Bug]: Deduplication rule ignoring a nested field (e.g. labels.pod) drops alerts that lack that field

Author: breken-aiCreated Sep 26, 2026Updated Sep 26, 2026

Describe the bug Take a full deduplication rule whose ignore fields include a nested field such as labels.pod. The deduplication page offers these fields, built from labels seen on earlier alerts. Any alert from that provider without that label raises KeyError and is dropped.

AlertDeduplicator._remove_field (keep/api/alert_deduplicator/alert_deduplicator.py:188-194, main @ fe5c8964) walks d[part] and runs del d[field_parts[-1]] with no existence check. process_event then fails:

  • the alert is not stored (it lands in the error alerts);
  • the arq job retries and fails again.

Alerts from one provider rarely all carry the same labels, so ignoring a label that only some alerts have drops every alert without it. The code dates from f107d2142 (2024-02).

To Reproduce

  1. Create a custom full deduplication rule for a provider with ignore field labels.pod.
  2. Send an alert from that provider whose labels have no pod.
  3. The alert is not ingested. The log shows Error processing event with KeyError: 'pod', then arq.worker.Retry.

Failing tests (red on main, green with the fix):

  • tests/deduplication/test_deduplications.py::test_full_deduplication_nested_ignore_field_missing_on_alert, end to end through process_event. On main: KeyError: 'pod', then arq.worker.Retry. With the fix, the first alert is stored and the second is a full duplicate (1 alert row, 1 full dedup event).
  • ::test_remove_missing_nested_field_keeps_alert (unit). On main: KeyError: 'namespace'.

Expected behavior A missing nested field means there is nothing to ignore. The alert is ingested and deduplicated normally.

Additional context A fix with a regression test is ready on breken-ai/keep fix/dedup-missing-nested-ignore-field:

  • It walks the path with .get and returns the alert unchanged when a parent isn't a dict or the key is missing.
  • It also keeps the top-level dict for paths deeper than two levels.
  • tests/deduplication + tests/test_get_alerts_custom_dedup.py: 34 passed.

The PR will follow once the CLA is signed (same account as #6805).

Prepared with AI assistance (Claude) from the breken-ai account.