Skip to content

fix(agent-core-v2): preserve raw bytes in task output tails - #4886

Merged
sailist merged 2 commits into
MoonshotAI:mainfrom
pvzheroes125:fix/background-task-output-tail-utf8
Nov 13, 2026
Merged

sailist merged 2 commits into
MoonshotAI:mainfrom
pvzheroes125:fix/background-task-output-tail-utf8

Conversation

@pvzheroes125

Copy link
Copy Markdown
Contributor

Requirement or Bug

订阅后台 Bash 输出时,首屏读取日志末尾的一段字节。窗口从多字节字符中间开始时,首屏可能出现乱码,后续输出去重使用的字节偏移也可能算错。

Bug Reproduction Steps

  1. 让后台 Bash 输出 background-ready💡\n 并保持任务运行。
  2. 通过 WebSocket task.watch 订阅该任务,设置 tail_bytes: 3。
  3. 修复前首段从偏移 18 返回 ��\n。修复后首段从偏移 20 返回一个换行符。

Root Cause

主日志路径按字节截取后先解码成字符串,再转回 Buffer。残缺 UTF-8 字节已被替换成 �,原始 3 字节膨胀成 7 字节。WebSocket 层因此无法按原字节对齐窗口。

Code Changes

刷新待写输出后,在同一文件句柄上获取大小并按范围读取原始字节。继续由 WebSocket 层跳过窗口开头残缺的 UTF-8 字节。主日志优先,主日志不存在时沿用旧目录的读取路径。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
后台任务订阅的首段截在 UTF-8 字符中间 返回替代字符,首段结束偏移可能超出实际文件位置 跳过残缺字节,首段和后续输出使用正确字节偏移 使用 WebSocket 查看后台 Bash 实时输出的用户 无需配置

验证覆盖了持久化层的原始字节和偏移、WebSocket 输出、真实 Bash 进程的 3 字节窗口。未运行 Windows 全量验证。

验证详情
  • Core 任务相关测试 239 项通过。
  • KAP 定向测试 25 项通过,包含真实 Bash 输出订阅。
  • agent-core-v2 类型检查和改动文件 lint 通过。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue.
  • I have added tests that prove the fix works.
  • The behavior-change table above is complete.
  • Ran gen-changesets and included the patch release note.
  • This PR needs no documentation update.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-12T17:49:02.105454Z ed76490 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 12, 2026

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

commit: ed76490

@sailist
sailist merged commit 1fc7be4 into MoonshotAI:main Nov 13, 2026
28 of 29 checks passed
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 15, 2026
Port MoonshotAI#4844: CronCreate/CronDelete and MCP authenticate calls never fold,
the authorization link stays visible (and click-inert) while the call is
running, the reason stays visible after a failure, and compact density
unfolds to rows instead of cards.

Disable the external-subagent deadline when subagent.timeoutMs is 0
(MoonshotAI#4868). The in-process path already guards on a positive timeout inside
the task service, so only executionBackend armed an immediate deadline.

Record MoonshotAI#4886 as equivalent: task output tails are already read as raw
bytes from the byte store, so the UTF-8 split that upstream fixed cannot
occur here.
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