Skip to content

refactor(health): load generated health registry in fork#11

Merged
lspassos1 merged 2 commits intomainfrom
refactor/health-generated-registry
Apr 11, 2026
Merged

refactor(health): load generated health registry in fork#11
lspassos1 merged 2 commits intomainfrom
refactor/health-generated-registry

Conversation

@lspassos1
Copy link
Copy Markdown
Owner

Summary

This stacks the health migration on top of the bootstrap registry foundation. The existing api/health.js status algorithm stays intact, but its dataset registrations now come from generated artifacts derived from registry/datasets.ts.

Root cause

api/health.js carried a second hand-maintained dataset contract alongside bootstrap. That split forced health-only metadata, on-demand flags, empty-ok semantics, and cascade groups to drift separately from the bootstrap registry source.

Changes

  • expand registry/datasets.ts to cover the existing health bootstrap and standalone registrations
  • emit api/_generated/health-registry.js from the registry generator
  • keep registry:check focused on generated artifacts only
  • replace inline health maps in api/health.js with generated imports
  • update bootstrap and health-focused tests to assert generated health parity

Validation

  • npm run registry:check
  • node --test tests/bootstrap.test.mjs tests/market-breadth.test.mjs tests/customs-revenue.test.mjs tests/resilience-static-seed.test.mjs
  • node --test tests/edge-functions.test.mjs
  • npm run typecheck
  • npm run typecheck:api

Risk

Low to moderate. The runtime algorithm is intentionally unchanged, but the generated registry now owns health bootstrap keys, standalone keys, seed metadata, on-demand keys, empty-ok keys, and cascade groups.

Refs #5
Depends on #10

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 11, 2026

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

Project Deployment Actions Updated (UTC)
worldmonitor Ready Ready Preview, Comment Apr 11, 2026 9:37pm

@lspassos1
Copy link
Copy Markdown
Owner Author

@greptileai

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 11, 2026

Greptile Summary

This PR migrates api/health.js from hand-maintained inline dataset maps to generated artifacts derived from registry/datasets.ts, eliminating a second source of truth that could drift from the bootstrap registry. The runtime status-checking algorithm is intentionally untouched; only the data contract definitions move. New tests assert health-registry parity for breadthHistory, customsRevenue, and resilienceStaticIndex.

Key changes:

  • registry/datasets.ts — consolidated source of truth; adds HEALTH_BOOTSTRAP_ADDITIONS, HEALTH_SEED_META, on-demand flags, empty-ok flags, and cascade groups
  • scripts/generate-dataset-registry.ts — extended to emit api/_generated/health-registry.js with all six health exports
  • api/health.js — replaces six inline maps with imports from the generated artifact
  • scripts/check-dataset-registry.mjsregistry:check now guards all three generated artifacts

Issue found:

  • The four keys in HEALTH_BOOTSTRAP_ADDITIONS (ddosAttacks, trafficAnomalies, cryptoSectors, economicStress) are registered with bucket: 'bootstrap' and onDemand: true. The generator correctly places them in both HEALTH_BOOTSTRAP_KEYS and HEALTH_ON_DEMAND_KEYS, but api/health.js only evaluates ON_DEMAND_KEYS in the standalone loop — the bootstrap loop has no on-demand guard. If any of these four keys is empty (Cloudflare Radar outage, upstream failure), health.js will report EMPTY (critical, raising critCount) rather than EMPTY_ON_DEMAND (warning). The fix is either to change their bucket to 'standalone' in HEALTH_BOOTSTRAP_ADDITIONS, or to add an ON_DEMAND_KEYS.has(name) guard to the bootstrap loop in api/health.js.

Confidence Score: 3/5

Safe to merge after the HEALTH_BOOTSTRAP_ADDITIONS bucket/on-demand mismatch is resolved — one targeted one-line fix required.

The overall migration is well-engineered: the generator validates, the check script guards CI, and the algorithm in health.js is untouched. However, there is a concrete behavioral bug: the four keys added via HEALTH_BOOTSTRAP_ADDITIONS are emitted into HEALTH_BOOTSTRAP_KEYS with an on-demand flag that the bootstrap loop never reads. An empty key incorrectly increments critCount instead of warnCount, potentially flipping the overall health status from WARNING to DEGRADED or UNHEALTHY. No existing test catches this gap. The fix is a one-line change (bucket: 'standalone').

registry/datasets.ts — specifically the HEALTH_BOOTSTRAP_ADDITIONS loop in buildDatasets() and the HEALTH_ON_DEMAND_KEYS.push() call at line 527.

Important Files Changed

Filename Overview
registry/datasets.ts Source of truth for the generated registry; well-structured, but HEALTH_BOOTSTRAP_ADDITIONS registers four keys with bucket: 'bootstrap' + onDemand: true — the onDemand flag is silently dropped by health.js's bootstrap loop, causing those keys to trigger EMPTY (crit) rather than EMPTY_ON_DEMAND (warn) when empty.
api/health.js Runtime algorithm unchanged; inline maps replaced with generated imports cleanly. The bootstrap loop still lacks an on-demand guard, which means bootstrap keys tagged as on-demand in the registry produce incorrect critical status when empty.
api/_generated/health-registry.js Generated artifact; correctly emits all six health registry exports with alphabetical sorting. The displacement key correctly uses a template literal for the current-year suffix.
scripts/generate-dataset-registry.ts Generator is well-validated; enforces health contract requirements for bootstrap datasets, checks seed-meta completeness, and deduplicates Redis keys globally. Emits all three artifact files in a single pass.
tests/bootstrap.test.mjs New Health key registries describe block validates cross-registry uniqueness, seed-meta referential integrity, and cascade group membership. Good coverage, though no test asserts that on-demand keys are restricted to the standalone registry.
scripts/check-dataset-registry.mjs Minimal CI guard: regenerates artifacts and checks git diff across all three generated files. Works correctly.
tests/market-breadth.test.mjs Adds health-registry parity assertions for breadthHistory (data key + seed-meta). Straightforward and complete.
tests/customs-revenue.test.mjs Pins the seed-meta key format in the generated health registry via a regex assert. Correctly verifies the :v1 suffix is stripped for health-meta compatibility.
tests/resilience-static-seed.test.mjs New resilience static health registrations describe block confirms the manifest key and seed-meta are present in the generated health registry. No issues.

Sequence Diagram

sequenceDiagram
    participant DTS as registry/datasets.ts
    participant GEN as generate-dataset-registry.ts
    participant HR as api/_generated/health-registry.js
    participant HJS as api/health.js
    participant Redis as Redis (Upstash)

    Note over DTS: HEALTH_BOOTSTRAP_KEYS<br/>HEALTH_BOOTSTRAP_ADDITIONS (onDemand:true)<br/>HEALTH_STANDALONE_KEYS<br/>HEALTH_SEED_META / on-demand / empty-ok / cascade

    DTS->>GEN: DATASETS[]
    GEN->>GEN: validateGlobal() — dedup ids, keys, aliases
    GEN->>HR: emit HEALTH_BOOTSTRAP_KEYS + HEALTH_STANDALONE_KEYS<br/>HEALTH_SEED_META + HEALTH_ON_DEMAND_KEYS<br/>HEALTH_EMPTY_OK_KEYS + HEALTH_CASCADE_GROUPS

    HJS->>HR: import all six exports
    HJS->>Redis: STRLEN all data keys + GET all seed-meta keys (pipeline)
    Redis-->>HJS: byte lengths + seed-meta payloads

    Note over HJS: Bootstrap loop — no on-demand check<br/>ddosAttacks/trafficAnomalies/cryptoSectors/economicStress<br/>in HEALTH_BOOTSTRAP_KEYS AND HEALTH_ON_DEMAND_KEYS<br/>but onDemand flag silently dropped → EMPTY (crit)

    HJS->>HJS: Standalone loop — checks ON_DEMAND_KEYS correctly
    HJS-->>HJS: overall: HEALTHY / WARNING / DEGRADED / UNHEALTHY
Loading

Fix All in Codex

Prompt To Fix All With AI
This is a comment left during a code review.
Path: registry/datasets.ts
Line: 596-597

Comment:
**On-demand flag silently dropped for bootstrap health additions**

`ddosAttacks`, `trafficAnomalies`, `cryptoSectors`, and `economicStress` are registered with `bucket: 'bootstrap'` and `onDemand: true`. The generator correctly emits them in both `HEALTH_BOOTSTRAP_KEYS` and `HEALTH_ON_DEMAND_KEYS`. However, `api/health.js` only consults `ON_DEMAND_KEYS` inside the **standalone** loop (lines 160, 218–221). The **bootstrap** loop (lines 84–154) has no on-demand check:

```js
// health.js bootstrap loop — missing on-demand guard
} else if (!hasData) {
  if (EMPTY_DATA_OK_KEYS.has(name)) { ... }
  else {
    status = 'EMPTY';   // ← should be EMPTY_ON_DEMAND for on-demand keys
    critCount++;
  }
}
```

This means if any of these four keys is empty (e.g. Cloudflare Radar outage, upstream refresh failure), health.js reports `EMPTY` (critical, increments `critCount`) instead of the intended `EMPTY_ON_DEMAND` (warning). When `critCount` is 1–3 the overall status becomes `DEGRADED`; above 3 it becomes `UNHEALTHY` — rather than the `WARNING` that on-demand semantics are designed to produce.

Two possible fixes:

**Option A — change the bucket to `'standalone'`** (the bootstrap _cache_ bucket and the health _monitoring_ bucket are orthogonal):

```suggestion
  register(logicalName, redisKey).health = { bucket: 'standalone', onDemand: true };
```

**Option B — add an on-demand guard to the bootstrap loop in `api/health.js`** (lines 125–128 and 138–141):
```js
} else if (!hasData) {
  if (EMPTY_DATA_OK_KEYS.has(name)) { ... }
  else if (ON_DEMAND_KEYS.has(name)) {
    status = 'EMPTY_ON_DEMAND';
    warnCount++;
  } else {
    status = 'EMPTY';
    critCount++;
  }
}
```

Option A is the lower-risk change — it requires no modification to `api/health.js`'s runtime logic.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: registry/datasets.ts
Line: 527

Comment:
**Pushed on-demand keys have no runtime effect**

The four keys pushed here — `cryptoSectors`, `ddosAttacks`, `economicStress`, `trafficAnomalies` — are all in `HEALTH_BOOTSTRAP_KEYS` (bucket: `'bootstrap'`). Because `api/health.js` only evaluates `ON_DEMAND_KEYS` inside the standalone loop, listing them here produces no runtime effect. The `push()` call also bypasses TypeScript's readonly inference.

If the intent is truly on-demand monitoring semantics, the bucket for these entries should be `'standalone'` (see the P1 comment above). If critical-when-empty is acceptable for all bootstrap health keys, this `push` call and the `onDemand: true` flag in `HEALTH_BOOTSTRAP_ADDITIONS` should both be removed to avoid misleading future contributors.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "refactor(health): load generated health ..." | Re-trigger Greptile

Comment thread registry/datasets.ts Outdated
Comment on lines +596 to +597
for (const [logicalName, redisKey] of Object.entries(HEALTH_BOOTSTRAP_ADDITIONS)) {
register(logicalName, redisKey).health = { bucket: 'bootstrap', onDemand: true };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 On-demand flag silently dropped for bootstrap health additions

ddosAttacks, trafficAnomalies, cryptoSectors, and economicStress are registered with bucket: 'bootstrap' and onDemand: true. The generator correctly emits them in both HEALTH_BOOTSTRAP_KEYS and HEALTH_ON_DEMAND_KEYS. However, api/health.js only consults ON_DEMAND_KEYS inside the standalone loop (lines 160, 218–221). The bootstrap loop (lines 84–154) has no on-demand check:

// health.js bootstrap loop — missing on-demand guard
} else if (!hasData) {
  if (EMPTY_DATA_OK_KEYS.has(name)) { ... }
  else {
    status = 'EMPTY';   // ← should be EMPTY_ON_DEMAND for on-demand keys
    critCount++;
  }
}

