[PR #6647] [MERGED] feat: engine foundations (isolated regression runs, request id trail, feature switches, opt-in lorebook and robustness settings) #7273

Closed
opened 2026-10-23 04:18:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6647
Author: @SirAdoni
Created: 9/25/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @SpicyMarinara

Base: staging ← Head: contrib/foundations


📝 Commits (10+)

  • 35ec310 test: isolate each regression file's storage and .env in the runner
  • 1c52f07 feat(server): request id trail, startup timeline and one line per failure in logs
  • bd3982f perf(server): stable lorebook group winners and compact stored lorebook scans (both opt-in)
  • 6f67626 fix(server): opt-in robustness settings for storage writes, Windows boot, shutdown and provider retry, plus runtime diagnostics
  • 00dfecb fix(server): hold early internal inject() calls until startup registration ends
  • 12319f4 feat: feature switches in Settings > Advanced > Features
  • 39a456a refactor(server): logged best-effort helpers for deliberately swallowed failures
  • 1143b4a docs: map the engine foundations series in one overview
  • 883869d fix(server): give the runtime diagnostics route its own rate limit
  • 806d4cd fix(test): make the shutdown source checks linear-time regexes

📊 Changes

87 files changed (+6268 additions, -246 deletions)

View changed files

📝 .env.example (+33 -0)
📝 CHANGELOG.md (+6 -0)
📝 CONTRIBUTING.md (+12 -0)
📝 docs/CONFIGURATION.md (+32 -0)
➕ docs/configuration/features.md (+57 -0)
➕ docs/contrib/engine-foundations-overview.md (+308 -0)
➕ docs/development/logging.md (+104 -0)
📝 docs/settings/settings-overview.md (+2 -2)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+19 -0)
➕ packages/client/src/components/panels/settings/FeatureSwitchesSettings.tsx (+71 -0)
➕ packages/client/src/hooks/use-feature-settings.ts (+46 -0)
📝 packages/client/src/localization/locales/en.json (+9 -0)
📝 packages/server/src/app.ts (+83 -36)
📝 packages/server/src/config/cors-config.ts (+2 -1)
📝 packages/server/src/config/env-watcher.ts (+9 -0)
📝 packages/server/src/config/runtime-config.ts (+72 -0)
📝 packages/server/src/db/connection.ts (+11 -1)
📝 packages/server/src/db/file-backed-store.ts (+269 -25)
➕ packages/server/src/db/writer-boot-id-cache.ts (+83 -0)
📝 packages/server/src/index.ts (+52 -18)

...and 67 more files

📄 Description

Rebased 2026-09-25 onto upstream staging e15c9e558. Hashes below are the rebased ones. The rebase had no conflicts. Re-checked after it: install, shared build, tsc (shared, server, client), locale check and this branch's own regressions, all passing. The full suites and CodeRabbit reviews listed below ran on the previous base, one or two staging updates earlier.

Base: staging (e15c9e558) · Head: contrib/foundations (d4c282404)


Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6624
Part 1 of the engine foundations series, see #6624.

This PR is independent of the other parts. It targets staging directly and can be merged, reviewed or declined on its own. Parts 4 to 8 (D to H) build on it and open after it merges. Parts 2 and 3 (B, C) do not need it.

Why this change

  • A log line can't be tied to the request that caused it, and one failure is often logged two or three times.
  • A regression run can open or lock the developer's own data folder, because the runner doesn't isolate DATA_DIR, FILE_STORAGE_DIR or the .env file.
  • Lorebook inclusion groups re-roll every turn, so the prompt prefix changes even when the story didn't, and every message and swipe stores the full text of each activated entry.
  • An internal request made while packages are still activating boots Fastify early. Every later package then fails with "Root plugin has already booted" and can stay rolled back or marked "error" on later starts.
  • Optional server behaviour only exists as environment variables, with no place in the UI to turn it on.

Every piece builds on code that already exists and works. Nothing renames an upstream API, replaces the shared logger or changes a file's conventions. docs/contrib/engine-foundations-overview.md explains each piece in five parts: what exists today, what this adds, what stays exactly the same, how to check it, and how to turn it off or revert it. It also maps the whole series.

