[GH-ISSUE #3026] [Issue]: Upgrading wipes user edits to the bundled "Marinara's Universal Preset" when its bundled content hash changes #1598

Closed
opened 2026-10-21 05:40:25 +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/3026

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
On startup, the seed re-applies the bundled default preset whenever the shipped default-preset.json hash differs from what was last applied. The re-apply matches the preset by name+author only, then DELETEs all of that preset's choice blocks, sections, and groups and overwrites its body from the bundle. A user who edited the bundled preset in place (changed sections, parameters, or order) without renaming it loses all those edits the first time they launch an upgraded build, with no warning or opt-out.

How to reproduce (try it yourself)

  1. On an existing install, edit the bundled "Marinara's Universal Preset" (change a section's content, tweak parameters, add a choice block) but keep its name and author.
  2. Upgrade to a build whose packages/server/src/db/default-preset.json differs (new sha256).
  3. Start the server.

You'll see: seedDefaultPreset detects the hash change and applyBundledPresetToExisting deletes the user's sections/groups/choice blocks and overwrites the preset body — the user's edits are gone.
Expected: an in-place-customized preset is detected and preserved (or refreshed into a fresh copy), not silently wiped.

Where it is
packages/server/src/db/seed.ts — applyBundledPresetToExisting (77-166) overwrites the preset body (86-97) and unconditionally deletes child rows (99-101); seedDefaultPreset opens the destructive re-apply at the gate existingMarinaraPreset && appliedHash !== bundled.hash (188-195); name+author match at 177-185. No "user customized this preset" guard exists.

What's happening
The re-seed is keyed only on name+author and a content-hash change. It does not detect user modifications and deletes the preset's child rows before re-importing, so any in-place edits are destroyed.

Suggested fix
Detect customization before re-applying by recording a content snapshot of the seeded state and skipping the destructive re-apply when the current rows diverge. In packages/server/src/db/seed.ts:

  1. Add a second app-settings key, e.g. MARINARA_PRESET_SNAPSHOT_KEY = "seed:marinara-universal-preset:snapshot-sha256".
  2. Add computePresetSnapshotHash(storage, presetId) that hashes ONLY content fields (preset name/description/prompts/parameters/wrapFormat/variableGroups/variableValues/defaultChoices; each section's identifier/name/content/role/enabled/group-membership/injection fields; each group's name/order/enabled/parent; each choice block's variableName/question/options/etc.; plus sectionOrder/groupOrder remapped to stable identifiers), excluding row ids and timestamps, sorted deterministically before hashing.
  3. Gate the re-apply: when appliedHash !== bundled.hash, compare a recorded snapshot to the freshly computed one. If a snapshot exists AND diverges, treat the preset as user-customized — record the new bundle hash (so it isn't re-evaluated every launch) and return without wiping. Otherwise re-apply as today, then write the new snapshot.
  4. Also write the snapshot after the fresh-install import path so first run records a baseline.

Regression avoided: a MISSING snapshot must be treated as "assume pristine, allow this one in-place refresh, then record the snapshot" — otherwise every legacy/untouched preset would be frozen from future updates on the first launch after this fix. The snapshot must be content-only and order-normalized, or zero-edit recomputation would never match the stored hash and would also freeze untouched presets. (Caveat: a user who customized in a PRE-fix build still loses edits once on the upgrade that introduces this fix, since there is no prior snapshot to compare against; behavior is correct from then on.)


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/3026 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** On startup, the seed re-applies the bundled default preset whenever the shipped `default-preset.json` hash differs from what was last applied. The re-apply matches the preset by name+author only, then DELETEs all of that preset's choice blocks, sections, and groups and overwrites its body from the bundle. A user who edited the bundled preset in place (changed sections, parameters, or order) without renaming it loses all those edits the first time they launch an upgraded build, with no warning or opt-out. **How to reproduce (try it yourself)** 1. On an existing install, edit the bundled "Marinara's Universal Preset" (change a section's content, tweak parameters, add a choice block) but keep its name and author. 2. Upgrade to a build whose `packages/server/src/db/default-preset.json` differs (new sha256). 3. Start the server. You'll see: `seedDefaultPreset` detects the hash change and `applyBundledPresetToExisting` deletes the user's sections/groups/choice blocks and overwrites the preset body — the user's edits are gone. Expected: an in-place-customized preset is detected and preserved (or refreshed into a fresh copy), not silently wiped. **Where it is** `packages/server/src/db/seed.ts` — `applyBundledPresetToExisting` (77-166) overwrites the preset body (86-97) and unconditionally deletes child rows (99-101); `seedDefaultPreset` opens the destructive re-apply at the gate `existingMarinaraPreset && appliedHash !== bundled.hash` (188-195); name+author match at 177-185. No "user customized this preset" guard exists. **What's happening** The re-seed is keyed only on name+author and a content-hash change. It does not detect user modifications and deletes the preset's child rows before re-importing, so any in-place edits are destroyed. **Suggested fix** Detect customization before re-applying by recording a content snapshot of the seeded state and skipping the destructive re-apply when the current rows diverge. In `packages/server/src/db/seed.ts`: 1. Add a second app-settings key, e.g. `MARINARA_PRESET_SNAPSHOT_KEY = "seed:marinara-universal-preset:snapshot-sha256"`. 2. Add `computePresetSnapshotHash(storage, presetId)` that hashes ONLY content fields (preset name/description/prompts/parameters/wrapFormat/variableGroups/variableValues/defaultChoices; each section's identifier/name/content/role/enabled/group-membership/injection fields; each group's name/order/enabled/parent; each choice block's variableName/question/options/etc.; plus `sectionOrder`/`groupOrder` remapped to stable identifiers), excluding row ids and timestamps, sorted deterministically before hashing. 3. Gate the re-apply: when `appliedHash !== bundled.hash`, compare a recorded snapshot to the freshly computed one. If a snapshot exists AND diverges, treat the preset as user-customized — record the new bundle hash (so it isn't re-evaluated every launch) and return without wiping. Otherwise re-apply as today, then write the new snapshot. 4. Also write the snapshot after the fresh-install import path so first run records a baseline. Regression avoided: a MISSING snapshot must be treated as "assume pristine, allow this one in-place refresh, then record the snapshot" — otherwise every legacy/untouched preset would be frozen from future updates on the first launch after this fix. The snapshot must be content-only and order-normalized, or zero-edit recomputation would never match the stored hash and would also freeze untouched presets. (Caveat: a user who customized in a PRE-fix build still loses edits once on the upgrade that introduces this fix, since there is no prior snapshot to compare against; behavior is correct from then on.) --- *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:4834697105 --> @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#1598
No description provided.