Repository navigation
Description
What happens
ws-server caches a session's questions in Redis for four hours:
// apps/ws-server/src/utils/cache.ts
const TTL = {
QUESTIONS: 60 * 60 * 4, // 4 hour
}http-server is what adds, edits and deletes questions — and it has no Redis client at all. There is no redis or ioredis dependency in apps/http-server/package.json, and no invalidation call anywhere in quizController.ts.
So nothing ever clears quiz:questions:${sessionId} when the question list changes. clearSessionCache runs only when a session ends, inside ws-server.
Why it matters
This is most likely what people hit when AI-generated questions "don't work like normal questions" — the questions save correctly, but the running quiz never sees them.
Concretely, once a session has started and the cache is warm:
- Add questions (by hand or via AI) → they are in Postgres, in the quiz builder, and absent from the live quiz
- Edit a question's text or answers → players still get the old version
- Delete a question → it still appears, and
quiz:next-questioncan serve a question that no longer exists
The window is up to four hours, or until the session ends. It is not specific to AI — AI generation just makes it easy to hit, because adding a batch of questions is the natural thing to do right after creating a quiz and opening the lobby to check it.
Worth noting the session cache was given this attention: invalidateSession exists, and there is a comment in startQuizSessionController about a fresh session id not being servable stale. The question cache never got the same treatment.
The fix
The clean shape is for http-server to invalidate the key whenever the question list changes. That means giving it a small Redis client — the key name is already public (Keys.questions in ws-server's cache.ts), and it only needs del.
Touch points in apps/http-server/src/controllers/quizController.ts:
createQuestionControllerupdateQuestionControllerdeleteQuestionController
A session id is needed to build the key, so the controllers must resolve the quiz's sessions (prisma.quizSession.findMany({ where: { quizId, status: { in: ['WAITING', 'ACTIVE'] } } })) and clear each one.
Two alternatives worth considering in the issue discussion before coding:
- Shorter TTL. Simple, but only narrows the window rather than closing it.
- Publish an invalidation message over the Redis channel ws-server already subscribes to. Avoids http-server knowing cache key names, and fits the existing pub/sub design.
Either way this needs a decision first — worth commenting before starting.
Related
A fix should also make sure the editing guard still behaves: updateQuestionController refuses to edit a question anyone has already answered (409), which is correct and should stay.
Files
apps/http-server/src/controllers/quizController.tsapps/ws-server/src/utils/cache.ts—Keys.questions,TTL.QUESTIONS
Activity
divyanshAgarwal123 commentedon Nov 25, 2026
Could you assign #259 to me and approve the direct-invalidation design you suggested? I checked main
dc7a83c: http-server still has no Redis dependency/client, question create/update/delete perform DB mutations without clearing the ws-server question key, and its TTL remains four hours. I propose a small configured http-server Redis client, resolving the quiz’s WAITING/ACTIVE sessions and deleting their question-cache keys only after a successful committed question mutation. This closes the stale-cache window rather than merely shortening the TTL. I would document the Redis environment wiring and coordinate the shared key contract with ws-server.Tests would cover create/update/delete with multiple active sessions, unrelated/ended sessions, failed/rolled-back mutations, cache failures, fresh subsequent loads, and preservation of the answered-question 409 guard, followed by full http/ws-server tests and existing CI. If you prefer your pub/sub option, please say so before allocation and I will follow that contract instead. This does not change #243 frontend files or duplicate #244 PDF caching. #242’s configuration stage is ready as #265; no new implementation has started. Please confirm actual assignment/design and your active-issue limit before allocating additional slots. The existing
nsoc26/level3labels remain subject to your final review.harshvardhan60792 commentedon Nov 28, 2026
If this is still open for assignment, I'd also be glad to take it. I'd add cache invalidation for
quiz:questions:<sessionId>whenever http-server creates, updates or deletes a question, with tests for each path. Happy to leave it if you'd rather give it to someone who asked earlier.