MemTrace: Tracing and Attributing Errors in Large Language Model Memory Systems

Xinle Deng, Ruobin Zhong, Hujin Peng, Xiaoben Lu, Yanzhe Wu, Guang Li, Buqiang Xu, Yunzhi Yao, Jizhan Fang, Haoliang Cao, Junjie Guo, Yuan Yuan, Ziqing Ma, Yuanqiang Yu, Rui Hu, Baohua Dong, Hangcheng Zhu, Ningyu ZhangarXiv 2026

TL;DR

MemTrace introduces a novel framework that treats complex Large Language Model (LLM) memory pipelines as executable graphs to automatically trace and diagnose errors. By pinpointing the exact operation where a memory failure originated, it enables a closed-loop prompt optimization system that automatically corrects faults and boosts end-task performance by up to 7.62%.

What Problem Does This Paper Address?

As LLM agents transition from stateless task-solvers to stateful systems capable of long-horizon reasoning, they increasingly rely on complex memory systems (like RAG, Mem0, or EverMemOS). However, debugging these memory systems is notoriously difficult.

In a stateless agent, a failure is usually localized to the current turn (e.g., a bad tool call). In contrast, a memory-augmented agent can suffer from "silent corruption": a user preference might be incorrectly extracted or overwritten in turn 2, but the failure only surfaces much later in turn 50 during retrieval or response generation. Standard chronological execution logs are flat and unstructured, making it nearly impossible to trace how variables evolve, merge, or corrupt over time. This paper addresses this traceability gap by formalizing the problem of error tracing and attribution in LLM memory systems.

Methods

The authors propose a two-part solution consisting of a tracing toolkit and an agentic graph explorer:

  1. smartcomment Tracing Toolkit: Instead of rewriting existing memory systems under a rigid framework, the authors developed a lightweight instrumentation package. Developers insert simple tracing statements at key operations. At runtime, smartcomment records variables and operations as a directed acyclic bipartite Execution Graph, explicitly capturing data dependencies and information flow across turns and sessions.
  2. MemTrace Agent: To find the root cause of a failure without scanning megabytes of logs, MemTrace treats failure attribution as an agentic graph exploration problem.
  3. Initialization: It uses hybrid retrieval (dense + sparse) to find the historical source messages most relevant to the failed question and golden answer, seeding a priority queue ("to-explore list").
  4. Graph Exploration: The agent inspects local operation subgraphs step-by-step, evaluating whether an operation was locally correct. If correct, it follows the downstream edges to add new variables to the queue. If it finds a faulty operation that, if fixed, would rescue the execution, it marks it as the decisive faulty operation.
Figure 1: Framework for automatic diagnosis of LLM memory systems. We first execute a memory system to construct an execution graph. Given a failed case, MemTrace performs step-by-step tracing over this graph to locate the faulty operation. This framework is general across different memory systems and enables faster failure attribution than human experts.

The authors also introduce MemTrace-OBS, a variant that flattens subgraphs into textual blocks and equips the agent with global regex search tools, significantly reducing token overhead on weakly structured traces.

Datasets

To evaluate their approach, the authors constructed MemTraceBench, a diagnostic benchmark containing 160 human-annotated, system-related failure cases spanning four representative memory systems: Long-Context, RAG, Mem0, and EverMemOS.

The underlying interaction trajectories were sampled from three public benchmarks:

  • LoCoMo (long-term conversational memory)
  • LongMemEval (chat assistants with long-term interactive memory)
  • RealMem (real-world memory-driven interactions)

Each case in MemTraceBench includes the full execution trace, question-answer pairs, ground-truth error labels, the exact faulty operation identifier, and human-authored explanations.

Key Insights and Ideas

  • Memory Failures are System-Dependent: Different architectures exhibit distinct bottlenecks. For instance, RAG suffers heavily from retrieval errors (failing to fetch the right context), whereas Mem0 and EverMemOS are prone to extraction and update errors (corrupting or omitting information during memory construction).
  • Graph Constraints Benefit Smaller Models: When using the search-based MemTrace-OBS, smaller models like GPT-4.1 mini frequently misclassified retrieval errors as extraction errors because global search allowed them to jump straight to the end of the log and guess. The step-by-step graph traversal of standard MemTrace forces the model to follow the actual information flow, drastically improving error-type accuracy for smaller LLMs.
  • Localization is the Secret to Prompt Optimization: Traditional prompt optimization fails in multi-session memory systems because the causal chain is too long to fit into an optimizer's context window. By using MemTrace to isolate the single faulty operation, prompt optimization becomes a local problem. Developers only need to optimize the specific prompt participating in that faulty operation.
Figure 2: An illustrative workflow of MemTrace. The initial to-explore list contains v1 and v10. Starting from v1, the agent inspects the operation subgraph corresponding to the operation o1, and finds that o1 correctly extracts the key user facts. The agent then adds v3 to the list to inspect subsequent operations. By continuing this graph exploration process, the agent identifies the faulty operation o3 in the third iteration.

Key Results

  • Attribution Accuracy: Using GPT-5.4 as a backbone, MemTrace achieved an Error Type Accuracy (ETA) of 54.38% and a Faulty Operation Identification Accuracy (OIA) of 38.13% across all memory systems, outperforming the baseline "All-at-Once" log analysis method.
  • Efficiency Gains: MemTrace-OBS reduced token costs by 84.75% and runtime by 70.58% on long-context memory traces compared to standard MemTrace, proving highly effective for weakly structured execution logs.
  • Closed-Loop Optimization: Integrating MemTrace with a prompt optimizer to fix faulty prompts in Mem0 led to a 7.62% absolute improvement in end-task accuracy (jumping from 66.70% to 74.32%). Conversely, attempting optimization without MemTrace's localization actually degraded performance due to noisy updates.

Limitations and Future Work

  • The Singleton Assumption: The current framework assumes a single root-cause error per failure. In highly complex agentic systems (e.g., multi-agent systems running in parallel), a failure might be jointly caused by multiple independent errors. Extending MemTrace to handle non-singleton error sets is a key next step.
  • Modality and Memory Diversity: MemTraceBench currently focuses on textual, non-parametric memory. Future work includes expanding the benchmark to cover task-specific memory and multimodal memory systems.

Summary updated

BibTeX
@misc{deng2026memtrace,
  author = {Xinle Deng and Ruobin Zhong and Hujin Peng and Xiaoben Lu and Yanzhe Wu and Guang Li and Buqiang Xu and Yunzhi Yao and Jizhan Fang and Haoliang Cao and Junjie Guo and Yuan Yuan and Ziqing Ma and Yuanqiang Yu and Rui Hu and Baohua Dong and Hangcheng Zhu and Ningyu Zhang},
  title = {{MemTrace: Tracing and Attributing Errors in Large Language Model Memory Systems}},
  year = {2026},
  eprint = {2605.28732},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.28732},
}
Figure