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 docs/11_ENGINEERING_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Mistr's normal UI follows `PRODUCT.md` and `DESIGN.md`; diagnostics remain hidde

Merged Phase 3 owns the explicit `National`/`Site` source panel because it delivers the complete National session, numeric renderer, exact interrogation, and paint-truth path. Selecting Site reveals the existing searchable station list; supporting/accessibility copy identifies National as CONUS. Keyboard, focus-return, compact-layout, painted-truth, and one-panel behavior remain mandatory.

Merged Phase 4 exposes up to 20 exact National timeline observations. It enables playback only after two complete common-level observations are resident, uses direct scrubbing without separate previous/next controls, and names partial backfill truthfully. Regional play may perform one bounded all-frame factor-1/factor-2 preparation before motion begins; once locked, active play/scrub performs no acquisition, grid decode, bulk IPC, or upload work. Hidden `window.__MISTR_NATIONAL_PHASE2__`, `window.__MISTR_NATIONAL_PHASE3__`, and `window.__MISTR_NATIONAL_PHASE4__` evidence APIs do not become normal controls.
Merged Phase 4 exposes up to 20 exact National timeline observations. It enables playback only after two complete common-level observations are resident, uses direct scrubbing without separate previous/next controls, and names partial backfill truthfully. Playback is motion-first (owner decision, 2026-08-04): motion begins immediately at the always-resident complete common level and is never held or stopped for sharpness or a camera change. A bounded all-frame factor-1/factor-2 preparation runs beside the loop as prefetch-only residency work, upgrades the quality lock between frames when complete, and is superseded silently by a newer camera. Frame selection itself remains resident-only: no acquisition, grid decode, bulk IPC, or upload ever gates a frame advance. Backfill and strictly-newer polling continue during playback; each history commit briefly pauses and resumes the loop through the existing replacement contract, and sharp preparation defers until retained history settles. Hidden `window.__MISTR_NATIONAL_PHASE2__`, `window.__MISTR_NATIONAL_PHASE3__`, and `window.__MISTR_NATIONAL_PHASE4__` evidence APIs do not become normal controls.

Required surfaces:

Expand Down
4 changes: 3 additions & 1 deletion docs/20_ALPHA_CURRENT_STATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ Release readiness also corrects a demonstrated installer defect: prior bundles d

## National performance remediation (2026-08-04)

