Utility Asset Heatmap Layer Tile Race Under Concurrent Boundary Updates
Problem Statement
The utility asset heatmap in src/components/map/AssetHeatmapLayer.tsx renders a tile-based heatmap overlay showing asset density across geographic regions. The updateTileLayer() function at line 90 fetches asset data per tile and updates the heatmap. When two geographic boundary updates arrive concurrently (e.g., a service district boundary changes while a flood zone boundary updates), both trigger tile recalculations. Both read the current asset positions, both compute heat values for overlapping tiles, and both write their heat values to the shared heatmap data store. The final heatmap shows a blend of old flood zone boundaries and new service district boundaries for the same tile, producing a visual artifact where heat values are spatially misaligned.
State Invariants & Parameters
- Tile size: 256×256 pixels
- Boundary layers: service districts, flood zones, grid regions
- Heatmap data store:
Map<tileKey, Float32Array<heatValues>>
- Concurrent boundary updates: up to 3 simultaneous
- Visual artifact: heat values misaligned with correct boundaries
Affected Code Paths
src/components/map/AssetHeatmapLayer.tsx:85-130 — Tile recalculation race
src/components/map/boundaryManager.ts:45-75 — Boundary update triggers
src/components/map/heatmapStore.ts:30-55 — Shared heatmap data store
Resolution Blueprint
- Add a per-tile write lock: use a
Map<tileKey, Mutex> that guards write access. Each boundary update acquires the mutex for its affected tiles before computing and writing heat values.
- Implement tile-level versioning: each tile has a
generation counter. Heatmap writes include the generation; stale writes (generation < current) are discarded.
- Use an atomic tile swap: compute the new heatmap for affected tiles in isolation, then swap the entire tile's data using an atomic reference update.
- Add a concurrent boundary update test with 3 boundary layers updating overlapping tiles simultaneously and verify the final heatmap is correct for all layers.
Labels
Complexity: Hardcore
Layer: Core-Engine
Type: Race-Condition
Utility Asset Heatmap Layer Tile Race Under Concurrent Boundary Updates
Problem Statement
The utility asset heatmap in
src/components/map/AssetHeatmapLayer.tsxrenders a tile-based heatmap overlay showing asset density across geographic regions. TheupdateTileLayer()function at line 90 fetches asset data per tile and updates the heatmap. When two geographic boundary updates arrive concurrently (e.g., a service district boundary changes while a flood zone boundary updates), both trigger tile recalculations. Both read the current asset positions, both compute heat values for overlapping tiles, and both write their heat values to the shared heatmap data store. The final heatmap shows a blend of old flood zone boundaries and new service district boundaries for the same tile, producing a visual artifact where heat values are spatially misaligned.State Invariants & Parameters
Map<tileKey, Float32Array<heatValues>>Affected Code Paths
src/components/map/AssetHeatmapLayer.tsx:85-130— Tile recalculation racesrc/components/map/boundaryManager.ts:45-75— Boundary update triggerssrc/components/map/heatmapStore.ts:30-55— Shared heatmap data storeResolution Blueprint
Map<tileKey, Mutex>that guards write access. Each boundary update acquires the mutex for its affected tiles before computing and writing heat values.generationcounter. Heatmap writes include the generation; stale writes (generation < current) are discarded.Labels
Complexity: HardcoreLayer: Core-EngineType: Race-Condition