Skip to content

feat(agent-runtime): carry the session checklist across compaction - #1275

Open
hxj04121-lab wants to merge 1 commit into
vastsa:mainfrom
hxj04121-lab:feat/todo-compaction-snapshot
Open

hxj04121-lab wants to merge 1 commit into
vastsa:mainfrom
hxj04121-lab:feat/todo-compaction-snapshot

Conversation

@hxj04121-lab

@hxj04121-lab hxj04121-lab commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

问题与修复

#1177 阶段 5 的必需项,加上阶段 4 的续跑提醒。实现方向按 issue 里的讨论(评论,@HanawaBanana 也倾向这个方案):清单快照写入压缩检查点,不在每轮请求里临时注入。

压缩会把维护清单的 TodoWrite 调用一起摘要掉,压缩后模型不知道哪些步骤已经做完,容易重新建一张清单。现在运行时安装检查点时:

  • 经 sidecar 代理调用一次 todos.get(只读本会话),仅当存在待办或进行中条目时,把 { revision, updatedAt, todos } 写入检查点的 details.todoSnapshot。
  • 生成模型上下文时,在压缩摘要之后渲染一段 <session_checklist revision="…">,说明“这是压缩时的清单,之后的 TodoWrite 以新的为准,每次调用仍需重发全部条目”。
  • 存储的 summary 不变:转录里的压缩行不会出现清单,下一次压缩把 previousSummary 往前带时也不会带上过期清单;每次压缩重新读取一次。
  • 快照随检查点持久化,重启后从检查点重建的上下文仍含清单;只在压缩时写一次,位于压缩后的前缀内,对前缀缓存友好。

权威源仍然只有 host 那张表,渲染器不读这份副本。降级行为:

  • todos.get 失败(旧 host、native Pi 会话、代理拒绝)→ 照常安装不带快照的检查点;
  • 清单为空或已全部完成/取消 → 不写快照;
  • 带上快照会让原本能装下的检查点超出安全预算 → 丢掉快照,而不是触发 fallback。

sidecar 白名单:HOST_PROXY_ALLOWED 只新增只读的 todos.get(与 session.get 同级),清单写入仍只能走 host 授权的 TodoWrite。

续跑提醒(阶段 4):Goal/Plan 批准后的执行指令加一句:多步执行用会话清单跟踪,TodoWrite 是延迟工具需先经 ToolSearch 激活,结束前每项都要完成或取消。

ADR 0312 增加 2026-10-01 修订;host RPC 协议规格与 E2E 场景 E2E-CHAT-session-todo-checklist(中英文)同步。

停滞提醒(阶段 5 可选项)不在本 PR 范围内。

验证

  • 任务候选:1e7430be8157;基线 main:3b036cc7810e;环境:macOS arm64,Node 23.11.0。
  • 2026-10-04 rebase 到最新 main(含 Pi 1.0 迁移):persistCheckpoint 保留上游新增的 details.systemMessageJson,再在其后计算预算并附加清单快照;session-context.ts 保留系统消息投影,并在其后渲染清单。rebase 后 agent-runtime 1247 项中 1244 项通过,3 项在高负载(load 14)下超时,单独重跑全部通过(4 个文件 84 项);host-runtime 121 项、lint、typecheck、check:pr-base 通过。
  • pnpm build:js、agent-runtime / host-runtime typecheck、pnpm lint、pnpm docs:check、git diff --check、以基线为准的 pnpm check:pr-base:通过。
  • agent-runtime 全量:82 个文件 1165 项通过。新增:
    • runtime.test.ts「session checklist ([Feature] 会话级任务清单(Todo):让多步任务的进度可见,一起来讨论方案 #1177)」5 项:检查点写入快照且摘要不变、模型上下文中快照位于摘要之后;todos.get 失败时压缩仍成功;已完成清单不写快照;快照超预算时丢弃且不触发 fallback;从持久化检查点恢复后上下文仍含清单。
    • runtime.test.ts 续跑提醒 2 项(plan / goal)。
    • checkpoint-todos.test.ts 7 项:解析容错、未完成过滤、格式、条目文本不能提前闭合 </session_checklist>、session-context 投影。
    • 一项既有测试改为按方法名查找 session.appendCompaction 调用(之前假设它是第一个 host 调用)。
  • host-runtime 全量:17 个文件 121 项通过;新增 sidecar-todo-proxy.test.ts 2 项(真实 stdio 反向 RPC:todos.get 放行,todos.set 仍以 -32601 拒绝)。
  • desktop node --test test/*.test.mjs:3346 项中 3337 通过,2 失败、7 取消,均与本改动无关且在 main 上同样存在:chat-error-message.test.mjs:53(test 嵌套在另一个 test 回调内被取消)、imported-package-skills-runtime.test.mjs:221(Node 23 错误文案与断言不同)、plugin-websocket.test.mjs 7 项取消(本机沙箱限制回环 socket)。
  • node scripts/check-architecture.mjs:报告的 6 条违规均为 main 上已有文件(live-voice、pt-BR 等),不涉及本 PR 文件。
  • E2E:NOT RUN。 相关套件 pnpm test:e2e:todos;本机主 checkout 与 worktree 均没有 Electron 二进制,未为此额外下载。替代验证为上面的 runtime 压缩路径测试和 sidecar 真实 stdio 代理测试;剩余风险是未在 Electron 中实跑“压缩 → 下一次请求带清单”的完整链路。

Refs #1177

Compaction summarizes the TodoWrite calls that kept the session checklist
current, so after a checkpoint the model no longer knew which steps were
done and could rebuild a second list (vastsa#1177, stage 5).

When the runtime installs a checkpoint it now reads todos.get for its own
session once and stores { revision, updatedAt, todos } in the
checkpoint's opaque details, only while unfinished items remain. The
context projection renders that copy after the checkpoint summary. The
stored summary is unchanged, so a later compaction never carries a stale
list forward and the transcript row does not show it. Because the copy
is persisted with the checkpoint it survives restart and is written once
per checkpoint instead of being injected on every request.

The host table stays the only authority. A failed read, an older host, a
native Pi session or a finished list installs the checkpoint without a
copy, and the copy is dropped rather than pushing a fitting checkpoint
over the safe budget. todos.get joins the sidecar proxy allowlist as a
read-only method; writes still go through host-authorized TodoWrite.

Approved Plan and Goal execution instructions now ask the model to keep
the checklist current (stage 4 continuation reminder).

Refs vastsa#1177
@hxj04121-lab
hxj04121-lab force-pushed the feat/todo-compaction-snapshot branch from 0246692 to 1e7430b Compare October 3, 2026 16:34

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant