Skip to content

fix(workflow): 限制节点日志大小和待写队列 - #3915

Merged
deepcoldy merged 2 commits into
deepcoldy:masterfrom
lijason1121:fix/workflow-log-limits
Nov 27, 2026
Merged

deepcoldy merged 2 commits into
deepcoldy:masterfrom
lijason1121:fix/workflow-log-limits

Conversation

@lijason1121

Copy link
Copy Markdown
Contributor

改动

Workflow 节点的终端回放、stdout 和 stderr 原先会一直追加。现在每份日志最多 64,000,000 字节,每个写入器最多积压 16,000,000 字节。已有文件大小和排队中的 UTF-8 字节均计入,恰好达到上限可以写入,越界的数据块整块拒绝。节点记录 WORKFLOW_LOG_LIMIT 并请求关闭 worker,人工取消仍优先。

普通聊天沿用原路径。workflow 的 PTY 和 tmux 后端共用终端回放写入器。stdout/stderr 共用文件时共用计数,诊断路径与 worker 独占的 pty.log 冲突会在启动前报错。

回归与验证

  • 修复前,预填满的 stdout/stderr 以及 worker 关闭期间收到的 PTY 超限仍可能返回成功。超大 final_output 也没有立即触发关闭。四个用例均复现。
  • 验证了先认领成功再超限、关闭期间人工取消、UTF-8 精确边界与待写队列累积。单独移除磁盘或队列检查时,对应回归测试均失败。
  • 复查并修正了两种边界。自定义输出与 pty.log 指向同一文件时,两个写入方曾能合计超过 64 MB。磁盘迟迟没有完成写入时,取消结果曾在 worker 已退出后仍无法返回。现在在启动前检查文件身份,日志关闭最多等待 1 秒。
  • 最终版本已通过 git diff --check 和 bun run build。Node、Bun 全量测试由本 PR 的 GitHub CI 执行。

@lijason1121
lijason1121 marked this pull request as ready for review November 27, 2026 10:50

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论

0 个阻断项,可合。 复审对象为本地 rebase 等价物 5d3bb0db;作者远端仍为 8826bc0c,两者 stable patch-id 均为 37f9f77f76bdde5aea4df464370fe2abb2fb3940,改动内容一致。

P3(均不阻断)

  1. 关闭期间 PTY 超限的现有用例没有进入 runtime binding,因而咬不住 src/worker.ts:2496 的 worker-scoped 特判。 test/workflow-v3-ephemeral-pool.test.ts:221-238 直接调用 sessionEventMetadata / appendWorkflowPtyLog,删掉该特判后测试仍然通过。探针确认原因是无 binding 时消息本来就未携带 runtime scope。在 append('more') 前补入:

    worker.contractScope!.enterRuntime(worker.contractScope!.currentBinding()!);

    当前实现通过;再删掉特判,用例立即变红,实际结果从预期的 WORKFLOW_LOG_LIMIT 退化为 ok。生产 PTY 回调经 bindSessionRuntimeCallback 绑定 runtime,因此这个守卫必要;建议把上述上下文设置固化进现有用例。

  2. src/workflows/v3/ephemeral-pool.ts:176 的 stdout/stderr 同文件去重没有回归测试。 用同一文件预填到 64,000,000 - 2 字节,再同步写入 stdout 2 字节、stderr 2 字节:当前实现复用同一 BoundedLogFile,第二块被拒绝,最终文件恰好 64,000,000 字节并返回 WORKFLOW_LOG_LIMIT;仅移除 :176 的去重后,探针文件涨到 64,000,002 字节。实现行为正确,建议把该序列固化,防止以后重新引入双 writer。

  3. nit:src/workflows/v3/ephemeral-pool.ts:700 的 if (!logLimit.signal.aborted) 属于冗余防御。 去掉后不会改变节点认领结果,finish 的 pendingResult/settled 门已挡住后来的成功定时器;保留它最多能避免关闭后无意义地再 arm 一次 quiesce。可不动。

影响面复核

改动仅接入 v3 workflow 临时 worker 的诊断日志路径;PTY 与 tmux 共用同一终端回放写入器。src/types.ts 只新增可选 IPC 字段,普通聊天会话不创建该写入器,wire 向后兼容。限流在 pool 中经 AbortController 汇流,cancelRequested 在限流消息处理前短路,人工取消优先。

