[GH-ISSUE #6624] [Feature]: Engine foundations: request-traced logs, prompt caching fixes, opt-in robustness and performance, a feature switch page, background generation jobs and a Ctrl+K command palette #3710

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Template: Feature request


Note

Update: this work is now split into eight pull requests, listed in the series map below. The earlier umbrella PR #6625 was closed in favour of the split, because at over 300 files it was past CodeRabbit's 150-file review limit. Each part is well under that limit and can be reviewed on its own.

Roadmap: every planned contribution

Everything this fork plans to offer upstream, announced early so anyone working in the same areas can say so before a PR. Each item below has its own issue listing the areas and files it touches. D to H and the three themes follow once part 1 (A) merges, one package at a time, and each is behind a setting that is off by default wherever it changes behaviour.

Package Link Status
A. Foundations #6647 In review
B. Dev MCP #6648 In review
C. Command palette #6649 Handed to the Omnibar work; not proposed again
D. Reviewed server fixes, part 1 (routes, middleware, storage recovery, importers, sidecars, SSRF) #6691 Proposed
E. Reviewed server fixes, part 2 (services and storage) #6692 Proposed
F. Prompt caching #6693 Proposed
G. Generation jobs and console tray #6694 Proposed
H. Diagnostics and launcher #6695 Proposed
Theme 1. Game Mode long campaigns: memory, continuity, Campaign Wiki, cache-stable Game prompts #6696 Proposed
Theme 2. Game Mode HUD, layout editor, phone and tablet layouts, GM table tools #6697 Proposed
Theme 3. Library, chat and accessibility #6698 Proposed

If you're working in any of these areas, please comment on the matching issue so we can coordinate before a PR.

What problem does this solve?

Running long campaigns with a lot of lorebook and memory data, mostly on Claude and ChatGPT subscriptions, a handful of engine-level problems keep costing time, tokens and quota. Each is small on its own, and they sit in the same few places:

  • Prompt caching breaks more than it should. On Claude (Subscription), a prompt that ends with injections after the user's turn gets no history cache marker (one measured case: 61% cached on a 520k-token prompt). Lorebook inclusion groups re-roll every turn, so the prompt changes even when the story didn't, and per-turn blocks sit early in the prompt.
  • Claude Opus 5.5 is listed but can't run on the Claude subscription provider, because the pinned Agent SDK predates it.
  • A log line can't be tied to the request that caused it, and one failure is often logged two or three times.
  • Stored lorebook scans grow very large, because every message and swipe keeps the full text of every activated entry.
  • A startup timing issue can quietly disable packages: an internal request made while packages are still activating boots Fastify early, and every later package fails with "Root plugin has already booted".
  • A stale build can run without anyone noticing, and the in-app updater can report success for it.
  • A model that always reasons fails outright when a request asks for reasoning off.
  • Image and video generations die with the tab, with no record of what happened.
  • There's no quick way to jump around the app.
  • A regression run can open the developer's own data, because the runner doesn't isolate the data folder or the .env file.
  • A code review of the server found about 50 small bugs, from SSRF and allowlist checks to importers and storage recovery.

Proposed solution

Additions that build on what the engine already has, rather than replacing it. The shared Pino logger and the Logging section of CONTRIBUTING.md, the regression runner, the atomic write and .bak design in file-backed-store.ts, the ordered shutdown, RateLimitAwareProvider and the existing Settings layout all stay as they are.

Everything that changes prompts, stored data, retries or background behaviour is behind a switch or setting that defaults off, so nothing changes for anyone until they turn it on. Pure bug fixes have no switch.

Series map

Part PR Branch What it contains Opens
1 A. Foundations (#6647) contrib/foundations Isolated regression runs; request id trail, startup timeline and one log line per failure; stable lorebook group picks and compact stored lorebook scans (opt-in); opt-in robustness settings for storage writes, Windows boot, shutdown and provider retry, plus a read-only runtime diagnostics route; the startup inject gate; the feature switch page (Settings > Advanced > Features) with its first two switches, stableLorebookGroupPicks and providerRetry; logged best-effort helpers; docs/contrib/engine-foundations-overview.md, which maps the whole series Now, independent
2 B. Dev MCP (#6648) contrib/dev-mcp An optional MCP server in tools/dev-mcp for coding assistants working on a local engine. Outside the pnpm workspace and the Docker image; nothing in the app depends on it Now, independent
3 C. Command palette (#6649) contrib/command-palette Ctrl+K (Cmd+K on Mac) command palette and a "?" keyboard shortcuts overlay. Client only, no switch Now, independent
4 D. Reviewed server fixes, part 1 contrib/d-server-fixes-1 Routes and middleware; storage recovery, chat and generate routes, importers, sidecars and SSRF; a summary timeout that keeps the process alive; path containment checks for CodeQL. Bug fixes, no switch, each with its own regression After A merges
5 E. Reviewed server fixes, part 2 contrib/e-server-fixes-2 Services and storage: agents, memory scans, providers, media, importers; gallery upload containment; the selfie abort signal. Bug fixes, no switch, each with its own regression After A merges
6 F. Prompt caching contrib/f-prompt-caching The Claude subscription history cache marker fix, Agent SDK 0.3.280 for Claude Opus 5.5, a cache-friendly prompt layout (cacheFriendlyPromptLayout, off), a ChatGPT cache session, a per-chat warning before a low-cache send (off), and cache diagnostics (MARINARA_CACHE_DIAGNOSTICS) After A merges
7 G. Generation jobs and console tray contrib/g-jobs-tray Media generations that keep running when the tab closes, with a jobs viewer (generationJobTracking, off), and a Windows console tray icon (consoleTray, off, or MARINARA_CONSOLE_TRAY) After A merges
8 H. Diagnostics and launcher contrib/h-diagnostics-launcher A build integrity check, runtime memory telemetry, prompt debug files (LOG_PROMPT_DEBUG_FILES, off), a background call cap (backgroundCallCap, off, 600 calls per hour by default), a launcher backup before git clean, opening the browser once the server answers, and a retry without reasoning-off for models that always reason After A merges

Which parts depend on which

  • A, B and C are independent. Each targets staging directly and can be merged, reviewed or declined on its own, in any order.
  • D to H open after A merges. They read A's feature switch registry, log through A's logging trail and best-effort helpers, or extend A's startup timeline and runtime diagnostics route. Until A merges, their branches also contain A's commits; each is rebased onto staging once A is in, so its diff shows only its own commits.
  • D to H do not depend on each other and can be opened together.

Merge order notes

  • D and G both touch the gallery, backgrounds and sprites routes, and E and G both touch the characters route. G wraps these routes in its job runner, so whichever merges second rebases. D's selfie save fix is written against staging's unwrapped gallery route.
  • D and E share generate.routes.ts, and F touches it as well.
  • F, G and H each add switches to the same registry, settings list, English strings, docs and the exact switch list in the feature-settings regression. Whichever lands later adds its rows next to the others.
  • The "Open generation jobs" command palette action follows as a small PR after both C and G have merged.
  • Everything else they share (CHANGELOG.md, index.ts, file-backed-store.ts) is a small rebase.

Alternatives considered

  • One large PR. Tried first as #6625 and closed, because it was past CodeRabbit's 150-file limit and too large to review in one sitting.
  • Making D to H independent of A. Each would need its own copy of the switch registry and logging helpers, which changes their behaviour. Waiting for A is the cleaner route.
  • Turning the caching and robustness pieces on by default. Rejected: they change prompts, stored data or retries. Upstream stays exactly as it is until a user opts in.
  • Fixing the startup issue inside each package. Rejected, because the timing problem is in the host, and every package that makes an early internal request would hit it.

Additional context

Parts 1 to 3 are based on staging e15c9e558; parts 4 to 8 are rebased onto part 1 when it merges, and each piece has regressions that check the default path is unchanged and the new path works. docs/contrib/engine-foundations-overview.md (added in part 1, with a section filled in by each later part) covers what exists today, what each piece adds, what stays the same, how to check it and how to turn it off. Part 1 was checked on Windows 11 and Linux (WSL Ubuntu, the CI-equivalent regression run). Built with AI assistance; the result has been read and checked, and each PR leaves the verification checkboxes for a human to tick.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @SirAdoni on GitHub (Sep 24, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6624 Originally assigned to: @SpicyMarinara on GitHub. **Template:** Feature request --- > [!NOTE] > **Update:** this work is now split into eight pull requests, listed in the series map below. The earlier umbrella PR #6625 was closed in favour of the split, because at over 300 files it was past CodeRabbit's 150-file review limit. Each part is well under that limit and can be reviewed on its own. ## Roadmap: every planned contribution Everything this fork plans to offer upstream, announced early so anyone working in the same areas can say so before a PR. Each item below has its own issue listing the areas and files it touches. D to H and the three themes follow once part 1 (A) merges, one package at a time, and each is behind a setting that is off by default wherever it changes behaviour. | Package | Link | Status | |---|---|---| | A. Foundations | #6647 | In review | | B. Dev MCP | #6648 | In review | | C. Command palette | #6649 | Handed to the Omnibar work; not proposed again | | D. Reviewed server fixes, part 1 (routes, middleware, storage recovery, importers, sidecars, SSRF) | #6691 | Proposed | | E. Reviewed server fixes, part 2 (services and storage) | #6692 | Proposed | | F. Prompt caching | #6693 | Proposed | | G. Generation jobs and console tray | #6694 | Proposed | | H. Diagnostics and launcher | #6695 | Proposed | | Theme 1. Game Mode long campaigns: memory, continuity, Campaign Wiki, cache-stable Game prompts | #6696 | Proposed | | Theme 2. Game Mode HUD, layout editor, phone and tablet layouts, GM table tools | #6697 | Proposed | | Theme 3. Library, chat and accessibility | #6698 | Proposed | If you're working in any of these areas, please comment on the matching issue so we can coordinate before a PR. ## What problem does this solve? Running long campaigns with a lot of lorebook and memory data, mostly on Claude and ChatGPT subscriptions, a handful of engine-level problems keep costing time, tokens and quota. Each is small on its own, and they sit in the same few places: - **Prompt caching breaks more than it should.** On Claude (Subscription), a prompt that ends with injections after the user's turn gets no history cache marker (one measured case: 61% cached on a 520k-token prompt). Lorebook inclusion groups re-roll every turn, so the prompt changes even when the story didn't, and per-turn blocks sit early in the prompt. - **Claude Opus 5.5 is listed but can't run on the Claude subscription provider**, because the pinned Agent SDK predates it. - **A log line can't be tied to the request that caused it**, and one failure is often logged two or three times. - **Stored lorebook scans grow very large**, because every message and swipe keeps the full text of every activated entry. - **A startup timing issue can quietly disable packages**: an internal request made while packages are still activating boots Fastify early, and every later package fails with "Root plugin has already booted". - **A stale build can run without anyone noticing**, and the in-app updater can report success for it. - **A model that always reasons fails outright** when a request asks for reasoning off. - **Image and video generations die with the tab**, with no record of what happened. - **There's no quick way to jump around the app.** - **A regression run can open the developer's own data**, because the runner doesn't isolate the data folder or the `.env` file. - **A code review of the server found about 50 small bugs**, from SSRF and allowlist checks to importers and storage recovery. ## Proposed solution Additions that build on what the engine already has, rather than replacing it. The shared Pino logger and the Logging section of `CONTRIBUTING.md`, the regression runner, the atomic write and `.bak` design in `file-backed-store.ts`, the ordered shutdown, `RateLimitAwareProvider` and the existing Settings layout all stay as they are. **Everything that changes prompts, stored data, retries or background behaviour is behind a switch or setting that defaults off**, so nothing changes for anyone until they turn it on. Pure bug fixes have no switch. ### Series map | Part | PR | Branch | What it contains | Opens | |---|---|---|---|---| | 1 | **A. Foundations** (#6647) | `contrib/foundations` | Isolated regression runs; request id trail, startup timeline and one log line per failure; stable lorebook group picks and compact stored lorebook scans (opt-in); opt-in robustness settings for storage writes, Windows boot, shutdown and provider retry, plus a read-only runtime diagnostics route; the startup inject gate; the feature switch page (Settings > Advanced > Features) with its first two switches, `stableLorebookGroupPicks` and `providerRetry`; logged best-effort helpers; `docs/contrib/engine-foundations-overview.md`, which maps the whole series | Now, independent | | 2 | **B. Dev MCP** (#6648) | `contrib/dev-mcp` | An optional MCP server in `tools/dev-mcp` for coding assistants working on a local engine. Outside the pnpm workspace and the Docker image; nothing in the app depends on it | Now, independent | | 3 | **C. Command palette** (#6649) | `contrib/command-palette` | Ctrl+K (Cmd+K on Mac) command palette and a "?" keyboard shortcuts overlay. Client only, no switch | Now, independent | | 4 | **D. Reviewed server fixes, part 1** | `contrib/d-server-fixes-1` | Routes and middleware; storage recovery, chat and generate routes, importers, sidecars and SSRF; a summary timeout that keeps the process alive; path containment checks for CodeQL. Bug fixes, no switch, each with its own regression | After A merges | | 5 | **E. Reviewed server fixes, part 2** | `contrib/e-server-fixes-2` | Services and storage: agents, memory scans, providers, media, importers; gallery upload containment; the selfie abort signal. Bug fixes, no switch, each with its own regression | After A merges | | 6 | **F. Prompt caching** | `contrib/f-prompt-caching` | The Claude subscription history cache marker fix, Agent SDK 0.3.280 for Claude Opus 5.5, a cache-friendly prompt layout (`cacheFriendlyPromptLayout`, off), a ChatGPT cache session, a per-chat warning before a low-cache send (off), and cache diagnostics (`MARINARA_CACHE_DIAGNOSTICS`) | After A merges | | 7 | **G. Generation jobs and console tray** | `contrib/g-jobs-tray` | Media generations that keep running when the tab closes, with a jobs viewer (`generationJobTracking`, off), and a Windows console tray icon (`consoleTray`, off, or `MARINARA_CONSOLE_TRAY`) | After A merges | | 8 | **H. Diagnostics and launcher** | `contrib/h-diagnostics-launcher` | A build integrity check, runtime memory telemetry, prompt debug files (`LOG_PROMPT_DEBUG_FILES`, off), a background call cap (`backgroundCallCap`, off, 600 calls per hour by default), a launcher backup before `git clean`, opening the browser once the server answers, and a retry without reasoning-off for models that always reason | After A merges | ### Which parts depend on which - **A, B and C are independent.** Each targets `staging` directly and can be merged, reviewed or declined on its own, in any order. - **D to H open after A merges.** They read A's feature switch registry, log through A's logging trail and best-effort helpers, or extend A's startup timeline and runtime diagnostics route. Until A merges, their branches also contain A's commits; each is rebased onto `staging` once A is in, so its diff shows only its own commits. - D to H do not depend on each other and can be opened together. ### Merge order notes - **D and G** both touch the gallery, backgrounds and sprites routes, and **E and G** both touch the characters route. G wraps these routes in its job runner, so whichever merges second rebases. D's selfie save fix is written against `staging`'s unwrapped gallery route. - **D and E** share `generate.routes.ts`, and F touches it as well. - **F, G and H** each add switches to the same registry, settings list, English strings, docs and the exact switch list in the `feature-settings` regression. Whichever lands later adds its rows next to the others. - The **"Open generation jobs" command palette action** follows as a small PR after both C and G have merged. - Everything else they share (`CHANGELOG.md`, `index.ts`, `file-backed-store.ts`) is a small rebase. ## Alternatives considered - **One large PR.** Tried first as #6625 and closed, because it was past CodeRabbit's 150-file limit and too large to review in one sitting. - **Making D to H independent of A.** Each would need its own copy of the switch registry and logging helpers, which changes their behaviour. Waiting for A is the cleaner route. - **Turning the caching and robustness pieces on by default.** Rejected: they change prompts, stored data or retries. Upstream stays exactly as it is until a user opts in. - **Fixing the startup issue inside each package.** Rejected, because the timing problem is in the host, and every package that makes an early internal request would hit it. ## Additional context Parts 1 to 3 are based on `staging` `e15c9e558`; parts 4 to 8 are rebased onto part 1 when it merges, and each piece has regressions that check the default path is unchanged and the new path works. `docs/contrib/engine-foundations-overview.md` (added in part 1, with a section filled in by each later part) covers what exists today, what each piece adds, what stays the same, how to check it and how to turn it off. Part 1 was checked on Windows 11 and Linux (WSL Ubuntu, the CI-equivalent regression run). Built with AI assistance; the result has been read and checked, and each PR leaves the verification checkboxes for a human to tick. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 06:06:25 +07:00
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#3710
No description provided.