From 0fa66a0bcbe622ff59c52854fda6f08b1c0d5d5c Mon Sep 17 00:00:00 2001 From: Aswin Date: Fri, 4 Sep 2026 15:57:02 +0530 Subject: [PATCH] fix(stcourier): use the newest scan as the headline status ST Courier's "Current Status" summary cell lags its own timeline: for AWB 64424565531 it still read "In Transit" while the latest scan was already "Out for Delivery". Preferring that cell made /api/track and the public tracking page report a status behind the scan list rendered right below it. Prefer the newest scan (matching the Blue Dart carrier) and keep the summary cell only as a fallback for shipments with no scans yet. Also log unknown carriers in the poller instead of skipping in silence. The poller is deployed separately from the web app, so a newly registered carrier is live on the site while this worker still runs the old bundle. That path stamped last_polled_at and left last_known_status null, so the dashboard read "awaiting first scan" indefinitely and no alerts fired, with nothing in the logs to explain why. Co-Authored-By: Claude Opus 5 --- src/carriers/stcourier.ts | 8 +++++--- workers/poller/index.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/carriers/stcourier.ts b/src/carriers/stcourier.ts index 9eafbbf..64ec57b 100644 --- a/src/carriers/stcourier.ts +++ b/src/carriers/stcourier.ts @@ -219,9 +219,11 @@ export const stcourier: Carrier = { return { carrier: "stcourier", trackingNumber: cleaned, - // Prefer the summary cell — it's ST Courier's own rollup — and fall back - // to the newest scan when the table is missing. - status: current ? mapStatus(current) : latest ? latest.status : "unknown", + // Prefer the newest scan. ST Courier's "Current Status" summary cell lags + // its own timeline — it still read "In Transit" while the latest scan was + // already "Out for Delivery" — so it's only a fallback when there are no + // scans to read. + status: latest ? latest.status : current ? mapStatus(current) : "unknown", origin, destination, events, diff --git a/workers/poller/index.ts b/workers/poller/index.ts index 6ad207a..43497eb 100644 --- a/workers/poller/index.ts +++ b/workers/poller/index.ts @@ -29,6 +29,14 @@ async function sha256Hex(input: string): Promise { async function processWatch(env: Env, w: WatchRow): Promise { const carrier = getCarrier(w.carrier); if (!carrier) { + // The poller is deployed separately from the web app (`npm run + // deploy:poller`), so a carrier added to the registry is live on the site + // while this worker still has the old bundle. That combination silently + // stamps last_polled_at and leaves last_known_status null — the dashboard + // shows "awaiting first scan" forever and no alerts fire. Log it loudly. + console.warn( + `watch ${w.id} references unknown carrier "${w.carrier}" — this poller bundle predates it; redeploy the poller.`, + ); await markPolled(env.DB, w.id); return; }