MoonshotAI / MoonshotAI/kimi-code

后台 agent 被标 lost 后经 resume 续跑不补记 task.started,基于 wire.jsonl 的外部工具漏计运行中任务

Open
#3,350 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

你运行的 Kimi Code 版本是?

0.39.0

你使用的是哪个开放平台/订阅?

Kimi Code coding plan

你使用的是哪个模型?

K3

你的电脑平台是?

Darwin 25.5.0 arm64 arm

你遇到了什么问题?

后台 agent 在 CLI 进程重启时被标记为 lost:agents/main/wire.jsonl 写入 task.terminated, status=lost,主循环收到 task.lost 通知(通知中建议 Agent(resume="<agentId>") 恢复)。

按通知 resume 后,agent 在新进程中正常续跑直至完成,并最终正常写入 task.terminated(completed)但 resume 路径不补写新的 task.started:从被标 lost 到最终完成的整个续跑窗口内,wire.jsonl 中该 taskId 的最新记录始终是 lost(终态)。

影响:任何通过重放 wire.jsonltask.started/task.terminated 记录、或读取 agents/main/tasks/<task_id>.json 任务持久化文件来统计"运行中任务数"的外部工具(如自定义 status line 命令),在整个 resume 续跑窗口内会把该任务计为 0——运行中任务计数恰好在任务真实运行时归零

内置 status line 的 tasks 项不受影响:它读进程内内存中的任务注册表,resume 后任务在内存中处于 running。

该任务持久化文件也无法弥补:续跑期间它尚无 endedAt,外部工具只能取 startedAt 作为最后更新时间,它比 lost 记录的时间旧,按"较新者为准"合并仍判 lost。即外部工具从现有落盘数据中原则上无法区分"lost 后被 resume 续跑"与"lost 后终止"。

实际发生在 tower 模式的 reviewer agent 上,但机制与 tower 无关,任何后台 agent 均可触发。

复现步骤?
  1. 启动一个 run_in_background=true 的 Agent 任务。
  2. 在 agent 运行期间退出并重启 CLI 进程,恢复原会话。
  3. 观察 wire 写入 task.terminated status=lost,主循环收到 task.lost 通知。
  4. 按通知执行 Agent(resume="<agentId>", run_in_background=true)
  5. 在 resume 续跑期间检查 agents/main/wire.jsonl:该 taskId 没有新的 task.started 行;最新状态保持 lost,直到 task.terminated(completed)
期望的行为是什么?

resume 一个后台 agent 时,向 wire.jsonl 补写一条 task.started 记录(同 taskId、新的时间戳;或新增 task.resumed 事件类型),并将 agents/main/tasks/<task_id>.json 的状态/startedAt 刷新为续跑起点,使落盘记录与进程内存实况一致。

补充信息

真实会话 wire 摘录(~/.kimi-code/sessions/<workspace>/<session>/agents/main/wire.jsonl):

15:50:50  task.started      agent-n3fz98a9  status=running    # tower reviewer (agentId agent-39)
15:55:02  task.terminated   agent-n3fz98a9  status=lost       # 进程重启后被标记
16:13:47  task.terminated   agent-n3fz98a9  status=completed  # resume 后续跑完成

15:55:02–16:13:47 之间无该 taskId 的任何 task.started 行;同窗口内置 status line 正确显示 1 个 agent 运行中。

同刻另一例(agentId agent-38 / taskId agent-8dr1yojq):15:50:07 started → 15:55:02 lost → 15:59:46 completed,同样无补记。

任务持久化文件 agents/main/tasks/agent-n3fz98a9.json

{
  "taskId": "agent-n3fz98a9",
  "status": "completed",
  "detached": true,
  "startedAt": 1787903450000,
  "endedAt": 1787904827571,
  "agentId": "agent-39",
  "subagentType": "tower-worker"
}

另附一处文档勘误(可选):data-locations 文档将会话任务持久化描述为会话根下的 tasks/<task_id>.json,实际布局是 agents/main/tasks/<task_id>.json

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the resume flow and tracing how agents/main/wire.jsonl and agents/main/tasks/<task_id>.json are written when a lost background agent resumes. Check the task.started, task.terminated, and resume handling paths, then verify that resumed tasks are represented as running until completion and that replayed records distinguish them from tasks that remain lost.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.