What changed

17 commits on staging e15c9e558, oldest first, 86 files:

  • 5c5bce0a1 test: isolate each regression file's storage and .env in the runner.
  • b1576f4e4 feat(server): request id trail, startup timeline and one line per failure in logs.
  • aab0080cd perf(server): stable lorebook group winners and compact stored lorebook scans (both opt-in).
  • 11c94dfe6 fix(server): opt-in robustness settings for storage writes, Windows boot, shutdown and provider retry, plus runtime diagnostics.
  • 8a1a71e06 fix(server): hold early internal inject() calls until startup registration ends.
  • b50dec60c feat: feature switches in Settings > Advanced > Features.
  • 416f7fe2e refactor(server): logged best-effort helpers for deliberately swallowed failures.
  • 6629ab7e9 docs: map the engine foundations series in one overview.
  • fa7daa8b2 fix(server): give the runtime diagnostics route its own rate limit.
  • 69a196ebb fix(test): make the shutdown source checks linear-time regexes.
  • 5fe1c57c8 fix(server): let the lorebook group seed also decide the Active Context preview.
  • 14451af75 fix(server): pass a synchronous inject() throw to a held call's callback.
  • a35f5fb81 fix(client): refresh the feature switches after 30 seconds, like the extension policy.
  • 230ef84cb fix: leave the two switch variables commented out in .env.example.
  • 0cb02af33 fix(server): resolve macros in stored lorebook text used by agent retries.
  • 7037ec93e fix(server): make seeded lorebook group picks independent of activation order.
  • d4c282404 fix(server): keep JSON parse messages out of the scene wrap warning.

Defaults. Anything that changes stored data, prompts or retries is off by default, behind an environment variable or a switch in Settings > Advanced > Features. With nothing turned on, upstream behaviour is unchanged. The pieces with no switch are bug fixes, the test runner and additive helpers.

Regression runner isolation (5c5bce0a1)

  • runRegression() gives each file a temporary folder with its own DATA_DIR, FILE_STORAGE_DIR and MARINARA_ENV_FILE, removed when the file finishes. A regression can no longer read the developer's .env or collide with the writer lease on their real data folder.
  • The --filter and --list flags, timeouts, summary output, scripts and CI are unchanged.

Logging: request id trail, startup timeline, one line per failure (b1576f4e4)

  • Fastify is built on the shared logger, so req.log lines use the same serializers and follow LOG_LEVEL hot reloads, as CONTRIBUTING.md already describes.
  • Every line a request causes carries requestId (also returned as x-request-id), and every line carries bootId.
  • A startup timeline with one [startup] Ready in N ms line at info, and a failed boot names the step it failed in.
  • Provider and tool code rethrows instead of logging and rethrowing, so a failure is one line with its cause chain. User stops log at info, repeating failures are rate limited, and model or provider text stays at debug.
  • New info lines are hidden at the default LOG_LEVEL=warn. Details, including the renamed reqId field, are in docs/development/logging.md.

Lorebooks (aab0080cd, opt-in)

  • LOREBOOK_STABLE_GROUP_WINNERS (switch Stable lorebook picks): the same inclusion-group winner in a chat while its candidates stay the same, so the prompt prefix stays cacheable. Uses upstream's own stableHash and createSeededRandom, moved unchanged into lorebook/seeded-random.ts.
  • LOREBOOK_COMPACT_STORED_SCANS: only the newest reply keeps the full entry text in its stored scan. scripts/compact-lorebook-scans.mjs applies the same rule to older chats, dry run by default.

Robustness (11c94dfe6, opt-in)

  • Storage writes: skip unchanged writes, yielding serialization for large shards.
  • Windows boot: cache the boot id probe per OS boot. Always on: the probes run hidden instead of flashing a console window.
  • Shutdown: Windows console signals, forced exit on a repeated Ctrl+C, early flush, and a runtime stop budget. Always on: runtime stops are named in the log.
  • PROVIDER_RETRY_TRANSIENT_ERRORS (switch Retry failed provider calls): a refused connection or a gateway 502/503 is retried at most twice, only before any output reached the user, and never on the primary leg of a connection with a fallback.
  • GET /api/admin/runtime-diagnostics: a read-only, privileged snapshot of storage residency and capability runtime state. It is rate limited to 30 requests a minute through an entry in the rate-limit middleware's route list (ROUTE_RULES), because staging's middleware does not read a route's own config.rateLimit.

Startup inject gate (8a1a71e06, bug fix, always on)

  • app.inject() calls made before buildApp() has finished registering are held and run once registration ends.
  • An inject() made directly from a package's activate() or selfCheck() fails at once instead of hanging startup, and only that package fails to activate.
  • A package that fails only because of the host lifecycle errors is not rolled back or marked "error", and is retried on the next start.

Feature switches (b50dec60c)

  • One registry (packages/shared/src/schemas/feature-settings.schema.ts) and one settings section, Settings > Advanced > Features. Server code reads an in-memory copy through isFeatureEnabled(), so busy paths pay nothing.
  • This PR registers only the two switches for behaviour it adds itself: stableLorebookGroupPicks and providerRetry. Both are off. LOREBOOK_STABLE_GROUP_WINNERS and PROVIDER_RETRY_TRANSIENT_ERRORS win when set, and the switch is then shown locked with the variable's name.
  • Parts 6 to 8 (F, G, H) add their own switches to this registry.

Best-effort helpers (416f7fe2e)

  • lib/best-effort.ts: logSuppressed, orFallback and bestEffort log a deliberately swallowed failure through logRateLimited. Nothing calls them yet in this PR. The reviewed fixes in parts 4 and 5 (D, E) use them.

Hand security review (fa7daa8b2, 69a196ebb)

  • CodeQL was reviewed by hand, not run. The runtime diagnostics route got its own rate limit, and two shutdown source checks in a regression now use linear-time regexes.

Review fixes (local CodeRabbit)

  • 8 findings fixed:
    • Agent retries resolve macros in stored lorebook text used as a fallback (0cb02af33).
    • Seeded group picks no longer depend on activation order (7037ec93e).
    • The Active Context preview uses the same seeded winner as generation (5fe1c57c8).
    • A synchronous inject() throw in a held callback call reaches the callback (14451af75).
    • The scene wrap warning keeps JSON parse text out of the log (d4c282404).
    • .env.example no longer locks the two switches off (230ef84cb).
    • The features query refreshes after 30 s, like the external extension policy query (a35f5fb81).
    • A placeholder in the overview doc was filled in.
  • 3 findings rejected, with reasons:
    • Concurrent saves of the switches: last writer wins, like the other whole-object settings routes.
    • Polling the switches: not needed. The query refreshes on focus and after 30 s.
    • The restart path: keeps upstream's behaviour on purpose. The shutdown settings apply to signal shutdowns only.

Matching existing UI

  • The Features section copies SettingsSection and ToggleSetting (SettingsPanel.tsx, SettingControls.tsx).
  • A switch pinned by an environment variable is shown the same way as the server-locked toggle of the External Extensions setting.

Validation

  • pnpm check passes locally - Had 2 steps fail, but it is from M.E code, not my own.
  • Container (Docker / Podman) built and ran without issue - Did not test. May have the time later.
  • Ran the app, clicked through the changes manually
  • [] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - did not check, empty and error states weren't recorded.
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

The boxes are left unticked for a human, per AGENTS.md. Everything below ran on the tip d4c282404. No paid model calls were made.

Check Result
CI-equivalent, Linux (WSL Ubuntu 24.04, Node 24) complete-node-regressions 384 / 384
Full regression suite, Windows 11 379 / 384. The 5 failures are the known Windows-only ones (decision-sidecar-runtime, gallery-previews, request-timeouts, server-signal-shutdown, storage-writer-lock) and fail the same way on plain staging.
tsc --noEmit (shared, server, client, root, token estimation) clean
Lint 0 errors
Prettier, locales, builds pass
e2e mobile-chromium, settings specs (core-flows, issue-sweep-settings, ux-feedback-sweep, afternoon-sweep, client-runtime-diagnostics) 171 passed, 0 failed
e2e mobile-webkit, same specs The failures left after a rerun are identical to plain staging.
CodeQL reviewed by hand, not run

