Skip to content

Fix stale race cache and update agent suggested prompts#99

Merged
Bitpass-dev merged 2 commits intomainfrom
copilot/fix-response-cache-stale-data
Mar 15, 2026
Merged

Fix stale race cache and update agent suggested prompts#99
Bitpass-dev merged 2 commits intomainfrom
copilot/fix-response-cache-stale-data

Conversation

Copy link

Copilot AI commented Mar 15, 2026

Response cache was serving stale "next race" answers across hour boundaries because the cache key didn't include time-of-day. Separately, agent chat panel suggested prompts were generic/future-focused rather than today-focused.

Backend — chat.ts

  • Cache key now includes current hour — prevents same question asked at 2pm and 3:30pm from hitting the same cache entry with an already-run race
  • TTL reduced from 60 min → 10 min — limits staleness window for time-sensitive racing queries
// Before
const cacheKey = `${sport}:${targetDate}:${trimmed}`;

// After
const cacheKey = `${sport}:${targetDate}:${new Date().toISOString().slice(0, 13)}:${trimmed}`;

Frontend — AgentChatPanel.tsx

  • Replaced all sport-specific and default fallback suggested prompts with three today-focused prompts applied uniformly across horse_racing, soccer, golf, and the default fallback:
    • "What's the best bet today across all cards?"
    • "Give me your top five selections for today"
    • "Any market movers today?"
Original prompt

Two fixes needed

Fix 1 — Response cache serves stale race data (wrong next race shown)

File: AI-Sports-Almanac/backend/src/api/routes/chat.ts

Problem: The response cache key is ${sport}:${targetDate}:${trimmed}. This means if a user asks "give me your tip for the next race please" at 2:00pm, the answer is cached. When they ask the same question at 3:30pm, they get the cached 2:00pm answer (the already-run race) instead of the 3:30pm next race.

Fix: Include the current hour in the cache key so the cache expires every hour:

Find this line:

const cacheKey = `${sport}:${targetDate}:${trimmed}`;

Replace with:

const currentHour = new Date().toISOString().slice(0, 13); // "2026-03-15T15"
const cacheKey = `${sport}:${targetDate}:${currentHour}:${trimmed}`;

Also reduce the cache TTL from whatever it currently is to 10 minutes for horse racing queries to ensure fresher data. Find CACHE_TTL_MS and if it's longer than 10 minutes, change it to:

const CACHE_TTL_MS = 10 * 60 * 1000; // 10 minutes

Fix 2 — Update suggested prompts in the agent chat panel

File: AI-Sports-Almanac/frontend/components/AgentChatPanel.tsx

Problem: The current suggested prompts are generic and not today-focused. Need to update them.

Current SUGGESTED_PROMPTS:

const SUGGESTED_PROMPTS: Record<string, string[]> = {
  horse_racing: [
    'Who should I back in tomorrow\'s races?',
    'Best each-way bets this week?',
    'Any big market movers to watch?',
  ],
  soccer: [
    'Who wins the big match this weekend?',
    'Best accumulator picks?',
    'Any value bets in the Premier League?',
  ],
  golf: [
    'Who\'s the favourite at this week\'s tournament?',
    'Best each-way picks for the weekend?',
    'Course specialist tips?',
  ],
};

And the default fallback:

  return [
    'What\'s your top prediction today?',
    'Any high confidence picks?',
    'What markets do you recommend?',
  ];

Replace ALL suggested prompts with the new ones below. ALL sport categories (horse_racing, soccer, golf) AND the default fallback should use these same three prompts:

const SUGGESTED_PROMPTS: Record<string, string[]> = {
  horse_racing: [
    'What\'s the best bet today across all cards?',
    'Give me your top five selections for today',
    'Any market movers today?',
  ],
  soccer: [
    'What\'s the best bet today across all cards?',
    'Give me your top five selections for today',
    'Any market movers today?',
  ],
  golf: [
    'What\'s the best bet today across all cards?',
    'Give me your top five selections for today',
    'Any market movers today?',
  ],
};

And update the default fallback to:

  return [
    'What\'s the best bet today across all cards?',
    'Give me your top five selections for today',
    'Any market movers today?',
  ];

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: ok both merged ?

Assistant: Let me check!

Assistant: ✅ Both merged successfully!

PR Title Merged At
#98 Fix 4 live data & agent bugs 15:21 today
#95 Fix system prompt rules across all 10 agents 15:22 today

Now you need to deploy to your VPS. Run this:

cd /root/awesome-intercom/AI-Sports-Almanac
git pull origin main
docker compose up -d --build backend

Also — add the ADMIN_EMAILS env var before restarting (from PR #98):

echo "ADMIN_EMAILS=info@akrido.com" >> .env
docker compose up -d --build backend

That single restart will deploy all the fixes:

  • ✅ ⏰ Next race filtering by current time
  • ✅ All UK Jumps meetings showing (Chepstow etc.)
  • ✅ Full Irish flat cards including late races
  • ✅ Your account permanently bypasses tier check
  • ✅ All 10 agents never ask users to paste data again

🚀

User: ok done !

Assistant: Now pull and rebuild on your VPS to deploy everything:

cd /root/awesome-intercom/AI-Sports-Almanac
git pull origin main
docker compose up -d --build backend

That single command will:

  • Pull both merged PRs from main
  • Rebuild the backend container with all fixes
  • Restart cleanly — takes about 60-90 seconds

Once it's done, test an agent and let me know how it goes! 🏇

User: done

Assistant: 🎉 Perfect — everything deployed successfully!

✅ Image ai-sports-almanac-backend    Built
✅ Container ai-sports-almanac-postgres-1  Healthy
✅ Container ai-sports-almanac-backend-1   Started

All fixes are now LIVE on your server. Here's what's active right now:

Fix Status
⏰ Next race filtering by current time ✅ Live
📍 All UK Jumps venues (Chepstow etc.) ✅ Live
🏇 Full Irish flat cards ✅ Live
🔐 Admin email bypass for tier check ✅ Live
🤖 All 10 agents never ask users to paste data ✅ Live

Go test it now — ask any horse racing agent:

*"tip for next ...

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: Bitpass-dev <186615221+Bitpass-dev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix stale race data in response cache Fix stale race cache and update agent suggested prompts Mar 15, 2026
Copilot AI requested a review from Bitpass-dev March 15, 2026 15:43
@Bitpass-dev Bitpass-dev marked this pull request as ready for review March 15, 2026 15:50
@Bitpass-dev Bitpass-dev merged commit 7375b0c into main Mar 15, 2026
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.

2 participants