Repository navigation
fix(agent-core-v2): truncate oversized skill content - #4834
Conversation
🦋 Changeset detectedLatest commit: 242ef0f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 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".
| const truncated = await truncation.truncateForModel({ | ||
| toolName: 'Skill', | ||
| toolCallId, | ||
| result: { output: skillContent }, | ||
| }); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 👍 / 👎.
* 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>
Requirement or Bug
通过
Skill工具加载超长 Skill 时,完整正文会进入后续模型上下文,没有长度上限。这个 PR 让模型调用及嵌套调用的超长 Skill 复用现有工具结果截断机制,同时保留可分页读取的完整渲染内容。Bug Reproduction Steps
Skill工具调用它。<skill-loaded>提醒。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
<skill-loaded>提醒output_path,完整渲染内容保存到工具结果文件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:通过。oxlint --type-aware:0 warning、0 error。lint:imports报告 4 个既有违规,位于fullCompactionService.ts、completionRestore.ts、taskOutput.ts和origin.ts;这些文件均不在本 PR diff 中,新增导入未触发违规。test (2)的 SDK undo 并发用例失败;该文件在当前分支远程单跑 18/18 通过。按用户要求重跑后,test (2)通过(3m15s),PR 全部检查通过(test-windows按既有条件跳过)。Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.