From 2da5f16d4b5687f29be59db6a2d6702fa0bbb434 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 25 Oct 2026 20:56:30 +0200 Subject: [PATCH] Starting to resolve the issue on prediction1 --- backend/src/domain/candle-predict/index.ts | 46 +++++++++++++++------- prediqo_mobile/lib/l10n/app_strings.dart | 4 +- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/backend/src/domain/candle-predict/index.ts b/backend/src/domain/candle-predict/index.ts index 2a4b431e..08a5fcfa 100644 --- a/backend/src/domain/candle-predict/index.ts +++ b/backend/src/domain/candle-predict/index.ts @@ -2118,15 +2118,24 @@ export async function executePlaceBetInternal( queueUserAdminStatsRefresh(userId); const mapped = mapBet(bet); + // Redis fan-out must not fail the HTTP bet after ledger/DB commit succeeded. + // A Redis replica READONLY error previously surfaced as a false "DB" failure. if (config.redis.enabled) { - const betVersion = await bumpUserBetVersionSafe(userId, interval.intervalMinutes); - await publishUserEvent(userId, { - type: 'bet.accepted', - payload: { - bet: mapped as unknown as Record, - ...(betVersion != null ? { versions: { bet: betVersion } } : {}), - }, - }); + try { + const betVersion = await bumpUserBetVersionSafe(userId, interval.intervalMinutes); + await publishUserEvent(userId, { + type: 'bet.accepted', + payload: { + bet: mapped as unknown as Record, + ...(betVersion != null ? { versions: { bet: betVersion } } : {}), + }, + }); + } catch (e) { + console.error( + '[candle-predict] post-bet Redis publish failed (bet already committed):', + e instanceof Error ? e.message : e + ); + } } return mapped; @@ -2217,13 +2226,20 @@ export async function placeBet( }); if (config.redis.enabled) { - const timingAfter = getActiveRoundTiming( - Date.now(), - interval.intervalMinutes, - interval.predictionWindowSeconds - ); - if (timingAfter.phase === 'betting') { - await publishRoundSnapshot(interval.intervalMinutes, timingAfter.openMs); + try { + const timingAfter = getActiveRoundTiming( + Date.now(), + interval.intervalMinutes, + interval.predictionWindowSeconds + ); + if (timingAfter.phase === 'betting') { + await publishRoundSnapshot(interval.intervalMinutes, timingAfter.openMs); + } + } catch (e) { + console.error( + '[candle-predict] post-bet round snapshot failed (bet already committed):', + e instanceof Error ? e.message : e + ); } } diff --git a/prediqo_mobile/lib/l10n/app_strings.dart b/prediqo_mobile/lib/l10n/app_strings.dart index d3fb8846..44022192 100644 --- a/prediqo_mobile/lib/l10n/app_strings.dart +++ b/prediqo_mobile/lib/l10n/app_strings.dart @@ -443,8 +443,8 @@ class AppStrings { String get placeMultiBet => placeMultiPrediction; String get predictionPlaced => t('Prediction placed', 'Prédiction placée'); String get predictionDbReadonly => t( - 'Server database is in read-only mode. Predictions cannot be saved right now — check DATABASE_URL points to the primary database.', - 'La base de données du serveur est en lecture seule. Les prédictions ne peuvent pas être enregistrées — vérifiez que DATABASE_URL pointe vers la base principale.', + 'Realtime cache (Redis) is read-only. Your prediction may still have been saved — check Recent predictions, then restart Redis as a primary (not a replica).', + 'Le cache temps réel (Redis) est en lecture seule. Votre prédiction a peut‑être quand même été enregistrée — vérifiez l’historique, puis redémarrez Redis en mode primaire (pas réplique).', ); String stakeAmountTitle(String coin) => t('Amount ($coin)', 'Montant ($coin)'); String stakeAmountHint(num min, num max) => t(