Republished from radiofreq’s architecture documentation.

Back to How it is built

The dispatch pipeline

RadioFreq takes each transmission a Uniden SDS100 hears off the radio over its USB serial link as a WAV, keeps it, turns it into text with a speech-to-text engine, and emits two events from the text: a push notification to the person's phone and, on a schedule, an AI-written Dispatch Report. The pipeline runs in two places. The browser tab on the person's computer detects the end of each call, pulls the recording, and uploads it; the server stores it, decides whether to transcribe it, calls the engine, and sends the events. Every call carries its own trace id (the recordings row's id) and a timestamp for each stage, and the stage latencies are measured per call and exposed as Prometheus metrics.

What it measures

From the run in docs/loadtest-results.md (2026-10-20, Apple M4 Max, Node 26, the sample engine answering in 800 to 1200 ms where Deepgram and Groq answer in 1 to 3 s; the pull off the radio simulated as a fixed 2.4 s, which is what the SDS100 takes for a short call over its serial link):

Speed Calls a second Queue wait p99 Engine p50 Call end to transcript p50 p99 Turned away
1x 0.34 5 ms 982 ms 3.46 s 3.67 s 0
2x 0.74 2 ms 972 ms 3.44 s 3.67 s 0
4x 1.48 543 ms 983 ms 3.48 s 4.16 s 0
8x 3.0 1.40 s 972 ms 3.61 s 4.79 s 0

At real time a call's text is on its row about 3.5 s after the call ended: 2.4 s of that is the pull, 70 ms the upload, under 5 ms the wait for an engine, and about 1 s the engine; the notification follows within 2 ms. The engines are the floor and the bound: four at once at about 1 s each answer about 4 calls a second, and at 8x (3 calls a second) the queue began to wait but nothing was turned away. The real engines' latency puts the same floor at 4 to 6 s and the same bound at a third of that rate.

The stages and every queue

The server (apps/server)

The browser tab that holds the scanner (apps/web/src/live/audio)

SDS100

Replay memory: one WAV per transmission
oldest handed out first, oldest dropped when full

Mute edge on the pushed status: the call ended
call_end_at

AFTER_CALL_MS 2 s, then one pull at a time
AUF INFO, DATA blocks of 2048 bytes, checksum, ACK

pull_done_at

unsent[]: unbounded retry buffer
resent every pass after 5 s; lost with the tab

Line in: squelch cuts calls from a sound input
unsent capped at 200, oldest dropped

POST /api/recordings (32 MiB)
POST /api/call-upload (SDR software; ffmpeg behind a gate: 2 at once, 16 waiting, then 503)

SQLite insert: recordings + recording_audio
received_at; UNIQUE (user_id, name)

Transcribe now? mode, filters, length, schedule
skipped: schedule, too-short, too-long

TranscriptionQueue: 4 at the engines, 1000 waiting in memory
queued_at; past the bound: skipped as overloaded

Engine: Deepgram Nova-3, Whisper on Groq, or the sample
60 s timeout; busy answers retried 3 times
working_at, transcribed_at

Transcript on the row: text, confidence, engine, cost

Push notification to phones
fan-out per device, no retry
notified_at

Dispatch Report tick every 60 s
one per person in flight; at most 400 calls; 10 min wait on pending calls

Hourly storage sweep: audio past the person's policy removed
a full disk answers 507

Every device: polls every 3 s (the list) or 15 s (the dock)

Stage From To Measured where Written by
pull call_end_at: the pushed status's Mute property going from Unmute to Mute pull_done_at: the audio-feed pull answered with the recording The browser's clock, both ends; sent as call_end and pull_done on the upload. Line in sends the moment the squelch closed for both. SDR uploads carry neither. apps/web/src/live/audio/store.ts, lineIn.ts
upload pull_done_at received_at: the row inserted The browser's clock to the server's; a skew between them shows here. routes/recordings.ts
queue_wait queued_at: put in line for an engine working_at: sent to one The server. Cleared and set again when a call is queued again by hand or after a busy engine, so the times are of the last attempt. services/transcribe.ts through Store.setTranscript
engine working_at transcribed_at: the engine answered, with a transcript or a failure The server. A skip (silent, quiet channel, budget) stamps nothing. the same
notify transcribed_at, or received_at for a call notified without text notified_at: the push was delivered to at least one device The server. routes/recordings.ts
to_transcript call_end_at, or received_at without it transcribed_at End to end, the person's view of "how long until I can read it". derived
to_notification the same start notified_at End to end to the phone's push service. The time from the push service to the screen is not measured. derived

Not measured: audio arrival to segment close (the radio segments, one WAV per transmission, and the browser learns of the end from the Mute edge only); the push service to the screen; the UI's next poll (3 s at most).

The trace id is recordings.id, assigned at insert; the browser knows the call by the scanner's file name until then (2026-10-05_21-51-47.wav, unique per radio per second, with .radio<n> for a second radio). The push tag is recording-<id>, the Dispatch Report cites ids, and the usage ledger carries the id with each charge. Fastify's pino log (JSON at LOG_LEVEL) records each request; the stage timestamps live on the row rather than in log lines, so a call's whole history is one GET /api/recordings?ids=<id>.

Backpressure: every buffer, its bound, its policy

Buffer Bound When full Why this policy
The radio's replay memory The Replay Duration setting (240 s recommended) The radio drops the oldest unsent recording. The radio's own rule. The browser keeps a recording it asked about for at most 60 s before deciding, so nothing waits on a question.
The browser's unsent[] (the feed) Unbounded Grows while the server refuses; resent every pass after 5 s. A call off the radio exists only here until the server has it; dropping it loses it for good. The bound is the tab's memory and the person's patience; a 507 (disk full) or a 5xx keeps the loop retrying with a notice.
Line in's unsent[] 200 Oldest dropped. A sound input keeps producing; an hour of calls is enough to ride out an outage. A 4xx other than 408 and 429 drops the call for good.
The intake Fastify body limits: 32 MiB a WAV, 32 MiB a multipart file 413. A call longer than ten minutes is not one call.
ffmpeg (SDR uploads in M4A, Ogg) 2 processes at once, 16 uploads waiting (FFMPEG_AT_ONCE, FFMPEG_WAITING_MOST, services/callAudio.ts) The 17th is refused with 503 and Retry-After: 2; the uploader (SDRTrunk, trunk-recorder) sends it again. A burst of uploads must not start a process each. Refusing at once is better than queueing minutes of conversions, since the uploader retries on its own.
TranscriptionQueue.waiting TRANSCRIPTION_QUEUE_MOST, default 1000 (MOST_WAITING, services/transcribe.ts); TRANSCRIPTION_CONCURRENCY, default 4, at the engines Newest dropped to on-demand: the call is kept, marked skipped with reason overloaded, its notification goes at once without text, and it is transcribed when opened, played, or read by a Dispatch Report, like a call outside the length window. A call the person asked for by hand (front) is never turned away. The queued rows survive a restart (resume()). The oldest calls have waited longest and are nearest an answer, so dropping the newest loses the least; a spill to SQLite already exists in the row's status; and "deferred to on demand" is the product's shipped default for most calls anyway. The bound is far above what the engines answer in an hour, so it trips only when an engine is down or very slow, which the busy retries and the 60 s timeout otherwise absorb.
The engine 60 s per request; 429 and 503 retried up to 3 times after Retry-After (capped at 60 s, default 10 s) A timeout or another error marks the call failed with the message; it is transcribed again by hand. Nothing is charged on failure. A circuit breaker is not implemented: every queued call still reaches the engine.
Push fan-out Unbounded per call (one send per device, in parallel) A failed send is dropped; 404 and 410 delete the subscription. A person has a handful of phones.
Dispatch Report One in flight per person; at most 400 calls read; 10 min wait on calls still being transcribed; 4 min wait transcribing on-demand calls first; 8 s before the route answers running A later refresh joins the one in flight. One model call per report; the page polls.
Call audio on disk The person's storage policy (days and size, by plan), swept hourly in batches of 200 The oldest audio is removed; text stays a year. Uploads are never refused for space, so up to an hour of overage is possible. The hourly sweep is the only control; a full disk is the failure mode below.
call_summaries, ai_calls, ai_traces 50 per person; 90 days; 3 days Oldest deleted.

Shedding keyed to provider latency (longer segments, skipped low-energy segments) is not implemented: the radio segments the audio, and the quiet-ends trim, the voice check, the quiet-channel rule, the length window, the schedule and the budget gate already keep most calls off the engine. The queue's depth, its peak and its drops are the metrics to alarm on.

Failure handling

Failure Detection Response User-visible effect Test
The serial link drops, or the radio enters a menu, search or weather The audio loop checks who owns the scanner each pass; the feed answers NG in a menu (feedRefusedBecause) The loop waits quietly and re-enables the feed once the radio scans again; Live control reconnects the port. Calls missed meanwhile stay on the radio, oldest first, and are offered as a backlog on the next start. No gap event is emitted. "Waiting for the radio" in the Call audio panel; the backlog question. apps/web/test/live/audioStore.test.ts, feedStates.test.ts
The upload fails (5xx, network) The fetch The feed keeps the call in unsent and resends each pass after 5 s; Line in every 15 s, 200 at most. A notice; the count of waiting calls. audioStore.test.ts (keep unsent and resend)
The disk is full (SQLITE_FULL, ENOSPC) isDiskFull in the error handler 507 with a plain message; counted in radiofreq_disk_full_total; the browser retries later. "The server's disk is full..." in the panel. apps/server/test/pipeline.test.ts
Too many SDR uploads need ffmpeg The gate's line is full 503 with Retry-After: 2; counted. The uploader retries. pipeline.test.ts (the gate)
The transcription queue is full waiting.length >= most on enqueue Skipped as overloaded, notified without text, transcribed on demand; counted. The call shows "Not transcribed: the server was busy when it came in"; opening it transcribes it. pipeline.test.ts (the bound), replay.test.ts
The engine is busy (429, 503) The status Back in line after Retry-After, up to 3 tries; counted as a provider error and a retry. The call stays "transcribing" a little longer. transcriptionControls.test.ts (Groq busy), pipeline.test.ts (the sample engine's knobs)
The engine times out or errors AbortSignal.timeout(60_000), a non-2xx failed with the message, nothing charged; a hand retry. "Transcription failed" with Retry. recordings.test.ts (failure and retry)
The engine returns no speech, or a channel keeps returning none hasWords, transcribe_channels.empty_run Empty text kept; after 5 empty in a row the channel's calls are skipped, 1 in 10 still sent. "Not transcribed: this channel's calls have had no words lately". transcriptionControls.test.ts
The budget or AI credit is spent UsageBudget.gate Skipped as budget; the report refused with 429; a push at 80 and 100 percent. The Usage line and the notice. usage.test.ts, aiAddon.test.ts
The Anthropic call fails The SDK's error 400 and 404 fall back once to the assistant's model; anything else fails the report with 502 and the schedule waits a whole interval. "Couldn't make a summary just now." reportCost.test.ts, recordings.test.ts
The push service fails The send Dropped (404 and 410 delete the subscription); the next call tries again. A missed notification. recordings.test.ts (410 removal)
The server restarts mid-queue resume() at start Every queued and working row is queued again. A delay. recordings.test.ts

Metrics

GET /api/admin/metrics, admin only, Prometheus text format (services/metrics.ts). In memory since the server started; Prometheus keeps the history.

Metric Type Labels What
radiofreq_pipeline_stage_seconds histogram stage Each stage above, per call, as it ends. Buckets from 25 ms to 300 s.
radiofreq_calls_received_total counter source: feed, line_in, upload Calls taken in.
radiofreq_calls_duplicate_total counter Calls sent again under a name already kept.
radiofreq_transcription_queued_total counter Calls put in line for an engine.
radiofreq_transcription_queue_depth, _in_flight, _queue_limit, _queue_peak gauge Waiting now, at the engines now, the bound, the most that waited since start.
radiofreq_transcription_skipped_total counter reason overloaded, silent, quiet-channel, budget, and the intake's schedule, too-short, too-long are on the rows.
radiofreq_transcriptions_total counter engine, outcome: done, failed Answers from an engine.
radiofreq_transcription_provider_errors_total counter engine, kind: busy, failed Answers that were not a transcript.
radiofreq_transcription_provider_retries_total counter engine Calls sent again after a busy answer.
radiofreq_call_notifications_total counter outcome: sent, none Pushes for calls.
radiofreq_ffmpeg_in_flight, _waiting, _limit, radiofreq_ffmpeg_refused_total gauge, counter The gate.
radiofreq_disk_full_total counter Requests answered 507.

Admin's System card (GET /api/admin/system) shows the queue's waiting, running, most, peakWaiting and dropped as well, next to the HTTP percentiles and the disk.

The load test

npm run loadtest (apps/server/src/loadtest/replay.ts, the command in apps/server/scripts/replay.ts) posts synthesized calls to the server at a speed multiplier, as the browser does for calls off the scanner, waits for the pipeline to finish with them, and reports each stage's p50, p99 and max from the calls' own stage timestamps, with the queue's peak depth and drops. With no --url it starts a server of its own in the process on a temporary database, with the sample engine at a set latency (--engine-latency-ms, --engine-jitter-ms) and the fake push sender, so it needs no network and no keys; with --url it drives a running server started with SAMPLE_DATA=1. The calls (loadtest/calls.ts) are invented: a seeded schedule of 48 calls with exponential gaps around 2.5 s, 3 to 12 s long, each a WAV in the scanner's format whose sound is tone bursts shaped like speech, enough for the voice check. Nothing recorded from a radio is in the tree.

It drives the server half. The pull off the radio is bound by the radio (one pull at a time, about 146 KB/s, paused during a transmission) and cannot run faster than real time, so the two browser stages are simulated as fixed gaps before each post (--pull-ms 2400, --upload-ms 60) and the pull and upload rows in a run say so.

  • CI runs it at 1x for 30 s on every pull request and fails the build when a call is turned away, fails or is left unfinished, or when to_transcript exceeds 5 s at the 99th percentile (.github/workflows/ci.yml).
  • The nightly workflow runs 1x, 2x, 4x and 8x for a minute each and writes docs/loadtest-results.md, which it puts up in a pull request (.github/workflows/loadtest.yml; master takes pull requests only).
  • docs/loadtest-results.md holds the latest run with the hardware described.
npm run loadtest -- --speed 1,2,4,8 --seconds 60 --out docs/loadtest-results.md
npm run loadtest -- --speed 4 --seconds 30 --engine-latency-ms 2000 --concurrency 2 --queue-most 20
SAMPLE_DATA=1 ./dev --no-nginx      # then, against it (its engine knobs are SAMPLE_TRANSCRIBE_* in .env):
npm run loadtest -- --url http://127.0.0.1:8787 --speed 2 --seconds 60

The sample engine's knobs (SampleTranscriber, services/transcribe.ts) are latency, jitter (seeded, so a run repeats), a failure every n-th call and a busy answer every m-th; the dev server reads them from SAMPLE_TRANSCRIBE_LATENCY_MS, _JITTER_MS, _FAIL_EVERY and _BUSY_EVERY.

Design notes and limitations

  • The first stage lives in a browser tab on the person's computer, only while that tab is open, and only one tab owns the scanner. There is no server-side agent on the radio; a hosted server has no scanner.
  • The radio is the segmenter: one WAV per transmission, with its names in the header. The browser detects the end from the Mute edge and waits two seconds for the radio to close the file.
  • The audio feed and Live control share one serial link. A pull waits while a transmission is heard, slows the status push to once a second, and is refused in a menu, search or analysis. A control-plane act (a menu left open, a save that reboots the radio) is a pipeline outage for its duration.
  • Latency floors: the two-second wait after a call, the pull at the radio's pace, the engine (1 to 3 s at Deepgram or Groq), and the 3 s UI poll. The engines are where the queue grows first.
  • Everything is per person: the queue is shared, but the schedule, filters, budget, storage policy and notifications are the person's. A load test drives one account.
  • No circuit breaker, no gap event, no server-sent stream to the UI, no rate limit on push bursts. Each is a known gap, listed in docs/INVENTORY.md Part 4.