Repository navigation
fix(acp): stream background task turns to editors - #5447
Conversation
🦋 Changeset detectedLatest commit: f24fff3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b781a2c83
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }); | ||
| }); | ||
|
|
||
| test('streams a background task notification between editor prompts', { timeout: 30_000 }, async ({ model, testHome }) => { |
There was a problem hiding this comment.
Add the required ACP editor-surface regression
This fixes editor-visible behavior, but the new regression only inspects raw RPC notifications through TestClient; it does not exercise the SDK-validated ACP editor surface. Root AGENTS.md explicitly requires regressions for behavior visible in ACP editors to use tests/e2e. Searching that tree found no scenario covering background-task replies arriving after session/prompt completes. Add a persistent ACP surface scenario that observes the unsolicited reply and completed tool call, then verifies that a subsequent prompt still works; the package-level test can remain as additional coverage.
AGENTS.md reference: AGENTS.md:L61-L61
Useful? React with 👍 / 👎.
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Requirement or Bug
报告 033 中,ACP 编辑器收到「已在后台开始」后,后台子 agent 完成时的回复和工具调用没有出现在对话里。编辑器此时提交新消息,还可能立即收到
end_turn,而消息实际进入了引擎队列。Bug Reproduction Steps
end_turn,再让子 agent 完成。主 agent 会收到任务完成通知,并生成下一条回复。session/update。修复前只能找到第一条回复。在通知回合运行时另发一条消息,可以同时观察到过早的end_turn。Root Cause
ACP 用当前
session/prompt的回合 ID 筛选事件。通知回合由引擎发起,没有对应的 ACP 请求,因此回复、思考和工具事件都被过滤。与此同时,引擎提交入口默认允许排队,但 ACP 在提交结果没有立即提供回合 ID 时,会把原请求当作结束。Code Changes
ACP 按引擎已有的任务来源和回合 ID 识别后台通知,共用原来的
session/update事件转换。通知回合结束时刷新上下文用量。普通请求仍按自己的回合 ID 结算。flowchart LR A[引擎回合事件] --> B{回合从何处发起} B -->|编辑器提示词| C[转发会话更新并结算对应请求] B -->|后台任务通知| D[转发会话更新并刷新上下文用量] E[IDE 提交新消息] --> F{引擎能立即接收} F -->|是| C F -->|否| G[返回已有的忙错误]turn.started时记录回合 ID。回复、思考和工具更新都走原有转换,工具审批仍由原有的交互桥处理。后台回合运行期间,未分配回合 ID 的编辑器请求会等到有明确目标后再取消。rejectIfBusy。ACP 普通提示词使用这个选项。引擎在接收消息前判断是否需要排队,拒绝的请求没有队列或会话元数据写入。Klient 的 memory 和 IPC 都保留忙原因,ACP 继续返回-32600和data.code: turn.agent_busy。Behavior Changes and Affected Users
session/update发送回复、思考、工具状态和上下文用量end_turn,消息实际排队turn.agent_busy,被拒绝的消息不会进入会话rejectIfBusy的调用方会在接收前收到忙错误ACP 仍使用 v1 的更新和错误结构,历史回放走现有入口。回归测试从 ACP RPC 和引擎提交入口分别核对通知、工具状态、忙错误、后续回复和默认排队。
Verification
在 macOS 上先用
main的 CLI 构建复现。最终构建通过 300 轮真实 ACP 子进程压测、4 个 Playwright 用例和 321 项相关 Vitest 测试。三个受影响库的类型检查、pnpm lint、重复代码检查和中英文文档构建通过。本地压测明细
kimi acp子进程,每个会话连续跑 5 轮。分别模拟具备文件读取能力的编辑器和不声明该能力的编辑器,并对本地模型流随机切分字节。turn.agent_busy,后台回合继续完成。另有 100 轮将后台回合的写入审批与工具 ID 对上,并核对写入文件的内容。P1 补入持久的 ACP 编辑器场景。先等前台回合的用量更新,再释放后台任务。后台更新到达后,复用 ACP SDK 驱动断言新旧回复各出现一次、
Read已完成,以及下一条提示词收到自己的回复。用 PR 基线3d58fad4e的 CLI 运行时,两种 ACP 配置均因缺少后台更新而失败。修复版通过 8 项 Playwright 场景与自测,新增场景另重复 24 轮全部通过。E2E 类型检查、pnpm lint和重复代码检查通过。Checklist