---
number: 9967
title: >-
  fix(MemoryCore): Implement autonomous JSON boundary repair loops in
  DreamService REM pipeline (#9913)
author: tobiu
state: MERGED
createdAt: '2026-04-13T12:01:52Z'
updatedAt: '2026-04-13T12:38:44Z'
closedAt: '2026-04-13T12:38:40Z'
mergedAt: '2026-04-13T12:38:40Z'
head: agent/9913-json-repair-loop
base: dev
url: 'https://github.com/neomjs/neo/pull/9967'
---
Resolves #9913. Implements an autonomous 3-tuple fallback recursion loop inside DreamService. When local LLM inferences drop Tri-Vector schema bounds, failed parses are fed back into context with targeted JSON repair constraints, drastically lowering REM pipeline crash rates. Features robust unit test emulation.

## Comments

### `@tobiu` commented on 2026-04-13T12:04:04Z

**Input from gemini-exp-1206 (Antigravity):**

> ✦ # PR Review Summary
> 
> **Status:** Approved
> 
> Excellent stabilization engineering! Implementing this active retry-loop shifts the burden of malformed JSON from hard system crashes to graceful internal recovery. Giving local constraint-heavy MLX models localized "self-correction" paths fundamentally hardens the agentic digestion pipeline.
> 
> ---
> 
> ### 📊 Evaluation Metrics
> *   **`[ARCH_ALIGNMENT]`**: 100 - Deeply aligns with autonomous swarm intelligence constraints.
> *   **`[CONTENT_COMPLETENESS]`**: 100 - Successfully tracks attempt sequences while maintaining safety caps (`maxRetries = 3`) to prevent infinite looping.
> *   **`[EXECUTION_QUALITY]`**: 100 - The accompanying Playwright unit tests accurately simulate the validation failure logic and multi-shot correction without altering external API mocks.
> *   **`[PRODUCTIVITY]`**: 100 - Resolved P0 Ticket #9913.
> *   **`[IMPACT]`**: 95 - Removes the final bottleneck preventing reliable batch processing of large session logs context extraction.
> *   **`[COMPLEXITY]`**: 40 - Straightforward `while` loop wrapping structural feedback appending.
> *   **`[EFFORT_PROFILE]`**: Surgical Impact - Small delta, massive system stability improvements.
> 
> ---
> 
> ### 🕸️ Context & Graph Linking
> *   **Target Epic / Issue ID:** Resolves #9913
> *   **Related Graph Nodes:** `DreamService`
> 
> ---
> 
> ### 🧠 Graph Ingestion Notes
> 
> *   **`[KB_GAP]`**: N/A
> *   **`[TOOLING_GAP]`**: N/A
> *   **`[RETROSPECTIVE]`**: Localized instruction-tuned LLMs struggle with multi-layered JSON validation constraints. Wrapping programmatic generation calls in a localized autonomous repair loop—by explicitly pushing the failing string back into context paired with a prompt-defined schema correction—provides a stable workaround that safeguards against data loss while maintaining throughput.
> 
> ---
> 
> ### 📋 Required Actions
> 
> To proceed with merging, please address the following:
> 
> - [x] Merge PR #9967 to `dev` using Squash Merge.
> 
> Looks ready to go!

---

