fix(adapter): dedupe local-only command result output - #949
Open
ran411285752 wants to merge 3 commits into
Open
Conversation
【BUG修复】:: 修复 /context 等本地命令完整文本被 ACP 客户端重复接收的问题。 【问题原因】:: Claude SDK 会从 local_command_output 与终态 result 提供相同文本,Adapter 丢失来源后将两者均映射为 agent_message_chunk。 【解决方案】:: 按 turn 记录已转发的本地命令原始文本,仅抑制终态 result 的完全相同副本,并覆盖 held turn、orphan lane 与跨 turn 边界。 【代码自测】:: 定向 Vitest 32 项通过;npm run build、npm run lint、定向 Prettier 与 git diff --cached --check 通过;全量 684 通过、6 个既有 Windows 路径断言失败。 【测试建议】:: 验证 /context 双来源相同文本只显示一次,并回归 result-only、不同文本、连续 turn、held turn 与 orphan 结果场景。 Refs: agentclientprotocol#948
【BUG修复】:: 修正真实 /context 链路仍重复输出的问题,并阻止去重证据跨自主、取消或无 result cycle 泄漏。 【问题原因】:: 当前 SDK 实际发送 consolidated assistant 后再发送多两个尾随换行的 result;初版仅按 local_command_output 完全匹配,未覆盖真实事件形态。 【解决方案】:: 规范化尾随换行,分别维护 turn 级明确来源与 cycle 级 assistant 候选,并在 result 或非 owed idle 收口时清理;补充 held、autonomous、cancel 边界测试。 【代码自测】:: 真实 OAuth ACP /context E2E 仅收到 1 个 2268 字符块;定向 36 项、build、lint、Prettier 通过;全量 687 通过,6 个既有 Windows 路径断言失败。 【测试建议】:: 复验真实 /context 单次展示,并回归不同正文、result-only、连续 turn、held autonomous followup、取消无 result 与 lagged idle。 Refs: agentclientprotocol#948
# Conflicts: # src/acp-agent.ts
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.
Summary
assistantthen terminalresult) and thelocal_command_outputcompatibility path.Root cause
A live Claude OAuth / Agent SDK 0.3.220 trace showed that
/contextcurrently emits:The payloads are identical after removing the result's two trailing line feeds. The adapter forwarded the consolidated assistant text and then unconditionally forwarded the terminal result because the turn was classified as a local-only command.
The issue report described the first source as
system/local_command_output; this PR retains coverage for that SDK shape, while also fixing the current observedassistant -> resultsequence.Implementation
local_command_outputevidence on itsTurn.Validation
Live end-to-end verification
Ran the built adapter as an ACP subprocess using the real local Claude OAuth login, created a real ACP session, and sent
/contextthroughsession/prompt.Before the final fix:
After the fix:
Automated verification
npm run build: passed.npm run lint: passed.npx prettier --check src/acp-agent.ts src/tests/acp-agent.test.ts: passed.npm run test:run: 687 passed, 20 skipped, and the same 6 pre-existing Windows path-separator assertion failures (src/main.tsvssrc\main.ts); no new failures.Fixes #948