[GH-ISSUE #4740] [Issue]: Boolean preset variables set to OFF are still injected in v2.4.1 #2606

Closed
opened 2026-10-21 05:51:11 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @The0th3r on GitHub (Aug 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4740

Originally assigned to: @SpicyMarinara on GitHub.

Summary

In Marinara Engine v2.4.1, a single-option preset variable configured as a Boolean toggle may still inject its option value into the assembled prompt when the toggle is OFF.
The UI represents the OFF state as an empty string (""), but resolveChoiceVariableValue() sanitizes that value as invalid and subsequently falls back to the first option. For a single-option Boolean variable, that first option is the ON value, so the toggle effectively becomes ON again during prompt assembly.
This conflicts with the documented Boolean-toggle behavior: ON should insert the option value, while OFF should insert nothing.

Steps to reproduce

  1. Create a preset variable with exactly one option.
    Example:
    Variable name:
    TEST_BOOLEAN
    Option label:
    Test enabled
    Option value:
    BOOLEAN_IS_ON
    Add this to a prompt section:
    BEFORE
    {{TEST_BOOLEAN}}
    AFTER

  2. Assign the preset to a chat.
    Set TEST_BOOLEAN to OFF.
    Inspect the assembled prompt.

Expected behavior

With the toggle OFF:
BEFORE

AFTER

Actual behavior

The option value is injected despite the toggle being OFF:
BEFORE
BOOLEAN_IS_ON
AFTER

Environment

  • Marinara Engine version: v2.4.1
  • Install type: (source / installer / docker / termux / other)
  • OS + version: macOS 26.3.1
  • Browser or app shell: Safari Version 26.3.1

Logs, screenshots, or video

Additional context

Cause

ChoiceSelectionModal intentionally represents an OFF Boolean toggle as an empty string.
However, in:
packages/server/src/services/prompt/assembler.ts
resolveChoiceVariableValue() passes that empty string through sanitizeChoiceSelection().
Because "" is not one of the option values, it becomes undefined. The function then reaches its fallback:
return input.options[0]?.value ?? "";
For a Boolean variable with one option, this restores the ON value.
An explicit OFF state therefore becomes indistinguishable from a missing selection.

Proposed fix

Preserve explicit empty selections before sanitizing:
const isMulti = readChoiceFlag(input.multiSelect) || (isRandom && Array.isArray(input.selected));

// Empty selections are intentional OFF states. Only an absent selection
// should fall back to the first option.
if (input.selected === "" || (Array.isArray(input.selected) && input.selected.length === 0)) {
return "";
}

const selected = sanitizeChoiceSelection(input.selected, input.options, isMulti);
This retains the existing fallback behavior for genuinely absent selections while preserving the intentional empty/off state.

Verification

Tested locally against v2.4.1.
After applying the change and rebuilding shared, server, and client:
Boolean toggle ON → option value is injected.
Boolean toggle OFF → nothing is injected.
Prompt assembly behaves as documented.
A regression test should cover at least:
Single-option Boolean ON returns its option value.
Single-option Boolean OFF ("") returns "".
Truly absent selection (undefined) retains the existing first-option fallback where appropriate.
Explicit empty multi-select remains empty rather than unexpectedly selecting an option.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • [] I DID NOT read this template and provide the requested details.
Originally created by @The0th3r on GitHub (Aug 7, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4740 Originally assigned to: @SpicyMarinara on GitHub. ## Summary In Marinara Engine v2.4.1, a single-option preset variable configured as a Boolean toggle may still inject its option value into the assembled prompt when the toggle is OFF. The UI represents the OFF state as an empty string (""), but resolveChoiceVariableValue() sanitizes that value as invalid and subsequently falls back to the first option. For a single-option Boolean variable, that first option is the ON value, so the toggle effectively becomes ON again during prompt assembly. This conflicts with the documented Boolean-toggle behavior: ON should insert the option value, while OFF should insert nothing. ## Steps to reproduce 1. Create a preset variable with exactly one option. Example: Variable name: TEST_BOOLEAN Option label: Test enabled Option value: BOOLEAN_IS_ON Add this to a prompt section: BEFORE {{TEST_BOOLEAN}} AFTER 2. Assign the preset to a chat. Set TEST_BOOLEAN to OFF. Inspect the assembled prompt. ## Expected behavior With the toggle OFF: BEFORE AFTER ## Actual behavior The option value is injected despite the toggle being OFF: BEFORE BOOLEAN_IS_ON AFTER ## Environment - Marinara Engine version: v2.4.1 - Install type: (source / installer / docker / termux / other) - OS + version: macOS 26.3.1 - Browser or app shell: Safari Version 26.3.1 ## Logs, screenshots, or video <!-- Paste relevant logs and add screenshots when possible --> ## Additional context ## Cause ChoiceSelectionModal intentionally represents an OFF Boolean toggle as an empty string. However, in: packages/server/src/services/prompt/assembler.ts resolveChoiceVariableValue() passes that empty string through sanitizeChoiceSelection(). Because "" is not one of the option values, it becomes undefined. The function then reaches its fallback: return input.options[0]?.value ?? ""; For a Boolean variable with one option, this restores the ON value. An explicit OFF state therefore becomes indistinguishable from a missing selection. ## Proposed fix Preserve explicit empty selections before sanitizing: const isMulti = readChoiceFlag(input.multiSelect) || (isRandom && Array.isArray(input.selected)); // Empty selections are intentional OFF states. Only an absent selection // should fall back to the first option. if (input.selected === "" || (Array.isArray(input.selected) && input.selected.length === 0)) { return ""; } const selected = sanitizeChoiceSelection(input.selected, input.options, isMulti); This retains the existing fallback behavior for genuinely absent selections while preserving the intentional empty/off state. ## Verification Tested locally against v2.4.1. After applying the change and rebuilding shared, server, and client: Boolean toggle ON → option value is injected. Boolean toggle OFF → nothing is injected. Prompt assembly behaves as documented. A regression test should cover at least: Single-option Boolean ON returns its option value. Single-option Boolean OFF ("") returns "". Truly absent selection (undefined) retains the existing first-option fallback where appropriate. Explicit empty multi-select remains empty rather than unexpectedly selecting an option. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:51:11 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Aug 8, 2026):

Claimed by @SpicyMarinara for the current assigned-issue sweep. Implementation and validation are tracked in draft PR #4747.

<!-- gh-comment-id:5225217782 --> @SpicyMarinara commented on GitHub (Aug 8, 2026): Claimed by @SpicyMarinara for the current assigned-issue sweep. Implementation and validation are tracked in draft PR #4747.
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#2606
No description provided.