Skip to content

fix(spr-policies): wire seed-spr-policies into seed-bundle-energy-sources#3089

Merged
koala73 merged 1 commit into
mainfrom
fix/spr-policies-bundle-wiring
Apr 14, 2026
Merged

fix(spr-policies): wire seed-spr-policies into seed-bundle-energy-sources#3089
koala73 merged 1 commit into
mainfrom
fix/spr-policies-bundle-wiring

Conversation

@koala73
Copy link
Copy Markdown
Owner

@koala73 koala73 commented Apr 14, 2026

Why this PR?

`scripts/seed-spr-policies.mjs` exists as a complete, runnable seeder with proper `isMain` guard at line 57-59. But no Railway service ever invokes it. `/api/health` shows `sprPolicies` as EMPTY with `seedAgeMin: null` — `energy:spr-policies:v1` has literally never been written to Redis since the seeder was added.

`scripts/seed-energy-spine.mjs` references the SPR key but only READS it; doesn't seed it. `api/health.js` registers `maxStaleMin: 576000` (400 days), confirming the intent for a static registry.

Fix

Add an entry to `scripts/seed-bundle-energy-sources.mjs` so the existing Railway bundle service runs SPR alongside its energy siblings.

```js
{ label: 'SPR-Policies', script: 'seed-spr-policies.mjs', seedMetaKey: 'energy:spr-policies', intervalMs: 7 * DAY, timeoutMs: 60_000 },
```

Weekly cadence is generous — the data is a static JSON registry (`scripts/data/spr-policies.json`); it only needs to run once after deploys + restarts. The 60s timeout is generous for a JSON-file read + Redis write.

Files

  • `scripts/seed-bundle-energy-sources.mjs` (1 file, +6 / -0)

Testing

  • `node --check scripts/seed-bundle-energy-sources.mjs` → clean
  • `npm run typecheck` → clean

Post-Deploy Monitoring & Validation

  • Logs: Next `seed-bundle-energy-sources` run (Railway bundle service watches `scripts/**` so it auto-redeploys on merge) — bundle should now show 8 sections including `[SPR-Policies] === energy:spr-policies Seed === ... Done` and `Verified: data present in Redis`.
  • Redis: `GET energy:spr-policies:v1` → non-empty payload with policy entries for required countries (CN, IN, JP, SA, US per the seeder's whitelist).
  • Health: `curl -sL https://worldmonitor.app/api/health | jq '.checks.sprPolicies'` — should flip from `EMPTY (seedAgeMin: null)` to `OK` within 1 cycle (~weekly first run).
  • Failure signal / rollback: if the JSON file is missing or malformed, the seeder will fail loudly with `FATAL:` and the bundle reports `failed:1`. Revert is one-line.
  • Validation window: 1 hour for the first scheduled run.
  • Owner: @koala73

Related

…rces

scripts/seed-spr-policies.mjs exists as a runnable seeder with proper isMain
guard, but no Railway service ever invokes it. /api/health shows
sprPolicies as EMPTY with seedAgeMin: null — energy:spr-policies:v1 has
literally never been written to Redis.

Wired it as a bundle entry alongside the other energy seeders. Cadence:
weekly. Static-registry data (scripts/data/spr-policies.json) only needs to
run once after deploys + restarts to populate the key; the 400d
maxStaleMin in api/health.js confirms intent. 60s timeout is generous
for a JSON-file read + Redis write.

Tests: node --check on the bundle clean; npm run typecheck clean.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
worldmonitor Ignored Ignored Apr 14, 2026 9:15am

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 14, 2026

Greptile Summary

Wires seed-spr-policies.mjs into the Railway energy-sources bundle so energy:spr-policies:v1 actually gets written to Redis — it was never seeded since the script was introduced, leaving /api/health showing sprPolicies: EMPTY. The seedMetaKey, TTL mechanics, bootstrap registration (api/bootstrap.js line 108), and health monitoring (api/health.js line 343) were already correctly set up; only the bundle entry was missing.

Confidence Score: 5/5

  • Safe to merge — minimal one-line config addition with no logic changes and all supporting infrastructure already in place.
  • The seedMetaKey (energy:spr-policies) matches what writeFreshnessMetadata writes and what health.js reads; the data file exists; bootstrap already includes sprPolicies; timeoutMs: 60_000 is ample for a JSON-file read + Redis write. No P0 or P1 findings.
  • No files require special attention.

Important Files Changed

Filename Overview
scripts/seed-bundle-energy-sources.mjs Adds SPR-Policies as an 8th section to the energy-sources bundle; seedMetaKey, timeout, and interval are all consistent with existing patterns and the health/bootstrap registrations already in place.

Sequence Diagram

sequenceDiagram
    participant Railway as Railway Bundle Service
    participant BR as _bundle-runner.mjs
    participant Redis as Redis (Upstash)
    participant Seeder as seed-spr-policies.mjs
    participant FS as scripts/data/spr-policies.json

    Railway->>BR: runBundle('energy-sources', [..., SPR-Policies])
    BR->>Redis: GET seed-meta:energy:spr-policies
    Redis-->>BR: null (never seeded)
    Note over BR: No fetchedAt → skip freshness gate, run seeder
    BR->>Seeder: execFile(node seed-spr-policies.mjs)
    Seeder->>FS: readFileSync('spr-policies.json')
    FS-->>Seeder: raw JSON registry
    Seeder->>Redis: SET energy:spr-policies:v1 (TTL 400d)
    Seeder->>Redis: SET seed-meta:energy:spr-policies (TTL 400d)
    Redis-->>Seeder: OK
    Seeder-->>BR: exit 0
    BR->>BR: ran++, log "Done"
    Note over Redis: health /api/health sprPolicies: OK
Loading

Reviews (1): Last reviewed commit: "fix(spr-policies): wire seed-spr-policie..." | Re-trigger Greptile

@koala73 koala73 merged commit 5152ed7 into main Apr 14, 2026
11 checks passed
@koala73 koala73 deleted the fix/spr-policies-bundle-wiring branch April 14, 2026 09:29
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