Skip to content

Service: accept station ids published as strings - #35

Open
kevinelliott wants to merge 1 commit into
mainfrom
claude/project-thread-xlxhmp
Open

kevinelliott wants to merge 1 commit into
mainfrom
claude/project-thread-xlxhmp

Conversation

@kevinelliott

@kevinelliott kevinelliott commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Kevin · project thread

Problem

The coverage service went live on production (Dockhand stack gh-coverage-v1 on papp-euc-1) and is healthy, but it produces no coverage: in the first six minutes it parsed about 400 events per second and rejected every one of them (0 processed, about 140,000 rejected).

The cause is an id type mismatch. The aggregation server's ORM models hold row ids as String, so NATS payloads carry "station": {"id": "1234", ...}. The service keys its station metadata by the numeric id returned by api.airframes.io/stations. A Map<number, …> lookup with a string key never matches, so every event fails the station trust check as an unknown station.

Staging hid this because almost no aircraft messages were flowing there.

Fix

  • New toStationId() helper that accepts a positive integer as a number or a digit string and returns a number, otherwise null.
  • The aircraft and marine parsers use it, so events carry a numeric station id. Events with no usable id are dropped at parse time, as before.
  • Station sync normalizes the API's id the same way, so both sides of the lookup agree whichever type either source sends.
  • Payload types now say id?: number | string.

Tests

service/test/parsers.test.ts (new): id normalization, both aircraft parsers with a production-shaped payload (string ids), and an end-to-end check that such an event is ingested rather than rejected. npm test (19 passing), npm run typecheck and npm run build pass.

Screenshots

None. This is a backend-only change with no UI.

After merge

CI publishes coverage-service:sha-<commit>. A follow-up stack PR pins that tag in prod/coverage/compose.yml, then the gh-coverage-v1 stack is redeployed through Dockhand.


Generated by Claude Code


Note

Medium Risk
Touches core event parsing and station sync for a production outage fix; behavior change is narrowly scoped to id normalization with tests, but incorrect handling would still drop or mis-attribute coverage events.

Overview
Fixes production coverage ingestion where every NATS event was rejected because aggregation publishes station.id as JSON strings while the service indexes metadata with numeric keys, so Map lookups never matched.

Adds toStationId() to coerce positive integer ids from numbers or digit-only strings (otherwise null). Aircraft and marine parsers and station sync now use it so emitted CoverageEvent.stationId and synced map keys stay numeric; unparseable ids still drop at parse/sync time. Payload types widen relevant id fields to number | string. New parsers.test.ts covers normalization, production-shaped string ids, and end-to-end ingest acceptance.

Reviewed by Cursor Bugbot for commit de4aa87. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of station identifiers across aircraft and marine event processing. Numeric and digit-only string identifiers are now normalized consistently, while missing or invalid identifiers are skipped.
    • Station synchronization now accepts valid numeric or digit-only string identifiers and skips invalid values.
    • Aircraft events with string station identifiers can be processed without being incorrectly rejected.
  • Tests
    • Added coverage for identifier normalization and handling of valid and invalid aircraft event data.

The aggregation server serializes row ids as JSON strings, while station
metadata synced from the API is keyed by number. Every production event
therefore failed the station trust check as an unknown station (0 processed).
Normalize station ids to numbers in the aircraft and marine parsers and in
station sync, and drop events whose id is not a positive integer.

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

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Aircraft and marine payload ID types now accept strings. A shared parser normalizes station IDs for station sync and event parsing. Parsers reject unusable station IDs and emit events with normalized IDs.

Changes: Station ID normalization

Layer / File(s) Summary
ID input types and normalization
service/src/types/events.ts, service/src/nats/parsers/station-id.ts
Aircraft and marine payload ID fields accept numbers or strings. The new toStationId function returns a positive safe integer for accepted values and null otherwise.
Station sync normalization
service/src/sync/station-sync.ts
Station sync skips IDs that do not normalize. It uses normalized IDs as map keys and stored station IDs.
Aircraft and marine event parsing
service/src/nats/parsers/aircraft.ts, service/src/nats/parsers/marine.ts, service/test/parsers.test.ts
Aircraft and marine parsers reject unusable station IDs and use normalized IDs in emitted events. Tests cover normalization, parsing, and ingestion with a string station ID.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to de4aa

This change lets events carrying station IDs published as strings match numeric station metadata, so they are no longer rejected. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Service: accept station ids published as strings" matches the main change. The PR normalizes station IDs that arrive as digit strings into positive integers in the aircraft and marine parse…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Service: accept station ids published as strings" matches the main change. The PR normalizes station IDs that arrive as digit strings into positive integers in the aircraft and marine parsers and in station sync, and widens the payload types to accept strings. The title is short, specific, and does not describe anything absent from the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2c5f13c8-3cf6-4012-a447-fcb9ccba72f0
Commits

Reviewing files that changed from the base of the PR and between c174921 and de4aa87.

Files selected for processing: 6

  • service/src/nats/parsers/aircraft.ts
  • service/src/nats/parsers/marine.ts
  • service/src/nats/parsers/station-id.ts
  • service/src/sync/station-sync.ts
  • service/src/types/events.ts
  • service/test/parsers.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying airframes-coverage with  Cloudflare Pages  Cloudflare Pages

Latest commit: de4aa87
Status: ✅  Deploy successful!
Preview URL: https://9bdd5bf9.airframes-coverage.pages.dev
Branch Preview URL: https://claude-project-thread-xlxhmp.airframes-coverage.pages.dev

View logs

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Cursor Bugbot completed successfully with no findings that need human review, so this change meets the approval criteria.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

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