[PR #2299] [MERGED] Fix preset choice selection sanitization #5526

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/issue-2266-choice-variable-selection


📝 Commits (5)

  • 7ca8dfe generation: sanitize preset choice selections
  • 30a884a generation: address preset choice review
  • 4e1b53d generation: address bunny choice review
  • 74cb906 Merge remote-tracking branch 'origin/refactor' into fix/issue-2266-choice-variable-selection
  • dde4204 llm: satisfy content delta clippy

📊 Changes

4 files changed (+193 additions, -36 deletions)

View changed files

📝 src-tauri/crates/llm/src/lib.rs (+2 -4)
📝 src/engine/generation/prompt-assembly.ts (+80 -25)
📝 src/engine/generation/prompt-preview.ts (+52 -4)
📝 src/features/catalog/presets/components/ChoiceSelectionModal.tsx (+59 -3)

📄 Description

Linked issue

Closes #2266

Why this change

  • Prompt preset choice variables could inject stale or invalid saved values, skip first-option fallback for missing values in inconsistent ways, and leave nested macros unresolved inside selected option values.
  • Explicit empty selections also need to remain explicit, so boolean toggles saved as off and empty multi-selects do not turn back on during prompt assembly.

What changed

  • Sanitized preset default choices and per-chat preset choices against the selected preset's current option values before injecting prompt variables.
  • Preserved explicit empty selections while still falling back to the first option when a single-select choice is missing.
  • Kept multi-select separator joins and random-pick behavior after sanitization.
  • Resolved macros inside selected choice values before prompt sections consume {{variableName}}.
  • Routed prompt preview choices through presetChoices so preview follows the same sanitizer as live generation.
  • Updated the choice selection modal to sanitize saved/default selections without turning saved-off toggles back on.

Refactor impact

Primary owner:

Engine generation, with catalog preset modal support.

Impact areas reviewed:

  • Prompt preset runtime assembly
  • Prompt preview path
  • Catalog preset choice selection modal
  • Roleplay/game shared prompt assembly consumers

Boundary notes:

  • Engine behavior stays in src/engine/generation with no React, Tauri, or shared API imports added.
  • UI derivation stays in src/features/catalog/presets and mirrors the runtime contract.
  • No Rust, shared API, or remote runtime boundary changes.

Pressure points touched:

  • None of the listed pressure points were touched.

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 typecheck
  • Focused Vite SSR assembler proof for stale per-chat/default selections, invalid single-selects, missing single-select fallback, empty/off boolean toggles, empty multi-selects, multi-select separator joins, random-pick sanitization, prompt preview sanitization, and nested choice-value macro resolution.
  • pnpm check
  • Native Tauri/manual modal pass was not run.

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:

  • This restores existing preset choice behavior and does not add a new discoverable feature.

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 screenshots or recordings. The visible modal derivation was covered by code inspection and typecheck; native/manual UI validation remains open.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved validation and normalization of preset choice selections with fallback handling for invalid values
  • Refactor

    • Enhanced choice variable resolution in prompt generation and preview for preset selections with better support for multi-select options

🔄 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/2299 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 6/5/2026 **Status:** ✅ Merged **Merged:** 6/5/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/issue-2266-choice-variable-selection` --- ### 📝 Commits (5) - [`7ca8dfe`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7ca8dfe8e352120f6812a2abb8ecc702d741bb48) generation: sanitize preset choice selections - [`30a884a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/30a884a4f6760dd2b5732fc2659a62570f173f62) generation: address preset choice review - [`4e1b53d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4e1b53dfcc2d0c8b08e424ff8e5758c816cb0a33) generation: address bunny choice review - [`74cb906`](https://github.com/Pasta-Devs/Marinara-Engine/commit/74cb906f8a277c30b3cf590e93b17bc5f0cb6fa4) Merge remote-tracking branch 'origin/refactor' into fix/issue-2266-choice-variable-selection - [`dde4204`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dde420472b7c2853825438a854589a340316504a) llm: satisfy content delta clippy ### 📊 Changes **4 files changed** (+193 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/llm/src/lib.rs` (+2 -4) 📝 `src/engine/generation/prompt-assembly.ts` (+80 -25) 📝 `src/engine/generation/prompt-preview.ts` (+52 -4) 📝 `src/features/catalog/presets/components/ChoiceSelectionModal.tsx` (+59 -3) </details> ### 📄 Description ## Linked issue Closes #2266 ## Why this change - Prompt preset choice variables could inject stale or invalid saved values, skip first-option fallback for missing values in inconsistent ways, and leave nested macros unresolved inside selected option values. - Explicit empty selections also need to remain explicit, so boolean toggles saved as off and empty multi-selects do not turn back on during prompt assembly. ## What changed - Sanitized preset default choices and per-chat preset choices against the selected preset's current option values before injecting prompt variables. - Preserved explicit empty selections while still falling back to the first option when a single-select choice is missing. - Kept multi-select separator joins and random-pick behavior after sanitization. - Resolved macros inside selected choice values before prompt sections consume `{{variableName}}`. - Routed prompt preview choices through `presetChoices` so preview follows the same sanitizer as live generation. - Updated the choice selection modal to sanitize saved/default selections without turning saved-off toggles back on. ## Refactor impact Primary owner: Engine generation, with catalog preset modal support. Impact areas reviewed: - Prompt preset runtime assembly - Prompt preview path - Catalog preset choice selection modal - Roleplay/game shared prompt assembly consumers Boundary notes: - Engine behavior stays in `src/engine/generation` with no React, Tauri, or shared API imports added. - UI derivation stays in `src/features/catalog/presets` and mirrors the runtime contract. - No Rust, shared API, or remote runtime boundary changes. Pressure points touched: - None of the listed pressure points were touched. ## 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 typecheck` - Focused Vite SSR assembler proof for stale per-chat/default selections, invalid single-selects, missing single-select fallback, empty/off boolean toggles, empty multi-selects, multi-select separator joins, random-pick sanitization, prompt preview sanitization, and nested choice-value macro resolution. - `pnpm check` - Native Tauri/manual modal pass was not run. ## 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: - This restores existing preset choice behavior and does not add a new discoverable feature. ## 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 screenshots or recordings. The visible modal derivation was covered by code inspection and typecheck; native/manual UI validation remains open. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Improved validation and normalization of preset choice selections with fallback handling for invalid values * **Refactor** * Enhanced choice variable resolution in prompt generation and preview for preset selections with better support for multi-select options <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <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:05 +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#5526
No description provided.