[GH-ISSUE #3051] [Issue]: ImportPersonaModal drops personaStats when imported JSON stores it as an object (uses stringField instead of jsonStringField like every sibling JSON field) #1620

Closed
opened 2026-10-21 05:40:55 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
In the plain-JSON import branch of ImportPersonaModal, every persona field holding a JSON object/array is normalized via jsonStringField() EXCEPT personaStats, which uses stringField(). stringField() returns the value only if it is already a string and returns "" for anything else (objects/arrays). So if an imported JSON file represents personaStats in its natural in-memory object shape ({ enabled, bars, rpgStats? }) rather than a pre-stringified JSON string, the persona's entire status-bar / RPG-stats configuration is silently discarded and the persona is created with personaStats = "". The three structurally identical sibling fields right next to it (trackerCardColors, tags, savedStatusOptions) all correctly accept the object form via jsonStringField, making this a clear inconsistency rather than a deliberate choice. (Marinara's own native/compatible exports serialize personaStats as a string and round-trip fine; this bites third-party / hand-authored / older-format JSON.)

How to reproduce (try it yourself)

  1. Hand-author a persona JSON file where personaStats is an object, e.g. { "name": "Test", "personaStats": { "enabled": true, "bars": [{ "name": "Energy", "value": 80, "max": 100, "color": "#22c55e" }] } }.
  2. Open Import Persona and drop the .json file (not a zip, not a marinara envelope, so it hits the plain-JSON POST branch).
  3. Open the imported persona's Stats tab.

You'll see: the status bars / RPG stats are gone; the Stats tab shows defaults (disabled), because stringField(json.personaStats) saw an object and returned "".
Expected: the imported personaStats object is preserved (serialized to its JSON-string storage form).

Where it is

  • packages/client/src/components/modals/ImportPersonaModal.tsx:114 — personaStats: stringField(json.personaStats), (helpers at :16-18 and :27-31; correct siblings at :113, :115, :116).
  • Shared object shape: packages/shared/src/types/persona.ts:33 (PersonaStatsConfig).
  • Storage: packages/server/src/services/storage/characters.storage.ts:419; DB default: packages/server/src/db/schema/characters.ts:65.

What's happening
personaStats is a JSON-encoded structured field (DB column stores a JSON string; in-memory shape is PersonaStatsConfig). The import mapper treats it as plain text via stringField(), which only passes through already-stringified values and yields "" for the object form, while the adjacent fields use jsonStringField() which JSON.stringifies arrays/objects.

Suggested fix
Map personaStats with jsonStringField like its three siblings. At ImportPersonaModal.tsx:114 change personaStats: stringField(json.personaStats), to personaStats: jsonStringField(json.personaStats, ""),. This keeps already-stringified values as-is (Marinara exports round-trip byte-identically) and additionally JSON.stringifies the natural object form so hand-authored / non-Marinara JSON keeps its stats. The "" fallback matches the DB default and guarantees a string is sent, satisfying the server's personaStats?: string contract. Regression notes: jsonStringField passes strings through unchanged and returns "" for null/undefined/absent/number/boolean — identical to the current stringField result and the server/DB default — so the happy path and all empty-stats edge cases are unchanged; the only behavior change is the intended one (object-form stats now preserved).


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/3051 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** In the plain-JSON import branch of ImportPersonaModal, every persona field holding a JSON object/array is normalized via `jsonStringField()` EXCEPT `personaStats`, which uses `stringField()`. `stringField()` returns the value only if it is already a string and returns `""` for anything else (objects/arrays). So if an imported JSON file represents `personaStats` in its natural in-memory object shape (`{ enabled, bars, rpgStats? }`) rather than a pre-stringified JSON string, the persona's entire status-bar / RPG-stats configuration is silently discarded and the persona is created with `personaStats = ""`. The three structurally identical sibling fields right next to it (`trackerCardColors`, `tags`, `savedStatusOptions`) all correctly accept the object form via `jsonStringField`, making this a clear inconsistency rather than a deliberate choice. (Marinara's own native/compatible exports serialize personaStats as a string and round-trip fine; this bites third-party / hand-authored / older-format JSON.) **How to reproduce (try it yourself)** 1. Hand-author a persona JSON file where personaStats is an object, e.g. `{ "name": "Test", "personaStats": { "enabled": true, "bars": [{ "name": "Energy", "value": 80, "max": 100, "color": "#22c55e" }] } }`. 2. Open Import Persona and drop the .json file (not a zip, not a marinara envelope, so it hits the plain-JSON POST branch). 3. Open the imported persona's Stats tab. You'll see: the status bars / RPG stats are gone; the Stats tab shows defaults (disabled), because `stringField(json.personaStats)` saw an object and returned `""`. Expected: the imported personaStats object is preserved (serialized to its JSON-string storage form). **Where it is** - `packages/client/src/components/modals/ImportPersonaModal.tsx:114` — `personaStats: stringField(json.personaStats),` (helpers at `:16-18` and `:27-31`; correct siblings at `:113`, `:115`, `:116`). - Shared object shape: `packages/shared/src/types/persona.ts:33` (`PersonaStatsConfig`). - Storage: `packages/server/src/services/storage/characters.storage.ts:419`; DB default: `packages/server/src/db/schema/characters.ts:65`. **What's happening** `personaStats` is a JSON-encoded structured field (DB column stores a JSON string; in-memory shape is `PersonaStatsConfig`). The import mapper treats it as plain text via `stringField()`, which only passes through already-stringified values and yields `""` for the object form, while the adjacent fields use `jsonStringField()` which JSON.stringifies arrays/objects. **Suggested fix** Map `personaStats` with `jsonStringField` like its three siblings. At ImportPersonaModal.tsx:114 change `personaStats: stringField(json.personaStats),` to `personaStats: jsonStringField(json.personaStats, ""),`. This keeps already-stringified values as-is (Marinara exports round-trip byte-identically) and additionally JSON.stringifies the natural object form so hand-authored / non-Marinara JSON keeps its stats. The `""` fallback matches the DB default and guarantees a string is sent, satisfying the server's `personaStats?: string` contract. Regression notes: `jsonStringField` passes strings through unchanged and returns `""` for null/undefined/absent/number/boolean — identical to the current `stringField` result and the server/DB default — so the happy path and all empty-stats edge cases are unchanged; the only behavior change is the intended one (object-form stats now preserved). --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

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

Claiming this for the current staging sweep in draft PR #3053 (branch codex/issue-sweep-3033-3052).

<!-- gh-comment-id:4834991125 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3053 (branch `codex/issue-sweep-3033-3052`).
Author
Owner

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

Fixed in PR #3053 on branch codex/issue-sweep-3033-3052 (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835091494 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3053 on branch `codex/issue-sweep-3033-3052` (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.
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#1620
No description provided.