Skip to content

Fix takeoff slice bug on duplicate GPS timestamps#164

Merged
pokle merged 1 commit into
masterfrom
claude/dazzling-clarke-c2d99b
May 30, 2026
Merged

Fix takeoff slice bug on duplicate GPS timestamps#164
pokle merged 1 commit into
masterfrom
claude/dazzling-clarke-c2d99b

Conversation

@pokle
Copy link
Copy Markdown
Owner

@pokle pokle commented May 11, 2026

Summary

  • detectFlightEvents used fixes.findIndex(f => f.time.getTime() === takeoffEvent.time.getTime()) to locate the takeoff fix. Cheap GPS loggers stall and emit consecutive fixes with identical timestamps, so the lookup can land on an earlier fix and silently feed pre-takeoff data into thermal/glide/altitude detection, producing spurious events. Read the index from takeoffEvent.details.fixIndex instead, which detectTakeoff already stores when it emits the event.
  • Two defensive cleanups in the same area:
    • evaluateTakeoffCriteria guarded the upper bound (index < fixes.length - 1) while reading fixes[index - 1]. Harmless today because the only caller starts at i = 1, but the guard now protects the correct boundary (index >= 1).
    • scoreTask replaces Math.max(...arr) / Math.min(...arr) with maxBy / minBy from array-utils, matching the policy already documented in array-utils.ts.

Why

Surfaced during a code-quality review of web/engine. The takeoff-slice bug is the only one with an observable failure on real-world IGC data — when triggered, it lets pre-takeoff climbs (e.g. a chairlift ride logged before launch) leak into thermal detection. The other two are consistency / robustness with no behavior change at realistic inputs.

Test plan

  • New regression test web/engine/tests/event-detector-duplicate-timestamp.test.ts — constructs a track with a pre-takeoff 0.6 m/s climb and a duplicate timestamp at fix 0. Fails on the previous code (thermal_entry emitted at fix 9) and passes on the fix.
  • Full repo suite: bun run test → 412 / 412 pass.
  • bun run typecheck:all clean.

detectFlightEvents re-derived the takeoff fix index by scanning fixes
for one whose timestamp matched the takeoff event. Cheap GPS loggers
stall and emit consecutive fixes with identical timestamps, so the
lookup could land on a fix earlier than the real takeoff and silently
feed pre-takeoff data (e.g. a stalled climb) into thermal/glide
detection, producing spurious events. The takeoff event already
carries the correct fix index in its details — use that directly.

Also two defensive cleanups in the same area:
- Fix the lower-bound guard in evaluateTakeoffCriteria (was guarding
  the wrong boundary; harmless today because callers start at i=1).
- Replace Math.max(...arr) / Math.min(...arr) in gap-scoring's
  scoreTask with maxBy/minBy from array-utils, matching the policy
  documented in array-utils.ts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pokle pokle force-pushed the claude/dazzling-clarke-c2d99b branch from a6acaaa to a5433c1 Compare May 30, 2026 11:42
@github-actions
Copy link
Copy Markdown

Preview Deployment
https://d62f60fa.glidecomp.pages.dev
Commit: a5433c1

@pokle pokle merged commit 650e707 into master May 30, 2026
7 checks passed
@pokle pokle deleted the claude/dazzling-clarke-c2d99b branch May 30, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant