Skip to content

fix(claude): preserve multiline HERDR submissions and honor transport rejection - #1688

Merged
deepcoldy merged 10 commits into
deepcoldy:masterfrom
baicaicc:fix/claude-herdr-submit-upstream
Oct 21, 2026
Merged

deepcoldy merged 10 commits into
deepcoldy:masterfrom
baicaicc:fix/claude-herdr-submit-upstream

Conversation

@baicaicc

@baicaicc baicaicc commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Claude input can remain in the composer when multiline messages arrive during an active turn. The HERDR path currently types each line separately using backslash + Enter, and ignores false acceptance results from text/key transport. This can corrupt the draft or continue sending keys after a rejected operation, eventually reporting submit_unconfirmed.

This change adds an explicit bracketed-paste capability to HERDR and makes the Claude-family adapter prefer one raw paste frame. Other transports keep their existing input strategy. Text, newline, raw-write and submit-key rejection now stop additional input immediately, retaining the native JSONL late-receipt check to avoid blind replay.

Claude failure diagnosis also recognizes expanded BotMux drafts in the actual composer and avoids claiming that Enter was never pressed. Other CLI diagnosis remains unchanged.

Validation:

  • Full build and TypeScript checks pass on current upstream master with this patch.
  • 611 targeted adapter, HERDR and diagnosis tests pass (one existing skip).
  • Opt-in real Claude Code + HERDR regression: enqueue an exact Chinese multiline payload while Bash is running, require one native queue-operation receipt and the expected model response. Handles Claude's generated pasted_content wrapper without weakening byte-for-byte payload validation.
  • Deployed validation on two installations: native Claude Max / Haiku and API-routed Claude CLI both accepted the complete multiline payload exactly once; actual Lark first-message and follow-up flows passed. Existing CLI sessions were preserved.

Limit: the original intermittent last-Enter failure was not deterministically reproduced under light load. The patch removes the confirmed per-line input and unchecked transport-result defects; it does not claim to reconstruct the exact historical failure of the last key.

@deepcoldy

Copy link
Copy Markdown
Owner

你好,感谢这个修复!以下是自动评审的初步意见,仅供参考,最终以维护者审阅为准。

主体改动(HERDR 一帧 bracketed paste、五个投递点检查 false 立即停手、保留 JSONL 延迟回执)我们在真机上验证过:herdr 0.9.0 下用 od -c 确认 ESC marker 与字面换行当一条字节流到达、不拆命令;Claude 2.1.289 上空闲多行消息 729ms 精确回执(中文/反斜杠/原生 pasted_content 包装均正常),Bash 忙时恰好产生 1 条内容精确的 queue-operation enqueue;新增测试的变异验证也全部有牙。方向正确、无回归。

有一处诊断能力在当前真机版本上没兑现,建议补上再合(改动很小):

composer 草稿诊断漏掉了折叠 chip 形态(建议修复)

hasClaudeComposerDraft 要求两条横线之间的输入框首行 ❯ 且框内含展开的 <user_message> 原文。但在 Claude Code 2.1.289 上,botmux 经一帧 bracketed paste 贴入的多行消息在 Enter 真的丢失、草稿停在 composer 时,框内只渲染成折叠态:

