[PR #2457] [MERGED] Fix deferred speaker macro resolution #5614

Closed
opened 2026-10-22 04:17:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2457
Author: @Promansis
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Promansis

Base: refactor ← Head: issue-2446-deferred-speaker-macros


📝 Commits (5)

  • 50e4d74 Fix deferred speaker macro resolution
  • c9e058d Fix scoped deferred macro reuse
  • 8f83ac8 Delete src/engine/shared/macros/macro-engine.test.ts
  • d1c4928 Delete src/engine/generation/prompt-assembly.test.ts
  • 2961041 Merge branch 'refactor' into issue-2446-deferred-speaker-macros

📊 Changes

2 files changed (+266 additions, -33 deletions)

View changed files

📝 src/engine/generation/prompt-assembly.ts (+89 -12)
📝 src/engine/shared/macros/macro-engine.ts (+177 -21)

📄 Description

Linked issue

Closes #2446

Why this change

  • Refactor prompt assembly resolved speaker-scoped character macros too early for multi-character individual roleplay turns, especially when a reusable prompt context was assembled before the final target speaker was known.
  • This could resolve {{char}}, character field macros, and character-dependent conditionals against the wrong speaker before provider handoff.

What changed

  • Added opt-in deferred character macro tokens and finalization helpers to the shared macro engine.
  • Deferred prompt-level speaker macros during targeted individual group assembly, then finalized them against the selected target character before prompt handoff.
  • Added a provider-handoff guard so deferred internal tokens cannot leak into prompt messages.
  • Added a focused regression test covering reused prompt context, {{char}}, {{description}}, and character-dependent conditionals.

Refactor impact

Primary owner:

engine generation / prompt assembly

Impact areas reviewed:

  • Roleplay individual group turns
  • Runtime prompt assembly
  • Shared macro engine
  • Lorebook, regex, prompt-choice, and greeting macro resolution paths used by prompt assembly

Boundary notes:

  • Behavior stays in React-free engine code.
  • No React UI, shared API wrapper, provider transport, card storage/import, Rust command, or remote-runtime routing changes.

Pressure points touched:

  • src/engine/generation/prompt-assembly.ts
  • src/engine/shared/macros/macro-engine.ts

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm test -- src/engine/generation/prompt-assembly.test.ts
  • pnpm typecheck
  • pnpm check:architecture
  • pnpm check
  • git diff --check

Durable test rationale: this fixes a regression-prone prompt assembly invariant where provider-ready prompt messages must resolve speaker-scoped macros against the target character and must not leak deferred placeholders. Existing tests did not cover reused prompt context across targeted individual group turns. The new test is narrow and stays in the existing prompt assembly test file.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Internal prompt assembly bugfix; no new user-discoverable feature or setting.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

No visible UI changes.


🔄 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/2457 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `refactor` ← **Head:** `issue-2446-deferred-speaker-macros` --- ### 📝 Commits (5) - [`50e4d74`](https://github.com/Pasta-Devs/Marinara-Engine/commit/50e4d7439a907967e6a239dcbf708f39e38274cb) Fix deferred speaker macro resolution - [`c9e058d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c9e058dbf729c59ffecf77b6b1782162a2a7f4d4) Fix scoped deferred macro reuse - [`8f83ac8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8f83ac86b060541be4def62e3793816febf5c7af) Delete src/engine/shared/macros/macro-engine.test.ts - [`d1c4928`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d1c4928066e5cad4e70df3704552cde44e078401) Delete src/engine/generation/prompt-assembly.test.ts - [`2961041`](https://github.com/Pasta-Devs/Marinara-Engine/commit/296104173aaef4feed2ae5c793fa9eca01296ea1) Merge branch 'refactor' into issue-2446-deferred-speaker-macros ### 📊 Changes **2 files changed** (+266 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/generation/prompt-assembly.ts` (+89 -12) 📝 `src/engine/shared/macros/macro-engine.ts` (+177 -21) </details> ### 📄 Description ## Linked issue Closes #2446 ## Why this change - Refactor prompt assembly resolved speaker-scoped character macros too early for multi-character individual roleplay turns, especially when a reusable prompt context was assembled before the final target speaker was known. - This could resolve `{{char}}`, character field macros, and character-dependent conditionals against the wrong speaker before provider handoff. ## What changed - Added opt-in deferred character macro tokens and finalization helpers to the shared macro engine. - Deferred prompt-level speaker macros during targeted individual group assembly, then finalized them against the selected target character before prompt handoff. - Added a provider-handoff guard so deferred internal tokens cannot leak into prompt messages. - Added a focused regression test covering reused prompt context, `{{char}}`, `{{description}}`, and character-dependent conditionals. ## Refactor impact Primary owner: engine generation / prompt assembly Impact areas reviewed: - Roleplay individual group turns - Runtime prompt assembly - Shared macro engine - Lorebook, regex, prompt-choice, and greeting macro resolution paths used by prompt assembly Boundary notes: - Behavior stays in React-free engine code. - No React UI, shared API wrapper, provider transport, card storage/import, Rust command, or remote-runtime routing changes. Pressure points touched: - `src/engine/generation/prompt-assembly.ts` - `src/engine/shared/macros/macro-engine.ts` ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm test -- src/engine/generation/prompt-assembly.test.ts` - `pnpm typecheck` - `pnpm check:architecture` - `pnpm check` - `git diff --check` Durable test rationale: this fixes a regression-prone prompt assembly invariant where provider-ready prompt messages must resolve speaker-scoped macros against the target character and must not leak deferred placeholders. Existing tests did not cover reused prompt context across targeted individual group turns. The new test is narrow and stays in the existing prompt assembly test file. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Internal prompt assembly bugfix; no new user-discoverable feature or setting. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence No visible UI changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:50 +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#5614
No description provided.