fix(relay): envelopeRead for OREF_REDIS_KEY bootstrap (Greptile P1)

orefPersistHistory() writes OREF_REDIS_KEY via envelopeWrite at line 1133,
but the bootstrap reader at line 1214 was still using raw upstashGet.
cached.history was therefore undefined and Array.isArray() always false,
so OREF alert history was never restored from Redis after a relay restart
— every cold start hit the upstream API unnecessarily.

Also adds the two regression guards Greptile flagged as missing:
- loadWsbTickerSet() reading market:stocks-bootstrap:v1 via envelopeRead
- orefBootstrapFromRedis reading OREF_REDIS_KEY via envelopeRead

Same class of bug as the three callsites fixed earlier in this PR.
This commit is contained in:
Elie Habib
2026-04-17 08:01:54 +04:00
parent fefaeae60a
commit 445f907253
2 changed files with 21 additions and 1 deletions

View File

@@ -1211,7 +1211,10 @@ async function orefBootstrapHistoryWithRetry() {
// Phase 1: try Redis first
try {
const cached = await upstashGet(OREF_REDIS_KEY);
// envelopeRead unwraps the {_seed, data} shape written by orefPersistHistory()
// at line 1133. Reading raw left cached.history undefined, so OREF state was
// never restored across relay restarts (reported in PR #3139 review).
const cached = await envelopeRead(OREF_REDIS_KEY);
if (cached && Array.isArray(cached.history) && cached.history.length > 0) {
const valid = cached.history.every(
h => Array.isArray(h.alerts) && typeof h.timestamp === 'string'

View File

@@ -522,6 +522,23 @@ describe('seedTransitSummaries Redis reads', () => {
assert.doesNotMatch(relaySrc, /const persisted = await upstashGet\(CORRIDOR_RISK_REDIS_KEY\)/);
});
it('loadWsbTickerSet reads market:stocks-bootstrap:v1 via envelopeRead', () => {
// Regression guard (Greptile review PR #3139): market:stocks-bootstrap:v1 is
// written via envelopeWrite at lines 1867 + dual-write elsewhere. Reading raw
// left data.quotes undefined, silently disabling WSB ticker matching.
assert.match(relaySrc, /envelopeRead\('market:stocks-bootstrap:v1'\)/);
assert.doesNotMatch(relaySrc, /upstashGet\('market:stocks-bootstrap:v1'\)/);
});
it('OREF bootstrap reads OREF_REDIS_KEY via envelopeRead (parity with orefPersistHistory)', () => {
// Regression guard (Greptile review PR #3139): orefPersistHistory() writes via
// envelopeWrite. Reading raw left cached.history undefined, so OREF history
// was never restored across relay restarts — every cold start hit the
// upstream API unnecessarily.
assert.match(relaySrc, /const cached = await envelopeRead\(OREF_REDIS_KEY\)/);
assert.doesNotMatch(relaySrc, /const cached = await upstashGet\(OREF_REDIS_KEY\)/);
});
it('PortWatch Redis read is the first statement (before early return)', () => {
const fnBody = relaySrc.match(/async function seedTransitSummaries\(\)\s*\{([\s\S]*?)\n\}/)?.[1] || '';
const readPos = fnBody.indexOf('envelopeRead(PORTWATCH_REDIS_KEY)');