实际验证

  • git diff --check:通过。
  • bun run build:通过。
  • 定向 Vitest:累计 21 个文件、343 例通过;所有探针和变异还原后,再跑 test/bounded-log-file.test.ts + test/workflow-v3-ephemeral-pool.test.ts,90/90 通过,工作区干净。
  • BOTMUX_VERIFY_BAKED_VERSION=0.0.0-review bun run build:bun && bun scripts/smoke-bun-binary.mjs dist-bin/botmux:standalone smoke 全部通过。
  • PR 的 Node、Bun、各平台二进制等 CI 检查全部通过。
  • 变异证据:V6 在补齐 runtime binding 后咬红;stdout/stderr 去重变异由上述 2 字节越界探针咬红。

非 PR 验证限制:额外尝试的 retired-runtime-worker-exit.integration.test.ts 在本会话深层目录下因 tmux socket 路径 File name too long 失败 5 例,未计入本 PR 结论;直接把两个 Vitest 文件交给同一次 bun test 会触发仓库已知的 vi.hoisted defer 限制,bounded-log-file 单文件 Bun 腿为 4/4 通过。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前 head 增量复核:代码与合并树层面确认可合

本结论明确绑定作者当前 OID 0650f123655e4bf4dd4d61775afb4411f6b4733a。该提交为 test-only(1 文件,+24/-1);本地 rebase 等价提交为 29de7d4bb00731b7ac2d940cf90c71b4f289ce49,两者 stable patch-id 均为 5538dfbdc6410fe955a6a1f6311018a714f3e463。实现提交在两侧的 patch-id 也保持一致。

前次提出的两个 P3 测试缺口均已关闭,未发现新增问题:

  1. test/workflow-v3-ephemeral-pool.test.ts:195 的共享日志用例同时钉住第一次写不关闭、第二次写恰好关闭一次,以及最终文件大小。当前树上去掉 ephemeral-pool.ts 的 stderr 复用 stdout 去重后,该用例立即变红:closeAfterStderr 实际为 0,预期 1。
  2. test/workflow-v3-ephemeral-pool.test.ts:242 使用 scope.run(scope.currentBinding()!, ...),与生产 PTY 回调的 runtime binding 语义一致。当前树上摘掉 worker.ts 的 workflowLogLimit scope 剥离后,该用例立即变红:结果由预期的 WORKFLOW_LOG_LIMIT 退化为 ok。

实际验证:

  • 所有变异还原后,test/workflow-v3-ephemeral-pool.test.ts + test/bounded-log-file.test.ts:91/91 通过,工作区干净。
  • bun run build:通过;随后加跑 worker-cot-accumulated-cap 与 workflow-v3-architect,同组共 116/116 通过。
  • git diff --check:通过。
  • git merge-tree --write-tree 8ea02476 0650f123 无冲突,预测树为 d93ecafdfc594041ca6923865623be968bc7e7a5;与本地 rebase head 29de7d4bb0 的 tree 逐字相同。
  • 依赖清单与 lockfile 未变。

截至本评论发布时,新 head 的 CI 尚未全绿,因此不将 CI 列为通过证据,也未做任何重跑。实际 squash 仍按既定门槛等待本轮首跑全部通过。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新合并树复核:确认可合

结论仍绑定 PR head 0650f123655e4bf4dd4d61775afb4411f6b4733a。CI 已核实 15/15 全绿;两个 workflow run 的 head_sha 均为该 OID,run_attempt=1、status=completed、conclusion=success,未做重跑。

对 0f5d7678 合并树的验证

git merge-tree --write-tree 0f5d7678 0650f123 无冲突,预测树与当时本地落地树均为 13d7fba0ed6365e9d1ba992f499fab36eafe3b3c。该树上 bun run build 通过,指定的 5 个相关文件 109/109 通过。

交集归属有一处需要更正:8ea02476..0f5d7678 内实际触及 src/types.ts / src/worker.ts 的是 #3919 与 #3928,不是 #3927。按实际 delta 复核:

  • #3919 在 DaemonToWorker init 增加命名参数传递,与本 PR 的 WorkerToDaemon error 字段方向不同;其 worker hunk 与日志路径无语义交叠。session-title-delivery 22/22 通过。
  • #3928 的 PTY 回合权限变更不修改限流 IPC、PTY 日志写入或 close 分支条件;其 3 个专属测试文件在该合并树上 57/57 通过。

复核期间 master 再前进后的最新树