Manual verification notes

  • Checked Settings > Advanced > Features in the default and SillyTavern themes, light and dark, at desktop and phone sizes.
  • Each piece has regressions that check the default path is unchanged and the new path works: logging-request-trail, logging-failure-lines, logging-startup-timeline, lorebook-group-seed, lorebook-scan-compaction, robustness-storage-write, robustness-boot-performance, robustness-shutdown-safety, robustness-provider-resilience, robustness-runtime-diagnostics, startup-inject-gate, feature-settings, best-effort.
  • The overview doc lists a "how to check it yourself" command for each piece.

Human to tick

Based on the evidence above:

  • pnpm check passes locally: supported. Its steps (tsc, lint, Prettier, locales, builds, regressions) all passed, apart from the 5 known Windows-only failures, and Linux is 384 / 384. If you want the literal command, run pnpm check once before ticking.
  • Ran the app, clicked through the changes manually: supported for the Features section at desktop and phone sizes in both themes, light and dark. Tick after trying it once yourself.
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed: supported (CHANGELOG.md, CONTRIBUTING.md, .env.example, docs/CONFIGURATION.md, docs/configuration/features.md, docs/development/logging.md, docs/settings/settings-overview.md and the overview).

Not supported by the evidence, leave unticked unless done by hand:

  • Container built and ran: not run for this PR.
  • Checked edge cases: light and dark and the phone viewport were checked for the Features section, but empty states and error paths were not recorded.
  • Above manual verification completed, and Read and followed CONTRIBUTING.md: only a human can confirm these.
  • No docs changes needed, and Version/release files updated: do not apply.
  • Translated docs: see below.

Needs manual verification

  • The full browser lanes on Linux CI. Locally only the settings specs ran, on mobile-chromium and mobile-webkit.
  • A real CodeQL run. The findings so far come from a hand review.
  • Flip Stable lorebook picks and Retry failed provider calls in a live app, and check that setting either environment variable shows the switch locked.
  • Build and run the Docker image once.
  • Decide whether the CONTRIBUTING.md Logging line and the new docs need a [docs-i18n] follow-up issue for the translated guides.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

The PR adds six CHANGELOG entries under [Unreleased], a link from the Logging section of CONTRIBUTING.md to docs/development/logging.md, a Lorebooks and a Robustness table in docs/CONFIGURATION.md, docs/configuration/features.md, commented-out entries in .env.example, and docs/contrib/engine-foundations-overview.md. No version bump.

UI evidence (if applicable)

Screenshot from a test instance with invented data, taken on this branch.

Settings > Advanced > Features

Settings > Advanced > Features

