Skip to content

fix(agent-core-v2): truncate oversized skill content - #4834

Merged
sailist merged 1 commit into
release/2026-11-12from
bug-351-11-11-skill-tool-output-truncation
Nov 11, 2026
Merged

sailist merged 1 commit into
release/2026-11-12from
bug-351-11-11-skill-tool-output-truncation

Conversation

@sailist

@sailist sailist commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

通过 Skill 工具加载超长 Skill 时,完整正文会进入后续模型上下文,没有长度上限。这个 PR 让模型调用及嵌套调用的超长 Skill 复用现有工具结果截断机制,同时保留可分页读取的完整渲染内容。

Bug Reproduction Steps

  1. 注册一个正文超过 50,000 字符的内联 Skill,并通过 Skill 工具调用它。
  2. 观察注入上下文的 <skill-loaded> 提醒。
  3. 修复前提醒包含完整正文;修复后提醒只包含有界预览、截断说明和 output_path,完整渲染内容可通过该路径读取。

Root Cause

Skill 的普通工具结果只有一句加载成功提示,因此通用工具执行适配器的截断不会处理 Skill 正文。真正的正文通过 loop.remind(...) 单独注入,绕过了这条截断路径。本 PR 在正文进入提醒前补上同一截断服务,是根本修复,而不是绕过。

Code Changes

核心改动是在包装 <skill-loaded> 之前截断渲染后的 Skill 正文,因此名称、trigger、source、dir、args 等外层元数据保持原样,普通工具返回值也保持简短。

 executeModelSkill
   renderSkillPrompt
+  truncateForModel(toolName: "Skill", toolCallId)
   renderModelToolSkillPrompt
   loop.remind

超过现有 50,000 字符限额时,完整渲染内容(包括参数展开)由现有服务保存,模型收到头尾预览、output_path 和读取提示。短 Skill 不经过截断转换,行为不变。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
模型调用或嵌套调用超过 50,000 字符的 Skill 正文 完整正文直接放入 <skill-loaded> 提醒 提醒包含有界预览和 output_path,完整渲染内容保存到工具结果文件 通过 TUI、print、desktop/web、VS Code、ACP 或 SDK 使用模型 Skill 调用的超长正文场景 按提醒中的 output_path 使用 Read 分页读取,或用 Grep 搜索

不超过限额的 Skill 保持完整内联;用户斜杠激活路径、工具返回形状、wire/API 契约和配置默认值均未修改。

  • skillTool.ts:接入现有截断服务并传递真实 toolCallId,嵌套调用复用同一路径。
  • skill.test.ts:验证超长正文的有界提醒、头尾预览、参数展开、完整内容保存,以及短 Skill 不截断。
  • skill-tool-manager.test.ts:验证嵌套变体调用适配后的共享执行路径。
验证记录
  • 远程 vitest run packages/agent-core-v2/test/features/skill/skill.test.ts packages/agent-core-v2/test/features/skill/catalog/skill-tool-manager.test.ts:2 个文件、27 个用例全部通过。
  • 远程 @moonshot-ai/agent-core-v2 typecheck:通过。
  • 远程针对本次 3 个 TypeScript 文件的 oxlint --type-aware:0 warning、0 error。
  • lint:imports 报告 4 个既有违规,位于 fullCompactionService.ts、completionRestore.ts、taskOutput.ts 和 origin.ts;这些文件均不在本 PR diff 中,新增导入未触发违规。
  • PR CI 初次运行时 test (2) 的 SDK undo 并发用例失败;该文件在当前分支远程单跑 18/18 通过。按用户要求重跑后,test (2) 通过(3m15s),PR 全部检查通过(test-windows 按既有条件跳过)。
  • 没有 UI 变化,因此无截图或录屏。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (N/A for this internal PR from a direct bug report).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 242ef0f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T10:19:42.845944Z 242ef0f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@242ef0f
npx https://pkg.pr.new/@moonshot-ai/kimi-code@242ef0f

