From eb32eb16906896fa08ae72b0327fe6a879b50391 Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 23 Nov 2026 17:15:56 +0100 Subject: [PATCH] fix(flight-live): take a departure near the origin without a vertical rate After the scheduled time an airborne aircraft within 60 km of the origin is the leg unless it is clearly descending, so a level climb-out or a feed without rates still records departed_at and the delay. --- .../nest/flight-live/flight-live.derive.ts | 10 +++++-- .../flight-live/flight-live.derive.test.ts | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/server/src/nest/flight-live/flight-live.derive.ts b/server/src/nest/flight-live/flight-live.derive.ts index 7c63d49bc..684030f59 100644 --- a/server/src/nest/flight-live/flight-live.derive.ts +++ b/server/src/nest/flight-live/flight-live.derive.ts @@ -24,6 +24,8 @@ const UNKNOWN_AFTER_MS = 2 * HOUR; const STALE_AFTER_MS = 10 * MIN; /** Approach, landing and taxi on top of the great-circle flight time. */ const APPROACH_BUFFER_MS = 8 * MIN; +/** A sink rate past the jitter a level aircraft reports, in feet per minute. */ +const DESCENDING_FPM = -250; /** One aircraft as the feed reported it, already validated. */ export interface FeedAircraft { @@ -172,7 +174,8 @@ function claimedBySibling( * same flight number, which nobody on the instance may have booked, and which * runs late past this leg's scheduled departure as often as not. After the * scheduled time a departure may climb out away from the destination before it - * turns, so one climbing near the origin then is taken for the leg. + * turns, level at its first cleared altitude or with no vertical rate in the + * feed, so one near the origin then is taken for the leg unless it descends. */ function stillInbound( ac: FeedAircraft, @@ -185,8 +188,9 @@ function stillInbound( if (departed || route.scheduled_departure === null || ac.alt_baro === 'ground') return false; if (kmTo(lat, lng, route.destination) < kmTo(route.origin.lat, route.origin.lng, route.destination)) return false; if (now < route.scheduled_departure) return true; - const climbing = (finite(ac.baro_rate) ?? finite(ac.geom_rate) ?? 0) > 0; - return !(climbing && kmTo(lat, lng, route.origin) <= 60); + const rate = finite(ac.baro_rate) ?? finite(ac.geom_rate); + const descending = rate !== null && rate < DESCENDING_FPM; + return descending || kmTo(lat, lng, route.origin) > 60; } /** diff --git a/server/tests/unit/nest/flight-live/flight-live.derive.test.ts b/server/tests/unit/nest/flight-live/flight-live.derive.test.ts index 2120c6b5e..eb4571183 100644 --- a/server/tests/unit/nest/flight-live/flight-live.derive.test.ts +++ b/server/tests/unit/nest/flight-live/flight-live.derive.test.ts @@ -202,6 +202,36 @@ describe('pickAircraft and observe', () => { expect(pick(swa({ alt_baro: 3000, lat: 41.79, lon: -87.55, baro_rate: 2200 }))).toBe('swa'); }); + it('FLDER-023: after its scheduled time a departure near the origin is taken without a vertical rate or while level', () => { + const at = (iso: string) => Date.parse(iso); + const mdw = { code: 'MDW', name: 'Chicago Midway', lat: 41.7868, lng: -87.7522, timezone: 'America/Chicago' }; + const den = { code: 'DEN', name: 'Denver', lat: 39.8561, lng: -104.6737, timezone: 'America/Denver' }; + const leg: ScheduledLeg = { + ...LEG, + callsign: 'SWA1234', + flight_number: 'WN 1234', + origin: mdw, + destination: den, + scheduled_departure: at('2026-07-01T14:45:00Z'), + scheduled_arrival: at('2026-07-01T17:15:00Z'), + }; + const late = at('2026-07-01T15:10:00Z'); + const outbound = (rates: Partial) => + ac({ hex: 'swa', flight: 'SWA1234', alt_baro: 5000, lat: 41.8, lon: -87.5, ...rates }); + const pick = (aircraft: FeedAircraft) => pickAircraft([aircraft], leg, { now: late, siblings: [] }); + + expect(pick(outbound({ baro_rate: null, geom_rate: null }))?.hex).toBe('swa'); + expect(pick(outbound({ baro_rate: 0 }))?.hex).toBe('swa'); + expect(pick(outbound({ baro_rate: -64 }))?.hex).toBe('swa'); + expect(pick(outbound({ baro_rate: -900 }))).toBeNull(); + expect(pick(ac({ hex: 'swa', flight: 'SWA1234', alt_baro: 12000, lat: 41.5, lon: -86.5 }))).toBeNull(); + + const taxiing = { ...emptyState('SWA1234', '2026-07-01', 'MDW', 'DEN'), phase: 'taxiing' as const }; + const next = advance(taxiing, pick(outbound({ baro_rate: null })), leg, late, 'adsb.lol'); + expect(next.phase).toBe('airborne'); + expect(next.departed_at).not.toBeNull(); + }); + it('FLDER-003: reads a report at its own time, on the ground at zero feet, the geometric height as a fallback', () => { const now = DEP; expect(observe(ac(), now)).toEqual({