Repository navigation
fix(delegation): keep the prompt prefix stable across settlements - #1903
Merged
Merged
Conversation
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.
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.
Owner
Author
|
已独立核实结算时重组 system prompt 的路径。两条新增结算/发现测试在主线旧实现上失败,候选版本通过;相关 runtime/委托测试 404 项通过,Desktop 委托展示测试 28 项通过。真实 runtime + 本地 SSE provider 的隔离 E2E 也通过 error、abort、stop、direct 四种场景,并验证错误后的可恢复委托继续可 resume。没有调用付费服务。当前主线已普通合并到贡献者分支,候选与更新后的 PR tree 一致;这次仅把动态清单移入 TaskList,保留 resume/error/cancellation 语义,准备合入。按维护者要求不以 CI 状态阻塞。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
父代理的系统提示里带着「可 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(语义不变,位置变了)。文档
TOOL_ACTIVATION与 budget reminder 是另外两条独立的前缀抖动线,不在本次范围。docs/spec/03-runtime/02-agent-runtime.md与 zh-CN 镜像同步。验证
packages/agent-runtime:tsc --noEmit通过;vitest run106 文件 / 1466 用例全部通过。composedSystemPrompt与 live system prompt 字节不变;可 resume 项出现在TaskList的文本和details.resumable中;运行中的委托不进入 resumable 列表。apps/desktop:subagent-transcript+transcript-summary28 用例通过(其余桌面测试需要out/构建产物,未跑)。node scripts/check-agent-policy-sync.mjs、node scripts/check-pr-base-main.mjs通过。影响
TaskList(它本来就有这个工具);未命中时错误信息仍给出 id。