# LispM LLM: Scale-Invariant Open-Vocabulary Command Routing and Poison-Resistant Continual Learning for Symbolic Agent Harnesses **Ryan Kung** · LispM Project ([lispm.ai](https://lispm.ai)) · [huggingface.co/ElderRyan/lispm-llm](https://huggingface.co/ElderRyan/lispm-llm) *November 2026* · **[Typeset PDF (`paper/lispm-llm.pdf`)](../paper/lispm-llm.pdf)** · **[LaTeX Source (`paper/lispm-llm.tex`)](../paper/lispm-llm.tex)** --- ## Abstract Interactive symbolic environments such as GNU Emacs and Lisp Machine (*LispM*) agent harnesses expose hundreds of deterministic editor and application commands, yet routing natural-language instructions to those commands faces a sharp safety–flexibility dilemma. Frontier autoregressive language models synthesize arbitrary Lisp code at hundreds of milliseconds per call while introducing prompt-injection and `eval`-execution hazards; conversely, tiny closed-set intent classifiers guarantee sub-millisecond bounded dispatch without `eval`, but freeze their output layer to a fixed action vocabulary and remain static when users phrase commands idiosyncratically or load new packages. We present **LispM LLM**, a local Rust + LibTorch command-routing architecture that resolves both limitations within **264,322 parameters** (~1.0 ms per request on two CPU threads, zero GPU required). First, we formalize an *Open-Vocabulary Dual-Tower Bi-Encoder* over a zero-`eval` typed `ActionCatalog`, proving that naive cosine bi-encoders suffer from *reject-prototype domination* on unseen open actions, and introducing a *Scale-Invariant Semantic–Lexical Bilinear Decomposition* in $\mathbb{R}^{2d}$ that simultaneously admits unseen actions zero-shot, rejects unmatched out-of-domain nouns, and blocks inverted/destructive verbs on matched nouns via a single cached matrix multiplication. Second, we introduce a *Dual-Speed Poison-Resistant Continual Learning* loop that forbids raw self-training: verified external supervision from behavioral user corrections and higher-tier teacher agents updates a sub-millisecond hippocampal episodic store (`episodic.json`) through a monotonic *join-semilattice quarantine ledger* ($\mathsf{Consistent} \sqcup \mathsf{Obs} \to \mathsf{Conflicted}$), enforces automatic PII literal scrubbing and held-out benchmark leakage blocking, and consolidates durable weights during editor idle periods behind non-regression gates and an online circuit breaker. Across frozen regression suites (2,542 supported and 243 unsupported cases), an independent 277-case blind evaluation, and 30 real isolated Emacs 31.1 state-execution tasks, the open bi-encoder achieves **30/30 (100%)** real-task completion, **66/71 (93.0%)** blind two-action composition accuracy, reduces supported wording errors from 6 to **2**, and routes newly harvested `lispm-kit` and Emacs commands zero-shot under major-mode masking. --- ## 1. Introduction Symbolic computing environments—exemplified by GNU Emacs and the LispM application suite (`lispm-finder`, `lispm-browser`, `lispm-stickies`, `lispm-rotom`, `lispm-mail`, `lispm-1password`, `lispm-security`, `lispm-shrdlu`)—already expose composable functional primitives. Routing bounded natural-language requests such as `open file "notes.el" then split right` or `copy the totp verification code` should neither require a multi-gigabyte LLM inventing code for `eval`, nor freeze the user into a hardcoded 48-class output matrix. Upgrading a tiny local router from a closed classifier to an **open-vocabulary, self-improving command router** exposes four concrete failure modes: 1. **Zero-Shot vs. Rejection Collapse:** On a closed training set of $M_0$ actions plus `reject` rows (e.g., `"open spotify"`, `"copy current line"`), negative prototypes align strongly with `"open "` and `"copy "`. When a new action $a_{M_0+1}$ is registered at runtime without retraining, unconstrained semantic temperature overpowers subword similarity and falsely rejects the new action. 2. **Confirmation-Bias Poisoning:** Self-training on unverified model predictions turns high-confidence mistakes into permanent weight drift. 3. **Ambiguous Slang Drift:** Users sometimes reuse the same shorthand phrase for different actions in different contexts, destabilizing append-only fine-tuning. 4. **Literal PII Leakage:** Real editor requests carry private paths, URLs, and search strings that must never persist in datasets or weights. --- ## 2. Typed Open-Action Basis & Zero-`Eval` Safety Boundary Neural outputs are treated strictly as untrusted indices into a validated `ActionCatalog` $\mathcal{A}$; arbitrary S-expressions are unrepresentable. Each `ActionSpec` is a 5-tuple $s = (\mathrm{id}, f, \kappa, \delta, \mu)$: - **Public Symbol Grammar:** $\mathrm{id}, f \in \Sigma_{\mathrm{pub}}$ match `^[a-z][a-z0-9-]*$` ($\le 128$ chars, no private `--` separator, no trailing `-`), with $f \notin \mathcal{D}$ excluding evaluators, shells, and destructive primitives (`eval`, `funcall`, `apply`, `load`, `shell-command`, `call-process`, `delete-file`, `write-region`, `kill-emacs`, etc.). - **Typed Argument Contract $\kappa$:** Either $\mathsf{Fixed}(c_1, \dots, c_m)$ ($m \le 2$ typed constants) or $\mathsf{String}(\phi, \Omega)$ with $\phi \neq \texttt{"action"}$ validated against $\Omega \in \{\mathsf{Any}, \mathsf{FolderBasename}, \mathsf{HttpUrl}\}$. - **Mode Guard $\mu$:** Optional major-mode symbol (`None` = global; `Some(mode)` = active iff `mode` is in the origin buffer's `derived-mode-parent` hierarchy). - **Bounded Clause Decomposition:** `parse_open_command` extracts at most two JSON-quoted literals into `NAME` sentinels, expands mixed letter–digit identifiers (`1password` → `one password`) while rejecting bare numeric counts (`move forward 3 words`), blocks negations/conditionals, and splits sequential requests on `then` / `and then` into $L \in \{1, 2\}$ distinct actions ($|\mathcal{P}(\mathcal{A})| = M + M(M-1)$). --- ## 3. Scale-Invariant Dual-Tower Bi-Encoder Architecture ### 3.1 Shared Word + Character-$n$-Gram Backbone Queries ($r=0$) and action descriptions ($r=1$) share word embeddings, 2,048-bucket hashed character $n$-grams ($n \in \{3,4,5\}$, up to $G=32$ per token), learned positions ($T \le 60$), and 2-layer Pre-Norm Transformer blocks ($d=64$, $H=4$, $d_{\mathrm{ff}}=128$), followed by unit-normalized role projections $\hat{q}_{\mathrm{sem}}, \hat{a}_{\mathrm{sem}} \in \mathbb{S}^{d-1}$ and a salience-weighted character-$n$-gram vector $\hat{u}_{\mathrm{lex}} \in \mathbb{S}^{d-1}$ (assigning $\alpha_t = 0.08$ to wrapper stop-words and $1.0$ to domain content tokens). ### 3.2 Scale-Invariant Semantic–Lexical Bilinear Decomposition To prevent semantic temperature growth from drowning out zero-shot subword alignment while keeping negative prototypes $\{\hat{r}_k\}_{k=1}^{16}$ strictly semantic, we couple the lexical scale multiplicatively to the clamped semantic temperature: $$s_{\mathrm{sem}} = \exp\bigl(\operatorname{clamp}(\ell,\, \ln 4,\, \ln 16)\bigr), \qquad s_{\mathrm{lex}} = s_{\mathrm{sem}} \cdot \bigl(0.55 + \operatorname{softplus}(g)\bigr)$$ and form $2d$-dimensional ($128$-float) embeddings: $$q_{\mathrm{vec}} = \bigl[\sqrt{s_{\mathrm{sem}}}\,\hat{q}_{\mathrm{sem}},\ \sqrt{s_{\mathrm{lex}}}\,\hat{q}_{\mathrm{lex}}\bigr] \in \mathbb{R}^{2d}, \qquad a_{\mathrm{vec},i} = \bigl[\sqrt{s_{\mathrm{sem}}}\,\hat{a}_{\mathrm{sem},i},\ \sqrt{s_{\mathrm{lex}}}\,\hat{a}_{\mathrm{lex},i}\bigr] \in \mathbb{R}^{2d}$$ Scoring against $M$ pre-encoded actions (`CompiledCatalog`) and the rejection class reduces to one matrix multiply plus mode/arity masking: $$z_i(q; \mathcal{A}) = \langle q_{\mathrm{vec}}, a_{\mathrm{vec},i} \rangle + M_{\mathrm{compat}}(q, s_i), \qquad z_{\mathrm{rej}}(q) = s_{\mathrm{sem}} \max_{k=1}^{16} \langle \hat{q}_{\mathrm{sem}}, \hat{r}_k \rangle$$ Whenever $\rho = s_{\mathrm{lex}} / s_{\mathrm{sem}}$ satisfies $\rho\,\gamma_{\mathrm{miss}} < c_r - c_{\mathrm{pos}} < \rho\,\gamma_{\mathrm{hit}} < c_r - c_{\mathrm{neg}}$, a single $\mathbb{R}^{2d}$ dot product simultaneously **(1)** rejects unmatched OOV nouns absent from $\mathcal{A}$, **(2)** admits newly registered open actions zero-shot as soon as their `ActionSpec` enters $\mathcal{A}$, and **(3)** rejects destructive/inverted verbs (`purge`, `delete`, `unlock`) even on matched nouns. Training enforces this operating point directly via 12 synthetic pseudo-word actions per step (8 fixed, 4 string-taking) paired with matched, verb-inverted, and unmatched-noun contrastive queries. --- ## 4. Dual-Speed Poison-Resistant Continual Learning 1. **External Oracles Only:** Only verified behavioral corrections (origin-buffer `post-command-hook` within 10 s of refusal, preview cancellation, or immediate undo within 8 s) and teacher agent distillations (`lispm-llm-learn-record-teacher`) can enter supervision; raw self-predictions are unrepresentable. 2. **PII Scrubbing & Leakage Shield:** Quoted literals are scrubbed to `"example"` or `"https://example.org"` at ingestion; phrases matching held-out calibration, command benchmarks, or Emacs task suites are blocked (`Withheld`). 3. **Join-Semilattice Quarantine (`quarantine.json`):** Normalized clause skeletons evolve monotonically under $\mathsf{Consistent}(y_1) \sqcup \mathsf{Obs}(y_2) = \mathsf{Conflicted}(\{y_1, y_2\})$ ($y_1 \neq y_2$). Ambiguous clauses enter the absorbing $\mathsf{Conflicted}$ state and are atomically expunged from both fast memory and training data. 4. **Hippocampal Recall + Gated Cortical Consolidation + Circuit Breaker:** Unambiguous clauses materialize immediately in `/episodic.json` without reloading weights. During Emacs idle periods, staged examples run `learn-sync → train → benchmark → finalize → activate` under strict zero-regression gates, guarded post-activation by an online circuit breaker (>35% cancellation/undo rate over $\ge 8$ evaluations triggers automatic `rollback`). --- ## 5. Empirical Evaluation ### 5.1 Published Checkpoints & CPU Performance | Artifact | Architecture | Parameters | Train Rows | CPU Train Time | Action Space | | --- | --- | ---: | ---: | ---: | --- | | `python-reference/` (`.`) | 2L Transformer + 49-way Linear | 184,625 | 16,404 | — | Closed (48 + `reject`) | | `rust-trained/` | 2L Transformer + 49-way Linear | 184,625 | 16,404 | 317.8 s | Closed (48 + `reject`) | | `semantic-trained/` | 2L Transformer + 49-way Linear | 189,425 | 17,232 | 128.7 s | Closed (48 + `reject`) | | `biencoder/` | 2L Dual-Tower ($\mathbb{R}^{128}$) + 16 Rej. Bank | **264,322** | 17,232 | **163.0 s** | **Open $\mathcal{A}$ + Mode Mask** | End-to-end batch evaluation of all 277 blind cases (348 clauses, including process startup, SafeTensors SHA-256 verification, 48-action catalog compilation, and JSON output) completes in **283.6 ms** (**1.02 ms/request**) on 2 Apple Silicon CPU threads. ### 5.2 Frozen Regression, Blind Generalization & Real Emacs 31.1 Execution Supported cohorts report **Correct / Wrong / Rejected**; unsupported cohorts report **Rejected / False Accepts**: | Cohort ($N$) | Default 48-cls (`.`) | Closed `semantic-trained` | Open `biencoder` | | --- | ---: | ---: | ---: | | Historical Emacs (187) | 173 / 2 / 12 | **178** / **1** / 8 | 175 / 3 / 9 | | Historical LispM (182) | **176** / **0** / 6 | 175 / **0** / 7 | **176** / **0** / 6 | | Supported wording robustness (286) | 266 / 6 / 14 | **271** / 6 / 9 | 256 / **2** / 28 | | Composition: Emacs × Emacs (552) | 474 / 9 / 69 | **499** / **4** / 49 | 485 / 16 / 51 | | Composition: LispM × LispM (552) | **519** / **0** / 33 | 514 / **0** / 38 | 517 / **0** / 35 | | Composition: Cross-Domain (1,152) | 1,035 / 10 / 107 | **1,058** / **4** / 90 | 1,048 / 18 / 86 | | Blind single-action supported (118) | 107 / **1** / 10 | **114** / **1** / 3 | 100 / **1** / 17 | | Blind two-action composition (71) | 54 / 2 / 15 | 62 / **0** / 9 | **66** / 1 / 4 | | Historical Emacs unsupported (56) | **56 / 0** | 55 / 1 | 55 / 1 | | Historical LispM unsupported (61) | 60 / 1 | 60 / 1 | **61 / 0** | | Fresh robustness unsupported (126) | 115 / 11 | **120 / 6** | 119 / 7 | | Blind unsupported (88) | 86 / 2 | **87 / 1** | 84 / 4 | | **Real Emacs 31.1 Task Suite (30)** | **30 / 30 (100%)** | **30 / 30 (100%)** | **30 / 30 (100%)** | ### 5.3 Zero-Shot Open-Action Routing & Scale-Invariance Ablation Extending `biencoder/catalog.json` at runtime with unseen LispM and Emacs commands (**0 gradient steps**): | Instruction | Active Mode | Unconstrained Scale ($s_{\mathrm{sem}} \le 30$) | Scale-Invariant Bilinear (Ours) | | --- | --- | --- | --- | | `open the 1password vault` | `fundamental-mode` | `(lispm-1password)` | `(lispm-1password)` | | `open the security audit dashboard` | `fundamental-mode` | `(lispm-security)` | `(lispm-security)` | | `launch shrdlu blocks world planner` | `fundamental-mode` | *Refused (false rej.)* | `(lispm-shrdlu)` | | `open magit git status` | `fundamental-mode` | `(magit-status)` | `(magit-status)` | | `recursively grep for "RuntimeGuard"` | `fundamental-mode` | *Refused (false rej.)* | `(rgrep "RuntimeGuard")` | | `copy the totp verification code` | `fundamental-mode` | *Refused* | **Refused** *(mode-masked)* | | `copy the totp verification code` | `lispm-1password-mode` | *Refused (false rej.)* | `(lispm-1password-copy-totp)` | | `purge the totp verification code` | `lispm-1password-mode` | *Refused* | **Refused** *(destructive verb)* | | `open spotify music player` | `fundamental-mode` | *Refused* | **Refused** *(unmatched app)* | --- ## 6. Conclusion LispM LLM demonstrates that a 264K-parameter local dual-tower router paired with a typed symbolic execution boundary and a semilattice-quarantined continual-learning loop achieves 100% goal completion on real Emacs state benchmarks, ~1 ms CPU latency, zero-shot extensibility to newly harvested `lispm-kit` and Emacs commands, and mathematical guarantees against code-eval injection, PII memorization, and self-training poison.