────────────────────────
❯ [Pasted text #2 +3 lines]
  paste again to expand
────────────────────────

展开态(框内出现 <user_message> 原文)需要人工「再贴一次」才会出现,botmux 自身产生不了。实测此时 diagnoseSubmitFailure({ cliId: 'claude-code' }) 与旧的 [Pasted Content N chars] 规则双双不中,落 unknown;提交正常完成的屏幕则正确不误报(一正一反均用真机截屏验证)。

建议在 DRAFT_PARKED_RULES 增加折叠 chip 规则,例如:

{ id: 'draft_parked:pasted_text_chip', re: /\[\s*pasted text\s+#\d+(?:\s*\+\d+\s+lines?)?\s*\]/i },

该正则已用 2.1.289 真机截屏预验证:停放态命中、提交完成后的 transcript 屏不命中。建议同时补一个该真实形状的 fixture(两横线夹 ❯ [Pasted text #N +M lines],以及 cliId 非 claude-code / 引用文本的反例)。

非阻断的既有问题(建议另开 issue,不在本 PR 处理)

2.1.289 忙时入队的消息在当前 turn 结束会被原生「吸收」:jsonl 记录 queue-operation remove(reason: "absorbed_mid_turn")+ attachment: queued_command,不再开启新轮、模型不回复。旧逐行路径同形状,非本 PR 引入,但用户会静默丢回复,建议 worker 后续监听该 remove 做重投或告警。对应的,opt-in e2e 末尾等待 QUEUED_PONG 模型回复的断言在 2.1.289 上必然超时(skip 着 CI 无感),建议把稳定契约收窄为「恰好 1 条内容精确的 enqueue」,或加版本门。

小的测试补强(不阻断)

  • src/worker.ts 把 cliId 传入 diagnoseSubmitFailure 的接缝目前没有接线测试(删掉该行测试全绿),建议补一条 source-pin 断言。
  • e2e 中 expect(next?.submitted).not.toBe(false) 对 undefined(无 jsonl 路径的信任返回)也通过,断言偏弱。
  • seed / relay 同样复用 createClaudeFamilyAdapter 与同一 composer,新诊断分支目前只对 claude-code 开启,同门变体是否一并覆盖可以斟酌。

再次感谢,以上仅为评审意见,最终结论以维护者审阅为准。

deepcoldy and others added 6 commits October 21, 2026 01:04
# Conflicts:
#	src/adapters/cli/claude-code.ts
Claude Code 2.1.289 下,忙时一帧 bracketed paste 若最后 Enter 丢失,
composer 只渲染折叠 chip「[Pasted text #N +M lines]」,展开态
<user_message> 需要人工再贴一次才出现——botmux 只贴一帧,因此
原有的 composer 识别规则永远不命中,真·停放草稿落 unknown。

在双横线 composer 框(首行 ❯)内补折叠 chip 识别,仍只限
claude-code,转录区引用与空输入框不误报;两种形状给独立 matched id。

把 worker 发卡前「zmx 不读屏 + 透传 cliId/活跃度 → 纯分类」的决策
抽成 diagnoseBackendSubmitFailure 纯函数并补接线测试(含 zmx 屏幕
屏蔽、cliId 缺失、活跃度时钟),变异验证新检测与接缝均有牙。

Co-Authored-By: Claude Code <[email protected]>
Linux 把单个 execve argv 元素限制在 MAX_ARG_STRLEN(32 页 = 131072
字节),与 ARG_MAX 无关。一帧 bracketed paste 的正文超过该长度时,
`pane send-text` 在 exec 前就抛 E2BIG,整段消息(含粘贴边界)都发不
出去,runHerdr 只能报 false。

write() 现在把超长载荷按 131072-8192 的 UTF-8 字节上限切成多段、
按序写入,任一段失败即中止并返回 false;分段点位于粘贴标记之间,
标记始终只有一对,pane 收到的字节序列与原文一致。真机 herdr 验证
201KB 多行帧分两段后逐字节完整到达;131071 可发、131072 报 E2BIG
的边界已坐实。补 chunkByUtf8Bytes 纯函数用例与 write() 分段/中止
用例,变异验证有牙。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit 593dccb into deepcoldy:master Oct 21, 2026
18 of 19 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

已合并,感谢这个修复!

最终落地的内容(在原提交之上追加、未改写作者提交):

  • HERDR 一帧 bracketed paste 保留多行,五个投递点检查失败即停;
  • 合并最新主干并使用共用的 wrapBracketedPaste 原语;
  • composer 停放草稿识别覆盖 Claude 新版的折叠 chip 形态;
  • 提交诊断补齐 worker cliId 接缝测试;
  • 超长正文(>131071 字节单 argv 上限)按 UTF-8 边界分段顺序写入,修复大消息 E2BIG 整条丢失。

未尽事项(follow-up,不影响本次合并):

欢迎继续贡献。

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.49.0

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