Skip to content

【记忆】修复 Skill 召回注入简介取值错误(MEMMY-814) - #774

Open
whqf1123 wants to merge 1 commit into
MemTensor:v1.2.7from
whqf1123:fix/memmy-814-skill-description
Open

whqf1123 wants to merge 1 commit into
MemTensor:v1.2.7from
whqf1123:fix/memmy-814-skill-description

Conversation

@whqf1123

@whqf1123 whqf1123 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

问题与修复

Skill 摘要注入原先直接把调用指南的第一段当作简介,导致自动生成的 Skill 简介重复名称,导入的 Skill 简介可能显示原始 YAML 文件头。

本次按以下优先级选取有效简介:retrievalBlurb → triggerContext → YAML 文件头中的 description → 有效正文。跳过标题、重复名称和代码块;没有可用内容时输出 (not provided)。全文(full)注入模式保持不变。

对应云效工单:MEMMY-814。本 PR 仅包含简介修复;MEMMY-815 的注入预算限制另行提交。两个修复也已放在一起进行联合验证。

验证结果

  • 单独修复的 Memory 全量测试:1451 项通过、1 项跳过;类型检查通过。
  • MEMMY-814 与 MEMMY-815 联合版本:1460 项测试通过、1 项跳过;类型检查通过。
  • 打包保护测试:130 项通过、1 项跳过;发布流程测试:31 项通过、5 项跳过。
  • 独立及联合版本的未签名 arm64 DMG 均构建成功,hdiutil 镜像完整性校验通过。包内模块回归测试通过,关键模块哈希与源码构建结果一致。
  • 独立及联合版本均使用隔离配置启动至登录界面,启动日志确认 Memory 和 Agent 后台服务已就绪。尚未测试登录后的云端交互、覆盖安装和升级。
  • 原有的可选 DMG 背景图替换步骤报告镜像空间不足;构建及镜像完整性检查均通过。

目标分支为 v1.2.7,修复基线为 88edd02a。本次修复不改变召回排序或候选条数。

@whqf1123 whqf1123 changed the title fix(memory): correct Skill injection descriptions (MEMMY-814) 【记忆】修复 Skill 召回注入简介取值错误(MEMMY-814) Oct 28, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #774
Task: 1eb0c61ef8aa88bd
Base: v1.2.7
Head: fix/memmy-814-skill-description

🔍 OpenCodeReview found 5 issue(s) in this PR.

⚠️ 2 warning(s) occurred during review.


1. Memory/src/service/retrieval/skill-injection-description.ts (L21)

This frontmatter parsing + "first prose line" extraction duplicates logic already present in editedSkillDisplay() (Memory/src/service/evidence/history-skill-policy.ts:70-83), which also parses YAML frontmatter with parseYaml/isRecord and picks the first non-heading prose line (agent-source/runtime.ts:1325 frontmatterValue is a third variant). Two independently maintained implementations will drift and produce different descriptions for the same skill. Consider extracting a shared skillFrontmatterSummary(body) helper and reusing it in both places.


2. Memory/src/service/retrieval/skill-injection-description.ts (L30)

The start/end --- pair is treated as frontmatter unconditionally, so a guide that opens with a Markdown horizontal rule (--- on line 1) and contains another --- separator later has everything between the two rules discarded, even though that text is ordinary prose (the YAML parse fails / returns a scalar, then the prose extraction only runs on the already-sliced body). Conversely, when a leading --- is an HR with no later ---, body is emptied entirely and the description becomes (not provided) despite valid prose below it. Consider only treating the block as frontmatter when it actually parses into a record (i.e. move the body = body.slice(...) inside the successful-parse branch) and falling back to the full body otherwise.


3. Memory/src/service/retrieval/skill-injection-description.ts (L62)

maxChars is not validated: if a caller ever passes NaN/Infinity (e.g. a malformed tuning/config value reaching skillSummaryChars), Math.floor yields NaN, Math.max(1, NaN) is NaN, description.length <= NaN is false and the function returns just "…"; with Infinity truncation is silently skipped. Guard with Number.isFinite before using it.

💡 Suggested Change

Before:

  const limit = Math.max(1, Math.floor(input.maxChars));

After:

  const limit = Number.isFinite(input.maxChars) ? Math.max(1, Math.floor(input.maxChars)) : 200;

4. Memory/src/service/retrieval/skill-injection-description.ts (L63)

slice(0, limit - 1) operates on UTF-16 code units, so an emoji or astral-plane CJK character at the cut boundary is split into a lone surrogate and the injected description contains a broken glyph. Truncate by code point, e.g. Array.from(description).slice(0, limit - 1).join("").

💡 Suggested Change

Before:

  return description.length <= limit ? description : `${description.slice(0, limit - 1)}…`;

After:

  return description.length <= limit ? description : `${Array.from(description).slice(0, limit - 1).join("")}…`;

5. Memory/src/service/retrieval/skill-injection-description.ts (L30-L33)

A guide that legitimately starts with a Markdown horizontal rule (--- on line 1) and contains no second --- falls into this branch, so the whole guide is discarded and the injected Description degrades to (not provided) even though plenty of prose exists. Only drop the body when the opening --- actually looks like a YAML header (e.g. a key: line follows); otherwise keep the body and let the prose scan skip the rule itself.

💡 Suggested Change

Before:

    } else if (/^---(?:\r?\n|$)/u.test(body)) {
      // An unterminated header has no safe prose boundary.
      body = "";
    }

After:

    } else if (/^---(?:\r?\n|$)/u.test(body) && /^[\w.-]+\s*:/u.test(body.split(/\r?\n/u)[1] ?? "")) {
      // An unterminated header has no safe prose boundary.
      body = "";
    }

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (6/6 executed). common/smoke: 6/6. Duration: 2s

Branch: fix/memmy-814-skill-description

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants