fix(subagents): busy 期间完成的结果也会自动唤醒父 Agent - #48
Merged
Conversation
Results that settled while the parent was busy were deliberately flushed as nextTurn at agent_settled. Pi only consumes that queue on another user prompt, so fire-and-forget results could not fulfill their documented automatic re-invocation contract. Flush the pending batch as one follow-up at the authoritative parent boundary, while preserving wait consumption, exactly-once delivery, synchronous retry, and aborted-turn suppression. Closes #47
Merged
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.
Closes #47
根因
这不是 Windows 专属问题,也不是
agent_settled事件偶发丢失,而是旧投递策略在下列时序里确定不会唤醒:Pi core 在
agent_settled前先把_isAgentRunActive置为false;但 OpenPI 没有在这个权威 idle 边界重新选择 wake,而是主动把整批结果降级成nextTurn。这与 README 和subagent_spawn工具说明中的「完成后自动回传并重新唤醒主 Agent」契约冲突。Windows 审计确认:OpenPI 子代理是同一 Node 进程内的 Pi Session,这条链路没有
process.platform分支、外部子进程或 session 文件 watcher。Windows 只可能改变任务耗时,让该时序更常出现。修复:双边无丢唤醒协议,不加 sleep
新增小型
createSubagentResultDelivery协调器:followUp + triggerTurn;agent_settled→ 把 pending 结果合成一条 follow-up 并唤醒;subagent_wait在 flush 前仍可consume,不会重复投递;Map drain 是 one-shot gate;所有未被显式
subagent_wait消费的后台结果都遵循同一合同:在父 Agent 的 idle 边界使用followUp + triggerTurn自动回传。用户中止不会把结果降级为nextTurn,否则会重新引入「必须再发一条消息才收到结果」的问题。可见报告仍由 session entry 在真实完成位置显示;注入模型的 message 保持
display:false,不会重复出现。测试
纯状态机和 wiring 测试覆盖:
subagent_waitconsume 后不投递;followUp + triggerTurn。验证:
bun run test:745 node tests + 29 vitest 全绿bun run check:退出 0(仅有file-search/binaries.ts既存 Effect warnings)