Skip to content

fix(delegation): keep the prompt prefix stable across settlements - #1903

Merged
vastsa merged 2 commits into
mainfrom
fix/stable-delegation-prompt
Oct 26, 2026
Merged

vastsa merged 2 commits into
mainfrom
fix/stable-delegation-prompt

Conversation

@vastsa

@vastsa vastsa commented Oct 26, 2026

Copy link
Copy Markdown
Owner

问题

父代理的系统提示里带着「可 resume 子代理」清单,而且每次委托结算都会重组提示。对于不支持 mid-conversation system message 的 provider(supportsMidConvoSystemMessages 为 false,绝大多数),pi-ai 的 collapseSystemMessages 会把所有 system 消息折叠进第一条,于是每次结算都会改写请求头部 —— 不是只丢尾部,而是整个 prompt cache 前缀失效。

复现路径见 ADR 0337 的 Context 段:syncSystemSections 追加新 system 消息 → 折叠 → 首条 system 变化。

改动

  • composeSystemPrompt 不再组装可 resume 段;删除 refreshResumablePrompt / applyPendingResumablePrompt / resumablePromptStale 及其 5 个调用点(settle、promptTurn、plan turn、两处 recovery cleanup)。
  • TaskList 承担发现职责:文本附带清单,details.resumable 给出结构化数据(agent / delegationId / objective / files / omitted)。
  • resume 失败时的工具错误仍内联可复用 id,发现不依赖先调用 TaskList。
  • DelegationChainRegistry.promptBlock → resumableBlock(语义不变,位置变了)。

文档

  • 新增 ADR 0337,记录权衡与替代方案,并注明 TOOL_ACTIVATION 与 budget reminder 是另外两条独立的前缀抖动线,不在本次范围。
  • ADR 0279 §9 改为 TaskList 发现。
  • docs/spec/03-runtime/02-agent-runtime.md 与 zh-CN 镜像同步。

验证

  • packages/agent-runtime:tsc --noEmit 通过;vitest run 106 文件 / 1466 用例全部通过。
  • 新增断言:结算后 composedSystemPrompt 与 live system prompt 字节不变;可 resume 项出现在 TaskList 的文本和 details.resumable 中;运行中的委托不进入 resumable 列表。
  • apps/desktop:subagent-transcript + transcript-summary 28 用例通过(其余桌面测试需要 out/ 构建产物,未跑)。
  • node scripts/check-agent-policy-sync.mjs、node scripts/check-pr-base-main.mjs 通过。

影响

  • 父模型不再被动看到可 resume 列表,需要主动调用 TaskList(它本来就有这个工具);未命中时错误信息仍给出 id。
  • 本 PR 只修这一条缓存抖动线,工具激活段与 budget reminder 留作后续独立工作。

The parent's system prompt carried the resumable-delegation list, and the
runtime recomposed that prompt every time a delegation settled. Transports
without mid-conversation system messages replay every system message into the
first one, so each settlement rewrote the head of the request and invalidated
the whole provider prompt cache instead of only its tail.

Move discovery to TaskList: its result now reports the resumable chains as both
text and details.resumable, while a failed resume still names the reusable ids
in its own tool error. Instructions no longer change for reasons the user did
not cause, so a long session that spawns many delegates keeps one cache
lineage.

ADR 0337 records the trade-off and supersedes ADR 0279 section 9; the runtime
spec, its zh-CN mirror, and the delegation tests follow the new read path.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 12:43

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

The docs check requires every ADR file to appear in the ADR index, so the new
record needs its row before the branch can land.
@vastsa
vastsa merged commit 3e4bbe1 into main Oct 26, 2026
9 of 10 checks passed

vastsa commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

已独立核实结算时重组 system prompt 的路径。两条新增结算/发现测试在主线旧实现上失败,候选版本通过;相关 runtime/委托测试 404 项通过,Desktop 委托展示测试 28 项通过。真实 runtime + 本地 SSE provider 的隔离 E2E 也通过 error、abort、stop、direct 四种场景,并验证错误后的可恢复委托继续可 resume。没有调用付费服务。当前主线已普通合并到贡献者分支,候选与更新后的 PR tree 一致;这次仅把动态清单移入 TaskList,保留 resume/error/cancellation 语义,准备合入。按维护者要求不以 CI 状态阻塞。

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