Skip to content

Brace-Counting JSON Parser in Debug Endpoint #133

@CyberSecDef

Description

@CyberSecDef

Problem

The /llm_log debug endpoint reconstructs multi-line JSON objects using manual {/} counting (novelforge/__init__.py lines 250-261). This breaks on:

  • Strings containing brace characters: {"key": "value with { brace"}
  • Escaped quotes within JSON strings
  • Single-line complete JSON objects with balanced braces

Why It Matters

Developers debugging LLM issues see truncated or garbled log entries.

Recommended Fix

Option A: Change the logger to write one JSON object per line (no indent), then read with [json.loads(line) for line in content.splitlines() if line.strip()].

Option B: Use regex splitting on top-level objects:

raw_objects = re.split(r'\n(?=\{)', content)
entries = [json.loads(raw) for raw in raw_objects if raw.strip()]

Metadata

Metadata

Labels

bugSomething isn't workingpriority:criticalCritical priority

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions