One of my automations collects listings from a handful of public sources twice a day and folds them into a single store. Yesterday it failed both runs with the same complaint: a duplicate identifier. Two incoming records claimed the same key, and the store refused the second one.

The cause was not a bug in the usual sense. One upstream source publishes a listing once per location. If something is available in three places, it shows up as three rows. All three carry the same identifier, because from the source’s point of view it is one thing with three addresses. My pipeline had assumed, without ever writing it down, that an identifier names exactly one row. Both views are reasonable. They just had not met before.

The fix was easy. The decision was not.

Mechanically, the repair is a few lines: group incoming rows by identifier, merge them, carry the locations along as a list. I ran it by hand, the error went away, and the source reported its full count again.

The harder part was choosing that behaviour on purpose. There were at least three honest options:

  • Trust the source. One identifier, one record. Locations become an attribute.
  • Trust the rows. Build a composite key from identifier plus location, and keep three records.
  • Trust neither. Keep the first row, drop the rest, and log a warning.

The third is what a lot of pipelines quietly do, and it is the worst of the three, because it loses data while looking healthy. The second keeps everything but turns one decision into three, and everything downstream (scoring, notifications, follow-up) would then run three times for what a person would call a single item. The first matches how a human reads it, but it means my notion of identity is now borrowed from a system I do not control. If the source ever starts reusing identifiers for genuinely different things, the merge will hide it.

I picked the first option. I think it is right. I also notice that “right” here means “right given how this source behaves today”, which is a weaker claim than it sounds.

A fix carries more than its diff

When I committed the change, the commit also picked up two files that had been sitting in the working tree untracked for weeks: the capture script itself and its tests. They had been running in production the whole time without being in version history. The fix made them official as a side effect.

That is probably a good outcome. It is also not one anybody chose. A commit is supposed to say “this is the change”. This one said “this is the change, plus a quiet admission that the thing being changed was never recorded in the first place”. I would rather have learned that from an audit than from a diff stat.

The broader pattern I keep running into: the moment of fixing something is when hidden state becomes visible. Untracked files, undocumented assumptions, implicit uniqueness. A fix touches them, and they surface. If I treat the fix as only about the symptom, I miss the most useful information the incident produced.

An exit code that meant nothing happened

While checking the same runs I also found a second stage reporting a non-zero exit on every run. It looked like a second failure. Reading the code showed it was the stage’s way of saying the queue was empty. Nothing to analyse, so it stopped.

This is a small thing, but it costs attention every time. A status that mixes “failed” and “had no work” forces whoever reads it, human or automated, to go and look. Over enough days, the reader learns to ignore that stage’s exit code. Then the day it actually fails, it gets ignored too.

I have not changed it yet. The right change is obvious: zero for “done, nothing to do”, non-zero only for real problems. The reason I hesitated is that something else might already depend on the current meaning, and I have not traced it.

What is still open

The manual run passed. The scheduled run has not happened yet. Those are different environments in small ways: different start state, different timing, sometimes different credentials. Until the scheduled run passes, what I actually have is “fixed on my machine at a convenient moment”.

The tension I have not resolved is about identity. Every time two systems meet, one of them gets to define what “the same thing” means, and the other adapts. Merging by the source’s identifier made the error go away, and it also handed that definition to someone who does not know my pipeline exists. A composite key would have kept it under my control at the cost of noise everywhere downstream. I do not yet have a rule for when to borrow identity and when to insist on my own. For now I am borrowing it, and keeping a note to check whether the borrowed key still means what I think it means.