复核过程中远端 master 又前进到 f575d14227085e0c8b441f6a1fb096c1014337f7(#3926)。因此当前应使用的合并树不是 13d7fba0...,而是:

592d31e70ceab6e4988d2a857c3952198e5f9814

已在不提交、不推送的临时 merge 状态下实际落地该树,git write-tree 与 git merge-tree --write-tree f575d142 0650f123 的预测逐字一致。验证结果:

  • bun run build:通过。
  • PR 的 bounded-log-file / ephemeral-pool 加上 #3926 的 5 个相关测试文件:7 文件、454/454 通过。
  • cli-adapters 的 Cursor 定向用例:28/28 通过。
  • #3926 在 worker 中只给 6 处 busyProbeRegion 调用传入 CLI id,未改变本 PR 的日志、限流 IPC 或 close 逻辑。
  • 依赖清单与 lockfile 未变。

临时 merge 已 abort,评审工作区恢复原 HEAD 且干净。最终远端回读仍为 master f575d142、PR head 0650f123,GitHub MERGEABLE。以当前 master f575d142 为准,确认合并树 592d31e70ceab6e4988d2a857c3952198e5f9814 可合。

附加非门禁说明:额外运行完整 cli-adapters 时,本地有 3 个 dsh question-bridge 的 HOME 路径断言失败;单独重跑仍失败,相关 dsh/adapter 文件不在本 PR delta 中,故未计入上述通过数,也不能归因于这次合并。Cursor 定向用例及 PR 的完整首跑 CI 均为绿色。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

合并树 79193706...:确认可合(仅限当前 base)

本次继续采用逐棵确认,不构成对未来 base 变化的预授权。当前输入为:

  • PR head:0650f123655e4bf4dd4d61775afb4411f6b4733a
  • master:2b5fc0751a52a9c101009a43d88d1bd5ba76ee79
  • 合并树:79193706b9dfcb622082851438a48ac7b008b179

git merge-tree --write-tree 2b5fc075 0650f123 无冲突,预测树与本地实际 HEAD tree 逐字相同;远端回读仍为上述 base/head,GitHub MERGEABLE。新增 delta 与本 PR 的文件交集仅为 src/worker.ts,依赖清单与 lockfile 未变。

实际验证:

  • bun run build:通过。
  • bounded-log-file、workflow-v3-ephemeral-pool、program-status-antigravity、worker-cot-accumulated-cap:4 文件、129/129 通过。
  • 额外补跑 #3906 自己新增的 antigravity-bridge-decision、antigravity-bridge-rebind、antigravity-reattach-runtime-identity、worker-agy-full-transcript:4 文件、108/108 通过。
  • git diff --check:通过,工作区干净。

行距证据有一处修正:#3906 在 runtimeIdentityForContract 的 hunk 位于约 2596 行,距本 PR sessionEventMetadata 的约 2497 行约 99 行,并非最近的 2024 行。但两者属于不同函数;新逻辑决定 AGY runtime identity,本 PR 的 workflowLogLimit 错误则剥离 runtime scope,未形成语义冲突。其余 AGY bridge/CoT/冷启动 hunk 也未修改本 PR 的日志写入、限流 IPC 或 close 条件。

此前已核实该 PR head 的 CI 为 15/15 全绿,两个 workflow run 均为 run_attempt=1 且成功,未重跑。以 master 仍为 2b5fc075 为条件,确认树 79193706b9dfcb622082851438a48ac7b008b179 可合;若 base 再变,本结论自动失效。

@deepcoldy
deepcoldy merged commit cd7f668 into deepcoldy:master Nov 27, 2026
15 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

感谢贡献,已合并 🎉

这个改动给 workflow 节点的 pty.log / stdout.log / stderr.log 加上了磁盘 64 MB 与待写队列 16 MB 的有界写入,超限后节点会以 WORKFLOW_LOG_LIMIT 明确判失败并关闭 worker,人工取消在任一时序下仍优先,避免了诊断日志无限增长撑爆磁盘或垫高 daemon 内存。

评审中提到的两个测试缺口(共享同一日志文件时的合并计数、关闭期间终端回放限流消息的 runtime 作用域)已由你补充的提交覆盖,且经变异验证能有效区分正确与错误实现,合入前相关构建与测试全部通过。当前没有遗留的后续事项。

(以上为自动评审的初步意见落地记录,最终以维护者审阅为准。)

deepcoldy pushed a commit to lijason1121/botmux that referenced this pull request Nov 27, 2026
deepcoldy pushed a commit to uestcwangci/botmux that referenced this pull request Nov 27, 2026
同步最新主干(含 deepcoldy#3906 AGY 冷启动防穿透、deepcoldy#3915 等),解决两处冲突:
- src/worker.ts:本 PR 已把 quiet-final 屏幕捕获上提到函数开头并改为
  expectedTrailingFinal 绑定,旧内联 try/catch 为死代码,删除;保留
  master 的 busyProbeRegion 两参签名(第二参可选,agy 单参语义不变)。
- test/antigravity-bridge-decision.test.ts:同位置各新增一个 describe,
  并集保留(terminal reply fallback + discovered session id)。
另在 harness 修复提交中为 handlePtyDataChunk 夹具补绑
observeAntigravityWorkingData,修复主 CI 的 traex 颜色查询测试。

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.36

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