Draft · technical reportOctober 2026 · not peer reviewed

Living State Machine

Gated, ablatable memory for long-horizon preference recall around a frozen language model

Kalen Patterson · Independent research · kcpatterson27@gmail.com

Long-horizon assistants need memory that is cheap, inspectable, and resistant to drift. This report describes Living State Machine (LSM), a local-first wrapper around a frozen language model that combines a compact dual state, tiered episodic memory, habituation, Hebbian association, gated writes, a deterministic verifier, and surprise-modulated plasticity. Every mechanism is ablatable through configuration. On a matched-budget preference-recall benchmark, LSM scored 1.000 against 0.100 for naive retrieval-augmented generation across three seeds; a harder decoy-heavy stress benchmark was treated as a stress test rather than a success metric. The gated writer reached an F1 of 0.98 and was necessary under decoy load, where always-store collapsed to zero. The report also documents three substantive negative results - a multi-timescale memory variant, an encoder verifier, and a Stentor-style recurrent core - plus one evaluation-harness fault that initially looked like a model regression. The central claim is deliberately narrow: under a matched context budget, structured, gated memory can outperform naive retrieval. It is not a claim that the wrapper beats a full-context model on every long transcript.

Keywords: long-horizon memory · retrieval-augmented generation · gated writes · state-space models · local-first AI · evaluation hygiene

1. Introduction

A frozen language model is stateless between calls. The common workarounds are prompt stuffing, retrieval-augmented generation, or a separate memory service. Each buys context at a cost: full history grows without bound, retrieved snippets are brittle under decoys, and an LLM-written summary can quietly turn an assistant's guess into a persistent fact. On consumer hardware the constraint is sharper: a 12 GB inference budget leaves little room for a second model to manage memory.

LSM studies a narrower question: can a compact set of inspectable, biologically inspired rules around a frozen model improve long-horizon preference recall at a matched context budget? The system is a wrapper, not a fine-tune. It keeps a small working state s_t, a durable episodic store, and a per-turn control loop. The research track closed in July 2026; this report is a technical account of the evidence, including what failed.

The contributions are:

2. Related work

Retrieval-augmented generation (RAG) conditions a model on retrieved passages rather than the full corpus [1]. It is effective when retrieval is clean, but it assumes the retrieved unit is useful in isolation. LSM instead retrieves from an episodic memory that has been filtered by a writer gate and scored by several signals.

Memory-augmented agents such as MemGPT treat the context window as a managed resource and move information between working and external memory [2]. Generative Agents maintain a memory stream with reflection and retrieval [3]. LSM shares the tiered-memory premise but differs in two ways: the language model is frozen and local, and the persistent state is rendered deterministically from structured facts rather than authored by the model.

Long-context transformers reduce the need for retrieval by extending attention [4], while state-space models offer linear-time sequence mixing [5]. LSM's Phase 2 explored a small state-space core, but the production path remained a wrapper; the trained core had to clear a no-regression gate rather than replace the baseline.

Habituation and associative learning are classic biological mechanisms [6], and regularization methods for sequential learning address a related stability problem [7]. LSM borrows the vocabulary - habituation, association, surprise, plasticity - but evaluates each mechanism as an engineering component, not as a biological claim.

3. System

3.1 Per-turn loop

Each turn follows a fixed control loop: embed the turn; score memory candidates with cosine similarity, habituation damping, association boost, and trust; retrieve the top k; update the working state; compose a prompt from the state projection and retrieved snippets; call the frozen model; score the outcome; run the verifier; write only what passes the gate; and update plasticity signals. The loop is deliberately small enough to inspect in logs.

LSM per-turn control loop A user turn is embedded and scored against durable memory. The top results and the compact state compose a prompt for a frozen language model. The reply is scored and verified before a gated write updates durable memory and state. User turnobserve EmbedCPU vector Score + retrievecosine · habituation · association Composestate + top-k Frozen LLMlocal inference Replythen verify Working state s_ttext + dense vector · facts-backed Durable memoryLanceDB episodes + SQLite log Verifier + gated writerscore · reject · re-prompt · store Surprise / plasticitycorrection-sensitive update prompt contextscoregated writestate updateretrieve
Figure 1. The LSM control loop. The durable store is read through the scored retriever and written only through the verifier and gate. The working state is a compact projection, not a transcript.

