#+TITLE: Root Cause Analysis: Implement Lisp Repair Syntax Gate #+DATE: 2026-04-11 #+FILETAGS: :rca:lisp:repair:syntax: * Executive Summary Implemented the `org-skill-lisp-repair` to address the issue of silent parser failures in System 1 (LLM) proposals. The system now attempts deterministic fixes (balancing parentheses) and neural fallback before discarding a thought. * 1. Issue: Silent Parser Failures ** Symptoms System 1 proposals containing minor syntax errors (like missing closing parens) were being discarded by the `think` function, leading to "Action rejected" or "Invalid output format" logs and wasted tokens. ** Root Cause The `think` loop used `ignore-errors` around `read-from-string`, providing no path for recovery or diagnostics for malformed Lisp. ** Resolution Replaced `ignore-errors` with a `handler-case` that invokes `repair-lisp-syntax`. * 2. Design Decision: Two-Tiered Repair ** Tier 1: Deterministic (Fast) - **Mechanism:** Count unclosed `(` and append `)`. - **Reasoning:** Most common error from LLMs under token limits or early termination. Cost: 0 tokens. ** Tier 2: Neural (Deep) - **Mechanism:** specialized `ask-neuro` prompt with the error message and broken code. - **Reasoning:** Necessary for unbalanced strings or hallucinated syntax that deterministic rules can't fix. * 3. PSF Mandate Alignment ** Literate Programming - Created `org-skill-lisp-repair.org` as a Universal Literate Note. - Tangle targets established for `src/lisp-repair.lisp`. ** High-Integrity Memory - Updated `neurosymbolic.org` documentation to reflect the new safety buffer in the `think` function. * 4. Permanent Learnings - **Dynamic Skill Invocation:** Use `member :skill-name *loaded-skills*` and `fboundp` to ensure kernel functions remain decoupled from non-essential skills. - **Test Package Exporting:** Always remember to export the `fiveam` suite symbol in the `defpackage` of new test files to avoid `SIMPLE-READER-PACKAGE-ERROR`.