feat: the state becomes California, and the port fills with ships
**Stage 1 of one California.** The owner's complaint had two halves and this is
the first: the state board was a CROPPED SLAB. `california.ts` stopped at 38.05 N,
so the board disagreed with its own minimap about the shape of California in a
single frame, and Bug Fire's 93,733 acres burned off-frame while the panel said
all clear. Bounds now run 32.50-42.05 N / -124.50 to -114.0 W — Cape Mendocino,
the ruled Oregon parallel, the 120th-meridian corner into the Nevada diagonal.
**And it got cheaper.** 391,169 triangles to 375,351, while gaining the North
Coast, the Sacramento Valley, the Klamath knot, the Cascade arc, Shasta at 4,320 m
and Lassen at 3,190 m. Extending the bounds alone would have doubled the lattice
to 168,813 points and blown the mobile cap; coarsening cellLat 0.022 -> 0.0312 and
cellLng 0.027 -> 0.0383 holds it at ~83,800. The cell as a FRACTION of the board
moves 0.0030 -> 0.0033 — unchanged in frame — because the camera retreats to frame
whatever it is given. That argument was already written in the pack's own comment.
The second half — three boards becoming one world you zoom through — is NOT here.
Merging at Bay density would be 34.04M triangles, 13x the highest budget, and
merging at SoCal density would downgrade San Francisco from 40 m lots to 164 m.
Both delete the board every marketing still is shot from. `sf.ts` and `socal.ts`
are untouched by design.
**Aerial perspective, which the state board could not have had before.** The old
fog started at 1.15 board spans = 944 km, on a board whose longest diagonal is
820 km — so no pixel could ever be fogged. Fog now responds to camera altitude,
clamped to the authored pair as a ceiling.
`Atmosphere.aerial(env, view)` is a second pure method returning `{ near, far }`
and **deliberately no colour**. That is structural, not stylistic: it is why a
future camera-dependent term cannot reach `environmentKey()`'s colour fingerprint
and start rebuilding the PMREM cubemap on every camera step. Coarsening the
fingerprint instead would have hidden one instance and armed the mechanism. A
mutation-tested seam guard fails if anyone merges the two paths back together.
**The port.** Terminal Island rendered as a bare tan polygon with generic white
blocks while the chapter text called it the busiest port complex in the
hemisphere. Now six container yards drawn as canvas atlases, 56 gantry cranes at
varied boom angles, the 13 km San Pedro breakwater, the dredged channel. Five
buckets merging ACROSS ports the way airports.ts merges across fields, so a
second complex costs no extra draws: +11 draws and +4,377 triangles for all of it.
At vertical exaggeration 3.4 a 130 m gantry is 1.132 units tall against a 400 m
ship's 1.024 long — the crane is the taller object, and it is what makes a port
read as a port from altitude.
**Ships, and the wake carries the information.** Moored hulls have no foam,
verified at three terminals; a tug under way in the Main Channel trails a clean
Kelvin V. One hull geometry, one InstancedMesh, orientation from the BERTH rather
than the wire. The AIS gate strips sog 102.3, heading 511 and cog 360 — all mean
"not available" — with an explicit test that cog 358.7 SURVIVES, because a naive
range check on cog eats real headings near north.
"Empty or full" is not in AIS position reports and is not invented per ship. The
honest answer is at port level and is a better story: 348,691 of 460,467 boxes
left Los Angeles empty in July 2026, corroborated by FBX01 $7,491 inbound against
FBX02 $347 outbound.
**Radar and birds ship dark, and say why.** California is 0.47% wet and migration
is nocturnal and seasonal, so both layers have nothing to say on most days. The
panel reads "No radar feed is configured, so this board draws no weather. That is
a fact about this box, not about the sky."
Also recorded, and it matters beyond this commit: **the GPU on amd-server never
leaves 500 MHz of a possible 2725**, traced across 80 seconds of sustained load.
`bay-area/desktop` is fragment-bound at that clock and sits on the vsync deadline,
so a trivial change in fragment work flips it between 16.8 and 33.3 with geometry
identical to the digit. Every frame-time number measured on this box is a floor.
Two investigations reached two different wrong conclusions from single-run
comparisons before this was traced. Geometry is the gate; frame time is advisory.
No cap was raised.
Tests 1,340 -> 1,540, server 280 -> 295.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
/**
|
||||
* The radar feed's one upstream: a **projection**, served by the machine that
|
||||
* owns the database.
|
||||
*
|
||||
* ### Read this before changing anything here
|
||||
*
|
||||
* `echo_cells` carries a column called `distance_km`, and it is measured **from
|
||||
* a private house**. It is the same leak class `server/src/fires/cloud1.ts` was
|
||||
* written to make impossible, and the resolution is the same one: this module
|
||||
* has **no database**. It makes two bounded GETs against an endpoint whose
|
||||
* SELECT lists are written out by hand on the other machine, and it cannot be
|
||||
* careless with a column it was never sent.
|
||||
*
|
||||
* That ordering is the security property. A route somebody writes next year
|
||||
* cannot select a column that is not on this box, and no amount of care in this
|
||||
* file would have been as strong. It is also why there is no sqlite driver in
|
||||
* this repo's dependency list and why `scripts/check-dependency-licenses.mjs` is
|
||||
* entitled to keep it that way.
|
||||
*
|
||||
* **Nothing here may ever name `distance_km` — not in a query string, not in a
|
||||
* field list, not in a comment that becomes a query string.**
|
||||
* `server/src/test/sky.test.ts` asserts the adopted key set *equals* an
|
||||
* allowlist and that no request path contains the word, which is the second
|
||||
* line: an `assert.ok(!keys.has("distance_km"))` would pass for every column
|
||||
* nobody thought to name, and that is precisely the class of column that gets
|
||||
* added later.
|
||||
*
|
||||
* ### Both halves, or neither
|
||||
*
|
||||
* Cells and station status are asked for in parallel and `null` is returned if
|
||||
* **either** fails. A lattice with a silently empty station list is a board that
|
||||
* has quietly stopped drawing its own coverage holes, and it would draw them as
|
||||
* clear sky — the strongest possible version of the failure this whole layer
|
||||
* exists to prevent. One snapshot, one answer; `upstream.ts` above this keeps
|
||||
* serving the last good whole body until a whole one arrives.
|
||||
*/
|
||||
|
||||
import { getJson } from "../http.ts";
|
||||
import type { RadarCell, RadarStation } from "../../../src/server/radar.ts";
|
||||
|
||||
/** How long either GET may take. The upstream reads sqlite behind its own cache. */
|
||||
const TIMEOUT_MS = 8_000;
|
||||
|
||||
/**
|
||||
* The most rows this build will adopt from either endpoint.
|
||||
*
|
||||
* The statewide lattice is under 1,700 cells and the whole station table is
|
||||
* sixteen rows, so both of these are two orders of magnitude clear of anything
|
||||
* real. They are the second of two bounds rather than the only one — a caller
|
||||
* that trusts an upstream's cap inherits the day the upstream's cap changes.
|
||||
*/
|
||||
const MAX_CELLS = 8_000;
|
||||
const MAX_STATIONS = 128;
|
||||
|
||||
export interface RadarSnapshot {
|
||||
/** Epoch ms at which this box completed the fetch. */
|
||||
fetchedAt: number;
|
||||
/** ISO-8601 of the volume scan the cells came from. */
|
||||
observedAt: string;
|
||||
/**
|
||||
* Share of California at or above the rain threshold, 0..1.
|
||||
*
|
||||
* Measured upstream over the whole state's pixels, not over our lattice. It is
|
||||
* what promotion is decided from, and it is scale-free — see
|
||||
* `RADAR_MIN_WET_FRACTION` in `src/server/radar.ts` for why that matters.
|
||||
*/
|
||||
wetFraction: number;
|
||||
cells: RadarCell[];
|
||||
stations: RadarStation[];
|
||||
attribution: string[];
|
||||
}
|
||||
|
||||
export interface RadarLog {
|
||||
warn(msg: string): void;
|
||||
}
|
||||
|
||||
/** What the projection endpoint answers with. Restated, never imported. */
|
||||
interface CellsResponse {
|
||||
observedAt?: unknown;
|
||||
wetFraction?: unknown;
|
||||
cells?: unknown;
|
||||
attribution?: unknown;
|
||||
}
|
||||
|
||||
interface StationsResponse {
|
||||
stations?: unknown;
|
||||
attribution?: unknown;
|
||||
}
|
||||
|
||||
export async function fetchProjection(
|
||||
base: string,
|
||||
key: string,
|
||||
log: RadarLog,
|
||||
): Promise<RadarSnapshot | null> {
|
||||
if (base === "") return null;
|
||||
const headers = key === "" ? undefined : { "x-tera-key": key };
|
||||
const options = { timeoutMs: TIMEOUT_MS, ...(headers === undefined ? {} : { headers }) };
|
||||
|
||||
const [cellsBody, stationsBody] = await Promise.all([
|
||||
getJson<CellsResponse>(`${base}/cells`, options),
|
||||
getJson<StationsResponse>(`${base}/stations`, options),
|
||||
]);
|
||||
|
||||
if (cellsBody === null || stationsBody === null) {
|
||||
log.warn(
|
||||
"radar:cloud1: the projection did not answer with both halves " +
|
||||
`(cells ${cellsBody === null ? "failed" : "ok"}, ` +
|
||||
`stations ${stationsBody === null ? "failed" : "ok"}); keeping the last whole body`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
fetchedAt: Date.now(),
|
||||
observedAt: nonEmptyString(cellsBody.observedAt) ?? "",
|
||||
// Clamped, not trusted. A `wetFraction` served as a percentage rather than a
|
||||
// fraction would promote every frame for ever, and the number is the only
|
||||
// thing standing between a quiet day and 1,596 texels of nothing.
|
||||
wetFraction: clamp01(finite(cellsBody.wetFraction) ?? 0),
|
||||
cells: readArray(cellsBody.cells, MAX_CELLS, readCell),
|
||||
stations: readArray(stationsBody.stations, MAX_STATIONS, readStation),
|
||||
attribution: mergeAttribution(cellsBody.attribution, stationsBody.attribution),
|
||||
};
|
||||
}
|
||||
|
||||
// ---- Reading somebody else's JSON -----------------------------------------
|
||||
//
|
||||
// Field by field, checked rather than cast, and the field list is exhaustive on
|
||||
// purpose: what is not named here does not enter this process. The upstream is a
|
||||
// machine on the same tailnet run by the same person, which is exactly the
|
||||
// relationship that produces "it will always be the right shape" — and then a
|
||||
// collector gains a column.
|
||||
|
||||
function readCell(raw: unknown): RadarCell | null {
|
||||
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
||||
const row = raw as Record<string, unknown>;
|
||||
const lat = finite(row.lat);
|
||||
const lon = finite(row.lon);
|
||||
const dbz = finite(row.dbz);
|
||||
if (lat === null || lon === null || dbz === null) return null;
|
||||
return { lat, lon, dbz };
|
||||
}
|
||||
|
||||
function readStation(raw: unknown): RadarStation | null {
|
||||
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
||||
const row = raw as Record<string, unknown>;
|
||||
const lat = finite(row.lat);
|
||||
const lon = finite(row.lon);
|
||||
const id = nonEmptyString(row.id);
|
||||
if (id === null || lat === null || lon === null) return null;
|
||||
return {
|
||||
id,
|
||||
lat,
|
||||
lon,
|
||||
// Carried verbatim and judged once, in the gate, where the argument for the
|
||||
// judgement can be read. Six of sixteen stations read "Maintenance Action
|
||||
// Mandatory" right now and every one of them is transmitting.
|
||||
type: nonEmptyString(row.type),
|
||||
operability: nonEmptyString(row.operability),
|
||||
};
|
||||
}
|
||||
|
||||
function readArray<T>(raw: unknown, cap: number, read: (row: unknown) => T | null): T[] {
|
||||
if (!Array.isArray(raw)) return [];
|
||||
const out: T[] = [];
|
||||
for (const row of raw) {
|
||||
if (out.length >= cap) break;
|
||||
const parsed = read(row);
|
||||
if (parsed !== null) out.push(parsed);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Both credit lines, de-duplicated, in the order they arrived. */
|
||||
function mergeAttribution(a: unknown, b: unknown): string[] {
|
||||
const out: string[] = [];
|
||||
for (const source of [a, b]) {
|
||||
if (!Array.isArray(source)) continue;
|
||||
for (const line of source) {
|
||||
if (typeof line !== "string" || line === "" || out.includes(line)) continue;
|
||||
out.push(line);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function nonEmptyString(value: unknown): string | null {
|
||||
if (typeof value !== "string") return null;
|
||||
const trimmed = value.trim();
|
||||
return trimmed === "" ? null : trimmed;
|
||||
}
|
||||
|
||||
function finite(value: unknown): number | null {
|
||||
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
||||
}
|
||||
|
||||
function clamp01(value: number): number {
|
||||
return Math.min(1, Math.max(0, value));
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Which reflectivity this box serves — which is California's, or none.
|
||||
*
|
||||
* The same shape as `fires/index.ts`, and it takes the same decisions for the
|
||||
* same reasons: one body, one cache key, no region parameter, a TTL with a
|
||||
* floor, and `none` serving a real empty body rather than an invented shower.
|
||||
*
|
||||
* ### The lattice is built here, on the server, and that is deliberate
|
||||
*
|
||||
* `RadarBody.field` is a lattice rather than a list of cells, so somebody has to
|
||||
* turn one into the other. Doing it here means the anomalous-propagation rule,
|
||||
* the coverage-hole rule and the promotion threshold are applied **once, in one
|
||||
* place, by the module that can be tested without a browser** — and it means a
|
||||
* quiet day costs the wire an empty body rather than 1,596 texels' worth of JSON
|
||||
* that the client would then throw away. `src/server/radar.ts` is imported by
|
||||
* both ends precisely so there is one statement about the data and not two.
|
||||
*
|
||||
* The board's own coastline comes from the city pack, which is data and types
|
||||
* and imports no renderer. That is the same arrangement `media/bindings.ts`
|
||||
* already uses for the office packs, and it is what keeps the land/sea test from
|
||||
* being a second, drifting copy of the shoreline.
|
||||
*
|
||||
* ### `none` serves an empty sky and never an invented one
|
||||
*
|
||||
* The flights service falls back to a simulated plan, because an empty sky over
|
||||
* a city reads as a bug. Nothing here does. An invented aeroplane is a plausible
|
||||
* aeroplane; an invented thunderstorm is a claim that it is raining on somebody
|
||||
* who can look out of the window. So the synthetic case *is* the clear sky —
|
||||
* `field: null`, `source: "none"`, `fetchedAt` at the Unix epoch — which is
|
||||
* exactly what `weather/synthetic.ts` does when it answers with
|
||||
* `precipitation: 0`, and it is what keeps `scripts/check-zero-config-boot.mjs`
|
||||
* green on a keyless clone.
|
||||
*
|
||||
* `fetchedAt` is the epoch and not "now", because "now" would be a claim that
|
||||
* this was fetched a moment ago. It was never fetched, and the board says so.
|
||||
*/
|
||||
|
||||
import { fetchProjection, type RadarSnapshot } from "./cloud1.ts";
|
||||
import { createUpstream } from "../upstream.ts";
|
||||
import { buildRadarField } from "../../../src/server/radar.ts";
|
||||
import CALIFORNIA_CITY from "../../../src/cities/california.ts";
|
||||
import type { Config } from "../config.ts";
|
||||
import type { RadarBody } from "../../../src/server/wire.ts";
|
||||
|
||||
export interface RadarService {
|
||||
current(): Promise<RadarBody>;
|
||||
}
|
||||
|
||||
export interface RadarLog {
|
||||
warn(msg: string): void;
|
||||
}
|
||||
|
||||
/** One state, one key. See `fires/index.ts` for the argument. */
|
||||
const CALIFORNIA_KEY = "california";
|
||||
|
||||
/**
|
||||
* Two minutes.
|
||||
*
|
||||
* The composite advances every ten minutes and reaches the collector about five
|
||||
* minutes late, so asking faster than this spends two machines' work to receive
|
||||
* identical bytes. The floor exists because `TERA_RADAR_TTL=0` reads like "as
|
||||
* fresh as possible" and means "one fetch pair per inbound request" — the trap
|
||||
* `TERA_FLIGHTS_TTL=0` and `TERA_FIRES_TTL=0` both were.
|
||||
*/
|
||||
const MIN_TTL_SECONDS = 120;
|
||||
|
||||
function emptyBody(ttlSeconds: number): RadarBody {
|
||||
return {
|
||||
source: "none",
|
||||
fetchedAt: new Date(0).toISOString(),
|
||||
field: null,
|
||||
ttlSeconds,
|
||||
};
|
||||
}
|
||||
|
||||
export function createRadarService(config: Config, log: RadarLog): RadarService {
|
||||
const { source, url, key, ttlSeconds } = config.radar;
|
||||
const ttl = Math.max(MIN_TTL_SECONDS, ttlSeconds);
|
||||
|
||||
const upstream = createUpstream<RadarSnapshot>({
|
||||
label: "radar:cloud1",
|
||||
ttlSeconds: ttl,
|
||||
log,
|
||||
});
|
||||
|
||||
return {
|
||||
async current(): Promise<RadarBody> {
|
||||
if (source === "none") return emptyBody(ttl);
|
||||
|
||||
const snapshot = await upstream.get(CALIFORNIA_KEY, () => fetchProjection(url, key, log));
|
||||
if (snapshot === null) return emptyBody(ttl);
|
||||
|
||||
const built = buildRadarField({
|
||||
cells: snapshot.cells,
|
||||
stations: snapshot.stations,
|
||||
bounds: CALIFORNIA_CITY.bounds,
|
||||
coast: CALIFORNIA_CITY.landmasses,
|
||||
observedAt: snapshot.observedAt,
|
||||
wetFraction: snapshot.wetFraction,
|
||||
});
|
||||
|
||||
return {
|
||||
source,
|
||||
fetchedAt: new Date(snapshot.fetchedAt).toISOString(),
|
||||
// `null` on a quiet day, which is nine days in ten and is not a fault.
|
||||
// The age beside it is what tells a viewer apart from a dead feed.
|
||||
field: built.field,
|
||||
ttlSeconds: ttl,
|
||||
...(snapshot.attribution.length > 0 ? { attribution: snapshot.attribution } : {}),
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user