Skip to content

Make CoreLocation geolocation resilient to cold starts#10

Merged
thornjad merged 2 commits into
mainfrom
robust-corelocation-cold-start
Jun 9, 2026
Merged

Make CoreLocation geolocation resilient to cold starts#10
thornjad merged 2 commits into
mainfrom
robust-corelocation-cold-start

Conversation

@thornjad

@thornjad thornjad commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Work Done

When CoreLocation failed on a cold start (e.g. right after wake-from-sleep, before WiFi positioning is ready), location resolution fell back to coarse IP geolocation. That fallback can land far enough from a configured Tempest station to trip the station proximity gate and silently disable Tempest enrichment — and because the resolved location was cached for the whole server lifetime, a single cold-start miss pinned the entire session to the wrong location.

  • The CoreLocation helper now waits for a real fix instead of giving up on the first attempt: startUpdatingLocation rather than one-shot requestLocation, a 30 s budget, kCLErrorLocationUnknown treated as transient, and an accuracy gate so a stale coarse fix isn't accepted.
  • A failed lookup is cached for only 120 s (a successful one for an hour), so a cold-start miss self-heals on a later call once locationd is warm, rather than pinning the session to the IP fallback.
  • The compiled helper is now rebuilt when its source changes, keyed off a source hash — previously a stale cached binary was reused indefinitely.

Testing

  • Given a configured Tempest station with ENABLE_CORELOCATION=true
  • Delete ~/Library/Application Support/stormscope/StormscopeLocation.app to force a clean build
  • Call get_conditions with no coordinates
  • Expect the helper to recompile and a fix to return, and the response data_source to read tempest
  • Confirm ~/Library/Application Support/stormscope/StormscopeLocation.app/Contents/.swift-version now exists
  • Edit the Swift source, call get_conditions again
  • Expect the helper to rebuild rather than reuse the old binary

The helper made a single-shot requestLocation with a 10s budget, so a
cold start (right after wake, before wifi positioning is ready) failed
and fell back to coarse IP geolocation. That fallback can trip the
Tempest station proximity gate and silently disable enrichment, and the
result was cached for the whole server lifetime.

- wait for a real fix: startUpdatingLocation, 30s budget, treat
  kCLErrorLocationUnknown as transient, accuracy gate on the fix
- cache failures for only 120s (success 1h) so a cold-start miss
  self-heals once locationd is warm
- rebuild the helper when its swift source changes, keyed off a hash
@thornjad thornjad marked this pull request as ready for review June 9, 2026 21:10
test_binary_exists_returns_path created the binary but no
.swift-version marker, so the new version gate fell through to a real
swiftc call that fails on the Linux CI runners. Write the marker so the
cache-hit short-circuit is exercised as the test name intends.
@thornjad thornjad merged commit c204602 into main Jun 9, 2026
4 checks passed
@thornjad thornjad deleted the robust-corelocation-cold-start branch June 9, 2026 21:40
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