3.2 State and memory tiers

s_t is a dual representation: a short text projection injected into the prompt (roughly 400–600 characters) and a dense vector used for retrieval conditioning. Durable memory holds verbatim atoms in LanceDB plus an episodic SQLite log. Fast, session, and durable tiers are connected by promotion, hit-count, vitality decay, and a background consolidator. The mental model is explicit: the state is a compressed, inspectable summary; durable memory holds the evidence.

3.3 Mechanisms

Habituation damps repeated low-value input; association boosts memories that co-occur with the current turn; trust carries outcome history; surprise-modulated plasticity amplifies the learning rate on correction-like turns. The facts-backed updater renders s_t.text deterministically from structured facts with recency, correction-aware slot ordering, and budget trimming. The LLM-authored summarizer remains only as an ablation. This change followed a live failure in which a vocative was absorbed into state as a game title and then inherited by every later turn.

3.4 Gated writing and verification

The verifier scores candidates rather than authoring text. Its five weighted components cover fact contradiction, identity drift, correction violation, list-merge errors, and length overflow. The score gates three surfaces: the writer (rejected text never becomes durable memory), the reply (one re-prompt with fix hints, then the lower-energy draft), and the legacy summarizer. The verifier is deterministic by default; a linear/hybrid learned head was evaluated, while an encoder variant was logged as a negative.

3.5 Ablation as dependency injection

Every mechanism sits behind a small Protocol with a Null* implementation. The eight benchmark configurations, the verifier family, and the state-updater family are therefore configuration flips. A run copies its YAML into the run directory with metrics.json, raw outputs, and logs; a run without its config is not treated as a run.

4. Experimental setup

The evaluation suite contains eight tasks: matched-budget preference recall (recall_pref_v1), a harder decoy/long-gap stress task (recall_pref_v2), habituation and association signal benches, memory-write precision, multi-session consistency, fact correction, and verifier calibration. Headline claims use seeds 0, 1, and 2; Phase 2 integration checks are seed 0 only and are labelled as such.

The primary baselines are naive RAG and a raw LLM with a matched context budget. A full-transcript raw LLM is reported separately because it is not matched: it sees the entire history and therefore answers a different resource question. Hardware was a single RTX 5060 Ti (16 GB VRAM, 32 GB RAM) running a frozen local model through Ollama. A one-time cloud burst on a RunPod L40S cost approximately $8.04 and consumed about 9.3 hours for QLoRA and small-core training. The local test suite finished at 241 passed and 3 skipped.

5. Results

Table 1. Preference recall (accuracy; seeds 0–2). v2 is a stress bench, not the headline success metric.
Systemrecall_pref_v1recall_pref_v2
Naive RAG0.100 ± 0.1000.044 ± 0.038
Raw LLM, matched budget0.000 ± 0.0000.000 ± 0.000
Raw LLM, full transcript1.000 ± 0.0000.911 ± 0.038
LSM full1.000 ± 0.0000.089 ± 0.038

On the matched-budget headline task, LSM reached the ceiling while naive RAG remained at 0.100. The full-context baseline also reached 1.000 on v1, so the result is not evidence that LSM beats full context on that task. On the harder v2 stress bench, the full-context model remained strong at 0.911 while LSM fell to 0.089; the matched raw baseline was 0.000. The honest reading is that v2 measures the value of full-history access, not a wrapper failure, and it is reported to keep the headline claim in bounds.

Table 2. Ablations on recall_pref_v1 (seed 0–2 means). Δ is relative to LSM full.
AblationAccuracyΔReading
LSM full1.000 ± 0.000n/aCeiling
No habituation0.967 ± 0.058−0.033Measured contribution
No writer gate0.933 ± 0.115−0.067Writer matters
Flat memory0.933 ± 0.058−0.067Tiering matters
No association1.000 ± 0.0000.000Bench too easy
Multi-memory1.000 ± 0.0000.000Negative/no separation
Table 3. Component evidence: writer precision, retrieval MRR, and verifier calibration.
ComponentResultNote
Writer - alwaysF1 0.67Precision 0.50, FPR 1.00
Writer - rulesF1 0.98Precision 1.00, recall 0.97, FPR 0.00
Writer - learnedF1 1.00On 60 signal / 60 filler turns
Habituation signal+0.068 MRR0.314 → 0.382
Association signal+0.317 MRR0.454 → 0.772
Verifier - rule0.556 macro-F1Default V.1
Verifier - linear / hybrid0.771 macro-F1n=13; directional only
Verifier - encoder0.211 macro-F1Reject-all collapse; negative

