Skip to content

Fix CII v6 score attribution and climate wiring#4147

Merged
koala73 merged 7 commits into
mainfrom
codex/cii-v6-score-attribution-climate
Jun 6, 2026
Merged

Fix CII v6 score attribution and climate wiring#4147
koala73 merged 7 commits into
mainfrom
codex/cii-v6-score-attribution-climate

Conversation

@koala73
Copy link
Copy Markdown
Owner

@koala73 koala73 commented Jun 6, 2026

Summary

  • Bump CII scoring to v6 so all score-changing attribution fixes ship under one methodology/cache-key version.
  • Align seed and server country attribution for token matching and high-value bbox overlaps, including US/MX Rio Grande segments, western Korean DMZ, RU/UA, IN/PK, CN/RU, and RU/JP.
  • Wire climate anomaly producer zone names and enum severities into CII climate boosts, including browser fallback mapping.
  • Update downstream risk-score cache-key consumers, methodology docs, changelogs, and focused drift/scoring tests.

Root Cause

The CII seed and server had drifted in both text matching and bbox-overlap attribution, and climate anomaly producer zones did not intersect the server consumer map for several score-relevant countries. Shipping these fixes separately would split score changes across silent methodology/cache versions.

Validation

  • node --import tsx --test tests/seed-military-cii-table-drift.test.mts tests/seed-military-cii.test.mts tests/cii-scoring.test.mts
  • node --import tsx --test tests/mcp-bootstrap-parity.test.mjs
  • node --test tests/regional-snapshot.test.mjs
  • npm run typecheck
  • npm run typecheck:api
  • git diff --check
  • Pre-push hook on git push -u origin codex/cii-v6-score-attribution-climate completed successfully, including changed tests, edge-function tests, markdown/MDX lint, and version sync.

@mintlify
Copy link
Copy Markdown

mintlify Bot commented Jun 6, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
WorldMonitor 🟢 Ready View Preview Jun 6, 2026, 9:54 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worldmonitor Ready Ready Preview, Comment Jun 6, 2026 12:08pm

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 6, 2026

Greptile Summary

This PR bumps the CII scoring methodology to v6, aligns the seed and server country-attribution logic (phrase matching, bounding-box overlap heuristics for US/MX, KP/KR, RU/UA, IN/PK, CN/RU, and RU/JP), and wires climate anomaly zone names and proto-enum severities through to CII boosts on both the server and browser-fallback paths.

  • All downstream cache-key consumers (scripts, API handlers, health endpoints, MCP tools) are updated from v5v6, including the FRESHNESS_REGISTRY and mcp-bootstrap-parity test.
  • normalizeForCountryMatch / hasCountryPhraseMatch phrase-boundary logic is replicated into the seed to prevent future drift, and a new climateSeverityScore helper maps proto-enum strings (ANOMALY_SEVERITY_EXTREME, ANOMALY_SEVERITY_MODERATE) to the numeric scale consumed by the blend formula.
  • Tests are significantly expanded with named city probes for every new border heuristic, plus a new intersection test that cross-checks the producer zone list (CLIMATE_ZONES) against the server consumer map (ZONE_COUNTRY_MAP).

Confidence Score: 4/5

Safe to merge; the scoring and attribution changes are well-tested with named city probes and the drift test enforces seed/server parity at each new border heuristic.

The core logic — piecewise Rio Grande chord, DMZ interpolation, proto-enum severity mapping, and ZONE_COUNTRY_MAP expansion — is correct and backed by the expanded test suite. The two concerns are: the 8/3 constant in climateSeverityScore lacks a comment tying it to the downstream * 3 multiplier, making the intended boost values opaque; and the drift test dropped its explicit coverage for the area-sort fallback pairs (AE/SA, AF/IR) that have no explicit border heuristic, leaving a gap if a future commit accidentally inserts a wrong rule for those pairs. Neither is a current defect.

The climateSeverityScore function in get-risk-scores.ts and the revised probe set in tests/seed-military-cii-table-drift.test.mts are worth a quick second look.

Important Files Changed

Filename Overview
server/worldmonitor/intelligence/v1/get-risk-scores.ts Core scoring logic: adds KP/KR DMZ heuristic, RU/UA, IN/PK, CN/RU, RU/JP overlap resolvers, piecewise Rio Grande chord, new climateSeverityScore helper, and expanded ZONE_COUNTRY_MAP. The 8/3 constant in climateSeverityScore is a magic number that encodes the downstream *3 multiplier implicitly.
scripts/seed-military-cii.mjs Seed script: full parity update matching the server's normalizeForCountryMatch, hasCountryPhraseMatch, and resolveKnownBBoxOverlap logic. The piecewise Rio Grande chord and all new overlap pairs mirror the server exactly.
src/services/country-instability.ts Browser-fallback ZONE_COUNTRY_MAP extended with 7 new zones. The existing ingestClimateForCII uses exact-match severity ('extreme' / 'normal'), which is correct here because the browser layer normalizes proto enums via mapSeverity before reaching this function.
tests/cii-scoring.test.mts Significantly expanded: adds named city probes for every new border heuristic, phrase-match checks for 'taiwanese' and 'north korean', and a producer/consumer zone intersection test. Good coverage of the new logic.
tests/seed-military-cii-table-drift.test.mts Drift test probes updated from area-sort tuples to named border-heuristic probes. Correct for the new overlap pairs, but no longer explicitly covers the area-sort fallback for unhandled pairs (AE/SA, AF/IR).
server/_shared/cache-keys.ts Simple v5→v6 bump for the stale risk-scores cache key.
scripts/regional-snapshot/freshness.mjs Cache key updated to v6 in FRESHNESS_REGISTRY; metaKey and maxAgeMin unchanged.
server/worldmonitor/intelligence/v1/_risk-config.ts CII_FORMULA_VERSION bumped from v5 to v6 with updated header comment.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Climate anomaly from Redis cache\nzone + severity proto-enum] --> B{Server path\nget-risk-scores.ts}
    A2[Climate anomaly via gRPC\nzone + severity proto-enum] --> M[mapSeverity\nclimate/index.ts\nexact switch match]
    M --> C[ClimateAnomaly\nseverity: normal/moderate/extreme]
    C --> D{Browser path\ncountry-instability.ts}

    B --> E[climateSeverityScore\nsubstring match on proto-enum]
    E -->|ANOMALY_SEVERITY_EXTREME| F[returns 5]
    E -->|ANOMALY_SEVERITY_MODERATE| G[returns 8/3]
    E -->|numeric| H[pass-through]
    E -->|other| I[returns 0]

    F --> J[climateSeverity = max prev, 5]
    G --> J
    H --> J
    J --> K[climateBoost = min 15, severity x 3\n extreme=15, moderate=8]
    K --> L[combinedScore += climateBoost]

    D --> N[ingestClimateForCII\nexact match: extreme=15, else=8]
    N --> O[climateStress = max prev, stress]
    O --> P[climateBoost = climateStress]
    P --> L2[CII score += climateBoost]

    subgraph ZONE[ZONE_COUNTRY_MAP lookup both paths]
        ZA[zone name from anomaly] --> ZB{match in ZONE_COUNTRY_MAP?}
        ZB -->|yes| ZC[boost all listed country codes]
        ZB -->|no| ZD[no boost]
    end
Loading

Comments Outside Diff (1)

  1. tests/seed-military-cii-table-drift.test.mts, line 41-90 (link)

    P2 Area-sort fallback no longer has test coverage

    The old probe set explicitly exercised the smallest-area-wins fallback for overlap pairs that have no explicit border heuristic (AE inside SA bbox, AF inside IR bbox, LB inside IL bbox). Those probes are gone from this revision. These pairs still rely on candidates[0].code in geoToCountry, but there is now no drift test to catch a future accidental resolveKnownBBoxOverlap entry for them with wrong logic. Consider re-adding at least one of the old area-sort probes (e.g., { name: 'Abu Dhabi inside SA bbox → AE wins by area', lat: 24.0, lon: 53.0, expected: 'AE' }) alongside the new border-heuristic probes.

Reviews (1): Last reviewed commit: "fix(cii): align country-risk freshness f..." | Re-trigger Greptile

Comment thread server/worldmonitor/intelligence/v1/get-risk-scores.ts
@koala73 koala73 merged commit 7b46751 into main Jun 6, 2026
19 checks passed
@koala73 koala73 deleted the codex/cii-v6-score-attribution-climate branch June 6, 2026 12:15
koala73 pushed a commit that referenced this pull request Jun 6, 2026
CII_FORMULA_VERSION bumped v5->v6 (#4147). No hashed coefficient changed
(country weights, defaults, strategic constants, getScoreLevel cutoffs),
so the v6 snapshot hash equals v5. Without this the version-keyed guard
fails assert.ok(expectedHash) on main.
koala73 added a commit that referenced this pull request Jun 6, 2026
* test(cii): guard formula protocol docs

* test(cii): harden score-level parser

* test(cii): add v6 protocol snapshot entry

CII_FORMULA_VERSION bumped v5->v6 (#4147). No hashed coefficient changed
(country weights, defaults, strategic constants, getScoreLevel cutoffs),
so the v6 snapshot hash equals v5. Without this the version-keyed guard
fails assert.ok(expectedHash) on main.

---------

Co-authored-by: e <e@e.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant