fix(resilience): apply 7 review fixes that didn't reach main#2729
fix(resilience): apply 7 review fixes that didn't reach main#2729
Conversation
These fixes were applied during review of PRs #2660/#2662 but those PRs merged to feature branches, not main. PR #2673 reimplemented handlers for main but omitted the review feedback. Fixes: 1. Remove cronbach > 0 guard (negative alpha = worse reliability) 2. Increase cachedFetchJson timeout 300ms → 2000ms (15+ Redis RTTs) 3. Import round() from resilience-stats (remove duplicate) 4. Restore HTTP status logging in runRedisPipeline 5. Register resilienceRanking in health.js (STANDALONE + SEED_META + ON_DEMAND) 6. Write seed-meta:resilience:ranking on complete ranking materialization 7. Use atomic pipeline for ranking + meta (both succeed or fail together)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR backports 7 review fixes from feature branches that were omitted when PR #2673 reimplemented the resilience handlers for Key changes:
Confidence Score: 4/5Safe to merge — all 7 fixes are targeted bug fixes with no new functionality, and the logic is straightforward and well-understood Score of 4 (not 5) because (a) the diff is not available for direct inspection so analysis is based on the current file state, and (b) fix #2 (negativeTtlSeconds change) cannot be fully verified without seeing the before state. All visible code paths look correct. server/worldmonitor/resilience/v1/_shared.ts — the negativeTtlSeconds=2000 argument is unreachable (fetcher never returns null) and could mislead future readers; server/worldmonitor/resilience/v1/get-resilience-ranking.ts — meta key constant is defined locally rather than co-located with sibling constants in _shared.ts Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant RankingHandler as get-resilience-ranking.ts
participant SharedLib as _shared.ts
participant Redis as Redis (Upstash)
participant Health as api/health.js
Client->>RankingHandler: getResilienceRanking()
RankingHandler->>Redis: getCachedJson('resilience:ranking')
Redis-->>RankingHandler: null (cache miss)
RankingHandler->>SharedLib: listScorableCountries()
SharedLib->>Redis: getCachedJson(RESILIENCE_STATIC_INDEX_KEY)
Redis-->>SharedLib: country list
SharedLib-->>RankingHandler: ["US", "DE", ...]
RankingHandler->>SharedLib: getCachedResilienceScores(countryCodes)
SharedLib->>Redis: runRedisPipeline([GET score:US, GET score:DE, ...])
Redis-->>SharedLib: cached scores
SharedLib-->>RankingHandler: Map<code, score>
Note over RankingHandler: warmMissingResilienceScores() if needed
RankingHandler->>SharedLib: ensureResilienceScoreCached(missing[])
SharedLib->>Redis: cachedFetchJson (score computation)
Redis-->>SharedLib: stored
RankingHandler->>RankingHandler: sortRankingItems()
Note over RankingHandler: Fix #7: atomic write
RankingHandler->>Redis: runRedisPipeline([\n SET resilience:ranking EX 21600,\n SET seed-meta:resilience:ranking EX 604800\n])
RankingHandler-->>Client: { items: [...] }
Health->>Redis: STRLEN resilience:ranking
Health->>Redis: GET seed-meta:resilience:ranking
Redis-->>Health: { fetchedAt, count }
Health->>Health: seedAge > 720min? → STALE_SEED
|
| const RESILIENCE_RANKING_META_KEY = 'seed-meta:resilience:ranking'; | ||
| const RESILIENCE_RANKING_META_TTL_SECONDS = 7 * 24 * 60 * 60; |
There was a problem hiding this comment.
Meta key constant not co-located with sibling constants
RESILIENCE_RANKING_META_KEY and RESILIENCE_RANKING_META_TTL_SECONDS are defined locally here, but all related resilience cache constants (RESILIENCE_RANKING_CACHE_KEY, RESILIENCE_RANKING_CACHE_TTL_SECONDS, etc.) live in _shared.ts. The meta key string 'seed-meta:resilience:ranking' is also hardcoded independently in api/health.js (line 257). If the key ever changes, both sites must be updated manually.
Consider moving these to _shared.ts and exporting them:
// in _shared.ts
export const RESILIENCE_RANKING_META_KEY = 'seed-meta:resilience:ranking';
export const RESILIENCE_RANKING_META_TTL_SECONDS = 7 * 24 * 60 * 60;Then import in the handler and reference from health.js as documentation.
Summary
PRs #2660 and #2662 merged to feature branches, not main. When #2673 reimplemented handlers for main, it omitted the review fixes we applied during code review. This PR backports all 7 fixes.
Fixes
cronbach > 0 &&guard skips negative alphalowConfidence: falseoverallScore: 0round()functionrunRedisPipelineswallows HTTP errors silentlyconsole.warnwith status coderesilienceRankingnot in health.jsTest plan
npm run typecheck+npm run typecheck:apinpx tsx --test tests/resilience-handlers.test.mts tests/resilience-stats.test.mts tests/resilience-dimension-scorers.test.mtsresilienceRankingafter first Pro ranking request