Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ A 10px status mark beside the frame age shows that a notice exists without a
banner: a hollow Scan Cyan ring for information, a solid Danger dot for a
problem. Hovering or focusing it reveals the notice text above the playback bar.

- **Top changes where and how radar is drawn:** explicit National/Site source selection, Site station selection, source-aware recenter, and the real `Smooth`/`Native` spatial display choice; other controls appear only after they become real capabilities.
- **Top changes where and how radar is drawn:** explicit National/Site source selection, Site station selection, source-aware recenter, and the real `Smooth`/`Native` spatial display choice; other controls appear only after they become real capabilities. *(Owner decision, 2026-09-28: zoom decides the source — picking a Site flies to it at zoom 9.5, picking National zooms out to the country, and zooming across ~9 cross-fades between them. See [docs/32](docs/32_SEAMLESS_RADAR_HANDOFF.md).)*
- **Sides stay clear:** no application menu, placeholder alert control, or control chain competes with radar.
- **Bottom controls when:** playback, measured time, numeric age, and inspection value.

Expand Down
2 changes: 2 additions & 0 deletions PRODUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ The product earns additional capabilities only when they improve live storm insp

## Approved National Direction

*Owner decision (2026-09-28): zoom decides the source. Zooming past about 9 over a Site's coverage cross-fades to that Site; zooming out returns to the resident National mosaic. See [Seamless radar handoff](docs/32_SEAMLESS_RADAR_HANDOFF.md).*

National radar is the approved next product milestone. Merged Phases 1 through 4 established the typed source coordinator, strict NOAA MRMS acquisition and numeric decoding, `PackedGrid v1`, the explicit `National`/`Site` choice, a 20-observation CONUS loop, exact Rust-owned interrogation, quality-locked playback, and atomic source handoff.

Phase 4 is merged. National now provides 20 exact chronological observations, newest-first visible startup, predecessor backfill, strictly newer polling, bounded all-frame overview residency, direct scrubbing, and common-quality playback. Once two complete observations are usable, background backfill keeps Play and direct scrubbing available; only the bounded atomic residency swap or graphics recovery may hold those controls briefly. A post-merge visual-fidelity correction prepares the finest complete all-frame viewport level that fits the 200 MiB GPU target before regional playback begins: exact factor 1 first, factor 2 as the bounded fallback, and factor 4 only for the country overview or when finer all-frame coverage cannot fit. Smooth and Native use the same selected numeric level; Smooth filters its appearance but never invents source resolution. The approved phased product and engineering contract is [National Radar Implementation Plan](docs/26_NATIONAL_RADAR_IMPLEMENTATION_PLAN.md).
Expand Down
41 changes: 41 additions & 0 deletions docs/32_SEAMLESS_RADAR_HANDOFF.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,44 @@ The Site layer gains a 320 MiB GPU ceiling (a 60-frame loop is about 152 MiB, ab

- Unit: broker lane isolation (Rust), client lane isolation, coordinator/session reveal, and a fake-WebGL state-machine suite for hidden commits, reveal, downgrade, a hidden fence finishing after reveal, recovery while hidden, and reveal waiting out a commit.
- Packaged (`npm run test:national:phase4:packaged`): `proveFailedSiteKeepsNational` (same generation, no backfill restart, playback resumed) and `proveResidentHandoff` (National resident while the Site paints; reveal under the original generation with zero network, decode, and bulk IPC activity within 250 ms; the Site layer removed).

## Phase B — zoom decides the source

**Date:** 2026-09-28. **Status:** Implemented; native packaged validation pending.

### Policy

`decideAutoSource` (`src/radar-session/autoSourcePolicy.ts`) is a pure function of zoom, view center, the displayed source, and the operator's picked Site:

| Condition | Result |
|---|---|
| National shown, zoom ≥ 9, a Site within 200 km of the center | Switch to the nearest such Site (or the picked Site while within 230 km) |
| National shown, zoom ≥ 8 and < 9, same Site condition | Stay on National; preload that Site |
| Site shown, zoom ≥ 9, a different picked Site within 230 km of the center | Return to National (then on to the picked Site) |
| Site shown, zoom ≥ 8.5 and center within 230 km of it | Stay on the Site |
| Site shown, otherwise | Return to National |

Moving between Sites always passes through National, so only one Site layer exists. A switch that succeeds re-checks the same camera, so one pan into another Site's coverage runs both legs. A pick stops applying once the center leaves its 230 km range. Site coordinates live in `src/data/radar-sites.json`: 150 from nexrad-model's registry (a Rust test keeps them in sync) and 5 from api.weather.gov.

Only camera moves the operator makes are evaluated (MapLibre events with an `originalEvent`), plus the landing of an explicit picker or recenter flight. A move made while any switch is running is evaluated once it ends. Programmatic cameras, including every packaged harness camera, never switch sources.

### Switching

- **Preload:** the likely Site's newest scan is fetched on the Site lane while National is shown. The switch reuses that generation (`SiteLevel2Session.start({ residentGeneration })`) and paints without a network wait. A preload older than 5 minutes is refetched.
- **Fade in:** the Site's first frame paints at `u_opacity = 0`, then fades to 1 over 300 ms (instant under reduced motion). Only then does the coordinator accept it, so the timeline follows a fully visible frame. National keeps playing underneath until it becomes resident.
- **Fade out:** National paints underneath first (a reveal, or a fresh acquisition), then the Site fades to 0 and is removed.
- **Layer order:** National is always inserted, and re-inserted after context loss, below the Site stack, so only the upper layer fades.
- **Guards:** one automatic switch runs at a time; a Site that just failed is not retried automatically for a minute.

### Camera

Automatic switches never move the camera. The picker flies to a Site at zoom 9.5 (preloading during the flight when National is shown) and makes it preferred, so the landing switches to it from National or from another Site; picking National always zooms out to the country, even when National is already shown; recenter uses the same targets. The camera is stored on every move and restored at launch.

### Known limits

- At the end of a fade-in, National disappears everywhere, including outside the Site's range ring, so corners of a wide view briefly lose echo.
- Playback time is not yet carried across a switch (Phase C); a Site starts at its newest scan.

### Validation

`proveZoomHandoff` in the National packaged gate: at zoom 8.3 over KTLX the Site preloads; at 9.6 the Site fades in under the preloaded generation with National resident and the camera untouched; one jump to KFWS at 9.6 goes KTLX, National, KFWS with no further move; at 7.5 the same National history returns, the Site layer is removed, and the camera is untouched.
39 changes: 37 additions & 2 deletions scripts/national-phase4-packaged-cdp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ try {
);
const detailScreenshot = await captureScreenshot();

// Hold background acquisition off for the measurement, as the scrub
// evidence does: a newer MRMS frame arriving is product behavior, not
// work done by sharp playback.
await evaluate(
"window.__MISTR_NATIONAL_PHASE4__.beginResidentEvidence()",
true,
300_000,
);
residentEvidenceHeld = true;
await evaluate("window.__MISTR_NATIONAL_PHASE4__.play()", true, 300_000);
await waitForReport(
"report.playback?.playing===true && report.renderer?.presentationFactor===1",
Expand Down Expand Up @@ -202,6 +211,8 @@ try {
true,
60_000,
);
await evaluate("window.__MISTR_NATIONAL_PHASE4__.endResidentEvidence()");
residentEvidenceHeld = false;
const activePlayback = {
...activePlaybackDuring,
activityBefore: playbackActivityBefore,
Expand Down Expand Up @@ -233,6 +244,12 @@ try {
300_000,
);

const zoomHandoff = await evaluate(
serialized("window.__MISTR_NATIONAL_PHASE4__.proveZoomHandoff('KTLX')"),
true,
300_000,
);

await evaluate(serialized("window.__MISTR_NATIONAL_PHASE4__.startSite('KTLX')"), true, 300_000);
await delay(500);
const restoredSite = {
Expand All @@ -258,6 +275,7 @@ try {
transferSnapshot,
failedSiteRecovery,
residentHandoff,
zoomHandoff,
restoredSite,
};
report.failures = validateNationalPhase4Acceptance(report);
Expand Down Expand Up @@ -380,6 +398,20 @@ async function observePlaybackChrome(durationMs) {
return value?{left:value.left,top:value.top,width:value.width,height:value.height}:null;
};
const samples=[];
// Exact point lookups can settle within one polling interval, so also
// record every readout change as it happens.
const observed=[];
const readout=()=>{
const sample=document.querySelector('.sample-readout');
return {
sampleText:sample?.textContent?.trim()??'',
sampleState:sample?.dataset.inspectionState??null,
sampleBusy:sample?.getAttribute('aria-busy')??null,
};
};
const observer=new MutationObserver(()=>observed.push(readout()));
const bar=document.querySelector('.playback-bar');
if(bar) observer.observe(bar,{subtree:true,childList:true,characterData:true,attributes:true,attributeFilter:['data-inspection-state','aria-busy']});
const deadline=performance.now()+${durationMs};
while(performance.now()<deadline){
const report=window.__MISTR_NATIONAL_PHASE4__.report();
Expand Down Expand Up @@ -410,7 +442,9 @@ async function observePlaybackChrome(durationMs) {
Math.abs(sample[key].height-baseline.height),
]));
};
const pending=samples.filter(sample=>sample.sampleState==='pending');
observer.disconnect();
const readouts=[...samples,...observed];
const pending=readouts.filter(sample=>sample.sampleState==='pending');
return {
innerWidth,
innerHeight,
Expand All @@ -426,7 +460,8 @@ async function observePlaybackChrome(durationMs) {
timelineMaxRectDelta:maxRectDelta('timeline'),
telemetryMaxRectDelta:maxRectDelta('telemetry'),
sampleReadoutMaxRectDelta:maxRectDelta('sampleReadout'),
distinctSampleTexts:[...new Set(samples.map(sample=>sample.sampleText))],
observedReadoutChangeCount:observed.length,
distinctSampleTexts:[...new Set(readouts.map(sample=>sample.sampleText))],
distinctAnnouncements:[...new Set(samples.map(sample=>sample.announcement))],
};
})()`), true, durationMs + 30_000);
Expand Down
60 changes: 58 additions & 2 deletions scripts/national-phase4-packaged-validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export function validateNationalPhase4Acceptance(report) {
|| failedSite?.renderer?.contextEpoch !== failedSite?.rendererBeforeFailure?.contextEpoch
) failures.push("failed Site transition keeps the active National session");
failures.push(...validateResidentHandoff(report.residentHandoff));
failures.push(...validateZoomHandoff(report.zoomHandoff));
const site = report.restoredSite;
if (
site?.sourceState?.painted?.source?.kind !== "site"
Expand Down Expand Up @@ -206,12 +207,67 @@ export function validateResidentHandoff(handoff) {
"bulkIpcBytes",
].every((field) => Number.isSafeInteger(before[field]) && after[field] === before[field]);
if (!quiet) failures.push("National reveal performs no acquisition, decode, or bulk transfer");
if (!(handoff?.reveal?.revealMs >= 0 && handoff.reveal.revealMs <= 250)) {
failures.push("National reveal completes within 250 ms");
// The switch deliberately includes the Site fade-out; the reveal itself stays within 250 ms.
const fadeMs = handoff?.reveal?.fadeMs ?? 0;
if (!(handoff?.reveal?.revealMs >= 0 && fadeMs >= 0 && handoff.reveal.revealMs <= 250 + fadeMs)) {
failures.push("National reveal completes within 250 ms plus the fade");
}
return failures;
}

function sameCamera(left, right) {
return Boolean(left && right)
&& Math.abs(left.longitude - right.longitude) < 1e-6
&& Math.abs(left.latitude - right.latitude) < 1e-6
&& Math.abs(left.zoom - right.zoom) < 1e-6;
}

// Zooming in past the threshold fades the preloaded Site in over resident
// National; zooming out fades back to that same National history. Neither
// switch moves the camera.
export function validateZoomHandoff(handoff) {
const failures = [];
const site = handoff?.site;
const preloaded = handoff?.preloaded;
const afterSite = handoff?.afterSite;
const fadeMs = handoff?.fadeMs ?? 0;
if (
!site
|| preloaded?.site !== site
|| afterSite?.sourceState?.painted?.source?.kind !== "site"
|| afterSite?.sourceState?.painted?.source?.siteIcao !== site
|| afterSite?.sourceState?.painted?.generation !== preloaded?.generation
|| afterSite?.siteOpacity !== 1
|| afterSite?.nationalRenderer?.visibility !== "resident"
|| !sameCamera(afterSite?.camera, afterSite?.cameraSet)
|| !(handoff?.siteSwitchMs >= 0 && handoff.siteSwitchMs <= 1_500 + fadeMs)
) failures.push("zooming in fades the preloaded Site in without moving the camera");
const hop = handoff?.afterHop;
const hopSources = hop?.sources ?? [];
if (
!hop?.site
|| hop.site === site
|| hop?.sourceState?.painted?.source?.kind !== "site"
|| hop?.sourceState?.painted?.source?.siteIcao !== hop.site
|| hop?.sourceState?.transition
|| hopSources.join(">") !== `${site}>national>${hop.site}`
|| hop?.siteOpacity !== 1
|| hop?.nationalRenderer?.visibility !== "resident"
|| !sameCamera(hop?.camera, hop?.cameraSet)
|| !(hop?.switchMs >= 0)
) failures.push("panning into another Site's coverage fades through National to that Site");
const afterNational = handoff?.afterNational;
if (
afterNational?.sourceState?.painted?.source?.kind !== "national"
|| afterNational?.sourceState?.painted?.generation !== handoff?.nationalGenerationBefore
|| afterNational?.siteLayerPresent !== false
|| afterNational?.nationalRenderer?.visibility !== "visible"
|| !sameCamera(afterNational?.camera, afterNational?.cameraSet)
|| !(handoff?.nationalSwitchMs >= 0 && handoff.nationalSwitchMs <= 750 + fadeMs)
) failures.push("zooming out fades back to the resident National without moving the camera");
return failures;
}

export function validateNationalPartialPlaybackChrome(chrome) {
const failures = [];
if (!stablePlaybackChrome(chrome)) failures.push("stable partial-history playback chrome");
Expand Down
87 changes: 84 additions & 3 deletions scripts/national-phase4-packaged-validation.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
validateNationalPhase4Acceptance,
validateResidentHandoff,
validateZoomHandoff,
} from "./national-phase4-packaged-validation.mjs";

function nationalActivity() {
Expand Down Expand Up @@ -81,8 +82,8 @@ describe("National Phase 4 packaged acceptance", () => {
);

const slow = validReport().residentHandoff;
slow.reveal.revealMs = 400;
expect(validateResidentHandoff(slow)).toContain("National reveal completes within 250 ms");
slow.reveal.revealMs = 600;
expect(validateResidentHandoff(slow)).toContain("National reveal completes within 250 ms plus the fade");

const report = validReport();
delete report.residentHandoff;
Expand All @@ -91,6 +92,53 @@ describe("National Phase 4 packaged acceptance", () => {
);
});

it("requires zoom to fade between the preloaded Site and resident National without moving the camera", () => {
expect(validateZoomHandoff(validReport().zoomHandoff)).toEqual([]);

const unpreloaded = validReport().zoomHandoff;
unpreloaded.afterSite.sourceState.painted.generation = 14;
expect(validateZoomHandoff(unpreloaded)).toContain(
"zooming in fades the preloaded Site in without moving the camera",
);

const moved = validReport().zoomHandoff;
moved.afterSite.camera.zoom = 7.5;
expect(validateZoomHandoff(moved)).toContain(
"zooming in fades the preloaded Site in without moving the camera",
);

const direct = validReport().zoomHandoff;
direct.afterHop.sources = ["KTLX", "KFWS"];
expect(validateZoomHandoff(direct)).toContain(
"panning into another Site's coverage fades through National to that Site",
);

const strandedOnNational = validReport().zoomHandoff;
strandedOnNational.afterHop.sources = ["KTLX", "national"];
strandedOnNational.afterHop.sourceState.painted = { source: { kind: "national" }, generation: 8 };
expect(validateZoomHandoff(strandedOnNational)).toContain(
"panning into another Site's coverage fades through National to that Site",
);

const reacquired = validReport().zoomHandoff;
reacquired.afterNational.sourceState.painted.generation = 15;
expect(validateZoomHandoff(reacquired)).toContain(
"zooming out fades back to the resident National without moving the camera",
);

const lingering = validReport().zoomHandoff;
lingering.afterNational.siteLayerPresent = true;
expect(validateZoomHandoff(lingering)).toContain(
"zooming out fades back to the resident National without moving the camera",
);

const report = validReport();
delete report.zoomHandoff;
expect(validateNationalPhase4Acceptance(report)).toContain(
"zooming in fades the preloaded Site in without moving the camera",
);
});

it("permits bounded exact point refresh while sharp playback stays transfer-free", () => {
const report = validReport();
report.activePlayback.activityAfter.pointLookupDecodes = 8;
Expand Down Expand Up @@ -345,7 +393,8 @@ function validReport() {
reveal: {
activityBefore: nationalActivity(),
activityAfter: nationalActivity(),
revealMs: 34,
revealMs: 334,
fadeMs: 300,
},
after: { painted: { source: { kind: "national", domain: "conus" }, generation: 8 } },
renderer: {
Expand All @@ -357,6 +406,38 @@ function validReport() {
backfillStartCountAfter: 1,
siteLayerRemoved: true,
},
zoomHandoff: {
site: "KTLX",
fadeMs: 300,
nationalGenerationBefore: 8,
preloaded: { site: "KTLX", generation: 13, fetchedAtUnixMs: 1 },
siteSwitchMs: 420,
afterSite: {
sourceState: { painted: { source: { kind: "site", siteIcao: "KTLX" }, generation: 13 } },
camera: { longitude: -97.2778, latitude: 35.3331, zoom: 9.6 },
cameraSet: { longitude: -97.2778, latitude: 35.3331, zoom: 9.6 },
siteOpacity: 1,
nationalRenderer: { visibility: "resident" },
},
afterHop: {
site: "KFWS",
switchMs: 4200,
sources: ["KTLX", "national", "KFWS"],
sourceState: { painted: { source: { kind: "site", siteIcao: "KFWS" }, generation: 15 } },
camera: { longitude: -97.3031, latitude: 32.5731, zoom: 9.6 },
cameraSet: { longitude: -97.3031, latitude: 32.5731, zoom: 9.6 },
siteOpacity: 1,
nationalRenderer: { visibility: "resident" },
},
nationalSwitchMs: 340,
afterNational: {
sourceState: { painted: { source: { kind: "national", domain: "conus" }, generation: 8 } },
camera: { longitude: -97.2778, latitude: 35.3331, zoom: 7.5 },
cameraSet: { longitude: -97.2778, latitude: 35.3331, zoom: 7.5 },
siteLayerPresent: false,
nationalRenderer: { visibility: "visible" },
},
},
restoredSite: {
sourceState: { painted: { source: { kind: "site", siteIcao: "KTLX" } }, transition: null },
display: { lastComplete: { site: "KTLX" } },
Expand Down
Loading