From 83806965746a99d7b0c68352595c04ca95916616 Mon Sep 17 00:00:00 2001 From: martbost Date: Fri, 28 Aug 2026 10:31:49 -0500 Subject: [PATCH] Traffic Desk: clamp refunds to what was actually bought A few rows on the network carry a remaining larger than their assigned (a pre-existing counter quirk), which surfaced as '1,002 returned' on a 1,000-impression ad. Derive served from bought - unserved instead of trusting the network counter. Verified live: a text ad with emoji round-tripped through the database byte-for-byte, then stopped and refunded in full. Co-Authored-By: Claude Fable 5 --- suite-traffic.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/suite-traffic.js b/suite-traffic.js index 5da728c..60b7cd5 100644 --- a/suite-traffic.js +++ b/suite-traffic.js @@ -203,6 +203,12 @@ async function stop(memberId, adId) { // `bought` preserves the original order size so the member's history still // shows what they launched, not just what it ended up costing them. if (row.bought == null) row.bought = row.impressions; + + // A handful of rows on the network carry a `remaining` larger than their + // `assigned` (a pre-existing counter quirk). Clamp, or a member sees + // "1,002 returned" on an ad they bought 1,000 impressions for. + unserved = Math.min(unserved, row.bought); + served = row.bought - unserved; row.stopped = true; row.stoppedAt = new Date().toISOString(); row.served = served;