This means if any of these four keys is empty (e.g. Cloudflare Radar outage, upstream refresh failure), health.js reports EMPTY (critical, increments critCount) instead of the intended EMPTY_ON_DEMAND (warning). When critCount is 1–3 the overall status becomes DEGRADED; above 3 it becomes UNHEALTHY — rather than the WARNING that on-demand semantics are designed to produce.

Two possible fixes:

Option A — change the bucket to 'standalone' (the bootstrap cache bucket and the health monitoring bucket are orthogonal):

Suggested change
for (const [logicalName, redisKey] of Object.entries(HEALTH_BOOTSTRAP_ADDITIONS)) {
register(logicalName, redisKey).health = { bucket: 'bootstrap', onDemand: true };
register(logicalName, redisKey).health = { bucket: 'standalone', onDemand: true };

Option B — add an on-demand guard to the bootstrap loop in api/health.js (lines 125–128 and 138–141):

} else if (!hasData) {
  if (EMPTY_DATA_OK_KEYS.has(name)) { ... }
  else if (ON_DEMAND_KEYS.has(name)) {
    status = 'EMPTY_ON_DEMAND';
    warnCount++;
  } else {
    status = 'EMPTY';
    critCount++;
  }
}

Option A is the lower-risk change — it requires no modification to api/health.js's runtime logic.

Prompt To Fix With AI
This is a comment left during a code review.
Path: registry/datasets.ts
Line: 596-597

Comment:
**On-demand flag silently dropped for bootstrap health additions**

`ddosAttacks`, `trafficAnomalies`, `cryptoSectors`, and `economicStress` are registered with `bucket: 'bootstrap'` and `onDemand: true`. The generator correctly emits them in both `HEALTH_BOOTSTRAP_KEYS` and `HEALTH_ON_DEMAND_KEYS`. However, `api/health.js` only consults `ON_DEMAND_KEYS` inside the **standalone** loop (lines 160, 218–221). The **bootstrap** loop (lines 84–154) has no on-demand check:

```js
// health.js bootstrap loop — missing on-demand guard
} else if (!hasData) {
  if (EMPTY_DATA_OK_KEYS.has(name)) { ... }
  else {
    status = 'EMPTY';   // ← should be EMPTY_ON_DEMAND for on-demand keys
    critCount++;
  }
}
```

This means if any of these four keys is empty (e.g. Cloudflare Radar outage, upstream refresh failure), health.js reports `EMPTY` (critical, increments `critCount`) instead of the intended `EMPTY_ON_DEMAND` (warning). When `critCount` is 1–3 the overall status becomes `DEGRADED`; above 3 it becomes `UNHEALTHY` — rather than the `WARNING` that on-demand semantics are designed to produce.

Two possible fixes:

**Option A — change the bucket to `'standalone'`** (the bootstrap _cache_ bucket and the health _monitoring_ bucket are orthogonal):

```suggestion
  register(logicalName, redisKey).health = { bucket: 'standalone', onDemand: true };
```

**Option B — add an on-demand guard to the bootstrap loop in `api/health.js`** (lines 125–128 and 138–141):
```js
} else if (!hasData) {
  if (EMPTY_DATA_OK_KEYS.has(name)) { ... }
  else if (ON_DEMAND_KEYS.has(name)) {
    status = 'EMPTY_ON_DEMAND';
    warnCount++;
  } else {
    status = 'EMPTY';
    critCount++;
  }
}
```

Option A is the lower-risk change — it requires no modification to `api/health.js`'s runtime logic.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Codex