Owner-reported National symptoms — slow startup, full restaging on every pan/zoom, and repeated pixelate/sharpen cycles — were diagnosed in [National radar performance findings](29_NATIONAL_RADAR_PERFORMANCE_FINDINGS.md) and remediated on `claude/national-performance-fixes`: the selected observation now refines to a camera-independent complete-domain factor-1 presentation at any zoom, history commits preserve that detail instead of resetting to the overview, and GPU uploads share a measured 4 ms frame budget instead of one fixed 32-row band per vsync. Playback's viewport-bounded sharp preparation and its zoom-6 gate are unchanged by memory necessity. Packaged before/after startup and pan/zoom evidence remains to be captured on the validation machine.
Owner-reported National symptoms — slow startup, full restaging on every pan/zoom, and repeated pixelate/sharpen cycles — were diagnosed in [National radar performance findings](29_NATIONAL_RADAR_PERFORMANCE_FINDINGS.md) and remediated on `claude/national-performance-fixes` (merged, PR #20): the selected observation now refines to a camera-independent complete-domain factor-1 presentation at any zoom, history commits preserve that detail instead of resetting to the overview, and GPU uploads share a measured 4 ms frame budget instead of one fixed 32-row band per vsync.

The owner's packaged retest showed the playing path still failed: camera changes stopped the loop for a full viewport re-preparation, supersession surfaced as a `could not change scans` notice, playback starved backfill, and home-view playback deleted the refined presentation. Round 2 (findings §0.1, `claude/national-playback-continuity`) makes playback motion-first as an owner decision dated 2026-08-04: motion starts immediately on the resident commons and never stops for sharpness or a camera change, quality preparation is prefetch-only beside the loop, supersession never reaches the operator, and backfill/polling continue during playback. Packaged before/after evidence remains to be captured on the validation machine.

## Pull-request checkpoint

Expand Down
11 changes: 11 additions & 0 deletions docs/29_NATIONAL_RADAR_PERFORMANCE_FINDINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@

Memory contract after F1: 20 factor-4 commons (61.3 MiB) + selected whole-domain factor-1 detail (46.7 MiB) + one staged replacement (46.7 MiB) ≈ **154.7 MiB** peak, inside the 200 MiB target; the 256 MiB hard-ceiling checks are unchanged and still enforced at commit time.

## 0.1 Round 2 — owner retest findings and remediation (2026-08-04)

The owner retested the packaged build after PR #20 merged: pan/zoom **while playing** still froze the loop, a `Mistr could not change scans` notice appeared on roughly half of pans, playback blocked backfill from ever finishing, and blur-then-sharpen persisted around playback sessions. Round 1 fixed only the paused path. Verified round-2 root causes, remediated on `claude/national-playback-continuity`:

1. **Playback stopped for every camera change and for quality preparation.** `notifyCameraChanged` paused the loop, re-prepared all 20 viewport-detail frames, and only then restarted; `play()` was also gated behind that preparation. Remediation: **motion-first playback** — motion starts immediately at the always-resident factor-4 commons, sharp preparation runs beside the loop as prefetch-only residency work (`prefetchDetail` for every frame, including the selected one, which the relaxed `commitPrefetchedStaging` guard now permits while the common level is active), and the quality lock upgrades between frames with a normal paint receipt. A camera change drops the lock to the commons — whole-domain, therefore camera-independent — without stopping motion, and re-prepares in the background.
2. **Supersession surfaced as a user-facing error.** A second pan during an in-flight preparation raised `RadarSourceSupersededError`, which the `moveend`/play/scrub handlers rendered as the playback-area notice. Remediation: supersession is normal control flow and is now filtered everywhere before `setPlaybackError`; the camera notification path no longer produces awaited rejections at all.
3. **Playback starved acquisition.** The play session held the exclusive resident-only reservation for its entire duration while `runNationalAcquisition` spun on it, so backfill and strictly-newer polling made no progress while playing. Remediation: motion is resident-only by construction and holds no reservation; backfill and polling continue during playback, with each commit briefly pausing/resuming the loop through the existing replacement contract. Sharp preparation defers until retained history settles (`pendingBackfillCount` = 0) and the post-commit resume re-runs it.
4. **Home-view playback deleted the complete-domain detail.** The below-threshold branch of quality preparation reset to the overview and pruned all detail, forcing a ~1 s re-refinement blur after every home-view play. Remediation: below the sharp threshold, preparation touches no residency at all.

Deferred with reason: pipelining backfill downloads against GPU commits requires a staged-frame queue in Rust (`national_history.rs` holds a single `staged` slot); backfill remains serial per frame. The engineering-contract playback sentence was updated for the motion-first model as an owner decision dated 2026-08-04.

## 1. Reported symptoms

1. **Initial National load takes far too long** before the timeline feels usable.
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The merged National path is:
fixed NOAA MRMS host -> strict chronological history -> exact u16/value-aware levels -> PackedGrid v1 -> shared two-credit IPC -> all-frame common GPU residency -> quality-locked playback/scrub -> coverage-aware GPU receipt
```

It paints the newest observation first, backfills up to 19 strictly older observations, then polls for strictly newer inventory. Every retained frame keeps a complete factor-4 GPU presentation, and the selected observation refines to a complete-domain factor-1 presentation that is camera-independent: pan and zoom never restage, refetch, or degrade the paused view at any zoom, and history commits preserve the selected frame's detail. Regional playback prepares factor-1 coverage for all frames, or factor 2 when needed to remain under the 200 MiB target, before zero-I/O motion begins. GPU uploads share a measured 4 ms per-frame budget rather than one fixed row band per vsync.
It paints the newest observation first, backfills up to 19 strictly older observations, then polls for strictly newer inventory — including while playback runs. Every retained frame keeps a complete factor-4 GPU presentation, and the selected observation refines to a complete-domain factor-1 presentation that is camera-independent: pan and zoom never restage, refetch, or degrade the paused view at any zoom, and history commits preserve the selected frame's detail. Playback is motion-first: the loop starts immediately on the resident commons and is never stopped by a camera change or by sharpness — regional factor-1/factor-2 preparation runs beside it as prefetch-only work and upgrades the quality lock between frames. GPU uploads share a measured 4 ms per-frame budget rather than one fixed row band per vsync.

## Alpha direction

Expand Down
77 changes: 56 additions & 21 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import {
} from "./national-radar/NationalGridLayer";
import {
NationalHistoryWorkingSetController,
isNationalWorkingSetBusy,
observationId as nationalObservationId,
type NationalHistoryWorkingSetResult,
} from "./national-radar/NationalHistoryWorkingSetController";
Expand Down Expand Up @@ -1679,6 +1680,10 @@ export function App() {
) {
throw new Error("National playback detail cannot prepare before paint is complete");
}
// Sharp preparation waits for the retained history to settle; motion
// runs at the complete common level while backfill continues, and the
// resume after the final backfill commit re-runs this preparation.
if ((latestNationalHistory?.pendingBackfillCount ?? 0) > 0) return 4;
const cameraKey = nationalCameraKey(instance);
const alreadyComplete = activeLayer.finestCompletePlaybackFactor();
if (
Expand All @@ -1692,7 +1697,6 @@ export function App() {
if (
!isCurrent()
|| cancelled
|| nationalResidentOnlyReservations < 1
|| transferGeneration !== expectedGeneration
|| nationalCameraKey(instance) !== cameraKey
|| painted?.source.kind !== "national"
Expand All @@ -1703,23 +1707,53 @@ export function App() {
);
}
};
const result = await prepareNationalPlaybackQuality({
zoom: instance.getZoom(),
observations,
selectedObservationId,
bounds,
workingSet: activeWorkingSet,
layer: activeLayer,
ownershipCheck,
});
if (result.factor === 1 || result.factor === 2) {
nationalPlaybackDetailCameraKey = cameraKey;
nationalPlaybackDetailFactor = result.factor;
} else {
nationalPlaybackDetailCameraKey = null;
nationalPlaybackDetailFactor = null;
// Motion may still be painting the selected observation's previous
// detail right after a camera change; prefetching that observation is
// only additive once the common level has actually painted. The active
// presentation factor alone flips before the receipt lands, so gate on
// the authoritative painted receipt.
const commonActiveDeadline = Date.now() + 5_000;
while (true) {
ownershipCheck();
const snapshot = activeLayer.getSnapshot();
if (
snapshot.status === "painted"
&& snapshot.presentationFactor === 4
&& snapshot.paintReceipt?.presentationFactor === 4
&& !snapshot.mutationAwaitingCommit
) break;
if (Date.now() > commonActiveDeadline) return 4;
await waitMilliseconds(50);
}
const maximumBusyAttempts = 3;
for (let attempt = 1; ; attempt += 1) {
ownershipCheck();
await activeWorkingSet.waitForIdle();
ownershipCheck();
try {
const result = await prepareNationalPlaybackQuality({
zoom: instance.getZoom(),
observations,
selectedObservationId,
bounds,
workingSet: activeWorkingSet,
layer: activeLayer,
ownershipCheck,
});
if (result.factor === 1 || result.factor === 2) {
nationalPlaybackDetailCameraKey = cameraKey;
nationalPlaybackDetailFactor = result.factor;
} else {
nationalPlaybackDetailCameraKey = null;
nationalPlaybackDetailFactor = null;
}
return result.factor;
} catch (error) {
if (attempt >= maximumBusyAttempts || !isNationalWorkingSetBusy(error)) {
throw error;
}
}
}
return result.factor;
};
nationalMoveHandler = () => {
if (radarSessionCoordinatorRef.current!.snapshot().painted?.source.kind !== "national") return;
Expand All @@ -1734,9 +1768,7 @@ export function App() {
if (!playbackEngaged) return;
nationalPlaybackDetailCameraKey = null;
nationalPlaybackDetailFactor = null;
void nationalPlaybackController?.notifyCameraChanged(true).catch((error) => {
setPlaybackError(error instanceof Error ? error.message : String(error));
});
nationalPlaybackController?.notifyCameraChanged();
};
instance.on("moveend", nationalMoveHandler);

Expand Down Expand Up @@ -2970,6 +3002,7 @@ export function App() {
if (snapshot.playing || snapshot.preparingQuality) controller.pause();
else {
void controller.play().catch((error) => {
if (isRadarSourceSuperseded(error)) return;
setPlaybackError(error instanceof Error ? error.message : String(error));
});
}
Expand Down Expand Up @@ -2997,7 +3030,9 @@ export function App() {
}
}
} catch (error) {
setPlaybackError(error instanceof Error ? error.message : String(error));
if (!isRadarSourceSuperseded(error)) {
setPlaybackError(error instanceof Error ? error.message : String(error));
}
} finally {
scrubRunningRef.current = false;
if (queuedScrubRef.current !== null) queueScrub(queuedScrubRef.current);
Expand Down
30 changes: 29 additions & 1 deletion src/national-radar/NationalGridLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,16 @@ export class NationalGridLayer implements CustomLayerInterface {
commitPrefetchedStaging(timelineObservationIds: readonly string[]): void {
const staging = this.requireCompleteStaging();
const identity = nationalObservationIdentity(staging.manifest);
if (identity.observationId === this.getSnapshot().selectedObservationId) {
// Prefetch is additive residency: it must never retire the presentation
// that is currently painting. The selected observation may prefetch new
// detail while its complete common level is active (motion-first playback
// paints the upgrade later, with a receipt, through frame selection), but
// replacing an active detail presentation without a paint is forbidden.
if (
identity.observationId === this.getSnapshot().selectedObservationId
&& this.active
&& this.active.manifest.presentationFactor !== 4
) {
throw new Error("selected National detail requires an authoritative paint receipt");
}
const previous = this.captureResidencyState();
Expand Down Expand Up @@ -677,6 +686,25 @@ export class NationalGridLayer implements CustomLayerInterface {
+ sharedBytes;
}

/**
* Wait until no frame paint or paint waiter is in flight. Residency
* mutations that bypass the paint path (prefetch commits) call this so a
* concurrent motion paint's captured rollback state can never be made
* stale by a mid-fence residency change.
*/
async waitForPaintQuiescence(timeoutMs = 10_000): Promise<void> {
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 120_000) {
throw new RangeError("National paint quiescence wait must be between 100 and 120000 ms");
}
const started = performance.now();
while (this.pendingPaint || this.paintWaiter) {
if (performance.now() - started > timeoutMs) {
throw new Error("National paint quiescence wait timed out");
}
await nextAnimationFrame();
}
}

async waitForCommonResidency(timeoutMs = 60_000): Promise<void> {
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 120_000) {
throw new RangeError("National residency wait must be between 100 and 120000 ms");
Expand Down
Loading