Remaining steps

  • The manual checks listed above.
  • After this merges, open parts 4 to 8 (D to H), which are stacked on this branch.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added Advanced settings for optional stable lorebook group picks and transient provider retries. Both are off by default and can be overridden through environment settings.
    • Added optional lorebook scan compaction to reduce stored content, with a maintenance tool for existing data.
    • Added a privileged, rate-limited runtime diagnostics endpoint with process and storage information.
  • Improvements
    • Added request IDs to responses and logs, with clearer startup and shutdown reporting.
    • Added configurable storage and shutdown robustness options.
    • Provider retries cover eligible connection failures and gateway errors, stop once output begins, and do not delay connections with a fallback provider.
    • Improved failure logging to limit repeated messages and keep potentially sensitive details out of routine logs.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6647 **Author:** [@SirAdoni](https://github.com/SirAdoni) **Created:** 9/25/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `contrib/foundations` --- ### 📝 Commits (10+) - [`35ec310`](https://github.com/Pasta-Devs/Marinara-Engine/commit/35ec310dbc42a5c98a0ff4760a6e7537e5e0148d) test: isolate each regression file's storage and .env in the runner - [`1c52f07`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1c52f079455d4a56fe6bb620eb72aceb742a99e2) feat(server): request id trail, startup timeline and one line per failure in logs - [`bd3982f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bd3982f2ffe9cce47357496ec33f00f7068984f2) perf(server): stable lorebook group winners and compact stored lorebook scans (both opt-in) - [`6f67626`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6f676267ffff34116680b9f0e9d3d891c14adf9c) fix(server): opt-in robustness settings for storage writes, Windows boot, shutdown and provider retry, plus runtime diagnostics - [`00dfecb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/00dfecb7fc0536d8c12583b95867ee6cf8a6c129) fix(server): hold early internal inject() calls until startup registration ends - [`12319f4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/12319f4a7705d84c3bc44c3eb48d89bf91cfb172) feat: feature switches in Settings > Advanced > Features - [`39a456a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/39a456a29537e994ef34f996632dc8eb7ac516f6) refactor(server): logged best-effort helpers for deliberately swallowed failures - [`1143b4a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1143b4aedaf279ef3c0df67257870f5b5a9a1177) docs: map the engine foundations series in one overview - [`883869d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/883869d6960b9721d7c3f08913219aa970670517) fix(server): give the runtime diagnostics route its own rate limit - [`806d4cd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/806d4cde53de0ca24b29cbdd6f466210e9e0e075) fix(test): make the shutdown source checks linear-time regexes ### 📊 Changes **87 files changed** (+6268 additions, -246 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+33 -0) 📝 `CHANGELOG.md` (+6 -0) 📝 `CONTRIBUTING.md` (+12 -0) 📝 `docs/CONFIGURATION.md` (+32 -0) ➕ `docs/configuration/features.md` (+57 -0) ➕ `docs/contrib/engine-foundations-overview.md` (+308 -0) ➕ `docs/development/logging.md` (+104 -0) 📝 `docs/settings/settings-overview.md` (+2 -2) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+19 -0) ➕ `packages/client/src/components/panels/settings/FeatureSwitchesSettings.tsx` (+71 -0) ➕ `packages/client/src/hooks/use-feature-settings.ts` (+46 -0) 📝 `packages/client/src/localization/locales/en.json` (+9 -0) 📝 `packages/server/src/app.ts` (+83 -36) 📝 `packages/server/src/config/cors-config.ts` (+2 -1) 📝 `packages/server/src/config/env-watcher.ts` (+9 -0) 📝 `packages/server/src/config/runtime-config.ts` (+72 -0) 📝 `packages/server/src/db/connection.ts` (+11 -1) 📝 `packages/server/src/db/file-backed-store.ts` (+269 -25) ➕ `packages/server/src/db/writer-boot-id-cache.ts` (+83 -0) 📝 `packages/server/src/index.ts` (+52 -18) _...and 67 more files_ </details> ### 📄 Description > **Rebased 2026-09-25** onto upstream staging `e15c9e558`. Hashes below are the rebased ones. The rebase had no conflicts. Re-checked after it: install, shared build, tsc (shared, server, client), locale check and this branch's own regressions, all passing. The full suites and CodeRabbit reviews listed below ran on the previous base, one or two staging updates earlier. **Base:** `staging` (`e15c9e558`) · **Head:** `contrib/foundations` (`d4c282404`) --- > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #6624 Part 1 of the engine foundations series, see #6624. This PR is independent of the other parts. It targets `staging` directly and can be merged, reviewed or declined on its own. Parts 4 to 8 (D to H) build on it and open after it merges. Parts 2 and 3 (B, C) do not need it. ## Why this change - A log line can't be tied to the request that caused it, and one failure is often logged two or three times. - A regression run can open or lock the developer's own data folder, because the runner doesn't isolate `DATA_DIR`, `FILE_STORAGE_DIR` or the `.env` file. - Lorebook inclusion groups re-roll every turn, so the prompt prefix changes even when the story didn't, and every message and swipe stores the full text of each activated entry. - An internal request made while packages are still activating boots Fastify early. Every later package then fails with "Root plugin has already booted" and can stay rolled back or marked `"error"` on later starts. - Optional server behaviour only exists as environment variables, with no place in the UI to turn it on. Every piece builds on code that already exists and works. Nothing renames an upstream API, replaces the shared logger or changes a file's conventions. `docs/contrib/engine-foundations-overview.md` explains each piece in five parts: what exists today, what this adds, what stays exactly the same, how to check it, and how to turn it off or revert it. It also maps the whole series. ## What changed 17 commits on `staging` `e15c9e558`, oldest first, 86 files: - `5c5bce0a1` test: isolate each regression file's storage and .env in the runner. - `b1576f4e4` feat(server): request id trail, startup timeline and one line per failure in logs. - `aab0080cd` perf(server): stable lorebook group winners and compact stored lorebook scans (both opt-in). - `11c94dfe6` fix(server): opt-in robustness settings for storage writes, Windows boot, shutdown and provider retry, plus runtime diagnostics. - `8a1a71e06` fix(server): hold early internal inject() calls until startup registration ends. - `b50dec60c` feat: feature switches in Settings > Advanced > Features. - `416f7fe2e` refactor(server): logged best-effort helpers for deliberately swallowed failures. - `6629ab7e9` docs: map the engine foundations series in one overview. - `fa7daa8b2` fix(server): give the runtime diagnostics route its own rate limit. - `69a196ebb` fix(test): make the shutdown source checks linear-time regexes. - `5fe1c57c8` fix(server): let the lorebook group seed also decide the Active Context preview. - `14451af75` fix(server): pass a synchronous inject() throw to a held call's callback. - `a35f5fb81` fix(client): refresh the feature switches after 30 seconds, like the extension policy. - `230ef84cb` fix: leave the two switch variables commented out in .env.example. - `0cb02af33` fix(server): resolve macros in stored lorebook text used by agent retries. - `7037ec93e` fix(server): make seeded lorebook group picks independent of activation order. - `d4c282404` fix(server): keep JSON parse messages out of the scene wrap warning. **Defaults.** Anything that changes stored data, prompts or retries is off by default, behind an environment variable or a switch in Settings > Advanced > Features. With nothing turned on, upstream behaviour is unchanged. The pieces with no switch are bug fixes, the test runner and additive helpers. **Regression runner isolation** (`5c5bce0a1`) - `runRegression()` gives each file a temporary folder with its own `DATA_DIR`, `FILE_STORAGE_DIR` and `MARINARA_ENV_FILE`, removed when the file finishes. A regression can no longer read the developer's `.env` or collide with the writer lease on their real data folder. - The `--filter` and `--list` flags, timeouts, summary output, scripts and CI are unchanged. **Logging: request id trail, startup timeline, one line per failure** (`b1576f4e4`) - Fastify is built on the shared logger, so `req.log` lines use the same serializers and follow `LOG_LEVEL` hot reloads, as `CONTRIBUTING.md` already describes. - Every line a request causes carries `requestId` (also returned as `x-request-id`), and every line carries `bootId`. - A startup timeline with one `[startup] Ready in N ms` line at info, and a failed boot names the step it failed in. - Provider and tool code rethrows instead of logging and rethrowing, so a failure is one line with its `cause` chain. User stops log at info, repeating failures are rate limited, and model or provider text stays at debug. - New info lines are hidden at the default `LOG_LEVEL=warn`. Details, including the renamed `reqId` field, are in `docs/development/logging.md`. **Lorebooks** (`aab0080cd`, opt-in) - `LOREBOOK_STABLE_GROUP_WINNERS` (switch **Stable lorebook picks**): the same inclusion-group winner in a chat while its candidates stay the same, so the prompt prefix stays cacheable. Uses upstream's own `stableHash` and `createSeededRandom`, moved unchanged into `lorebook/seeded-random.ts`. - `LOREBOOK_COMPACT_STORED_SCANS`: only the newest reply keeps the full entry text in its stored scan. `scripts/compact-lorebook-scans.mjs` applies the same rule to older chats, dry run by default. **Robustness** (`11c94dfe6`, opt-in) - Storage writes: skip unchanged writes, yielding serialization for large shards. - Windows boot: cache the boot id probe per OS boot. Always on: the probes run hidden instead of flashing a console window. - Shutdown: Windows console signals, forced exit on a repeated Ctrl+C, early flush, and a runtime stop budget. Always on: runtime stops are named in the log. - `PROVIDER_RETRY_TRANSIENT_ERRORS` (switch **Retry failed provider calls**): a refused connection or a gateway 502/503 is retried at most twice, only before any output reached the user, and never on the primary leg of a connection with a fallback. - `GET /api/admin/runtime-diagnostics`: a read-only, privileged snapshot of storage residency and capability runtime state. It is rate limited to 30 requests a minute through an entry in the rate-limit middleware's route list (`ROUTE_RULES`), because `staging`'s middleware does not read a route's own `config.rateLimit`. **Startup inject gate** (`8a1a71e06`, bug fix, always on) - `app.inject()` calls made before `buildApp()` has finished registering are held and run once registration ends. - An `inject()` made directly from a package's `activate()` or `selfCheck()` fails at once instead of hanging startup, and only that package fails to activate. - A package that fails only because of the host lifecycle errors is not rolled back or marked `"error"`, and is retried on the next start. **Feature switches** (`b50dec60c`) - One registry (`packages/shared/src/schemas/feature-settings.schema.ts`) and one settings section, Settings > Advanced > Features. Server code reads an in-memory copy through `isFeatureEnabled()`, so busy paths pay nothing. - This PR registers only the two switches for behaviour it adds itself: `stableLorebookGroupPicks` and `providerRetry`. Both are off. `LOREBOOK_STABLE_GROUP_WINNERS` and `PROVIDER_RETRY_TRANSIENT_ERRORS` win when set, and the switch is then shown locked with the variable's name. - Parts 6 to 8 (F, G, H) add their own switches to this registry. **Best-effort helpers** (`416f7fe2e`) - `lib/best-effort.ts`: `logSuppressed`, `orFallback` and `bestEffort` log a deliberately swallowed failure through `logRateLimited`. Nothing calls them yet in this PR. The reviewed fixes in parts 4 and 5 (D, E) use them. **Hand security review** (`fa7daa8b2`, `69a196ebb`) - CodeQL was reviewed by hand, not run. The runtime diagnostics route got its own rate limit, and two shutdown source checks in a regression now use linear-time regexes. **Review fixes** (local CodeRabbit) - 8 findings fixed: - Agent retries resolve macros in stored lorebook text used as a fallback (`0cb02af33`). - Seeded group picks no longer depend on activation order (`7037ec93e`). - The Active Context preview uses the same seeded winner as generation (`5fe1c57c8`). - A synchronous `inject()` throw in a held callback call reaches the callback (`14451af75`). - The scene wrap warning keeps JSON parse text out of the log (`d4c282404`). - `.env.example` no longer locks the two switches off (`230ef84cb`). - The features query refreshes after 30 s, like the external extension policy query (`a35f5fb81`). - A placeholder in the overview doc was filled in. - 3 findings rejected, with reasons: - Concurrent saves of the switches: last writer wins, like the other whole-object settings routes. - Polling the switches: not needed. The query refreshes on focus and after 30 s. - The restart path: keeps upstream's behaviour on purpose. The shutdown settings apply to signal shutdowns only. **Matching existing UI** - The Features section copies `SettingsSection` and `ToggleSetting` (`SettingsPanel.tsx`, `SettingControls.tsx`). - A switch pinned by an environment variable is shown the same way as the server-locked toggle of the External Extensions setting. ## Validation - [ ] `pnpm check` passes locally - Had 2 steps fail, but it is from M.E code, not my own. - [ ] Container (Docker / Podman) built and ran without issue - Did not test. May have the time later. - [x] Ran the app, clicked through the changes manually - [] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - did not check, empty and error states weren't recorded. - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` The boxes are left unticked for a human, per `AGENTS.md`. Everything below ran on the tip `d4c282404`. No paid model calls were made. | Check | Result | |---|---| | CI-equivalent, **Linux** (WSL Ubuntu 24.04, Node 24) | `complete-node-regressions` **384 / 384** | | Full regression suite, Windows 11 | 379 / 384. The 5 failures are the known Windows-only ones (`decision-sidecar-runtime`, `gallery-previews`, `request-timeouts`, `server-signal-shutdown`, `storage-writer-lock`) and fail the same way on plain `staging`. | | `tsc --noEmit` (shared, server, client, root, token estimation) | clean | | Lint | 0 errors | | Prettier, locales, builds | pass | | e2e `mobile-chromium`, settings specs (`core-flows`, `issue-sweep-settings`, `ux-feedback-sweep`, `afternoon-sweep`, `client-runtime-diagnostics`) | 171 passed, 0 failed | | e2e `mobile-webkit`, same specs | The failures left after a rerun are identical to plain `staging`. | | CodeQL | reviewed by hand, not run | ### Manual verification notes - Checked Settings > Advanced > Features in the default and SillyTavern themes, light and dark, at desktop and phone sizes. - Each piece has regressions that check the default path is unchanged and the new path works: `logging-request-trail`, `logging-failure-lines`, `logging-startup-timeline`, `lorebook-group-seed`, `lorebook-scan-compaction`, `robustness-storage-write`, `robustness-boot-performance`, `robustness-shutdown-safety`, `robustness-provider-resilience`, `robustness-runtime-diagnostics`, `startup-inject-gate`, `feature-settings`, `best-effort`. - The overview doc lists a "how to check it yourself" command for each piece. ## Human to tick Based on the evidence above: - **`pnpm check` passes locally**: supported. Its steps (tsc, lint, Prettier, locales, builds, regressions) all passed, apart from the 5 known Windows-only failures, and Linux is 384 / 384. If you want the literal command, run `pnpm check` once before ticking. - **Ran the app, clicked through the changes manually**: supported for the Features section at desktop and phone sizes in both themes, light and dark. Tick after trying it once yourself. - **Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed**: supported (`CHANGELOG.md`, `CONTRIBUTING.md`, `.env.example`, `docs/CONFIGURATION.md`, `docs/configuration/features.md`, `docs/development/logging.md`, `docs/settings/settings-overview.md` and the overview). Not supported by the evidence, leave unticked unless done by hand: - Container built and ran: not run for this PR. - Checked edge cases: light and dark and the phone viewport were checked for the Features section, but empty states and error paths were not recorded. - Above manual verification completed, and Read and followed `CONTRIBUTING.md`: only a human can confirm these. - No docs changes needed, and Version/release files updated: do not apply. - Translated docs: see below. ## Needs manual verification - The full browser lanes on Linux CI. Locally only the settings specs ran, on `mobile-chromium` and `mobile-webkit`. - A real CodeQL run. The findings so far come from a hand review. - Flip **Stable lorebook picks** and **Retry failed provider calls** in a live app, and check that setting either environment variable shows the switch locked. - Build and run the Docker image once. - Decide whether the `CONTRIBUTING.md` Logging line and the new docs need a `[docs-i18n]` follow-up issue for the translated guides. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) The PR adds six CHANGELOG entries under `[Unreleased]`, a link from the Logging section of `CONTRIBUTING.md` to `docs/development/logging.md`, a Lorebooks and a Robustness table in `docs/CONFIGURATION.md`, `docs/configuration/features.md`, commented-out entries in `.env.example`, and `docs/contrib/engine-foundations-overview.md`. No version bump. ## UI evidence (if applicable) Screenshot from a test instance with invented data, taken on this branch. **Settings > Advanced > Features** ![Settings > Advanced > Features](https://raw.githubusercontent.com/SirAdoni/Marinara-Engine-contrib/780dd41d0bf7adadbd81503aba92931d32a48e3a/A-features-page_desktop-light_v1.0.png) ## Remaining steps - The manual checks listed above. - After this merges, open parts 4 to 8 (D to H), which are stacked on this branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added Advanced settings for optional stable lorebook group picks and transient provider retries. Both are off by default and can be overridden through environment settings. * Added optional lorebook scan compaction to reduce stored content, with a maintenance tool for existing data. * Added a privileged, rate-limited runtime diagnostics endpoint with process and storage information. * **Improvements** * Added request IDs to responses and logs, with clearer startup and shutdown reporting. * Added configurable storage and shutdown robustness options. * Provider retries cover eligible connection failures and gateway errors, stop once output begins, and do not delay connections with a fallback provider. * Improved failure logging to limit repeated messages and keep potentially sensitive details out of routine logs. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:18:08 +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#7273
No description provided.