Skip to content

Service: marine (AIS) coverage, and drop the flight subscriptions that never match - #41

Merged
kevinelliott merged 1 commit into
mainfrom
claude/project-thread-xlxhmp
Nov 20, 2026
Merged

kevinelliott merged 1 commit into
mainfrom
claude/project-thread-xlxhmp

Conversation

@kevinelliott

@kevinelliott kevinelliott commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Kevin · project thread

Why

Marine coverage has been empty in production. The marine parsers expected a station object on every event, but the aggregation server does not publish one for marine:

  • v1.marine.ais_message.created is { source, ais_message }, where ais_message.station_id is the station UUID and there is no position.
  • v1.marine.voyage-position.created is { source, voyage_position }, with latitude and longitude but no station.

So every marine event was dropped at the parser. Separately, the v1.aircraft.ingest.*.flight.* subscriptions match nothing (flights are published on v1.aircraft.flight.*), and those events name no station, so they cannot contribute to coverage.

What changes

  • New MarineCorrelator (service/src/nats/marine-correlator.ts) joins the two marine events on marine_voyage_id. The aggregator publishes the AIS message first and its position right after, so an AIS message waits up to 5 s for its position. Each AIS message becomes exactly one reception:
    • paired with the position that follows it, or
    • given the vessel's last known position if that is under 2 minutes old (static data messages carry no position), or
    • counted as a reception without position.
  • Station UUIDs are resolved through the existing UUID index from the station sync. Receptions from stations the sync does not know are counted and dropped.
  • The flight subscriptions, parseAircraftFlight, the old marine parsers and the voyage created/updated subscriptions are removed.
  • /api/v1/health gains a marine block: paired, fromLastPosition, withoutPosition, unknownStation, pending, trackedVoyages.
  • MARINE_COVERAGE_ENABLED=false leaves the marine subjects unsubscribed, as an off switch that needs no new image.

Load

Marine is the busiest feed (about 600 events a second across the two subjects). Measured locally:

  • Ingest handles about 165,000 marine events a second on one core, so CPU is not a concern.
  • The existing per-station limit of 900 a minute still applies.
  • AIS range is capped at 70 km, so each station touches few cells in the long windows. A uniform worst case of 150 AIS stations added about 86 MiB of heap. Production currently sits at about 550 MiB of its 2 GB limit after 19 hours.

Worth watching cellsInMemory and the marine block on /api/v1/health after deploy. If unknownStation is high, the station sync is not returning UUIDs for those stations.

Testing

  • npm run typecheck and npm test pass (35 tests; 7 new for the correlator, using payloads in the aggregation server's shape).
  • Not tested against live NATS. The payload shapes are taken from the aggregation server's serializers (ais_message.g.dart, voyage_position.g.dart) and the publish order from aiscatcher_json_message_importer.dart.

Screenshot

The map's Marine filter, fed by the real store, API and correlator with synthetic AIS payloads (demo stations, blank basemap because the basemap host is not reachable from the build container; the "NATS disconnected" banner is because the demo has no NATS):

Marine coverage


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Marine AIS coverage now pairs messages with voyage-position data, using a recent known position when available.
    • Health reporting now includes marine pairing and tracking metrics.
    • Marine coverage can be disabled through configuration.
  • Changes
    • Aircraft flight-update events are no longer included in coverage processing.
  • Tests
    • Added coverage for marine message pairing, position fallback, invalid data, and voyage tracking.

…scriptions

Marine events carry no station object: ais_message.created has the station
UUID and voyage-position.created the vessel position. Join them on the
voyage id so each AIS message becomes one reception, with the vessel's last
known position standing in for messages without one. Flight events name no
station and matched nothing, so their subscriptions and parser are removed.
MARINE_COVERAGE_ENABLED=false leaves the marine subjects unsubscribed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PS44Q7WRmAzMJLhi44dzdo
@kevinelliott kevinelliott self-assigned this Nov 20, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying airframes-coverage with  Cloudflare Pages  Cloudflare Pages

Latest commit: f085c5d
Status: ✅  Deploy successful!
Preview URL: https://84d9ce3a.airframes-coverage.pages.dev
Branch Preview URL: https://claude-project-thread-xlxhmp.airframes-coverage.pages.dev

View logs

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Marine coverage now correlates AIS messages with voyage positions by voyage ID. The service conditionally subscribes to marine subjects, emits coverage events for known stations, and includes marine metrics in the health response.

Changes: Marine coverage

Layer / File(s) Summary
Correlate AIS messages and positions
service/src/nats/marine-correlator.ts, service/src/nats/parsers/marine.ts, service/src/types/events.ts, service/test/marine.test.ts
MarineCorrelator pairs AIS messages with voyage positions by voyage ID. It uses recent positions when available and emits null coordinates when no recent position exists. Tests cover pairing, expiry, and invalid payloads. The previous marine parsers and payload interfaces are removed.
Subscribe and report marine coverage
service/src/nats/subscriber.ts, service/src/config.ts, service/src/nats/parsers/aircraft.ts, service/test/parsers.test.ts, service/src/api/routes/health.ts, service/CLAUDE.md
NatsSubscriber conditionally subscribes to marine AIS and voyage-position subjects, flushes the correlator, and emits marine coverage events for known stations. The configuration flag, health metrics, and architecture documentation are updated. Aircraft flight subscriptions and the flight parser are removed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant NATS
  participant NatsSubscriber
  participant MarineCorrelator
  NATS->>NatsSubscriber: AIS message or voyage position
  NatsSubscriber->>MarineCorrelator: Parsed payload
  MarineCorrelator->>NatsSubscriber: MarineReception
  NatsSubscriber->>NatsSubscriber: Emit marine AIS coverage event
Loading

Possibly related PRs

Suggested reviewers: claude, cursor

Merge Risk: Low · up to f085c

Marine AIS coverage is added behind a config flag, and the health endpoint reports its counters. Under a sustained burst above 50,000 pending messages, some AIS messages skip pairing and use a fallback or no position. Normal load is unaffected, and the flag allows a quick disable. This is mergeable with awareness of the overflow behavior.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kevinelliott
kevinelliott merged commit a2908c3 into main Nov 20, 2026
8 of 9 checks passed
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.

2 participants