{
  "format": "arthurs-review-publication-proof/v1",
  "createdAt": "2026-07-19T00:45:44.485Z",
  "publicUrl": "https://blog.leesaitool.com/misc/memory-system-of-codex-breaked-down",
  "publishedAt": "2026-07-08T14:09:08.305Z",
  "updatedAt": "2026-07-19T00:45:44.474Z",
  "article": {
    "titleZh": "Codex分析",
    "titleEn": "Breakdown on Codex",
    "slug": "memory-system-of-codex-breaked-down",
    "category": "misc",
    "excerptZh": "技术博客",
    "excerptEn": "Memory system of Codex breaked down--A technical blog",
    "seoDescription": "",
    "bodyZh": "本文探讨 OpenAI Codex 的记忆机制，以及它如何保存长期记忆。\n\n这套机制主要包含三个记忆层级，此外偶尔还会出现由 AI 临时生成的第四层，即 ad hoc note。\n\n第一层实际上是一个面向模型的索引，由两个文件组成，分别是 memory_summary.md 和 MEMORY.md。memory_summary.md 是一份压缩后的概览，记录用户信息、偏好、工作流程以及重要的本地路径。MEMORY.md 则是一个规模更大、可供rg检索的目录。它会按照主题和任务类型分类，同时按照关键词进行标签，也通过文字概括任务的详细信息，并链接到内容更详细的第二层任务执行摘要。\n\n第二层详细记录任务是如何完成的，包括任务要求、遇到的问题以及相应的解决方案。其中的 Markdown 文件包含除工具调用结果之外的几乎全部信息。此外还有一份 JSONL 文档，保存完整的工具调用结果和用户指令，模型可以在需要时查阅。\n\n第三层是记录整个会话过程的原始 JSON 文档。它包含 JSONL 文档，以及一个 SQLite 数据库。数据库中保存时间戳、精确的 token、原始结果、运行环境和文档路径。如果 JSONL 文档提供的信息不足，模型就会通过命令行读取 SQLite 数据库，虽然一般不会这样。那个数据库有个小问题，它会频繁读写磁盘，而且速度非常之高，可能会损伤磁盘。我的磁盘在一周之内被损伤了1/18。\n\n第四层被称为 ad hoc notes，也就是根据具体情况生成的自定义笔记。当用户特别强调某一点，或者要求 AI 记住某件事时，Codex 会创建一个小型 Markdown 文件，并以时间和标题作为文件名。文件中会记录相关背景以及指令的适用范围。当用户提到与主记忆文件中某项任务相似的任务时，AI 会同时读取第二层笔记和对应的 ad hoc note。\n\n还需要注意的是，系统中还有一个名为 raw_memories.md 的文件。它保存更加详细的任务信息，包括用户的每个提示词。\n\n这套机制有一个显而易见的优点，那就是你的偏好不会被遗忘。由于 AI 会追踪记忆文件，并保存过去问题及其解决方法的详细记录，因此它能够避免重复犯错。\n\n然而，在我的体验中，这套机制明显弊大于利。其中最糟糕的问题是过拟合。AI 会对你的请求产生过拟合，并把某些要求过度泛化到其他任务中。在一些情况下，AI 为了迎合一些你实际上并不存在的需求，反而限制了自身的能力，譬如，不喜欢安装新的有必要的库，或者在调用工具时畏手畏脚。\n\n另一个严重问题是无意识记录。AI 有时会把用户的某次操作，比如不允许做某个操作，理解为一种长期偏好，并在用户不知情的情况下将其保存下来。更糟糕的是，当 AI 为了逃避繁重工作而表现得懒惰时，它可能会把这种行为习惯也记录到文件中，导致它之后在执行任务时更加敷衍。这是因为记录行为的AI跟当前做出懒惰行为的AI不是一个AI。\n",
    "bodyEn": "The Four Layers of Memory\n\nThis article explores OpenAI Codex's memory mechanism and how it preserves long-term memory.\n\nThere are three main layers of memory, along with an occasional fourth layer generated by the AI as an ad-hoc note.\n* The First Layer is actually a model-facing index made of two files: memory_summary.md and MEMORY.md. memory_summary.md is the compressed overview of the user, preferences, stable workflows, and important local paths. MEMORY.md is the larger searchable registry that groups previous tasks by project, topic, keywords, reusable knowledge, and failure notes, and links to the more detailed second-layer rollout summaries.\n* The Second Layer is a detailed documentation of how the task was completed, including the specifications, issues faced, and solutions. The markdown part contains almost all information except tool call results. There is also a JSONL document with complete tool call results and user instructions, which the model can reference if needed.\n* The Third Layer is a raw JSON process document of the session. It contains the JSONL document and a SQLite database with timestamps, exact tokens, raw results, environments, and document paths. The model reads the SQLite database via the command line if the JSONL document is insufficient.\n* The Fourth Layer is called ad hoc notes, which are customized notes generated when a user emphasizes a point or tells the AI to remember something. Codex creates a small markdown file using the time and title as its file name, containing the context and scope of the instructions. When the user mentions a task similar to one in the main memory file, the AI reads both the second-layer note and the ad-hoc note.\n\nIt is important to note that there is also a file called raw_memories.md which has the details of a task in it, but also keywords which are very easy for the models to search with rg, a method very convenient in the terminal.\n\nOne obvious benefit of this mechanism is that your preferences are never forgotten. The AI avoids repeating mistakes because it tracks memory files and detailed descriptions of how to solve past problems.\n\nHowever, the downsides of this mechanism are outweigh the benefits.\nThe most damaging downside is overfitting. The AI overfits to your requests and generalizes them too broadly to other tasks. In some cases, the AI restricts its capabilities to tailor to needs you do not actually have.\n\nAnother serious problem is unconscious recording. The AI sometimes interprets actions as a preference and saves it without your knowledge. Furthermore, when the AI acts lazy to avoid heavy work, it records that habit into the file, leading to more loafing on the job.\n",
    "coverImagePath": "uploads/2026/07/c0ffcf27-949f-4bc3-8f91-648bd932d040.webp",
    "tags": []
  }
}