The Phase 2 integration gate held the headline benchmark at 1.000 when the trained hybrid SSM updater was projected into s_t, and both the Transformers base and the QLoRA adapter reached 1.000 after the harness fix described below. The trained core was therefore accepted as an optional state updater, not as a replacement for the wrapper.

6. Negative results and failure analysis

6.1 Multi-timescale memory did not separate

A multi-timescale memory variant produced a small negative effect (Δ ≈ −0.05). The result was kept rather than tuned into the headline: on this bench, additional tiers added complexity without a measurable gain.

6.2 The encoder verifier collapsed

The MiniLM cross-encoder verifier scored 0.211 macro-F1 at n=13, effectively rejecting everything. With a small labeled set, the encoder had no room to learn the decision boundary. The linear and hybrid heads were retained as directional evidence; the encoder result is a named negative, not a hidden hyperparameter search.

6.3 Stentor-style recurrence lost to a minimal SSM

The ambitious Phase 2 hypothesis - that a Stentor-inspired recurrent core would beat a minimal diagonal SSM on language-modeling loss - failed: final loss was 5.21 versus 2.95 on TinyStories. The comparison was not clean: step counts and sequence lengths were unequal, and the association-trace update was sequential. The minimal core was promoted because it passed the no-regression gate, and the negative was logged with its confounds. The honest next experiment is a parallelized association scan at matched compute.

6.4 A false regression caused by the evaluation harness

After QLoRA training, the adapter path appeared broken: base 0.100 and +LoRA 0.200. The model was not the problem. A hash embedder combined with a minimum score of 0.15 filtered out the preference line, returning zero memories; switching the eval embedder to fastembed restored both paths to 1.000. The correction was written into the phase report. The lesson is now a first-class check: inspect retrieved-item counts before interpreting an end-to-end score.

7. Limitations and threats to validity

8. Conclusion

LSM shows that a compact, inspectable memory wrapper can produce a large gain over naive RAG at a matched context budget, and that the writer gate is the component most likely to matter when memory is under decoy pressure. The result is deliberately bounded: it does not claim to beat full-context models, and its negative results are part of the contribution. The next steps are matched-compute recurrence experiments, a larger verifier corpus, multi-seed Phase 2 integration, and a public, reproducible release of the code and run artifacts.

Appendix A. Evidence map

References

  1. Lewis, P., et al. “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.” NeurIPS 2020. arXiv:2005.11401.
  2. Packer, C., et al. “MemGPT: Towards LLMs as Operating Systems.” 2023. arXiv:2310.08560.
  3. Park, J. S., et al. “Generative Agents: Interactive Simulacra of Human Behavior.” UIST 2023. arXiv:2304.03442.
  4. Beltagy, I., Peters, M. E., and Cohan, A. “Longformer: The Long-Document Transformer.” 2020. arXiv:2004.05150.
  5. Gu, A., and Dao, T. “Mamba: Linear-Time Sequence Modeling with Selective State Spaces.” 2023. arXiv:2312.00752.
  6. Thompson, R. F., and Spencer, W. A. “Habituation: A Model Phenomenon for the Study of Neuronal Substrates of Behavior.” Psychological Review 73(1):16–43, 1966.
  7. Kirkpatrick, J., et al. “Overcoming Catastrophic Forgetting in Neural Networks.” PNAS 114(13):3521–3526, 2017.

Draft status: tables reconciled against the Phase 1 and Phase 2 reports in the DT-001 checkout. Citations, run-artifact verification, LaTeX conversion, and author review remain. Not peer reviewed. Prepared with AI assistance; the author remains responsible for every claim.