Files
worldmonitor/todos/164-pending-p3-fetch-sector-dependency-no-circuit-breaker.md
Elie Habib 60e727679c feat(supply-chain): Sprint E — scenario visual completion + service parity (#2910)
* feat(supply-chain): Sprint E — scenario visual completion + service parity

- E1: fetchSectorDependency exported from supply-chain service index
- E2: PRO gate + all-renderer dispatch in MapContainer.activateScenario
- E3: scenario summary banner in SupplyChainPanel (dismiss wired)
- E4: "Simulate Closure" trigger button in expanded chokepoint cards
- E5: affectedIso2s heat layer in DeckGLMap (GeoJsonLayer, red tint)
- E6: SVG renderer setScenarioState (best-effort iso2 fill)
- E7: Globe renderer scenario polygons via flushPolygons
- E8: integration tests for scenario run/status endpoints

* fix(supply-chain): address PR #2910 review findings (P1 + P2 + P3)

- Wire setOnScenarioActivate + setOnDismissScenario in panel-layout.ts (todo #155)
- Rename shadow variable t→tmpl in SCENARIO_TEMPLATES.find (todo #152)
- Add statusResp.ok guard in scenario polling loop (todo #153)
- Replace status.result! non-null assertion with shape guard (todo #154)
- Add AbortController to prevent concurrent polling races (todo #162)
- Add polygonStrokeColor scenario branch (transparent) in GlobeMap (todo #156)
- Re-export SCENARIO_TEMPLATES via src/config/scenario-templates.ts (todo #157)
- Cache affectedIso2Set in DeckGLMap.setScenarioState (todo #158)
- Add scenario paths to PREMIUM_RPC_PATHS for auth injection (todo #160)
- Show template name in scenario banner instead of raw ID (todo #163)

* fix(supply-chain): address PR #2910 review findings

- Add auth headers to scenario fetch calls in SupplyChainPanel
- Reset button state on scenario dismiss
- Poll status immediately on first iteration (no 2s delay)
- Pre-compute scenario polygons in GlobeMap.setScenarioState
- Use scenarioId for DeckGL updateTriggers precision

* fix(supply-chain): wire panel instance to MapContainer, stop button click propagation

- Call setSupplyChainPanel() in panel-layout.ts so scenario banner renders
- Add stopPropagation() to Simulate Closure button to prevent card collapse
2026-04-10 21:31:26 +04:00

2.1 KiB

status, priority, issue_id, tags, dependencies
status priority issue_id tags dependencies
pending p3 164
code-review
quality
supply-chain
reliability

fetchSectorDependency Has No Circuit Breaker — Retries Indefinitely on Persistent Failure

Problem Statement

src/services/supply-chain/index.ts:fetchSectorDependency() catches all errors and returns emptySectorDependency. While this prevents crashes, it means every call during a persistent outage (e.g., server restart, network partition) makes a live gRPC attempt before falling back. If the supply-chain panel calls this per-chokepoint on every render, a 30-chokepoint list during an outage = 30 sequential timeouts per render cycle.

Findings

  • File: src/services/supply-chain/index.ts
  • Code:
    export async function fetchSectorDependency(iso2, hs2 = '27') {
      try {
        return await client.getSectorDependency({ iso2, hs2 });
      } catch {
        return { ...emptySectorDependency, iso2, hs2 };
      }
    }
    
  • No timeout, no cached failure state, no back-off
  • Minor issue today (called rarely), but will matter at scale
  • Identified by kieran-typescript-reviewer during PR #2910 review

Proposed Solutions

Option A: Add a short timeout to the gRPC call

const ac = new AbortController();
setTimeout(() => ac.abort(), 3000);
return await client.getSectorDependency({ iso2, hs2 }, { signal: ac.signal });

Fails fast, reduces hung call duration. Effort: Small | Risk: Low

Option B: Deduplicate in-flight requests with a request Map

Cache the promise keyed by ${iso2}:${hs2} — deduplicates concurrent calls for the same country. Effort: Small | Risk: Low

Combine A + B: timeout + in-flight dedup. Low-effort, prevents worst-case pile-up.

Technical Details

  • Affected files: src/services/supply-chain/index.ts

Acceptance Criteria

  • fetchSectorDependency times out within ~3s rather than hanging indefinitely
  • Concurrent calls for the same (iso2, hs2) share one in-flight promise

Work Log

  • 2026-04-10: Identified by kieran-typescript-reviewer during PR #2910 review

Resources

  • PR: #2910