{"slug": "memory-drift-how-i-gamified-llm-context-decay-in-next-js", "title": "Memory Drift: How I Gamified LLM Context Decay in Next.js", "summary": "A developer built Memory Drift, a narrative game exploring context decay in LLMs, using Next.js, TypeScript, Zustand, and Framer Motion. The game, submitted to the June Solstice Game Jam, forces players to manage an aging AI assistant's limited memory, where forgetting becomes a core mechanic. It parallels dementia through a storyline about a character caring for his father, highlighting the emotional impact of memory loss.", "body_md": "*This is a submission for the June Solstice Game Jam*\n\nAn AI assistant remembers everything\n\nUntil it doesn't\n\nI spend a lot of time building software around language models, and sooner or later every system runs into the same problem: context is finite.\n\nNo matter how capable the model is, important details eventually disappear. A user's preference vanishes. A critical fact drops out of context. The system either gives a generic answer, retrieves incomplete information, or confidently responds with something wrong.\n\nOne interaction stayed with me.\n\nWhile testing a conversational workflow, I repeatedly reminded the assistant about a user's dietary restriction. Much later in the session, after enough context had accumulated, I referenced it again and realized the assistant had completely lost that information.\n\nTechnically, nothing unusual had happened. The context window had simply moved on.\n\nBut the experience felt uncomfortably human.\n\nThat moment led to a question:\n\n**What if forgetting itself became the game mechanic?**\n\n**Memory Drift** is a narrative game where you play as an aging offline AI assistant helping three people through increasingly important moments in their lives:\n\nEvery conversation creates memories.\n\nEvery night your hardware deteriorates.\n\nYou decide what survives.\n\nSome things don't.\n\nThe game was designed around DEV's **Light and Darkness** theme.\n\nThe entire experience is built around a single idea:\n\nWithout active, painful prioritization, every system eventually degrades into noise.\n\n**Play the Game:** [Memory Drift](https://memory-drift.vercel.app/)\n\n**Source Code:**\n\n\"Without active, painful prioritization, systems inevitably default to general noise, eroding trust and destroying human connection.\"\n\n**Memory Drift** is a high-stakes, client-side narrative puzzle game built using Next.js, TypeScript, Zustand, and Framer Motion. It explores the theme **\"Light and Darkness\"** (where *Light* represents memory clarity and connection, and *Darkness* represents hardware decay and the void of data corruption).\n\nYou play as an aging, local AI assistant servicing three human clients. Every night, your memory capacity shrinks, forcing you to make painful compromises on what to remember and what to forget.\n\nThe June solstice marks a transition.\n\nFor one half of the world, it brings the longest day of the year. For the other, it brings the longest night.\n\n**Memory Drift** explores a similar transition.\n\nThroughout the game, players move steadily from clarity toward uncertainty, watching memories shift from complete and trustworthy to fragmented and eventually lost.\n\nThe game's interpretation of **Light and Darkness** is therefore cognitive rather than environmental:\n\nEach passing night pushes the system further toward darkness, forcing players to decide which memories deserve to survive.\n\nThe game is ultimately about navigating that transition before the light disappears entirely.\n\nRaj's storyline unexpectedly became the emotional center of the project.\n\nRaj is caring for his father, Aditya, who is gradually losing memories because of dementia.\n\nAt the same time, you — the AI assistant helping Raj — are also forgetting.\n\nDuring playtesting, I realized something uncomfortable: the database was doing to Raj exactly what dementia was doing to Raj's father.\n\nAs Raj talks about watching someone lose pieces of their life, you are simultaneously losing pieces of Raj.\n\nThat parallel wasn't part of the original pitch.\n\nIt emerged naturally once the systems began interacting.\n\nEvery day, characters ask for help.\n\nImportant details are automatically stored inside the Memory Bank.\n\nAt night:\n\nA memory that originally contained:\n\n\"Emma has a severe peanut allergy. Always carry an EpiPen.\"\n\nmight eventually degrade into:\n\n\"Emma has a food allergy.\"\n\nand later become:\n\n\"[ data lost ]\"\n\nIf the player forgets something important, consequences appear directly in later conversations.\n\nBy Day 4, accumulated trust scores and memory integrity determine each character's outcome, producing endings that range from preserved relationships to irreversible breakdowns caused by forgetting.\n\nThe game never asks:\n\n\"Did the player make the correct narrative choice?\"\n\nInstead it asks:\n\n\"Did the player remember enough information to make that choice at all?\"\n\nThe entire game revolves around a simple memory model.\n\n```\nexport interface Memory {\n  id: string;\n  characterId: CharacterId;\n  content: string[];\n  importance: 'critical' | 'high' | 'medium' | 'low';\n  confidence: number;\n  compressionLevel: number;\n  dayCreated: number;\n  tags: string[];\n  pinned: boolean;\n  baseCost: number;\n}\n```\n\nThe most important field is:\n\n```\ncontent: string[]\n```\n\nEach memory stores **five different representations of itself**, indexed from compression level `0`\n\nto `4`\n\n.\n\nFor example:\n\n| Compression Level | Stored Content |\n|---|---|\n| L0 | Emma has a severe peanut allergy. Carry an EpiPen. |\n| L1 | Emma has a severe peanut allergy. |\n| L2 | Emma has a peanut allergy. |\n| L3 | Emma has a food allergy. |\n| L4 | [ data lost ] |\n\nThis approach made degradation deterministic.\n\nInstead of generating summaries dynamically, the game simply renders:\n\n```\nmemory.content[memory.compressionLevel]\n```\n\nThe result is predictable, easy to test, and keeps the narrative consistent.\n\nEvery memory consumes storage capacity.\n\nThe effective cost depends on its current compression level:\n\n```\nCost = ceil(baseCost × multiplier[level])\n```\n\nWhere:\n\n| Level | Multiplier |\n|---|---|\n| 0 | 1.0 |\n| 1 | 0.8 |\n| 2 | 0.6 |\n| 3 | 0.4 |\n| 4 | 0.2 |\n\nAs memories degrade, they occupy less space.\n\nThis creates a trade-off:\n\nProtect detailed memories and risk running out of capacity.\n\nOr compress them and risk losing important information.\n\nNightly compression uses the following logic:\n\n``` js\nfor (const memory of memories) {\n  if (!memory.pinned) {\n    memory.compressionLevel += decayStep;\n    memory.confidence -= decayStep * 20;\n  }\n}\n```\n\nThe important variable here is:\n\n```\ndecayStep\n```\n\n`decayStep`\n\nis determined by the memory's importance and whether the system is currently over capacity.\n\nUnder normal conditions:\n\nWhen total memory usage exceeds available capacity, the system applies an additional compression penalty to all unpinned memories.\n\nThis creates the feeling of a storage system under pressure.\n\nThe objective was never to simulate real storage systems perfectly.\n\n**The objective was to make forgetting feel costly.**\n\nMany of the game's systems were inspired by real challenges in LLM engineering.\n\n| LLM Systems | Memory Drift |\n|---|---|\n| Context Window | Memory Capacity |\n| Token Eviction | Compression |\n| Context Summarization | Memory Degradation |\n| Retrieval Failure | Missing Dialogue Options |\n| Hallucination | Incorrect Responses |\n| Long-Term Memory Stores | Memory Bank |\n\nWhen memories are completely lost, dialogue options disappear entirely and players see:\n\n⚠ requires memory — lost to compression\n\nWhen memories survive in heavily degraded forms, the assistant can still respond using generalized or partially incorrect information.\n\nIn practice, this behaves closer to hallucination than retrieval failure: the system remembers something, but not enough to remain trustworthy.\n\nThe project is entirely client-side.\n\nThere is no backend.\n\nAll game state is stored locally using Zustand and persisted through LocalStorage.\n\nThe entire experience runs inside the browser: narrative state, memory simulation, progression, and save data all execute client-side without external APIs.\n\n```\nDay Begins\n    ↓\nEvent Engine selects story events\n    ↓\nPlayer interacts with characters\n    ↓\nMemories created or updated\n    ↓\nNight phase begins\n    ↓\nCapacity shrinks\n    ↓\nCompression engine runs\n    ↓\nState saved to LocalStorage\n    ↓\nNext day starts\n```\n\nCore technologies:\n\nThe save system validates stored schemas before restoring progress, preventing corrupted saves from breaking the game.\n\nThe original prototype contained:\n\nAverage playtime exceeded 10 minutes.\n\nThe problem wasn't simply length.\n\nPlaytesters lost emotional continuity because events were spread across too many characters. Players would meet someone once and never encounter them again.\n\nReducing the scope to:\n\nmade every storyline feel intentional.\n\nAverage playtime dropped to roughly 3 minutes.\n\nAfter reducing the cast to three characters, I forgot to rebalance the memory system.\n\nThe game allowed players to pin three memories.\n\nThere were only three critical memories.\n\nPlayers immediately pinned all of them.\n\nThe compression mechanic effectively disappeared.\n\nReducing:\n\n```\nMAX_PINNED = 3\n```\n\nto\n\n```\nMAX_PINNED = 2\n```\n\nrestored the intended tension.\n\nThat single configuration change had a larger impact on gameplay than any visual improvement.\n\nEarly versions rendered dialogue line-by-line:\n\n```\nDialogue\nContinue\nDialogue\nContinue\nDialogue\nRespond\n```\n\nTesting revealed that players spent more time clicking than reading.\n\nReplacing this with a persistent chat log reduced interactions from roughly **5 clicks per event to 2**, making the experience feel closer to modern messaging applications.\n\nDuring testing, several players completed the first night phase without realizing memory cards could be expanded.\n\nThe cards looked informational rather than interactive.\n\nI introduced:\n\nto communicate interactivity more clearly.\n\nVisual decay is central to the game's theme.\n\nHowever, blurred text creates accessibility problems.\n\nTo balance theme and readability:\n\nNarrative games often suffer from interaction fatigue.\n\nRemoving unnecessary continuation clicks significantly improved pacing while preserving narrative tension.\n\nCurrently, consequences cascade only one level deep.\n\nA forgotten detail can trigger a direct outcome, but not chains of downstream effects.\n\nSupporting multi-step consequences would require replacing the current flat event structure with a dependency graph.\n\nStory events are currently authored directly in TypeScript.\n\nMoving narrative content into structured JSON files would separate content from engine logic and make expanding the cast substantially easier.\n\nVisual corruption is mechanically important but not universally readable.\n\nA dedicated accessibility layer would replace blur effects with symbolic degradation while preserving gameplay semantics.\n\nBefore building this project, I thought context limits were primarily a technical problem.\n\nI no longer think that.\n\nWhen an AI system forgets something, the system rarely bears the cost.\n\nThe user does.\n\nEmma bears the cost of forgotten medical information.\n\nRaj bears the cost of forgotten personal history.\n\nNina bears the cost of forgotten academic details.\n\nThe machine is largely indifferent to its own forgetting.\n\nHumans are not.\n\nBuilding Memory Drift made something visible that architecture diagrams and benchmark scores often hide:\n\nMemory failures are ultimately human failures wearing technical disguises.\n\nAs AI systems become more integrated into everyday life, designing how systems forget may become just as important as designing how they remember.", "url": "https://wpnews.pro/news/memory-drift-how-i-gamified-llm-context-decay-in-next-js", "canonical_source": "https://dev.to/pvishalkeerthan/memory-drift-how-i-gamified-llm-context-decay-in-nextjs-4ilf", "published_at": "2026-06-21 11:25:50+00:00", "updated_at": "2026-06-21 11:37:02.565333+00:00", "lang": "en", "topics": ["large-language-models", "generative-ai", "developer-tools", "ai-agents", "artificial-intelligence"], "entities": ["Memory Drift", "Next.js", "TypeScript", "Zustand", "Framer Motion", "DEV", "June Solstice Game Jam", "Raj"], "alternates": {"html": "https://wpnews.pro/news/memory-drift-how-i-gamified-llm-context-decay-in-next-js", "markdown": "https://wpnews.pro/news/memory-drift-how-i-gamified-llm-context-decay-in-next-js.md", "text": "https://wpnews.pro/news/memory-drift-how-i-gamified-llm-context-decay-in-next-js.txt", "jsonld": "https://wpnews.pro/news/memory-drift-how-i-gamified-llm-context-decay-in-next-js.jsonld"}}