Skip to content

Utility Asset Heatmap Layer Tile Race Under Concurrent Boundary Updates #45

Description

@elizabetheonoja-art

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

  1. 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.
  2. Implement tile-level versioning: each tile has a generation counter. Heatmap writes include the generation; stale writes (generation < current) are discarded.
  3. 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.
  4. 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

Metadata

Metadata

Assignees

Labels

Complexity: HardcoreIssues requiring deep systems-level engineering rigorGrantFox OSSIssue tracked in GrantFox OSSLayer: Core-EngineCore engine layerMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignType: Race-ConditionConcurrency and race condition related issues

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions