[GH-ISSUE #3435] [Issue]: New conversation macros don't resolve inside {{#if}} conditions (block always renders); removed blocks leave blank lines #1858

Closed
opened 2026-10-21 05:43:18 +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/3435

Originally assigned to: @kolacheee on GitHub.

Summary

Two problems when using the new Conversation preset macros inside {{#if}} blocks:

  1. (functional) A condition like {{#if char_about != ""}} is always true — the block renders even when the macro's value is empty — because the {{#if}} condition evaluator doesn't resolve the new conversation macros.
  2. (cosmetic) When an {{#if}} block is removed, it leaves an extra blank line.

Expected behavior

  1. {{#if char_about != ""}} evaluates the actual value of {{char_about}} — so the block is hidden when the about-me is empty.
  2. A removed standalone {{#if}} block leaves no blank line.

Actual behavior

This template:

<participant_profiles>
Each conversation participant's "about me". ...
{{#if char_about != ""}}
- {{char}}: {{char_about}}
{{/if}}
{{#if persona_about != ""}}
- {{user}}: {{persona_about}}
{{/if}}
</participant_profiles>

resolves to (note - Locutus: renders with an empty about, and the spacing has extra blank lines):

<participant_profiles>
Each conversation participant's "about me". ...

- Locutus: 

- Kat: :camera: Photographer, :d20lesbian: Dork

</participant_profiles>

Steps to reproduce

  1. In a Conversation-mode preset, add a block gated on a new macro, e.g. {{#if char_about != ""}}- {{char}}: {{char_about}}{{/if}}.
  2. Use it with a character/persona whose about-me is empty.
  3. The block renders anyway (empty value), and the removed sibling blocks leave blank lines.

Environment

  • Marinara Engine version: 2.1.x (staging)
  • Install type: installer
  • OS + version: Windows 11
  • Browser or app shell: Chrome

Logs, screenshots, or video

See the before/after template above.

Additional context

Bug 1 root cause (verified on staging): the {{#if}} condition evaluator and the flat {{...}} substitution use two different, non-shared resolution paths, and the new conversation macros were only added to the flat pass.

  • The left operand of char_about != "" is resolved by resolveConditionalOperand (packages/shared/src/utils/macro-engine.ts:634-701), whose switch has cases for char/user/persona/description/… but none for char_about/persona_about (nor reactRules/commands/status/context). It falls through to the default return ctx.variables[token] ?? token (~:698), returning the unresolved literal string "char_about".
  • The comparison then computes "char_about" !== "" → true, so the block always renders.
  • {{char_about}}/{{persona_about}} are only resolved to their real values in the flat replace pass (macro-engine.ts:1298-1299, from ctx.convoFields), which runs on the block body — after the condition has already (wrongly) passed → hence - Locutus: with an empty about.
  • (Aside: writing {{char_about}} != "" with braces happens to work today, because a pre-pass expands braced macros before the condition is parsed. But bare tokens are the intended {{#if}} convention.)

Suggested fix: make the condition evaluator resolve the same macro set as the flat pass — ideally route unknown bare operands through the full macro resolver (so any macro valid in {{...}} is also valid inside {{#if}}), instead of the ctx.variables[token] ?? token fallback. Mirror in isCharacterConditionalOperand / conditionDependsOnCharacter if those gate per-character re-evaluation.

Bug 2 (the extra blank lines) root cause (verified): the macro engine never "chomps" the newline of a standalone block tag. When an {{#if}} block is false, resolveConditionalBlocks (macro-engine.ts:950-990) keeps the newline before the tag, replaces the block with an empty string, then resumes right after the {{/if}} keeping the newline after it — so the two bracketing newlines merge into a blank line. There is no standalone-tag newline trim anywhere (only a whole-output trim at :1403-1405, which doesn't touch interior blank lines). This affects all {{#if}} blocks, not just conversation macros. Fix: chomp the trailing newline + leading indent of a standalone block tag (Handlebars trim_blocks / Jinja style), guarding inline conditionals. Cosmetic / low priority.

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/3435 Originally assigned to: @kolacheee on GitHub. ## Summary Two problems when using the new Conversation preset macros inside `{{#if}}` blocks: 1. **(functional)** A condition like `{{#if char_about != ""}}` is **always true** — the block renders even when the macro's value is empty — because the `{{#if}}` condition evaluator doesn't resolve the new conversation macros. 2. **(cosmetic)** When an `{{#if}}` block is removed, it leaves an extra **blank line**. ## Expected behavior 1. `{{#if char_about != ""}}` evaluates the actual value of `{{char_about}}` — so the block is hidden when the about-me is empty. 2. A removed standalone `{{#if}}` block leaves no blank line. ## Actual behavior This template: ``` <participant_profiles> Each conversation participant's "about me". ... {{#if char_about != ""}} - {{char}}: {{char_about}} {{/if}} {{#if persona_about != ""}} - {{user}}: {{persona_about}} {{/if}} </participant_profiles> ``` resolves to (note `- Locutus:` renders with an **empty** about, and the spacing has extra blank lines): ``` <participant_profiles> Each conversation participant's "about me". ... - Locutus: - Kat: :camera: Photographer, :d20lesbian: Dork </participant_profiles> ``` ## Steps to reproduce 1. In a Conversation-mode preset, add a block gated on a new macro, e.g. `{{#if char_about != ""}}- {{char}}: {{char_about}}{{/if}}`. 2. Use it with a character/persona whose about-me is empty. 3. The block renders anyway (empty value), and the removed sibling blocks leave blank lines. ## Environment - Marinara Engine version: 2.1.x (staging) - Install type: installer - OS + version: Windows 11 - Browser or app shell: Chrome ## Logs, screenshots, or video See the before/after template above. ## Additional context **Bug 1 root cause (verified on staging):** the `{{#if}}` condition evaluator and the flat `{{...}}` substitution use two different, non-shared resolution paths, and the new conversation macros were only added to the flat pass. - The left operand of `char_about != ""` is resolved by `resolveConditionalOperand` (`packages/shared/src/utils/macro-engine.ts:634-701`), whose `switch` has cases for `char`/`user`/`persona`/`description`/… but **none for `char_about`/`persona_about`** (nor `reactRules`/`commands`/`status`/`context`). It falls through to the default `return ctx.variables[token] ?? token` (~:698), returning the **unresolved literal string `"char_about"`**. - The comparison then computes `"char_about" !== ""` → **true**, so the block always renders. - `{{char_about}}`/`{{persona_about}}` are only resolved to their real values in the flat replace pass (`macro-engine.ts:1298-1299`, from `ctx.convoFields`), which runs on the block **body** — after the condition has already (wrongly) passed → hence `- Locutus:` with an empty about. - (Aside: writing `{{char_about}} != ""` *with braces* happens to work today, because a pre-pass expands braced macros before the condition is parsed. But bare tokens are the intended `{{#if}}` convention.) Suggested fix: make the condition evaluator resolve the same macro set as the flat pass — ideally route unknown bare operands through the full macro resolver (so any macro valid in `{{...}}` is also valid inside `{{#if}}`), instead of the `ctx.variables[token] ?? token` fallback. Mirror in `isCharacterConditionalOperand` / `conditionDependsOnCharacter` if those gate per-character re-evaluation. **Bug 2 (the extra blank lines) root cause (verified):** the macro engine never "chomps" the newline of a standalone block tag. When an `{{#if}}` block is false, `resolveConditionalBlocks` (`macro-engine.ts:950-990`) keeps the newline **before** the tag, replaces the block with an empty string, then resumes right **after** the `{{/if}}` keeping the newline after it — so the two bracketing newlines merge into a blank line. There is no standalone-tag newline trim anywhere (only a whole-output trim at `:1403-1405`, which doesn't touch interior blank lines). This affects **all** `{{#if}}` blocks, not just conversation macros. Fix: chomp the trailing newline + leading indent of a standalone block tag (Handlebars `trim_blocks` / Jinja style), guarding inline conditionals. Cosmetic / low priority. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:43: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#1858
No description provided.