An automatic repricing tool changes sellers' prices on a marketplace on a schedule. The seller picks a pricing rule: match the featured offer, go one cent under it, a newer smart rule that prices from market data, and a few more.
There is also one safety tick, the skip tick: "skip items where I already hold the featured offer". In plain words: if I am already winning, do not lower my price. One seller had it on, was already the cheapest, and the tool lowered prices anyway.
Key facts
- The check behind the tick read a by-product, the reference price a rule had just beaten. Only some rules set it.
- The smart rule prices without the seller's own offer, so it never sets a reference. The check read nothing, and nothing meant "no reason to hold".
- In one scheduled run, 72 rows of a seller who was already the cheapest went down, $64.40 in total. One went from $40.72 to $29.10.
- An earlier fix and its test covered three older rules. Both passed while the smart rule stayed unguarded.
- A read-only replay of the failed run held 71 of the 72 rows. The next real run held 86 of 86.
What happened
The skip tick was built as one condition: hold the row when "the reference price the rule just beat is my own price". If the price being undercut is the seller's own, the seller is winning, so leave the row alone.
That reference price is a by-product some rules compute along the way. The older rules pick an offer to beat and keep it, so they set it. The smart rule prices from the market without the seller's own offer, so it never sets a reference at all.
For every row priced by the smart rule, the check read an empty value. Empty is never equal to the seller's price, so the answer was "do not hold". The tick was on, the seller was the cheapest, and prices went down.
In one scheduled run that came to 72 rows lowered for one seller who was already the cheapest, $64.40 in total. One row went from $40.72 to $29.10. The seller had written to support twice asking why the tool kept lowering their items.
Why the earlier fix and its test passed
This was not the first report. Days before, a fix had repaired the same symptom for three older rules. It came with a test that said, in effect, "when the price the rule beat equals my price, hold".
That condition can never be true for a rule that has no reference. The test ran through the rules that set the value, so it passed, and the check looked covered. Meanwhile the seller had moved all their templates to the smart rule, which neither the fix nor the test ever reached.
A missing value read as a safe answer is an old trap (another form of it: a lookup that read two matches as none). Here an empty input switched a safety check off, silently, for one whole family of rows.
The fix: ask the question itself
The tick asks one question: is the seller already the cheapest? The old check guessed the answer from a value only some rules leave behind. The fix makes every rule report that fact, and the check reads it. A sketch, with made-up names:
// Before: guess "I am winning"
// from a by-product.
const priced = rule.price(item);
// smart rule: refPrice is undefined
const hold = skipTick &&
priced.refPrice === item.myPrice;
// undefined === 40.72: false
// After: every rule reports the fact.
type Priced = {
price: number;
sellerIsCheapest?: boolean;
};
function shouldHold(item, p, tick) {
if (!tick) return false;
// only downward moves
if (p.price >= item.myPrice)
return false;
const cheapest = p.sellerIsCheapest;
if (cheapest === undefined) {
log.warn("cannot tell", item.id);
return true; // hold when unsure
}
return cheapest;
}
The smart rule now reports its own "seller is the cheapest" fact. If a rule cannot tell, the check logs it and holds, instead of quietly letting the price fall. The earlier fix stays as it was: the new hold applies only with the tick on and only to downward moves, so the older rules behave exactly as before.
Prove it with the real run
Before merge, the real failed run was replayed, read-only, through the new code: same inputs, decisions compared row by row.
The replay held 71 of the 72 lowered rows, so $63.51 of the $64.40 would not have been cut. The one row left moved for a different, valid reason. And it held no row outside those 72.
After deploy, the next real scheduled run held 86 of 86 such rows.
The checklist
Anyone with more than one strategy behind a safety check can do these tomorrow:
- Let the check ask its own question. Compute it from facts every path has, or make every strategy return that fact explicitly. Do not infer it from a by-product of some strategies.
- Treat a missing input as "cannot tell". Decide that case on purpose: hold, or log and go ahead. Never let it pass by default.
- Keep one table for every new strategy. Strategies down, guards across. Prove each guard fires for each strategy before the strategy ships.
- Replay the real failed run before merge. Read-only, same inputs, compare decisions: the rows that broke must change, and no other row may.
- Keep the new behaviour narrow. Scope it to the case that broke, so the paths that already worked behave exactly as before.
The lesson in one line: a safety check that reads a value only some code paths set is switched off on the others, silently, because "no value" reads as "no reason to act". It looks covered because it was tested through the paths that set the value.
Common questions
Why did the earlier test pass?
It checked that the price the rule beat equals the seller's price. That can only be true for a rule that sets a reference price. The test ran through the older rules, which all do, so it passed and said nothing about the rule that never sets one.
Should a safety check always hold when an input is missing?
Not always, but it should decide on purpose. Holding is the safe side for a check that stops prices going down; for other checks, logging and going ahead may be right. What must not happen is a missing value quietly reading as a pass.
Why replay the real run instead of writing a new test?
A new test is written by the same person who missed the case, so it tends to share the blind spot. The real run already holds the inputs that broke, and a read-only replay shows the new decision for every one of them, plus every row it must leave alone.
Melta is free; get it on the App Store or Google Play.