[GH-ISSUE #2138] [Issue]: Game mode — model-JSON parsing uses a weak parser, losing malformed-JSON recovery #1048

Closed
opened 2026-10-21 05:25:39 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @cha1latte on GitHub.

Summary

Severity: major. Game-mode LLM-JSON parsing routes through a weak local parseJsonObject instead of the ported parseGameJsonish, so slightly-malformed model output that main auto-recovers fails to parse — and the JSON-repair modal's apply path uses the same weak parser, so it cannot recover either.

Expected behavior

As in main: all game LLM-JSON (setup, map, session conclusion, lorebook, campaign progression, cards) funnels through parseGameJsonish, which tolerates unescaped control chars in strings, ////* */ comments, trailing/missing commas, code fences, trailing junk (brace-depth extraction), and doubly-stringified JSON.

Actual behavior

llmJson (game-api.ts:1614) and the repair-apply path (applyGameJsonRepair, game-api.ts:2876) both call parseJsonObject (game-api.ts:453-474), which only does JSON.parse / fenced-regex / naive first-{ to last-} slice — no repairJsonish. The faithful port parseGameJsonish exists but is wired only into roleplay/scene paths, never game-mode.

Steps to reproduce

  1. In game mode, trigger setup/map/conclusion generation against a model that emits slightly-malformed JSON (e.g. a trailing comma, a // comment, or a raw newline inside a string).
  2. Parsing returns null -> 422 -> the JSON-repair modal opens.
  3. Apply the raw JSON in the modal: it still fails ("Repaired JSON is not a JSON object"), because the apply path re-runs the same weak parser. Example input main recovers but refactor rejects: {"worldOverview": "line1\nline2", "x": 1,}.

Impact area

  • Game mode
  • React-free engine behavior, contracts, agents, or capability ports

Environment

  • Branch or commit: refactor @ 14894608
  • Run mode: Tauri desktop
  • Compared against: main @ c49f1d95 (legacy web app)

Regression notes

Worked in the legacy web app.

  • main: packages/server/src/routes/game.routes.ts:1636-1637 (parseJSON -> parseGameJsonish), used at 3337/3390/3871/4002/4311/4495/4585/5160. Pipeline: packages/server/src/services/game/jsonish.ts.
  • refactor: src/features/modes/game/api/game-api.ts:1614 and :2876 call parseJsonObject (:453-474). Port exists at src/engine/shared/parsing-jsonish.ts:149 but is never imported by game-api.ts. Fix: route both through parseGameJsonish.
Originally created by @Romuromylus on GitHub (Jun 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2138 Originally assigned to: @cha1latte on GitHub. ## Summary **Severity: major.** Game-mode LLM-JSON parsing routes through a weak local `parseJsonObject` instead of the ported `parseGameJsonish`, so slightly-malformed model output that main auto-recovers fails to parse — and the JSON-repair modal's apply path uses the same weak parser, so it cannot recover either. ## Expected behavior As in main: all game LLM-JSON (setup, map, session conclusion, lorebook, campaign progression, cards) funnels through `parseGameJsonish`, which tolerates unescaped control chars in strings, `//`/`/* */` comments, trailing/missing commas, code fences, trailing junk (brace-depth extraction), and doubly-stringified JSON. ## Actual behavior `llmJson` (`game-api.ts:1614`) and the repair-apply path (`applyGameJsonRepair`, `game-api.ts:2876`) both call `parseJsonObject` (`game-api.ts:453-474`), which only does `JSON.parse` / fenced-regex / naive first-`{` to last-`}` slice — no `repairJsonish`. The faithful port `parseGameJsonish` exists but is wired only into roleplay/scene paths, never game-mode. ## Steps to reproduce 1. In game mode, trigger setup/map/conclusion generation against a model that emits slightly-malformed JSON (e.g. a trailing comma, a `//` comment, or a raw newline inside a string). 2. Parsing returns null -> 422 -> the JSON-repair modal opens. 3. Apply the raw JSON in the modal: it still fails ("Repaired JSON is not a JSON object"), because the apply path re-runs the same weak parser. Example input main recovers but refactor rejects: `{"worldOverview": "line1\nline2", "x": 1,}`. ## Impact area - [x] Game mode - [x] React-free engine behavior, contracts, agents, or capability ports ## Environment - Branch or commit: `refactor` @ `14894608` - Run mode: Tauri desktop - Compared against: `main` @ `c49f1d95` (legacy web app) ## Regression notes Worked in the legacy web app. - main: `packages/server/src/routes/game.routes.ts:1636-1637` (`parseJSON` -> `parseGameJsonish`), used at 3337/3390/3871/4002/4311/4495/4585/5160. Pipeline: `packages/server/src/services/game/jsonish.ts`. - refactor: `src/features/modes/game/api/game-api.ts:1614` and `:2876` call `parseJsonObject` (:453-474). Port exists at `src/engine/shared/parsing-jsonish.ts:149` but is never imported by `game-api.ts`. Fix: route both through `parseGameJsonish`.
bsakaguchi 2026-10-21 05:25:39 +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#1048
No description provided.