commit: 242ef0f

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 242ef0fd81

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +132 to +136
const truncated = await truncation.truncateForModel({
toolName: 'Skill',
toolCallId,
result: { output: skillContent },
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Truncate the fully rendered skill reminder

When the rendered skill content is just below 50,000 characters, or when args is large, this check does not bound the actual reminder sent to the model: renderModelToolSkillPrompt subsequently adds the prefix, XML wrapper, and a second untruncated copy of skillArgs in the args attribute. Since SkillToolInputSchema places no length limit on args, a large argument can still produce an arbitrarily large <skill-loaded> message and trigger the context-overflow behavior this change is meant to prevent. Apply truncation to the completed reminder (while preserving an appropriate full representation in the spill file) rather than only to skillContent.

Useful? React with 👍 / 👎.

skillName: skill.name,
skillArgs,
skillContent,
skillContent: truncated.output,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep oversized skills usable without Read or Grep

For an agent profile or tool-policy configuration that enables Skill but disables Read and Grep, replacing the body with truncated.output makes the omitted instructions inaccessible: the spill notice only offers those tools, while tool activation policy filters each tool independently and does not require either recovery tool whenever Skill is active. Such configurations previously delivered the complete skill body, so an oversized skill can now run with only its head/tail preview and miss required instructions. Preserve an accessible recovery mechanism for these profiles or avoid externalizing content when no spill reader is available.

AGENTS.md reference: AGENTS.md:L112-L112

Useful? React with 👍 / 👎.

approvalRule: this.name,
matchesRule: (ruleArgs) => matchesGlobRuleSubject(ruleArgs, args.skill),
execute: () => executeModelSkill(
execute: (executionContext) => executeModelSkill(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop activation when truncation is aborted

When a user cancels an oversized Skill call while truncateForModel is awaiting its spill-file write, the executor aborts executionContext.signal and can abandon the tool response, but this callback retains only toolCallId and never checks that signal. The underlying execution therefore continues to recordModelToolActivation and loop.remind, causing instructions from a visibly aborted tool call to be injected into a later model context. Pass or recheck the execution signal after the newly introduced asynchronous truncation step before recording the activation.

Useful? React with 👍 / 👎.

@sailist
sailist changed the base branch from main to release/2026-11-12 November 11, 2026 10:41
@sailist
sailist merged commit bd62933 into release/2026-11-12 Nov 11, 2026
31 of 32 checks passed
@sailist
sailist deleted the bug-351-11-11-skill-tool-output-truncation branch November 11, 2026 10:46
@github-actions github-actions Bot mentioned this pull request Nov 11, 2026
Grapedge added a commit that referenced this pull request Nov 12, 2026
* fix(agent-core-v2): truncate oversized skill content (#4834)

* fix(kap-server): bind the main agent when a session is created (#4839)

* fix(kap-server): bind the main agent when a session is created

* fix(kap-server): reject a profile on prompt submissions

* fix(kap-server): reject a profile change through the session profile

* fix(kap-server): wait for model configuration before binding a new session

* fix(agent-core-v2): deduplicate restored task notifications (#4836)

* fix(agent-core-v2): deduplicate restored task notifications

* chore: add notification replay fix changeset

* fix(agent-core-v2): preserve task notifications after prompt-only crashes

* fix(agent-core-v2): complete prompts before ending turns

* test: align lifecycle snapshots with prompt completion order

* fix(agent-core-v2): settle all prompts during turn finalization

* fix(kap-server): drop reserved metadata keys from session profile updates (#4842)

* fix(kap-server): drop reserved metadata keys from session profile updates

* fix(kap-server): keep stored reserved metadata keys on profile updates

* docs: split and rewrite the server API reference (#4841)

* docs: split and rewrite the server API reference

* docs: redirect old server API anchors to the split pages

* docs: describe profile metadata as a replacement

* docs: mark question responses as answered-only

* fix(kap-server): avoid heartbeat timeout after scheduling stalls (#4823)

* fix(kap-server): avoid heartbeat timeout reaping after stalls or clock jumps

* fix(kap-server): grace heartbeat window for short scheduling stalls

* fix(kap-server): treat only clearly late heartbeats as scheduling stalls

* fix(kap-server): time heartbeats on a monotonic clock and drain queued input before reaping

---------

Co-authored-by: Kimi Code (Grok Bot) <[email protected]>

* fix(kap-server): undo a turn only once when requests race (#4846)

* docs: describe heartbeat stall handling (#4849)

* docs: describe heartbeat stall handling

* docs: explain the monotonic clock in the heartbeat notes

* fix(agent-core-v2): acquire session lock before loop restoration (#4848)

* fix(agent-core-v2): acquire session lock before loop restoration

* chore: add session lock lifecycle changeset

* fix(agent-core-v2): hold session lock through loop restoration

- add an operation-scoped lease to the session run gate
- hold it across loop initialization, reset, and pending drains
- cover idle timeout and release ordering

* fix(agent-core-v2): keep the output of stopped tool calls (#4854)

* fix(kap-server): drop the partial reply of a retried step (#4855)

* fix(agent-core-v2): dedupe historical tool schemas (#4862)

* fix(agent-core-v2): dedupe historical tool schemas

* chore: add duplicate tool schema changeset

* fix(agent-core-v2): preserve first tool schema declaration

* fix(agent-core-v2): remind on changed tool schemas

* fix(agent-core-v2): block stale tool schema calls

* fix(agent-core-v2): normalize registry schemas in pending checks

* fix(agent-core-v2): import registry tool metadata type

* fix(agent-core-v2): preserve abort handling during validation

* fix(agent-core-v2): refine validation hook preparation

* fix(agent-core-v2): make validation hooks synchronous

* fix(agent-core-v2): preserve tool result notes on fork (#4867)

* fix(agent-core-v2): preserve tool result notes on fork

* chore: add fork tool result note changeset

* fix(agent-core-v2): scope tool result note restoration to forks

* fix(agent-core-v2): normalize inherited tool result notes

* fix(agent-core-v2): isolate fork note restoration

* feat(tui): sweep running titles toward text and add KIMI_CODE_TUI_ANIMATION_FPS (#4843) (#4870)

* chore: sync web dist from code-app (#4871)

code-app: 8ab17294e031323186d357d121c5360b8353900e

Co-authored-by: kimi-agent-bot <[email protected]>

* ci: release packages (#4835)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: sync web dist from code-app

code-app: 5835391dac3a2b9e0c65ffbd418f0d6042a7adb2

---------

Co-authored-by: Haozhe <[email protected]>
Co-authored-by: qer <[email protected]>
Co-authored-by: Kimi Code (Grok Bot) <[email protected]>
Co-authored-by: grapedge <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants