Auditor recorded output

← All 27 packs

Proven

Composite id join is ambiguous, so distinct items can share an id

bugmedium src/argus_scout/sources/json_poll.py:10

The finding

Multi-path ids are built with "/".join(str(v).strip() for v in values) and returned as-is whenever the values are plain and short. The separator is never escaped, so different tuples produce the same string. For example, ("a/b", "c") and ("a", "b/c") both become name:a/b/c. Values containing slashes are common (URLs, paths, image refs). The .strip() adds more collisions: " x" and "x" map to the same id, and a whitespace-only value passes the empty-string check but contributes an empty segment. When two different events get the same id, downstream dedup or upsert treats them as one event. The result is silently dropped or overwritten status events.

    1| """The ``json_poll`` source: scout GETs a JSON status endpoint and maps it onto status events.
    2| 
    3| Any producer is config, not code::
    4| 
    5|     - kind: json_poll
    6|       name: backups
    7|       url: http://backups:8080/status
    8|       items: data.jobs            # dotted path to the list; leave out if the response is one item
    9|       fields:                     # status event field -> dotted path within an item
   10|         event_id: id
   11|         summary: message
   12|         severity: level
   13| 
   14| A field that isn't mapped is read from the item's key of the same name, so an endpoint that already
   15| speaks the envelope needs no ``fields`` at all. Path segments that are integers index lists
   16| (``alerts.0.labels.name``).
   17| 
   18| **Stable ids.** A poller sees the same state on every poll, so an item's event id is derived from the item,
   19| never random. In order:
   20| 
   21| 1. ``id:`` in the config (a dotted path, or a list of them): ``<name>:<the values>`` (hashed when long or not
   22|    plain text). Use it whenever the endpoint has a real identity, e.g. ``[labels.alertname, labels.instance]``.

The work pack

Recommendation. Build an injective encoding. Either escape or percent-encode the separator inside each value before joining, or use the _digest(values) path whenever there is more than one path or any value contains /. Also reject values that are empty after stripping, or stop stripping.

Acceptance criteria

  • Address: Composite id join is ambiguous, so distinct items can share an id
  • Keep the change scoped to the cited file/symbols unless impact requires otherwise
  • Build an injective encoding. Either escape or percent-encode the separator inside each value before joining, or use the _digest(values) path whenever there is more than one path or any value contains /. Also reject values that are empty
  • Re-check src/argus_scout/sources/json_poll.py after the fix

Status

  1. claimed
  2. resolved

The fix

9df9c6f045 fix: configured json_poll ids are injective (no separator or whitespace collisions).

diff --git a/src/argus_scout/sources/json_poll.py b/src/argus_scout/sources/json_poll.pyindex b321fd0..c18c6f8 100644--- a/src/argus_scout/sources/json_poll.py+++ b/src/argus_scout/sources/json_poll.py@@ -18,8 +18,8 @@ speaks the envelope needs no ``fields`` at all. Path segments that are integers **Stable ids.** A poller sees the same state on every poll, so an item's event id is derived from the item, never random. In order: -1. ``id:`` in the config (a dotted path, or a list of them): ``<name>:<the values>`` (hashed when long or not-   plain text). Use it whenever the endpoint has a real identity, e.g. ``[labels.alertname, labels.instance]``.+1. ``id:`` in the config (a dotted path, or a list of them): ``<name>:<the values>`` joined by ``/`` (hashed when long,+   not plain text, padded with spaces, or when several values and one holds a ``/``, so ids never collide). Use it whenever the endpoint has a real identity, e.g. ``[labels.alertname, labels.instance]``.    An item missing one of the paths is skipped. 2. An ``event_id`` the item carries (or ``fields`` maps), as is. 3. With no ``items`` the response *is* the event: id ``<name>``.@@ -126,12 +126,16 @@ def _configured_id(cfg: JsonPollSource, item: Any) -> str:     values = []     for path in paths:         value = lookup(item, path)-        if value is _MISSING or value is None or value == "":+        if value is _MISSING or value is None or (isinstance(value, str) and not value.strip()):             raise InvalidEvent(f"id: {path!r} is not in the item")         values.append(value)     plain = all(isinstance(v, str | int | float) and not isinstance(v, bool) for v in values)-    text = "/".join(str(v).strip() for v in values)-    if plain and len(text) <= ID_TEXT_MAX:+    texts = [str(v) for v in values]+    # The readable form must be injective: a value with surrounding whitespace, or a "/" when several values+    # are joined ("a/b" + "c" vs "a" + "b/c"), would collide, so those are hashed (the hash keeps them apart).+    readable = all(t == t.strip() for t in texts) and (len(texts) == 1 or not any("/" in t for t in texts))+    text = "/".join(texts)+    if plain and readable and len(text) <= ID_TEXT_MAX:         return f"{cfg.name}:{text}"     return f"{cfg.name}:{_digest(values)}" diff --git a/tests/test_sources.py b/tests/test_sources.pyindex e1f72be..fd42983 100644--- a/tests/test_sources.py+++ b/tests/test_sources.py@@ -165,6 +165,28 @@ def test_configured_id_paths_identify_items_across_severity_changes():     assert missing.events == [] and missing.skipped == ["item 0: id: 'labels.instance' is not in the item"]  +def test_configured_ids_never_collide_on_the_separator_or_whitespace():+    cfg = AM.model_copy(update={"id": ["labels.alertname", "labels.instance"]})++    def ids(*pairs):+        return [+            e.event_id+            for e in map_response(+                cfg, {"alerts": [{"labels": {"alertname": a, "instance": i}} for a, i in pairs]}+            ).events+        ]++    split = ids(("a/b", "c"), ("a", "b/c"), (" x", "y"), ("x", "y"))+    assert len(set(split)) == 4 and split[3] == "am:x/y"+    blank = map_response(cfg, {"alerts": [{"labels": {"alertname": "  ", "instance": "y"}}]})+    assert blank.events == [] and "labels.alertname" in blank.skipped[0]+    single = AM.model_copy(update={"id": "labels.instance"})+    assert (+        map_response(single, {"alerts": [{"labels": {"alertname": "X", "instance": "http://h/x"}}]}).events[0].event_id+        == "am:http://h/x"+    )++ def test_derived_id_ignores_volatile_fields_but_keeps_payload_identity():     cfg = JsonPollSource(kind="json_poll", name="jobs", url="http://backups:8080/status", items="jobs")     base = {"summary": "Backup late", "payload": {"job": "nas"}}

How it was judged

Proven 1 test(s) fail on dev and pass with the fix: tests/test_sources.py::test_configured_ids_never_collide_on_the_separator_or_whitespace

Judged 24 Nov 2026, 04:47 UTC against dev at d0c0f66.

Teston devdev + patch
tests/test_sources.py::test_configured_ids_never_collide_on_the_separator_or_whitespacefailedpassed
The other 22 tests in the run (22 with the same result on both trees)
tests/test_sources.py::test_a_plugin_model_raising_anything_fails_only_its_entrypassedpassed
tests/test_sources.py::test_a_polled_item_cannot_post_as_another_sourcepassedpassed
tests/test_sources.py::test_allow_hostpassedpassed
tests/test_sources.py::test_bad_source_entries_do_not_stop_the_otherspassedpassed
tests/test_sources.py::test_builtins_are_registered_through_entry_pointspassedpassed
tests/test_sources.py::test_configured_id_paths_identify_items_across_severity_changespassedpassed
tests/test_sources.py::test_derived_id_ignores_volatile_fields_but_keeps_payload_identitypassedpassed
tests/test_sources.py::test_items_sharing_a_summary_get_distinct_stable_idspassedpassed
tests/test_sources.py::test_json_poll_maps_a_feeds_spoken_sentence_onto_speechpassedpassed
tests/test_sources.py::test_lookuppassedpassed
tests/test_sources.py::test_map_response_missing_items_pathpassedpassed
tests/test_sources.py::test_map_response_single_item_without_fieldspassedpassed
tests/test_sources.py::test_map_response_with_stable_ids_and_skipspassedpassed
tests/test_sources.py::test_poll_once_failures_are_source_errorspassedpassed
tests/test_sources.py::test_poll_once_through_argus_cortex_net_reaches_a_lan_hostpassedpassed
tests/test_sources.py::test_poll_once_uses_the_guarded_fetch_with_config_host_allowedpassedpassed
tests/test_sources.py::test_poll_result_is_incomplete_when_an_item_was_skippedpassedpassed
tests/test_sources.py::test_third_party_kind_from_an_entry_pointpassedpassed
tests/test_sources.py::test_webhook_list_bodypassedpassed
tests/test_sources.py::test_webhook_single_envelope_from_bytespassedpassed
tests/test_sources.py::test_webhook_tokenpassedpassed
tests/test_sources.py::test_webhook_token_falls_back_to_server_token_and_fails_closedpassedpassed