[GH-ISSUE #3023] [Issue]: Imported presets lose defaultChoices, so choice variables render with wrong values (first option instead of the author's saved default) #1593

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
Exporting a preset and re-importing it silently loses the author's saved choice-variable defaults (defaultChoices). At generation time the assembler then falls back to each choice block's FIRST option, so any choice variable whose intended default was not the first option (e.g. {{role}}, {{pov}}, {{length}}) resolves to a different value, changing the actual system prompt sent to the model.

How to reproduce (try it yourself)

  1. Export the bundled "Marinara's Universal Preset" via GET /api/prompts/:id/export. Its defaultChoices contains non-first selections for role/guidelines/narration/pov/tense/length.
  2. Re-import the resulting .marinara.json via POST /api/import (importMarinara -> importPreset).
  3. Open or generate with the imported preset (no per-chat choices set).

You'll see: the imported preset's defaultChoices is {}, and choice macros (e.g. {{narration}}, {{tense}}) resolve to each block's first option, producing a different assembled prompt than the original.
Expected: the import round-trip preserves defaultChoices, so choice variables resolve to the author's saved defaults.

Where it is
packages/server/src/services/import/marinara.importer.ts — the storage.create() call at lines 557-570 omits defaultChoices (and createPromptPresetSchema doesn't accept it), and the final storage.update() at line 647 only sets sectionOrder/groupOrder. So p.defaultChoices from the envelope is never written.
Export includes it: packages/server/src/routes/prompts.routes.ts:42-56 (full row). Consumed at packages/server/src/services/prompt/assembler.ts:251-280 (first-option fallback at 276-279) and packages/server/src/routes/generate.routes.ts:1817-1822. Storage already supports the key: packages/server/src/services/storage/prompts.storage.ts:111-112.

What's happening
importPreset never reads or writes preset.defaultChoices. create() cannot set it (schema omits it), and the post-create update only carries the order arrays, so the exported value is dropped on the floor and the DB column stays at its default "{}".

Suggested fix
Persist defaultChoices by adding it to the final storage.update() call in importPreset() at packages/server/src/services/import/marinara.importer.ts:647:

await storage.update(newPreset.id, {
  sectionOrder: newSectionOrder,
  groupOrder: newGroupOrder,
  defaultChoices: safeParseJson(p.defaultChoices, {}),
});

This uses the importer's existing safeParseJson helper (lines 657-668) and storage.update's existing defaultChoices support (prompts.storage.ts:111-112). Legacy exports lacking the field yield undefined, and safeParseJson(undefined, {}) returns {}, which is identical to the column default — so presets without choice defaults are unchanged. This is the same compensating step the seed path already performs (seed.ts:222-226).

Related: a sibling issue covers the same defaultChoices-dropped bug on the preset DUPLICATE path (prompts.storage.ts duplicate()) — same root-cause shape (create cannot accept defaultChoices; the trailing update() only carries the order arrays).


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3023 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** Exporting a preset and re-importing it silently loses the author's saved choice-variable defaults (`defaultChoices`). At generation time the assembler then falls back to each choice block's FIRST option, so any choice variable whose intended default was not the first option (e.g. `{{role}}`, `{{pov}}`, `{{length}}`) resolves to a different value, changing the actual system prompt sent to the model. **How to reproduce (try it yourself)** 1. Export the bundled "Marinara's Universal Preset" via `GET /api/prompts/:id/export`. Its `defaultChoices` contains non-first selections for role/guidelines/narration/pov/tense/length. 2. Re-import the resulting `.marinara.json` via `POST /api/import` (`importMarinara` -> `importPreset`). 3. Open or generate with the imported preset (no per-chat choices set). You'll see: the imported preset's `defaultChoices` is `{}`, and choice macros (e.g. `{{narration}}`, `{{tense}}`) resolve to each block's first option, producing a different assembled prompt than the original. Expected: the import round-trip preserves `defaultChoices`, so choice variables resolve to the author's saved defaults. **Where it is** `packages/server/src/services/import/marinara.importer.ts` — the `storage.create()` call at lines 557-570 omits `defaultChoices` (and `createPromptPresetSchema` doesn't accept it), and the final `storage.update()` at line 647 only sets `sectionOrder`/`groupOrder`. So `p.defaultChoices` from the envelope is never written. Export includes it: `packages/server/src/routes/prompts.routes.ts:42-56` (full row). Consumed at `packages/server/src/services/prompt/assembler.ts:251-280` (first-option fallback at 276-279) and `packages/server/src/routes/generate.routes.ts:1817-1822`. Storage already supports the key: `packages/server/src/services/storage/prompts.storage.ts:111-112`. **What's happening** `importPreset` never reads or writes `preset.defaultChoices`. `create()` cannot set it (schema omits it), and the post-create update only carries the order arrays, so the exported value is dropped on the floor and the DB column stays at its default `"{}"`. **Suggested fix** Persist `defaultChoices` by adding it to the final `storage.update()` call in `importPreset()` at `packages/server/src/services/import/marinara.importer.ts:647`: ```ts await storage.update(newPreset.id, { sectionOrder: newSectionOrder, groupOrder: newGroupOrder, defaultChoices: safeParseJson(p.defaultChoices, {}), }); ``` This uses the importer's existing `safeParseJson` helper (lines 657-668) and `storage.update`'s existing `defaultChoices` support (`prompts.storage.ts:111-112`). Legacy exports lacking the field yield `undefined`, and `safeParseJson(undefined, {})` returns `{}`, which is identical to the column default — so presets without choice defaults are unchanged. This is the same compensating step the seed path already performs (`seed.ts:222-226`). *Related: a sibling issue covers the same `defaultChoices`-dropped bug on the preset DUPLICATE path (`prompts.storage.ts` `duplicate()`) — same root-cause shape (create cannot accept `defaultChoices`; the trailing `update()` only carries the order arrays).* --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed on staging in PR #3031 (merged as f542e282). Closing manually because GitHub auto-close keywords only close issues when merged into the default branch (main), not staging.

<!-- gh-comment-id:4834696223 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed on staging in PR #3031 (merged as f542e282). Closing manually because GitHub auto-close keywords only close issues when merged into the default branch (main), not staging.
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#1593
No description provided.