[GH-ISSUE #6696] [Feature]: Game Mode long campaigns: campaign-wide memory, continuity, Campaign Wiki and cache-stable Game prompts #3751

Closed
opened 2026-10-21 06:06:50 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @SirAdoni on GitHub (Sep 26, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6696

Originally assigned to: @SpicyMarinara on GitHub.

Part of the contribution roadmap in #6624 (Game Mode theme 1 of 3).

What problem does this solve?

Game Mode works well within a session. Across a long campaign of many sessions, a few things get harder:

  • Each new session starts with little of what happened before. Facts, who knows what, and the last known state of people and places live in earlier session chats, and the GM only sees a recap.
  • Recaps drift. Names, possessions and relationships in the "previously on" recap can come out slightly wrong, and a long recap can time out.
  • There's no place to read or correct what the campaign "knows", so a wrong fact keeps coming back.
  • NPCs slip. A character named in narration may never get tracked, a death or a move never reaches the NPC list, and the journal keeps adding stale "Tracked at" lines.
  • Long Game prompts cache poorly. Session-level blocks (memory, continuity, map context, NPC cards, output format) sit after the history and are rewritten every turn, so a subscription Game turn can end up 55 to 65% cached.
  • GM turns always run at the highest reasoning effort, which makes some models slow and expensive for every turn.

Proposed solution

These build on what Game Mode already has: the session recap, the Lorebook Keeper, the journal, the NPC tracking and the cache-friendly prompt work in package F.

Campaign memory

  • A read-only campaign view, so a new session sees the facts, knowledge and last known state from every earlier session of the same game. It can be set per chat to "this session only".
  • A readable GM memory block: names instead of ids, a session tag on each fact, pinned canon first, then the people present, then keyword matches, within a budget (10,000 characters by default).
  • Pin a fact as canon, correct it, or mark it wrong so it stays hidden in every session.
  • The session recap is checked against this memory, and its timeout is longer.
  • Party members carry their own memory into the next session.
  • Session conclusion salvage: a conclusion whose model output is slightly malformed is repaired instead of lost.

Continuity pipeline (per game, off until turned on)

  • After turns, a background pass extracts, reviews and publishes facts into the game's Lorebook Keeper book, which the Keeper and memory then share.
  • It salvages imperfect model output, splits a cut-off batch instead of failing it, parks a chat with no usable connection on its own, and offers one "Retry all" for failed batches.
  • Campaign indexing and backfill for games that already have history: resumable and cancellable.

Campaign Wiki

  • A reader for the campaign: a front page, one page per person, place, item or quest across sessions, a campaign timeline, open promises, a canon page, "what links here", and a side-by-side view for reviewing duplicates.
  • A Memory panel that explains how the GM uses memory, with the budget and recap settings.
  • A Markdown or JSON campaign codex export.

NPCs and scenes

  • A scene timeline after each GM turn feeds who is present and the recap's scene index.
  • Missing NPCs recovered from transcripts, stable NPC ids shared by client and server, optional isolated NPC knowledge, and NPC status and location updates from the session conclusion (the journal replaces its stale line instead of adding another).

Game prompt caching and cost

  • Cache-stable Game prompt (Claude subscription): session-level blocks go into a per-chat cached baseline before the history, and only small changes and live values ride after the last exchange. Measured on a copy of a real Game chat: from about 74% to about 96% of each request read from cache.
  • Session-frozen NPC cards: a reworded card is sent as a small update until the next session instead of rewriting the cached prefix; rewordings without a fact change are not saved.
  • Stable lore order: newly matched lorebook entries are appended instead of inserted, and a flickering keyword may linger a couple of turns.
  • ChatGPT history replay: Game turns reuse the previous expanded prompt and append the newest state.
  • Final checks and World Maps context placed so they stop breaking the prefix.
  • A per-game GM reasoning effort. Its Default keeps today's behaviour.

How it's switched: every piece sits behind a switch or a per-game or per-chat setting: the continuity pipeline (per game), campaign memory scope (per chat), Scene timeline (per game), ChatGPT history replay, Cache-stable Game prompt, Session-frozen NPC cards, Stable lore order (with Linger turns) and the final-checks opt-in (per chat). The fork turns most of them on; the upstream versions will default off, and off keeps today's prompts and data byte for byte, checked by regressions that compare the off path with staging.

  • Areas touched (for spotting overlap):
    • packages/server/src/services/game: campaign memory, continuity, session summary and conclusion, scene timeline, NPC sync and backfill, named-card cache, GM prompts, Lorebook Keeper integration, codex
    • packages/server/src/services/generation: GM prompt runtime, game lore prompt, new stable layout and history replay modules
    • packages/server/src/services/lorebook: stable lore order; services/llm/providers: ChatGPT cache helper, Anthropic marker placement
    • packages/server/src/routes: generate, game, new campaign memory, campaign index and continuity routes
    • packages/server/src/db/schema and services/storage: campaign memory and game continuity tables
    • Client components/game: Campaign Wiki, Memory panel, continuity panel, scene timeline, GM reasoning effort section
    • packages/shared: memory and continuity types, NPC id helpers, feature switch registry
  • Size: about 270 files and 70,000 added lines, including regressions. It will be split into several PRs of well under 150 files each (memory, continuity, wiki, NPCs, Game caching).
  • Status: implemented and tested in a fork, used over multi-session campaigns.

Alternatives considered

  • A longer recap instead of memory: recaps grow and still lose detail; a queried memory block stays within a fixed budget.
  • Putting memory straight into lorebooks: the pipeline does publish into the Keeper's book, so lorebook users see it, but facts need provenance, retraction and per-session state that plain entries don't carry.
  • Making the Game caching changes default on: they change prompt order, so they stay opt-in upstream.

Additional context

  • The Game caching parts also build on package F (prompt caching) in #6624.
  • Implementation depends on #6647 (foundations); PRs will follow once it merges, one package at a time.
  • If you're working in any of these areas, please comment so we can coordinate before a PR.

Screenshots

Taken from the fork build with invented demo data (characters, lorebooks and a campaign made up for these shots). Model replies and token counts come from a local test stub, so no real model was called.

Campaign Wiki front page: people, player characters, organizations and lore across sessions, with recent changes.

Campaign Wiki front page

A wiki page: facts grouped by session, the source quote, who else knows it, and Correct or Wrong.

A wiki page

The Memory panel: mode, how the GM uses memory, campaign or session scope, and the memory budget.

The Memory panel

A concluded session's recap with resume point, discoveries, character moments and NPC updates.

A concluded session's recap with resume point, discoveries, character moments and NPC updates

Indexing an existing campaign: what will be read, per-session progress, and a quota warning before anything starts.

Indexing an existing campaign

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @SirAdoni on GitHub (Sep 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6696 Originally assigned to: @SpicyMarinara on GitHub. <!-- roadmap theme issue 1, draft v1.0 --> Part of the contribution roadmap in #6624 (Game Mode theme 1 of 3). ## What problem does this solve? Game Mode works well within a session. Across a long campaign of many sessions, a few things get harder: - **Each new session starts with little of what happened before.** Facts, who knows what, and the last known state of people and places live in earlier session chats, and the GM only sees a recap. - **Recaps drift.** Names, possessions and relationships in the "previously on" recap can come out slightly wrong, and a long recap can time out. - **There's no place to read or correct what the campaign "knows"**, so a wrong fact keeps coming back. - **NPCs slip.** A character named in narration may never get tracked, a death or a move never reaches the NPC list, and the journal keeps adding stale "Tracked at" lines. - **Long Game prompts cache poorly.** Session-level blocks (memory, continuity, map context, NPC cards, output format) sit after the history and are rewritten every turn, so a subscription Game turn can end up 55 to 65% cached. - **GM turns always run at the highest reasoning effort**, which makes some models slow and expensive for every turn. ## Proposed solution These build on what Game Mode already has: the session recap, the Lorebook Keeper, the journal, the NPC tracking and the cache-friendly prompt work in package F. **Campaign memory** - A read-only campaign view, so a new session sees the facts, knowledge and last known state from every earlier session of the same game. It can be set per chat to "this session only". - A readable GM memory block: names instead of ids, a session tag on each fact, pinned canon first, then the people present, then keyword matches, within a budget (10,000 characters by default). - Pin a fact as canon, correct it, or mark it wrong so it stays hidden in every session. - The session recap is checked against this memory, and its timeout is longer. - Party members carry their own memory into the next session. - Session conclusion salvage: a conclusion whose model output is slightly malformed is repaired instead of lost. **Continuity pipeline** (per game, off until turned on) - After turns, a background pass extracts, reviews and publishes facts into the game's Lorebook Keeper book, which the Keeper and memory then share. - It salvages imperfect model output, splits a cut-off batch instead of failing it, parks a chat with no usable connection on its own, and offers one "Retry all" for failed batches. - Campaign indexing and backfill for games that already have history: resumable and cancellable. **Campaign Wiki** - A reader for the campaign: a front page, one page per person, place, item or quest across sessions, a campaign timeline, open promises, a canon page, "what links here", and a side-by-side view for reviewing duplicates. - A Memory panel that explains how the GM uses memory, with the budget and recap settings. - A Markdown or JSON campaign codex export. **NPCs and scenes** - A scene timeline after each GM turn feeds who is present and the recap's scene index. - Missing NPCs recovered from transcripts, stable NPC ids shared by client and server, optional isolated NPC knowledge, and NPC status and location updates from the session conclusion (the journal replaces its stale line instead of adding another). **Game prompt caching and cost** - Cache-stable Game prompt (Claude subscription): session-level blocks go into a per-chat cached baseline before the history, and only small changes and live values ride after the last exchange. Measured on a copy of a real Game chat: from about 74% to about 96% of each request read from cache. - Session-frozen NPC cards: a reworded card is sent as a small update until the next session instead of rewriting the cached prefix; rewordings without a fact change are not saved. - Stable lore order: newly matched lorebook entries are appended instead of inserted, and a flickering keyword may linger a couple of turns. - ChatGPT history replay: Game turns reuse the previous expanded prompt and append the newest state. - Final checks and World Maps context placed so they stop breaking the prefix. - A per-game GM reasoning effort. Its Default keeps today's behaviour. **How it's switched:** every piece sits behind a switch or a per-game or per-chat setting: the continuity pipeline (per game), campaign memory scope (per chat), **Scene timeline** (per game), **ChatGPT history replay**, **Cache-stable Game prompt**, **Session-frozen NPC cards**, **Stable lore order** (with **Linger turns**) and the final-checks opt-in (per chat). The fork turns most of them on; the upstream versions will default off, and off keeps today's prompts and data byte for byte, checked by regressions that compare the off path with `staging`. - **Areas touched (for spotting overlap):** - `packages/server/src/services/game`: campaign memory, continuity, session summary and conclusion, scene timeline, NPC sync and backfill, named-card cache, GM prompts, Lorebook Keeper integration, codex - `packages/server/src/services/generation`: GM prompt runtime, game lore prompt, new stable layout and history replay modules - `packages/server/src/services/lorebook`: stable lore order; `services/llm/providers`: ChatGPT cache helper, Anthropic marker placement - `packages/server/src/routes`: generate, game, new campaign memory, campaign index and continuity routes - `packages/server/src/db/schema` and `services/storage`: campaign memory and game continuity tables - Client `components/game`: Campaign Wiki, Memory panel, continuity panel, scene timeline, GM reasoning effort section - `packages/shared`: memory and continuity types, NPC id helpers, feature switch registry - **Size:** about 270 files and 70,000 added lines, including regressions. It will be split into several PRs of well under 150 files each (memory, continuity, wiki, NPCs, Game caching). - **Status:** implemented and tested in a fork, used over multi-session campaigns. ## Alternatives considered - **A longer recap instead of memory:** recaps grow and still lose detail; a queried memory block stays within a fixed budget. - **Putting memory straight into lorebooks:** the pipeline does publish into the Keeper's book, so lorebook users see it, but facts need provenance, retraction and per-session state that plain entries don't carry. - **Making the Game caching changes default on:** they change prompt order, so they stay opt-in upstream. ## Additional context - The Game caching parts also build on package F (prompt caching) in #6624. - Implementation depends on #6647 (foundations); PRs will follow once it merges, one package at a time. - If you're working in any of these areas, please comment so we can coordinate before a PR. ## Screenshots Taken from the fork build with invented demo data (characters, lorebooks and a campaign made up for these shots). Model replies and token counts come from a local test stub, so no real model was called. **Campaign Wiki front page: people, player characters, organizations and lore across sessions, with recent changes.** ![Campaign Wiki front page](https://raw.githubusercontent.com/SirAdoni/Marinara-Engine-contrib/e98c448478676a9b4a6fad4bed1b6c29c046e9a4/roadmap/T1-1-campaign-wiki.png) **A wiki page: facts grouped by session, the source quote, who else knows it, and Correct or Wrong.** ![A wiki page](https://raw.githubusercontent.com/SirAdoni/Marinara-Engine-contrib/e98c448478676a9b4a6fad4bed1b6c29c046e9a4/roadmap/T1-2-wiki-page-with-evidence.png) **The Memory panel: mode, how the GM uses memory, campaign or session scope, and the memory budget.** ![The Memory panel](https://raw.githubusercontent.com/SirAdoni/Marinara-Engine-contrib/e98c448478676a9b4a6fad4bed1b6c29c046e9a4/roadmap/T1-3-memory-panel.png) **A concluded session's recap with resume point, discoveries, character moments and NPC updates.** ![A concluded session's recap with resume point, discoveries, character moments and NPC updates](https://raw.githubusercontent.com/SirAdoni/Marinara-Engine-contrib/e98c448478676a9b4a6fad4bed1b6c29c046e9a4/roadmap/T1-4-session-recap.png) **Indexing an existing campaign: what will be read, per-session progress, and a quota warning before anything starts.** ![Indexing an existing campaign](https://raw.githubusercontent.com/SirAdoni/Marinara-Engine-contrib/e98c448478676a9b4a6fad4bed1b6c29c046e9a4/roadmap/T1-5-index-campaign-history.png) ## Template check - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 26, 2026):

@kolacheee, tagging you since you've been working on Game mode; please check if this doesn't overlap with what you're doing.

<!-- gh-comment-id:5848558106 --> @SpicyMarinara commented on GitHub (Sep 26, 2026): @kolacheee, tagging you since you've been working on Game mode; please check if this doesn't overlap with what you're doing.
Author
Owner

@kolacheee commented on GitHub (Sep 27, 2026):

@SirAdoni, nothing here blocks my Game Mode work either, but a few seams to keep in mind:

  • Cache-stable Game prompt. The Game Master's format reminder after the history carries values that change every turn:

    • the party's inventory, now one line per member once anyone besides the player carries something;
    • the ruleset character sheets (<character_sheets>);
    • the one-request dice pool block (#6216);
    • soon, item details, load and encumbrance from the items arc.

    Those need to stay in the live tail rather than the cached baseline. The command grammar lines ([sheet:], [inventory:]) are fixed per game, so they could move into the baseline.

  • Session start and conclusion. The carry-over in POST /session/start now carries every party member's bag (carryGameInventory) and the ruleset sheets. Please keep both when adding party memory there.

  • NPC ids. Inventory bags name their holder by the character's name, the same way ruleset sheets and live sheet state are keyed. If stable NPC ids land, bags could move onto them, so a heads-up when that PR is up would help.

  • generate.routes.ts. Inventory tags are now carried out right after the reply is saved (#6772). Changes to the post-generation flow should keep that step after the save.

  • Caching. My earlier caching audit (#6217 to #6222) is already closed, so nothing of mine is open there. Any further caching work I had in mind I'll leave to Package F and the Game caching work here rather than build something in parallel.

<!-- gh-comment-id:5858416506 --> @kolacheee commented on GitHub (Sep 27, 2026): @SirAdoni, nothing here blocks my Game Mode work either, but a few seams to keep in mind: - **Cache-stable Game prompt.** The Game Master's format reminder after the history carries values that change every turn: - the party's inventory, now one line per member once anyone besides the player carries something; - the ruleset character sheets (`<character_sheets>`); - the one-request dice pool block (#6216); - soon, item details, load and encumbrance from the items arc. Those need to stay in the live tail rather than the cached baseline. The command grammar lines (`[sheet:]`, `[inventory:]`) are fixed per game, so they could move into the baseline. - **Session start and conclusion.** The carry-over in `POST /session/start` now carries every party member's bag (`carryGameInventory`) and the ruleset sheets. Please keep both when adding party memory there. - **NPC ids.** Inventory bags name their holder by the character's name, the same way ruleset sheets and live sheet state are keyed. If stable NPC ids land, bags could move onto them, so a heads-up when that PR is up would help. - **`generate.routes.ts`.** Inventory tags are now carried out right after the reply is saved (#6772). Changes to the post-generation flow should keep that step after the save. - **Caching.** My earlier caching audit (#6217 to #6222) is already closed, so nothing of mine is open there. Any further caching work I had in mind I'll leave to Package F and the Game caching work here rather than build something in parallel.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3751
No description provided.