feat(pizzint): compute GDELT country-pair tensions from our own GDELT event export instead of PizzINT
Problem
The Geopolitical Tensions section of the Pentagon Pizza Index panel has been empty since 2026-09-25.
- Where the pairs come from: its six country pairs (US–Russia, Russia–Ukraine, US–China, China–Taiwan, US–Iran, US–Venezuela) are copied from PizzINT's private
https://www.pizzint.watch/api/gdelt/batch?method=gprendpoint. We don't compute them. - What PizzINT returns now:
500 {"error":"Failed to fetch data from Supabase"}. - What the relay logs every tick:
[PizzINT] GDELT tensions request rejected (HTTP 500).
We already ingest GDELT's global 15-minute event export ourselves (scripts/_conflict-gdelt-bulk.mjs, via the seed-gdelt-intel Railway service running scripts/seed-gdelt-bulk-materializer.mjs). That export records who acted toward whom and how hostile each event was, which is what a country-pair tension score needs. We should compute the pairs ourselves and stop depending on PizzINT for them.
Current code path
Producer:
scripts/ais-relay.cjs, inseedPizzint(grepGDELT_BATCH_API,DEFAULT_GDELT_PAIRS,tensionPairs), fetches PizzINT's batch endpoint. For each pair it maps the last two points to:score= the last point's value;changePercent= the change between the last two points;trend= rising or falling beyond ±5%, otherwise stable.
The result goes into
intelligence:pizzint:seed:v1alongside the pizza index.Reader:
server/worldmonitor/intelligence/v1/get-pizzint-status.tsreturnstensionPairsonly whenreq.includeGdeltis set, and returns empty pairs whenever the pizza payload is missing. So the tensions also disappear whenever the pizza feed is down, even though the two are unrelated.Contract:
GdeltTensionPairinproto/worldmonitor/intelligence/v1/intelligence.protohasid,countries(ISO-2),label,score(0–100, validated),trendandchange_percent, plusregion.UI: the
.pizzint-tensions-listinsrc/components/PizzIntIndicator.ts, fed byupdateTensions.
Proposed design
1. Aggregate country-pair events in the bulk materializer
In the materializer's event-export pass, the same files _conflict-gdelt-bulk.mjs parses, count events between the two countries of each configured pair, in either direction. The GDELT 2.0 export fields to use (0-based) are:
| Field | Index |
|---|---|
Actor1CountryCode |
7 |
Actor2CountryCode |
17 |
IsRootEvent |
25 |
EventRootCode |
28 |
QuadClass |
29 |
GoldsteinScale |
30 |
NumMentions |
31 |
AvgTone |
34 |
The existing parser already reads 25, 28 and 29 at _conflict-gdelt-bulk.mjs (fields[25], fields[28], fields[29]). Actor country codes are 3-letter CAMEO codes: USA, RUS, UKR, CHN, TWN, IRN, VEN. Map them to the proto's ISO-2 codes.
- Daily buckets per pair (UTC):
- total events;
- conflict events (
QuadClass3 verbal conflict, 4 material conflict); - a mentions-weighted conflict intensity,
Σ NumMentions × max(0, −GoldsteinScale)over conflict events; - mean
AvgTone.
- Storage: keep a rolling window of at least 90 days in a new key, e.g.
gdelt:bulk:dyad-tension:v1. Declare it inscripts/_gdelt-bulk-contract.mjs, give itseed-meta:gdelt:bulk:dyad-tension, and follow the existing materializer state and TTL conventions (GDELT_BULK_*). Old buckets must age out, and a restart must not double-count a cohort; the materializer's cohort state already tracks processed files. - Configuration: make the pair list a constant shared with the relay/handler, starting with the current six.
2. Score and trend (document the formula)
For each pair:
score: the percentile of the last 7 days' mean conflict intensity against the pair's own 90-day daily history, scaled to 0–100.- This makes pairs comparable even though raw volumes differ by orders of magnitude, e.g. US–China vs US–Venezuela.
- A pair with fewer than N conflict events in the window (choose N from the measurement in step 0) is published as
insufficient datarather than a misleading 0.
changePercent/trend: the last 7 days against the previous 7 days, rising or falling beyond ±10%.- Write the formula in the code and in the panel's docs. Pin its outputs with tests.
The score is on World Monitor's scale, not PizzINT's gpr scale; do not present it as PizzINT's.
3. Serve it independently of the pizza feed
- Handler: change
get-pizzint-status.tsto read the new tension key directly whenincludeGdeltis set, so tensions no longer vanish whenintelligence:pizzint:seed:v1is empty. - Relay: remove the PizzINT
gdelt/batchcall once the new source is live. There's no reason to keep a second, weaker source for the same field. - Health: register the new key in
api/health.jswith a staleness budget matching the materializer's cadence.- Add it as a
STANDALONE_KEYSorSEED_METAentry; see AGENTS.md "Landmarks". - Redis seeds must write
seed-meta:<key>(AGENTS.md "Critical boundaries").
- Add it as a
4. Attribution in the panel
Label the section's source as World Monitor, computed from GDELT events, e.g. Tensions: World Monitor from GDELT events. The pizza index footer is covered by #8675. Localize any new strings under components.pizzint.*.
Step 0: measure before building (required, go/no-go)
Before writing the aggregation, measure whether the event export carries enough events for each pair.
- Download about 24 hours of export files (96 files from
http://data.gdeltproject.org/gdeltv2/lastupdate.txthistory) with a small scratch script outside the repo. - For each of the six pairs, count total and conflict events per day.
- Paste the counts in the PR.
- Go if every pair averages at least 20 conflict events a day. Otherwise either drop the thin pairs (likely candidate: US–Venezuela) or widen them to a 7-day window. Record the decision.
- Don't run this parse inside a Railway container (see memory:
railway sshshares the production container's memory).
Acceptance criteria
- The step 0 measurement and the go/no-go decision are in the PR description.
- Materializer tests (
tests/gdelt-bulk-materializer.test.mjs/tests/seed-gdelt-bulk-materializer.test.mjs), using fixture export rows:- events in both directions count toward the same pair;
- only
QuadClass3 and 4 count as conflict; - Goldstein weighting is applied;
- a re-processed cohort is not double-counted;
- buckets older than the window are dropped;
- actor codes outside the pair list are ignored.
- Score tests: a pair whose last 7 days sit at its 90-day median scores about 50. A pair at its 90-day maximum scores 100. A thin pair publishes insufficient data. Trend thresholds are pinned.
- Handler test: tension pairs are returned when the pizza payload is missing, and the proto
scorerange (0–100) is respected. - Relay: the PizzINT
gdelt/batchcall is removed, and the relay tests are updated (tests/pizzint-seed-publication.test.mjscurrently pins the YYYYMMDD window request; remove or replace that case). - Health: the new key is registered with seed-meta, and
node --test tests/health*.test.mjspasses. - Source attribution: new external hosts, if any, are added with
node scripts/source-attribution.mjs --write, andnode scripts/docs-stats.mjs --checkpasses. The data comes from the existingdata.gdeltproject.orgfeed, so none is expected. - Checks:
npm run typecheck,npm run typecheck:api,npm run lint:boundaries, andmake generateif the proto changes, with the generated diff verified. - UI evidence: the PR includes screenshots of the panel showing populated tension pairs and the new attribution (AGENTS.md UI-evidence rule).
Verification after deploy
- The
seed-gdelt-intellogs show the dyad aggregation running, andgdelt:bulk:dyad-tension:v1holds daily buckets for every configured pair. -
/api/healthreports the new key OK. - The panel shows the six pairs (or the kept subset) with scores and trends while PizzINT is still down.
Context and references
- Why we can't use GDELT's query API: GDELT's DOC API is load-shed for us (#5843, #5864). That's why ingestion moved to the bulk export, so don't build on
api.gdeltproject.org. - Parsing to reuse: event export parsing in
scripts/_conflict-gdelt-bulk.mjs; FIPS→ISO-2 country codes inscripts/_gdelt-country-codes.mjs. The actor codes here are CAMEO 3-letter, not FIPS. - Related: #8675 and its attribution; #8671 (BestTime fallback); #8666 (the PizzINT GDELT date window).
Out of scope
- The pizza index or DEFCON algorithm; see #8675.
- Adding pairs beyond the current six. The design makes the list configurable, but new pairs need their own step 0 measurement.
Source: koala73/worldmonitor