A small online store keeps a ledger with one record per product: cost, notes, links to the marketplace, and a section of search-optimization values such as attributes and tags. Thirty-six of those products had been linked to entries in the marketplace’s shared catalog. When a new daily analysis compared the ledger against the marketplace that morning, five of the 36 records had no catalog ID at all. The links existed on the marketplace side. The ledger had simply forgotten them.

Where the field went

The catalog ID was not a top-level field. It lived inside the search-optimization section of each record, next to the attributes and tags. That detail turned out to be the whole story.

Twelve days earlier, a script had applied a batch of search-optimization changes. Its job was narrow: take a plan of new attribute and tag values and write them into the ledger. It built the new section from the plan and wrote it back in place of the old one. Anything in the old section that was not in the plan, including the catalog ID, did not survive. The script did what its author asked of it, and the ledger lost a value nobody had asked it to touch. The log pins the loss to one run of that script, a two-minute window on one evening, and records the cause as confirmed.

The script never reported an error, because from its point of view there was none. It wrote what it was given. The loss only became visible when something else needed the catalog ID and went looking.

Merge first, then restore

The fix had two parts, in that order. First the script was changed to merge: read the existing section, update only the keys the plan names, and leave every other key as it was. Restoring the data before fixing the tool would have left the same trap armed for the next plan.

Then the five IDs were put back. Each one was taken from the store’s own record of the links it had made, and checked against the model ID the marketplace reported in a recent snapshot of the store. All five agreed. The ledger went back to 36 of 36.

Two things the log does not settle. It records the catalog ID being restored, but not whether any other value in that section was lost in the same run. And it does not say why only five records were affected and not all 36; the likeliest reading is that only those five were in that batch, but that was not checked.

A script asked to change three things in a record should change three things. Writing back a whole section is a replace, even when it is labeled an update. Make merging the default, and make replacing something a script has to ask for by name.