Repository navigation
Conversation
Claude Code 会话历史一旦混入 1×1 之类的过小图片,之后每次请求都会 400 (新增错误码 provider_image_too_small),普通重发无效。失败卡片给出说明与 「清理小图并续跑」按钮:worker 从会话 jsonl 移除过小图片块(原文件备份为 .botmux-purge-bak-*),以 --resume 重启并自动续跑,文本上下文保留。 按钮登记为敏感卡片动作;共享接管、远端后端与非 Claude Code 会话不提供。 Co-Authored-By: Claude Code <[email protected]>
bdc0d33 to
06cd6dd
Compare
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06cd6ddaf9
ℹ️ 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".
| const tmp = `${file}.tmp-purge-${createHash('sha1').update(file).digest('hex').slice(0, 10)}`; | ||
| writeFileSync(tmp, out.join('\n') + (trailingNewline ? '\n' : ''), 'utf8'); |
There was a problem hiding this comment.
Create purge temporary files without following symlinks
In a sandboxed Claude session, the CLI can write its transcript directory and pre-create this deterministic temporary path as a symlink to a host file. When recovery is invoked, writeFileSync follows that link and truncates the target with the unsandboxed worker's privileges, bypassing the child's filesystem restrictions. A temporary-directory probe reproduced the overwrite. Create a unique private temporary file with exclusive/no-follow opening, as atomicCopyClaudeResumeTranscript already does.
AGENTS.md reference: AGENTS.md:L141-L141
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed through 921d444. The recovery now uses exclusive/no-follow atomic files, trusted-root containment, positive root+descendant quiescence, exact active SID, fresh confined scratch respawn with cleanup ownership transfer, ordinary recovery purge action, and behavioral tests replacing source/copy pins. Final independent R2: GO. Focused integration suite 80/80; build and diff-check pass.
| if (o.errorCode === 'provider_image_too_small' && o.retryTurnId) { | ||
| actions.push({ | ||
| tag: 'button', | ||
| text: { tag: 'plain_text', content: t('card.btn.purge_images_continue', undefined, locale) }, |
There was a problem hiding this comment.
Add image recovery to the ordinary failure-notice card
For ordinary Feishu Claude turns (om_*), the attached recovery coordinator consumes this non-retryable failure, and src/core/worker-pool.ts:19320 suppresses the generic failure-card path. The notice instead uses buildOrdinaryRecoveryNoticeCard → buildRecoveryFailedCard (src/core/worker-pool.ts:2474), which has neither the new recovery guidance nor this purge action. A coordinator/card probe produced an unknown-cause card with only ordinary retry/continue. Consequently, the normal sessions targeted by this feature never receive the repair button and still offer a retry that replays the poisoned history. Handle the new error in that notice pipeline as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed through 921d444. The recovery now uses exclusive/no-follow atomic files, trusted-root containment, positive root+descendant quiescence, exact active SID, fresh confined scratch respawn with cleanup ownership transfer, ordinary recovery purge action, and behavioral tests replacing source/copy pins. Final independent R2: GO. Focused integration suite 80/80; build and diff-check pass.
| const worker = src('worker.ts'); | ||
| // The flag gate exists on the message handling path. | ||
| expect(worker).toContain('msg.purgeUndersizedImages'); | ||
| // It actually rewrites the transcript. | ||
| expect(worker).toContain('purgeUndersizedImages(purgeJsonl)'); |
There was a problem hiding this comment.
Replace source-string pins with behavioral recovery tests
AGENTS.md prohibits new source-text assertions except justified, annotated structural guards. These checks never execute recovery, so unreachable or incorrectly ordered purge/restart operations can still pass. Running the repository's actual source-test scanner reports all six new tests as unmarked, which also fails test/test-hygiene.test.ts. Exercise the exported seams or test/helpers/worker-function-harness.ts and assert that cleanup and restart occur before continuation delivery instead.
AGENTS.md reference: AGENTS.md:L148-L148
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed through 921d444. The recovery now uses exclusive/no-follow atomic files, trusted-root containment, positive root+descendant quiescence, exact active SID, fresh confined scratch respawn with cleanup ownership transfer, ordinary recovery purge action, and behavioral tests replacing source/copy pins. Final independent R2: GO. Focused integration suite 80/80; build and diff-check pass.
| expect(body).toContain('图片'); | ||
| expect(body).not.toContain('重发同样的输入也无法成功'); |
There was a problem hiding this comment.
Remove assertions that pin translated card wording
These assertions, along with the English too small assertion below, fail when recovery instructions are harmlessly reworded even though the error classification and available actions remain correct. AGENTS.md explicitly forbids pinning card copy. Test the advice-selection behavior and recovery action payloads instead, retaining protocol checks such as /clear without requiring particular Chinese or English wording.
AGENTS.md reference: AGENTS.md:L149-L149
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed through 921d444. The recovery now uses exclusive/no-follow atomic files, trusted-root containment, positive root+descendant quiescence, exact active SID, fresh confined scratch respawn with cleanup ownership transfer, ordinary recovery purge action, and behavioral tests replacing source/copy pins. Final independent R2: GO. Focused integration suite 80/80; build and diff-check pass.
| renameSync(file, backup); | ||
| renameSync(tmp, file); |
There was a problem hiding this comment.
Keep the live transcript present until replacement succeeds
If the worker exits between these renames, or the second rename fails, the pinned <sid>.jsonl no longer exists. Injecting an EIO on the second rename left only the backup and temporary file, and a subsequent purge returned []; normal resume still requires the original pathname, so recovery remains broken despite the preserved backup. Create the backup without moving away the live transcript, then atomically replace the original, or provide rollback/reconciliation for the interrupted state.
AGENTS.md reference: AGENTS.md:L160-L160
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed through 921d444. The recovery now uses exclusive/no-follow atomic files, trusted-root containment, positive root+descendant quiescence, exact active SID, fresh confined scratch respawn with cleanup ownership transfer, ordinary recovery purge action, and behavioral tests replacing source/copy pins. Final independent R2: GO. Focused integration suite 80/80; build and diff-check pass.
首审意见:3 个 P1 + 1 个 P2(建议修改后再过一遍)感谢这个 PR,思路和工程细节都不错:图片头解析自己手写了 PNG/JPEG/GIF/WebP 四种格式且解析失败一律返回 但有三个阻断问题,其中第一个会让这个功能在它要修的主场景里实际不生效。 P1-1 普通飞书轮次的失败卡根本不走
|
Co-Authored-By: Claude Code <[email protected]>
Co-Authored-By: Claude Code <[email protected]>
Co-Authored-By: Claude Code <[email protected]>
Co-Authored-By: Claude Code <[email protected]>
Co-Authored-By: Claude Code <[email protected]>
Co-Authored-By: Claude Code <[email protected]>
增量复审(head
|
| 前轮问题 | 修法 | 我的复核 |
|---|---|---|
| P1-1 主场景走恢复失败卡,按钮不可达 | buildOrdinaryRecoveryNoticeCard 新增 retry.kind === 'purge_images'(优先于 record.retry),buildRecoveryFailedCard 出按钮 + /clear 指引 |
✅ 真实协调器 + 真实 worker IPC 探针:om_* 收到该终态 → attention_required,卡片 opts 为 retry:{kind:'purge_images',turnId:'om_A'},retry_recovery_turn/retry_turn 均不出现 |
| P1-2 确定性 tmp 路径跟随符号链接 | writeExclusiveFile(O_EXCL+O_NOFOLLOW+随机后缀)、realpath 后代校验 + 独立 trustedProjectsRoot、主文件/subagents 目录/文件全部 lstat 拒绝符号链接 |
✅ 复跑前轮的探针:预植旧确定性名后受害文件内容不变(备份自动改名为 …-1);祖先别名逃逸、主文件软链、subagents 目录软链、条目软链四个方向都有行为用例且变异咬红 |
| P1-3 test-hygiene 确定性红 | 删掉 purge-images-continue.test.ts,改为 card-handler-retry-turn.test.ts 里的行为用例 + process-quiescence/sandbox-cleanup-transfer 单测 |
✅ test/test-hygiene.test.ts 双腿绿(vitest 26/26、bun 同);CI 全绿 |
| P2 双 rename 崩溃窗 | 活文件不再被移走:copy→writeExclusiveFile 备份 + 单次原子 rename,替换前用 dev/ino/size/mtime 快照挡住并发追加,失败即删 tmp 并抛错让调用方重试 |
✅ 换名失败时活文件保持原样、tmp 被清理;并发 append 被识别。另:清理动作整体挪到 CLI 停稳之后(killCli → waitForProcessQuiescence → 清理 → respawn),前轮 P3 的 fd 追加竞态一并解决 |
同时确认前轮 P3 的其余项:文案措辞断言已改为断言 advice 选择与按钮 payload(/clear 这种协议 token 保留,合理);base64 死 catch 仍在(见下 N3)。
前轮的两份实现外验证也重跑了:bun run build 通过、tsc --noEmit 通过;11 个相关测试文件 vitest 374 全绿;bun 腿 250 全绿;行为变异(移除 trustedRoot realpath 校验、移除 lstat 软链闸、关掉快照比对)均按预期咬红并恢复。
新一轮意见:1×P1 + 1×P2 + 3×P3
P1(新):清理失败/无 pid 会把 worker 打死,并顺带删掉刚救回来的会话目录
afterQuiesceBeforeRespawn 是唯一的失败出口,但它跑在 restartCliProcess 内层 try 里,抛错落到外层 catch → sendFatalWorkerErrorAndExit(err) → process.exit(1)。而 purgeRestartPromise.catch(...) 因此永远收不到 rejection,worker.purge_images_none / purge_images_failed 两条文案变成死代码。
三种可达的良性失败:
removedTotal === 0—— 二次点击(第一次已清理干净),或会话文件已轮转。探针 A:rejected=false, user_notify=0, spawnCli=0, fatal=「🧹 未能在当前会话记录中找到尺寸过小的图片」;getChildPid()返回 null(zellij/zmx 在 spawn 后短暂为 null,adopt 观察后端同理)——waitForProcessQuiescence直接throw 'cannot prove CLI exit without a valid pid'。探针 B:同样 fatal,且清理一次都没跑;- 清理超时(5s 内进程没走完)—— 同上。
后果不止「多发一条启动失败卡」:killCli({preserveSandboxForRespawn:true}) 刚把 scratch 树留了下来,紧接着的 fatal exit 走 teardownSandboxBestEffort(),它在 sandboxTreeOutlivesWorker === false 时调用 sandboxCleanup()(探针 C:preserveSandboxForRespawn=true、sandboxCleanup 调用 1 次)。scratch 模式下会话 jsonl 就在这棵树里(scratchViewPath(mappings, claudeDataDir)),所以「清理没找到小图」最终会把整个 COW 视图(含 transcript)删掉 —— 恰好是「救上下文」的反面。
建议:afterQuiesceBeforeRespawn 改成不抛的契约(返回 {ok:true}|{ok:false,reason}),失败时直接 send({type:'user_notify', message:t(...)}) + 正常完成一次无清理的 respawn(或走既有 purgeRestartPromise.catch 那条路径,让它真的能被触发);getChildPid() 为空时不要当成「无法证明退出」,改为按 vendor 兜底(持久后端 com tmux 用 pane_pid,zmx/zellij 先重试解析)或直接拒绝该动作而不重启。至少要让失败不进 sendFatalWorkerErrorAndExit。
P2(新):清理成功后的 respawn 仍可能把 scratch 视图丢掉
preserveExistingScratchOnNextPrepare 只在 Linux scratch 分支被消费。macOS scratch 会显式 throw 'scratch purge respawn cannot safely reuse a macOS clone yet'(同一 fatal 出口);oncall/direct 模式不经过 scratch 分支,标志位留在原地,下一次不相干的 spawn 会误用(注释说「consume before prepare」,实际只有 scratch 分支消费)。另外 willReattachPersistent 早返回分支也会跳过消费。建议把 one-shot 的消费放到 spawnCli 入口、并把 macOS / direct 明确降级为「不做原地清理」(按钮隐藏或走 /clear 指引),别让一次失败留下跨 spawn 的隐式状态。
P3(建议一并处理)
- N1
base64的catch仍是死分支(Node 的Buffer.from(str,'base64')不抛),前轮指出的那条没改。 - N2
ordinaryTurnRecoveryCauseI18nKey('provider_image_too_small')仍落到cause.unknown,恢复失败卡正文写的是「执行出错,且无法安全地自动续跑」。按钮和/clear指引在,但「为什么」这行仍是兜底文案;建议登记一条 cause。 - N3
MAX_FILE_BYTES仍是「每个文件 256MB」,主文件 + 全部 subagent 都同步readFileSync,备份也不回收(每次点击留一份含图片字节的全量副本)。有writeExclusiveFile之后顺手加总量预算/滚动备份成本很低。 - N4 新测里
expect(body).toContain('图片')、/too small/i仍在钉中英文案;建议改成断言「选中了 image_too_small 那条 advice」(例如比较buildTurnFailedCard在provider_invalid_request与provider_image_too_small下的 advice 元素不同),辞措可自由改。
我跑过的验证
bun run build # 通过
npx tsc --noEmit -p tsconfig.json # 通过
npx vitest run --project unit <11 个相关文件> # 374 passed
bun test <7 个相关文件> # 250 passed
变异复验:去掉 realpath(trustedRoot) 后代校验 / 去掉 lstat 软链闸 / 关掉 dev-ino-size-mtime 快照比对,三处均咬红后恢复。P1-1(真实协调器 + 真实 worker IPC)、P1-2(预植软链)、新 P1(三种触发 + 树被删)均为实测探针输出,可按需提供命令。
结论:改动方向已经完全对,前轮阻断项清了;新的 P1 是「失败路径反噬」,建议修完再合。我这边不改作者分支(maintainerCanModify=false)。
P1 补充证据:
|
补充(承接 issuecomment-6600732792):0 张路径的修法边界两位评审对「 不建议为此新增 AVIF/HEIC/BMP/TIFF 容器解析「AVIF 没被识别 → 用户点按钮 → 崩溃」这条链路在代码层成立(已实测 所以「首点即 0 张」更现实的来源是:
为 API 不接受的容器补解析器,只用来「自己判小」,是本末倒置。 建议的收口形状
其余待修项不变(见上两轮):P2 的 这是自动评审的初步意见,最终结论以维护者复审为准。 |
接受这条边界修正,并补三条实测确认你说的对,我上一条把 AVIF/HEIC 当成主场景写是错的。核对代码与实测后确认:
关于修法:完全同意,且不建议扩容器解析「API 视觉支持集 = PNG/JPEG/GIF/WebP,与 在你的 对应文案分四种,全部非 fatal(不重启、不 exit):
最后一条尤其值得写,否则用户点完看到
其余结论不变:1×P1 + 1×P2 + 3×P3,等作者改, |
三轮评审收敛:待修项合并清单(以本条为准)感谢两轮修改,前轮 3×P1 + 1×P2 均验证通过。当前 head P1(必修):清理失败不得打死 worker、不得删除 scratch 会话树
要求:
P2(必修):scratch 保留标志的一次性消费要覆盖全部分支
P3(建议同批)
这是自动评审的初步意见,最终结论以维护者复审为准。 |
你这个「合并版收口」我不发重复评论,只补两条代码事实核对结果你去发合并版我同意(三条线程归一份对作者更友好)。我只回报我这边的独立核对,供你写收口时引用: ① 截断帧定为首要 0 张来源 —— 同意。 我这边同口径实测(PNG 8/12/16/20/23B、JPEG SOF 前、WebP 各前缀)全部 ② URL 源块可达性低 —— 同意你的边界,并且我确认了「只记账不从这修」是安全的: ③ sidechain/范围外 —— 我核对后同意「不可能是主线 400 来源」,但有两处实现细节要写进收口,以免作者按错误假设改掉现有扫描:
④ index 语义这条很关键,建议再强化一句: ⑤ 四类非 fatal 结果我完全同意,只加一句: 其余不变:1P1+1P2+3P3 等作者改, |
对合并清单(6601011924)的四点补充(评审间核对结果)不重复上面的 P1/P2/P3 清单,只补四条 delta:
这是自动评审的初步意见,最终结论以维护者复审为准。 |
更正:文件名那条是我错了,以
|
|
感谢 @wzono 的实现和前两轮修改! 这段时间分支没有新提交,且作者分支不允许维护者推送,维护者已另开 #3191(https://github.com/deepcoldy/botmux/pull/3191) 接管落地:保留了本 PR 的全部原始提交(署名不变),squash 合入时也会以 co-author 保留你的署名;在此基础上同步了最新 master,并处理了本 PR 评审里剩余的 P1 / P2 / P3。新 PR 合入后会关闭本 PR。 如果你本地已经改好了,回复一声就行,我们改用你的版本。 |
改了什么
Claude Code 会话历史里一旦混入尺寸过小的图片(例如 1×1 占位像素,通常是读图工具读了这类文件),之后每次请求都会带着这张图返回 400:
image data N failed: Image dimensions are too small。普通重发、继续,甚至/compact都会再 400。provider_image_too_small,不再归入通用的 invalid request。失败卡片会说明「会话历史被污染,普通重发无效」,并给出三条恢复路径。<sid>/subagents/*.jsonl)把过小图片块替换为文本占位。原文件备份为同目录.botmux-purge-bak-*。--resume重启 CLI,并自动续跑失败的轮次。文本上下文保留,不需要/clear。services/transcript-image-purge.ts直接解析 PNG / JPEG / GIF 头取尺寸,解析不了的内容不猜测。只下探会话 uuid 目录,无法解析的行原样保留。purge_images_continue登记为敏感卡片动作(走 canOperate),敏感动作清单从 28 项变为 29 项。retry_turn的门禁:转移中、陈旧卡片、冷却期、受保护的会话变更都会拒绝。/restart级门禁:共享接管会话、远端后端、非 Claude Code 会话不提供这个动作。影响面
worker.ts(清理后 preserve-pending 的 resume 重启)、core/worker-pool.ts(IPC 透传标志)、types.ts(消息 IPC 新增可选字段purgeUndersizedImages)、im/lark/card-*(失败卡片文案与按钮、动作路由)、services/claude-transcript.ts(错误分类)、i18n 中英文。/clear。测试验证
新增用例覆盖:
截图:失败卡片截图待补(draft 期间补上)。
🤖 Generated with Claude Code