fix(memory): enforce typed and lifecycle-safe updates - #3916
Open
yuanqingz wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
@qin-ctx @heaoxiang-ai 麻烦有空帮忙 review 一下这个 PR,重点包括 typed MCP memory write、Agent Evolution 前置条件、memory identity/page ID 更新边界,以及 Experience lifecycle filtering。 本地 focused tests 和上游 API/CLI integration 均已通过。当前 Docs 红灯是 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
memory_typeto MCPrememberfor explicit Preference or Experience extraction while preserving the existing untyped behavior.Why
The generic
rememberpath could accept an explicit Experience intent while Agent Evolution was disabled and silently update an unrelated Preference. LLM-generated update operations could also bind an existing page ID to the wrong schema or rewrite immutable identity fields. Separately, recalled Experience candidates were not checked against their authoritative lifecycle metadata.This change makes those boundaries explicit and fail-closed while keeping existing untyped callers and legacy Experience documents without lifecycle metadata compatible.
User impact
remember(messages=...)keeps its current behavior.remember(..., memory_type="preferences")constrains extraction to Preferences.remember(..., memory_type="experiences")queues the Case → Trajectory → Experience pipeline and returns an explicit precondition error when Agent Evolution is disabled.Typed Experience writes accept caller-supplied transcripts and are documented as a trusted-author operation.
Validation
git diff --checkand Python compilation passed.CI note
The Docs workflow currently reports an API-reference baseline failure: the route
PATCH /api/v1/sessions/{session_id}/configis mounted onmain, while the existing English and Chinese API reference still says runtime session-config updates are unavailable. This PR does not change that route or those API-reference pages; its MCP guide changes merely trigger the repository-wide API-reference check.Related
The independent Codex memory-plugin reliability changes are in #3917. Neither PR contains the other's commit.
中文说明
改动概述
remember增加可选的memory_type,支持显式提取 Preference 或 Experience,同时保持原有未指定类型时的行为不变。问题背景
此前,调用者即使明确希望保存 Experience,在 Agent Evolution 关闭时,通用
remember路径仍可能接受请求并把内容更新到不相关的 Preference。LLM 生成的更新操作也可能将已有 page ID 绑定到错误的 schema,或者改写本应不可变的 identity 字段。此外,召回 Experience 时没有根据源文件中的权威 lifecycle metadata 做最终校验。本 PR 将这些边界改为显式、fail-closed 的行为,同时兼容现有未指定
memory_type的调用,以及没有 lifecycle metadata 的历史 Experience 文档。用户影响
remember(messages=...)保持现有行为。remember(..., memory_type="preferences")只允许提取 Preference。remember(..., memory_type="experiences")会进入 Case → Trajectory → Experience 流水线;Agent Evolution 未开启时返回明确的前置条件错误。Typed Experience 接受调用者提供的 transcript,因此文档中明确将它定义为可信写入方接口;不可信应用应提交由服务端实际记录的 session。
验证结果
git diff --check与 Python 编译检查通过。CI 说明
Docs workflow 当前命中了上游 API reference 的既有缺口:
main已挂载PATCH /api/v1/sessions/{session_id}/config,但现有中英文 API 文档仍声明运行时 session config 不可更新。本 PR 没有修改该路由或对应 API reference,只是 MCP guide 的改动触发了全仓 API reference 检查。相关 PR
Codex memory plugin 的独立可靠性修复位于 #3917;两个 PR 均不包含对方的提交。