[PR #8323] [MERGED] fix: prevent unintended post-history macro rerolls #8275

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

📋 Pull Request Information

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

Base: staging ← Head: fix/8318-single-macro-evaluation


📝 Commits (3)

  • 5c4d430 test: reproduce deferred character memory rerolls
  • 8ab2246 fix: reuse resolved post-history instructions per prompt pass
  • 334c052 test: cover merged post-history prompt reuse

📊 Changes

5 files changed (+263 additions, -27 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+19 -2)
📝 packages/server/src/services/prompt/assembler.ts (+3 -0)
📝 packages/server/src/services/prompt/macro-context.ts (+4 -1)
📝 packages/shared/src/utils/macro-engine.ts (+15 -24)
➕ scripts/regressions/deferred-character-side-effects.regression.ts (+222 -0)

📄 Description

Linked issue

Closes #8318

Why this change

A card can reveal one memory to the main model while silently marking another memory as fired. Post History Instructions were evaluated again when preparing character profiles, and deferred name expansion also evaluated unused card fields.

What changed

  • Reuse the exact Post History Instructions resolved during prompt injection when preparing agent and responder profiles. Preserve the later Game injection order and evaluate fresh instructions on the next turn.
  • Resolve deferred card fields only when their token is present. Repeated tokens share the same field result.
  • Add deterministic memory-reroll and actual generation-route regressions covering preset Individual and merged groups and default single-character Roleplay, Conversation, and Game.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Local proof at final head 334c052d19040daaea8ee5e09f5498cb584abefa:

  • Preserved staging negative: the prompt says PROMISE, but an unrelated deferred name changes the die to BEGINNING and leaves both memory flags FIRED. A second retained negative captures the activated agent receiving BEGINNING while the main provider prompt contains PROMISE.
  • Focused regression passes: the main model, activated custom agent, and persisted variables agree on the same memory in all five route variants, including merged responders. The next normal turn evaluates once again. Eight field controls retain requested expansion and shared repeated-token values.
  • Existing prompt and chat-variable-history regressions pass. Shared/server non-emitting TypeScript checks, the new regression's separate type check, formatting, and git diff --check pass.
  • Guarded pnpm check passes, including the production build. pnpm regression:prompt passes all three regression files. The focused fixture also passes against the actual compiled server/shared modules.
  • pnpm smoke:ui passes 7/7 desktop Chromium tests with one worker. No UI layout changes are included.
  • Fresh full local CodeRabbit review covered all five files at 8ab224699 and reported two duplicate requests for merged-responder coverage. That coverage was added; a fresh final test-only delta review at 334c052d1 reports zero findings. Production source did not change between those review heads.
  • The worktree is clean; package manifests and the installed lock retain their baseline hashes. The server build records 334c052d1904, its built-file fingerprint verifies clean, and the new compiled artifacts were hashed separately from the retained earlier Gacha baseline.

GitHub CI and Dottore Review remain independent merge gates.

Manual verification notes

  • Manually verify the reported Hangover card produces one memory flash and matching Chat Settings variables after one turn.
  • The reported card was not supplied. Controlled fixtures exercise its described random/one-time-memory pattern through real prompt/generation code and a local fake provider; no real model or physical device is claimed.

Claim boundary

This fixes unintended re-evaluation during character-profile preparation and unused deferred-field expansion. Explicitly authoring the same executable macro in multiple prompt sections remains separate execution. It adds no global macro cache and changes no persisted format or provider routing.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened
  • Version/release files updated

No user-facing docs, localization, release metadata, or storage format changes.

UI evidence

No UI changes. Before/after proof is deterministic macro state plus actual main-provider and activated-agent payloads.


🔄 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/8323 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/25/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/8318-single-macro-evaluation` --- ### 📝 Commits (3) - [`5c4d430`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5c4d43006587a2f118b1e6a516bae6e5009b7fc6) test: reproduce deferred character memory rerolls - [`8ab2246`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8ab224699f1d6fddf26fe6d88e17bc1b92677ad6) fix: reuse resolved post-history instructions per prompt pass - [`334c052`](https://github.com/Pasta-Devs/Marinara-Engine/commit/334c052d19040daaea8ee5e09f5498cb584abefa) test: cover merged post-history prompt reuse ### 📊 Changes **5 files changed** (+263 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+19 -2) 📝 `packages/server/src/services/prompt/assembler.ts` (+3 -0) 📝 `packages/server/src/services/prompt/macro-context.ts` (+4 -1) 📝 `packages/shared/src/utils/macro-engine.ts` (+15 -24) ➕ `scripts/regressions/deferred-character-side-effects.regression.ts` (+222 -0) </details> ### 📄 Description ## Linked issue Closes #8318 ## Why this change A card can reveal one memory to the main model while silently marking another memory as fired. Post History Instructions were evaluated again when preparing character profiles, and deferred name expansion also evaluated unused card fields. ## What changed - Reuse the exact Post History Instructions resolved during prompt injection when preparing agent and responder profiles. Preserve the later Game injection order and evaluate fresh instructions on the next turn. - Resolve deferred card fields only when their token is present. Repeated tokens share the same field result. - Add deterministic memory-reroll and actual generation-route regressions covering preset Individual and merged groups and default single-character Roleplay, Conversation, and Game. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Local proof at final head `334c052d19040daaea8ee5e09f5498cb584abefa`: - Preserved staging negative: the prompt says PROMISE, but an unrelated deferred name changes the die to BEGINNING and leaves both memory flags FIRED. A second retained negative captures the activated agent receiving BEGINNING while the main provider prompt contains PROMISE. - Focused regression passes: the main model, activated custom agent, and persisted variables agree on the same memory in all five route variants, including merged responders. The next normal turn evaluates once again. Eight field controls retain requested expansion and shared repeated-token values. - Existing prompt and chat-variable-history regressions pass. Shared/server non-emitting TypeScript checks, the new regression's separate type check, formatting, and `git diff --check` pass. - Guarded `pnpm check` passes, including the production build. `pnpm regression:prompt` passes all three regression files. The focused fixture also passes against the actual compiled server/shared modules. - `pnpm smoke:ui` passes 7/7 desktop Chromium tests with one worker. No UI layout changes are included. - Fresh full local CodeRabbit review covered all five files at `8ab224699` and reported two duplicate requests for merged-responder coverage. That coverage was added; a fresh final test-only delta review at `334c052d1` reports zero findings. Production source did not change between those review heads. - The worktree is clean; package manifests and the installed lock retain their baseline hashes. The server build records `334c052d1904`, its built-file fingerprint verifies clean, and the new compiled artifacts were hashed separately from the retained earlier Gacha baseline. GitHub CI and Dottore Review remain independent merge gates. ### Manual verification notes - Manually verify the reported Hangover card produces one memory flash and matching Chat Settings variables after one turn. - The reported card was not supplied. Controlled fixtures exercise its described random/one-time-memory pattern through real prompt/generation code and a local fake provider; no real model or physical device is claimed. ## Claim boundary This fixes unintended re-evaluation during character-profile preparation and unused deferred-field expansion. Explicitly authoring the same executable macro in multiple prompt sections remains separate execution. It adds no global macro cache and changes no persisted format or provider routing. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened - [ ] Version/release files updated No user-facing docs, localization, release metadata, or storage format changes. ## UI evidence No UI changes. Before/after proof is deterministic macro state plus actual main-provider and activated-agent payloads. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-26 04:04:18 +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#8275
No description provided.