mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #4925] [Feature]: Upgrade summary parser JSON repair to use shared json-repair.ts module #2729
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#2729
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @xDanteMD on GitHub (Aug 11, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4925
Originally assigned to: @SpicyMarinara on GitHub.
What problem does this solve?
PR #4761 (fixing #4753) created a shared JSON repair utility (
packages/server/src/lib/json-repair.ts) and wired it into both the workspace agent and download agents. However, the summary parsers were excluded from that scope and still use bareJSON.parse()with minimal pre-processing.MoE models (Deepseek, Kimi, GLM, MiMo) have a known failure mode of producing JSON that is structurally malformed sometimes — single quotes instead of double quotes, unquoted keys, missing closing brackets when truncated. The shared
repairJsonText()function handles all of these via a 4-candidate waterfall (raw → jsonrepair → bracket-closing → combined). The summary parsers do not.The two repair systems
Shared module (robust) — introduced in PR #4761
Location:
packages/server/src/lib/json-repair.ts:39-584-candidate waterfall: raw → jsonrepair → bracket-closing → combined. Handles single quotes, unquoted keys, missing brackets, comments, trailing commas, unescaped control characters.
Summary parsers (minimal) — unchanged
Roleplay rolling summary (
roleplay-summary-runtime.ts:135-160):Conversation auto-summary (
auto-summary.service.ts:233-256):Both fall through to raw text on parse failure. No
jsonrepair, no bracket closing, no structural repair.What the summary parsers fix vs miss
repairJsonText){"a": 1,}//and/* */comments...ellipsis placeholders{'key': 'val'}{key: "val"}{closeOpenJsonContainers)Impact
The roleplay rolling summary fires every N messages (default: 5) and requests JSON output:
If the model produces malformed JSON (common with MoEs), the current fallback silently returns the raw text as the summary. This means:
namefield is lost (empty string fallback)The conversation auto-summary has the same gap — it requests
{ "summary": "...", "keyDetails": [...] }and falls through to raw text on parse failure.Proposed solution
Option A: Import
repairJsonTextinto both parsers (recommended)Replace bare
JSON.parsewith the shared repair utility:roleplay-summary-runtime.ts:auto-summary.service.ts:Option B: Add retry with user-visible toast on parse failure
If
repairJsonTextreturns null (unrepairable JSON), retry the LLM call once with a JSON-specific reminder prompt, and show a toast if the retry also fails. This mirrors the agent retry pattern from #4753.Recommended: Option A + B combined. Upgrade the repair AND add a single retry with toast notification.
Retry consideration
The roleplay summary currently has zero retry logic — if
parseChatSummaryResultreturns raw text, it's silently accepted. Adding one retry (with a focused "return valid JSON" reminder) would catch cases where the model's first attempt was malformed but the second succeeds. This mirrors the agent retry pattern already established in #4753.Related issues
json-repair.tsmodule. PR #4761 implemented it for agents and the workspace agent. The summary parsers were out of scope. This FR extends the fix to cover the remaining code paths.maxOutputlimits for MoE models. Correct token budgets reduce truncation-induced parse failures, but don't fix structurally malformed JSON from MoEs.*Research undertaken: Analysis of
parseChatSummaryResult(roleplay-summary-runtime.ts:135-160),cleanJsonishResponse/parseSummaryResponse(auto-summary.service.ts:233-256),repairJsonText/tryParseJsonRecord(json-repair.ts:39-65). Confirmed both summary parsers use bareJSON.parse()with fallback to raw text. Verifiedjson-repair.tsis already a dependency and imported byagent-executor.ts(line 38) andworkspace-agent.service.ts(line 45). Confirmed no prior art for summary parser repair upgrade in existing issues or PRs — #4753 explicitly scoped to agents and workspace agent only.