[GH-ISSUE #3450] [Issue]: #3449 relocation-{{#if}} regressions — context double-inject, slot over-match drops retrieval, else-branch blank line #1865

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

Originally created by @kolacheee on GitHub (Jul 10, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3450

Summary

A post-merge review of #3449 (relocation macros in {{#if}}) surfaced three regressions in staging: the current-context block is injected twice, a {{#if}} comparing to a relocation-alias string literal silently drops retrieval, and a deferred {{else}} branch keeps a stray blank line.

Expected behavior

  1. The current-context block is sent to the model once.
  2. {{#if topic == "memories"}} (comparing to the literal string "memories") does not affect memory recall.
  3. A deferred standalone {{#if}}…{{else}}…{{/if}} whose else branch is selected has no leading blank line — same as an evaluated block.

Actual behavior

  1. Context double-injection. A preset that references {{context}} only inside a deferred conditional (e.g. {{#if context != ""}}…{{context}}…{{/if}}) leaves no literal {{context}} after deferral. The context tail-fallback keys on replaceConversationContextMacro's return value, which is false for a deferred token, so it pushes the context block as a trailing user message — and the decode pass also inlines it into the system prompt. Result: the context block (latest user message, status, activity, timestamp, mentions) is sent twice, every turn. generate.routes.ts ~2110.

  2. Slot-detection over-match drops retrieval. Slot detection uses a loose regex over {{#if …}} bodies (conversationContextMacroConditionPattern, ~499/528). For {{#if topic == "memories"}} or {{#if user.status == "x"}}, \bmemories\b/\bstatus\b matches inside the quoted literal / dotted operand, flipping slots.memories (or .status/.commands/.reactRules/.lorebook) true — but the parser-based defer predicate correctly declines. With the slot wrongly true, the code takes the "macro placed" branch (replace a bare {{memories}} that isn't there) instead of the normal recall injection, so memory recall / react rules / commands / lorebook silently vanish.

  3. Deferred else-branch blank line. trimDeferredStandaloneBranches (macro-engine.ts ~998) trims the leading newline only for branch index 0, but the evaluate-now path strips whichever branch is selected — so a selected {{else}}/{{else if}} branch keeps a stray blank line the inline path removes.

Steps to reproduce

  1. Conversation preset with {{#if context != ""}}Current situation:\n{{context}}{{/if}} and no bare {{context}} → context block appears twice.
  2. Preset with {{#if topic == "memories"}}…{{/if}} and no bare {{memories}} → memory recall no longer injected.
  3. Preset with a standalone {{#if memories != ""}}…{{else}}…{{/if}} and empty memories → the else branch renders with a leading blank line.

Environment

  • Marinara Engine version: staging (post-#3449)
  • Install type: source
  • OS + version: Windows 11
  • Browser or app shell: N/A (prompt-assembly)

Logs, screenshots, or video

N/A — traced in code; fix PR incoming.

Additional context

Root cause of (1) and (2) is a slot-detection path that disagrees with the parser-based defer decision. Fix: drive slot detection from the actual deferred tokens (same parser) and key the context fallback on the slot, not the replace() return. Follow-up to #3449 / #3448.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jul 10, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3450 ## Summary A post-merge review of #3449 (relocation macros in `{{#if}}`) surfaced three regressions in `staging`: the current-context block is injected twice, a `{{#if}}` comparing to a relocation-alias string literal silently drops retrieval, and a deferred `{{else}}` branch keeps a stray blank line. ## Expected behavior 1. The current-context block is sent to the model **once**. 2. `{{#if topic == "memories"}}` (comparing to the literal string `"memories"`) does not affect memory recall. 3. A deferred standalone `{{#if}}…{{else}}…{{/if}}` whose else branch is selected has no leading blank line — same as an evaluated block. ## Actual behavior 1. **Context double-injection.** A preset that references `{{context}}` only inside a deferred conditional (e.g. `{{#if context != ""}}…{{context}}…{{/if}}`) leaves no literal `{{context}}` after deferral. The context tail-fallback keys on `replaceConversationContextMacro`'s return value, which is `false` for a deferred token, so it **pushes the context block as a trailing user message** — and the decode pass **also inlines it** into the system prompt. Result: the context block (latest user message, status, activity, timestamp, mentions) is sent twice, every turn. `generate.routes.ts` ~2110. 2. **Slot-detection over-match drops retrieval.** Slot detection uses a loose regex over `{{#if …}}` bodies (`conversationContextMacroConditionPattern`, ~499/528). For `{{#if topic == "memories"}}` or `{{#if user.status == "x"}}`, `\bmemories\b`/`\bstatus\b` matches inside the quoted literal / dotted operand, flipping `slots.memories` (or `.status`/`.commands`/`.reactRules`/`.lorebook`) true — but the parser-based defer predicate correctly declines. With the slot wrongly true, the code takes the "macro placed" branch (replace a bare `{{memories}}` that isn't there) instead of the normal recall injection, so **memory recall / react rules / commands / lorebook silently vanish**. 3. **Deferred else-branch blank line.** `trimDeferredStandaloneBranches` (`macro-engine.ts` ~998) trims the leading newline only for branch index 0, but the evaluate-now path strips whichever branch is selected — so a selected `{{else}}`/`{{else if}}` branch keeps a stray blank line the inline path removes. ## Steps to reproduce 1. Conversation preset with `{{#if context != ""}}Current situation:\n{{context}}{{/if}}` and no bare `{{context}}` → context block appears twice. 2. Preset with `{{#if topic == "memories"}}…{{/if}}` and no bare `{{memories}}` → memory recall no longer injected. 3. Preset with a standalone `{{#if memories != ""}}…{{else}}…{{/if}}` and empty memories → the else branch renders with a leading blank line. ## Environment - Marinara Engine version: staging (post-#3449) - Install type: source - OS + version: Windows 11 - Browser or app shell: N/A (prompt-assembly) ## Logs, screenshots, or video N/A — traced in code; fix PR incoming. ## Additional context Root cause of (1) and (2) is a slot-detection path that disagrees with the parser-based defer decision. Fix: drive slot detection from the actual deferred tokens (same parser) and key the context fallback on the slot, not the replace() return. Follow-up to #3449 / #3448. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:43:21 +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#1865
No description provided.