Comment thread registry/datasets.ts
'resilienceRanking',
] as string[];

HEALTH_ON_DEMAND_KEYS.push('cryptoSectors', 'ddosAttacks', 'economicStress', 'trafficAnomalies');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Pushed on-demand keys have no runtime effect

The four keys pushed here — cryptoSectors, ddosAttacks, economicStress, trafficAnomalies — are all in HEALTH_BOOTSTRAP_KEYS (bucket: 'bootstrap'). Because api/health.js only evaluates ON_DEMAND_KEYS inside the standalone loop, listing them here produces no runtime effect. The push() call also bypasses TypeScript's readonly inference.

If the intent is truly on-demand monitoring semantics, the bucket for these entries should be 'standalone' (see the P1 comment above). If critical-when-empty is acceptable for all bootstrap health keys, this push call and the onDemand: true flag in HEALTH_BOOTSTRAP_ADDITIONS should both be removed to avoid misleading future contributors.

Prompt To Fix With AI
This is a comment left during a code review.
Path: registry/datasets.ts
Line: 527

Comment:
**Pushed on-demand keys have no runtime effect**

The four keys pushed here — `cryptoSectors`, `ddosAttacks`, `economicStress`, `trafficAnomalies` — are all in `HEALTH_BOOTSTRAP_KEYS` (bucket: `'bootstrap'`). Because `api/health.js` only evaluates `ON_DEMAND_KEYS` inside the standalone loop, listing them here produces no runtime effect. The `push()` call also bypasses TypeScript's readonly inference.

If the intent is truly on-demand monitoring semantics, the bucket for these entries should be `'standalone'` (see the P1 comment above). If critical-when-empty is acceptable for all bootstrap health keys, this `push` call and the `onDemand: true` flag in `HEALTH_BOOTSTRAP_ADDITIONS` should both be removed to avoid misleading future contributors.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Codex

@lspassos1
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b801fcb45

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread registry/datasets.ts
Comment on lines +596 to +598
for (const [logicalName, redisKey] of Object.entries(HEALTH_BOOTSTRAP_ADDITIONS)) {
register(logicalName, redisKey).health = { bucket: 'bootstrap', onDemand: true };
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Classify on-demand additions as standalone health keys

These datasets are marked onDemand but still assigned bucket: 'bootstrap', and api/health.js only applies on-demand downgrade logic in the standalone loop. That means a missing value for any of these newly added keys is treated as EMPTY (critical) instead of EMPTY_ON_DEMAND (warning), so cold/evicted caches can incorrectly push overall health to DEGRADED/UNHEALTHY.

Useful? React with 👍 / 👎.

Expand the dataset contract source to cover the existing health semantics, emit an edge-safe health registry, and switch api/health.js to imports without changing the status algorithm.

Validation: npm run registry:check; node --test tests/bootstrap.test.mjs tests/market-breadth.test.mjs tests/customs-revenue.test.mjs tests/resilience-static-seed.test.mjs; node --test tests/edge-functions.test.mjs; npm run typecheck; npm run typecheck:api
Route HEALTH_BOOTSTRAP_ADDITIONS through the standalone bucket so api/health.js downgrades cold or evicted data to EMPTY_ON_DEMAND instead of EMPTY.
Add a regression test covering the generated bucket assignment for the on-demand additions.
@lspassos1 lspassos1 force-pushed the refactor/health-generated-registry branch from 2b801fc to 141a159 Compare April 11, 2026 21:29
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 11, 2026

PR author is not in the allowed authors list.

1 similar comment
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 11, 2026

PR author is not in the allowed authors list.

@lspassos1 lspassos1 marked this pull request as ready for review April 11, 2026 21:31
@lspassos1 lspassos1 changed the base branch from chore/registry-bootstrap-parity to main April 11, 2026 21:32
@lspassos1 lspassos1 merged commit 3624dd4 into main Apr 11, 2026
14 of 15 checks passed
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