Skip to content

Prevent SOP runs from hanging after artifact write failures - #1301

Merged
Robert0622 merged 21 commits into
Tencent:mainfrom
Robert0622:codex/fix-sop-artifact-terminal-write
Nov 25, 2026
Merged

Robert0622 merged 21 commits into
Tencent:mainfrom
Robert0622:codex/fix-sop-artifact-terminal-write

Conversation

@Robert0622

@Robert0622 Robert0622 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Store legacy inline run artifacts as MEDIUMTEXT so old deployments can accept the inline format. Migration 042 preserves existing data, character set, collation, and nullability.
  • Settle the node with the storage error if the artifact and terminal-state transaction fails. A completed agent is eligible for an operator retry after recovery.
  • Emit artifact.published only after the outcome is committed for the current run and node.
  • Transfer declared SOP files independently of task completion, up to 20 MiB per file with Runner 0.13.0. The downstream node reads the archived bytes and verifies the checksum. Legacy Runner completion accepts multiple inline files.
  • Retry transient file transfer errors without rerunning the completed process. Let the workflow proceed when optional files or repository inventories fail and report a concrete failure when a required handoff cannot be saved.
  • Use artifact metadata for workflow progress and store larger files in bounded binary chunks. Existing artifact records remain readable.

Compose applies migrations/042_run_artifacts_content_mediumtext.sql before the platform starts, including normal ./start.sh pull upgrades. The native development script runs the same migration. Custom deployments with an external MySQL server can include the SQL in their pre-start schema upgrade step.

Validation

  • MySQL 8.4.13 with the original engine reproduced the stall in all 3 runs. A 65,536-byte artifact triggered MySQL error 1406, the node remained running, and its trace announced publication.

  • The fixed engine passed 5 repeated MySQL regressions. Legacy TEXT rejects that same write and the node ends as failed with the cause. After applying the migration twice, 65,536-byte and 1 MiB artifacts round-trip and the downstream approval starts.

  • The SQLite write-rejection test passed in all 5 runs. The node fails on its first attempt and retains the write error.

  • The public content check and Git whitespace check passed.

  • The repository package suite and the focused engine tests for artifact handoff, approvals, and run-state writes passed.

  • The full engine suite timed out in TestRunnerIntegrateAndConversationPushCanceled. The same test timed out against the original engine and schema on this host.

  • The Compose upgrade preserved the legacy row and column metadata and passed on a repeated upgrade. A denied ALTER blocked the platform, and retrying the upgrade after restoring permission succeeded.

  • The real SOP engine on the automatically upgraded MySQL database archived 65,536 bytes and 1 MiB. A 1 MiB plus one byte plan reported the artifact size limit and left downstream approval pending.

  • The installer test suite completed 64 tests with two environment-specific skips.

SOP handoff and Runner validation

  • A real Runner and HTTP API transferred a 20 MiB plan and two 1 MiB files in one SOP. A dropped upload acknowledgement triggered an idempotent retry and the producer ran once. The review read all files, the optional oversized output was skipped, and the SOP finished after its configured human approval.
  • MySQL 8.4.13 archived a 20 MiB required file and an exact binary payload. A required file one byte over the limit produced a failed node in a single attempt without advancing the downstream approval.
  • Focused engine, Runner, repository, HTTP API, and runtime regressions passed. They cover optional archive rejection, partial uploads, legacy multi-file completion, child SOP artifacts, and approval order.
  • The broader suites hit host-dependent Git, Chromium, and private temporary-directory checks and package timeouts on this test host. The scoped Git gate and Runner Chromium failure also reproduced on the pre-change branch.

Related to #1092 and #1193. Builds on the approach in #1184 with the current migration sequence, attempt-scoped error handling, and an end-to-end MySQL regression of SOP node completion.

crispinhu27
crispinhu27 previously approved these changes Nov 24, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approve at 91332e3d52fa8c7c0079d1244e4e609891501123 (base main@be35aff8). No confirmed defects found.

Scope: full diff against main: models.go MEDIUMTEXT, migration 042, artifact commit error handling in node_execute.go / node_outcome.go, the new artifact-migration one-shot in compose.yaml, scripts/dev.sh, the install test scripts and docs/deployment.md.

Verification run in an isolated environment (synthetic data):

  • go test ./internal/engine -run 'TestNodeArtifactCommit|TestMySQLNodeArtifactCommit' on SQLite and MySQL 8.4.7, also with -count=3: pass. On a legacy TEXT column, 65,535 bytes is accepted and 65,536 bytes gets Error 1406, and the node now fails on its first attempt. After 042, 65,536 bytes and 1 MiB are stored and the downstream approval starts. 1 MiB + 1 byte is rejected.
  • The same tests on base be35aff8 fail as the PR describes: the node stays running, no artifact is stored, and artifact.published is still emitted. So the fix is real.
  • go test ./internal/repo: pass. The full ./internal/engine suite passes except 2 tests that also fail on base because of the host (no Chromium, exit 127).
  • python3 scripts/test-install.py: OK (64 tests, 2 skipped for Bash 3.2).
  • Migration 042, run with the exact compose command as a non-root user with GRANT ALL ON loopforge.*: it widens the column and keeps charset, collation, NOT NULL, data and indexes. It is a no-op success on a fresh DB and idempotent on rerun. Without ALTER privilege it exits 1, which blocks platform startup as intended.
  • docker compose --profile platform config -q is valid, alone and with compose.dev.yaml. Real container startup is covered by CI first-run on this head: artifact-migration exits 0, up -d --wait succeeds, platform is Healthy, and 25 e2e tests pass.
  • All 16 check runs on this head are green.

Non-blocking notes:

  • A transient commit error (for example a deadlock) now fails the node permanently even with MaxAttempts > 1. Recovery is an operator retry, which is better than the hang on main.
  • freezeAvailableArtifacts (internal/engine/artifacts.go) still ignores write errors. That path is not touched here and could be a follow-up.
  • 042 is not listed in the "Required upgrade migrations" table in docs/deployment.md.
  • Migration numbering 042 collides with other open PRs, so renumber at merge time if needed.

The PR is still a draft. This review covers the head above only.

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审 377db662(base main be35aff8)。上次 APPROVE 6038871054(针对 91332e3d)已因新推送被 dismiss,这次重点看增量 91332e3d..377db662(43 个文件):产物分块存储 run_artifact_blobs、Runner 0.13.0 文件传输接口(output-file / input-file)、RunProgress 替换 RunState、可选产物与仓库变更清单失败后继续、提交失败后只保留必需产物重试。

新增已确认问题(1 条,见行内评论)

  • [P2] 下游 Agent 提示词里的 {{artifact.<节点>.<产物>}} 被替换成空字符串。在 91332e3d 和 main be35aff8 上替换正常,在 377db662 上稳定复现为空。

已执行的验证(隔离工作区,最小环境变量,不含任何凭据;Go 1.26.11)

  • go build ./... 和 go vet(domain/repo/runner/httpapi/engine/runtime)通过。
  • internal/domain、internal/repo 全部通过(包含新增的 run_artifact_blobs_test)。
  • internal/runner、internal/httpapi、internal/runtime 在 377db66 和 91332e3 上的失败用例完全一致。这些失败来自本机环境:容器不支持 user namespace,bwrap 无法启动;另有 Chromium 相关用例。用一个只转发命令的测试用 bwrap 替身后,TestSOPRunnerArtifactHandoffReachesApprovalAndCompletes、TestRunnerReportedOutputs* 等 Runner 交接用例在 head 上通过。
  • engine 中产物、交接、提交、SOP 相关的用例子集(-run 'Artifact|Handoff|Output|Transfer|Legacy|Commit|Blob|Prompt|SOP')用 bwrap 替身运行时,head 上只有上面这条复现用例失败,91332e3d 上全部通过。
  • CI 16 项全部成功。

未验证:真实 MySQL 8.x 上 20 MiB 分块写入、真实 Runner 进程跨机传输、旧版 Runner 混跑。以上没有在本机实际部署验证,所以不作为结论。

非阻塞观察(未作为缺陷):archiveFile 在节点终态提交之前就单独写入 blob,如果终态提交失败,会留下没有引用的 blob 行;loadArtifactContents 里只要有一个 blob 读取失败,整个 RunState 就会返回 not found。

Comment thread internal/engine/node_execute.go Resolved
roberttwang and others added 3 commits November 24, 2026 14:57
Agent invocations now read run progress without artifact bodies, so
{{artifact.<node>.<name>}} was replaced with an empty string. Load the
stored body of each referenced artifact before substitution.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The claim loop and child SOP wait loop re-read run state every few
seconds or 200 ms. RunState now hydrates chunked files of up to 20 MiB,
so these loops read every archived body on each tick. Poll with
RunProgress and read the child's bodies once when it finishes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Keep both Runner protocol additions: project credentials (0.12.1) and
artifact transfer (0.13.0). The runner reports 0.13.0, which also
satisfies the project credential requirement. Script and agent tasks
carry project credential IDs and use the artifact payload check.

Co-Authored-By: Claude Code <noreply@anthropic.com>
crispinhu27
crispinhu27 previously approved these changes Nov 24, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审 c146f081(base main be35aff8)。上次 REQUEST_CHANGES 6039862840 针对的是 377db662。

历史问题

  • [P2] 下游提示词里的 {{artifact.<节点>.<产物>}} 被替换成空字符串:FIXED。在 SQLite 和 MySQL 8.4.7 上分别实测,377db662 上能复现,head 上不再出现,详情见原线程。

增量 377db662..c146f081

  • prompt.go:占位符实际出现、并且产物正文为空时,才按需读取正文(包括分块存储)。所有渲染路径都经过这里。
  • run_recovery.go:恢复扫描改用 RunProgress。核对过后续函数都不读产物正文,真正接管时 acquireLease 会重新读 RunState。
  • sop_node.go:子 SOP 轮询只读元数据,结束后再读一次 RunState,交给 importChildArtifacts。额外跑了子 SOP 交接 3 MiB 分块产物的临时测试:下游 sha256 校验一致,节点 succeeded。

验证(隔离环境,最小环境变量,不含凭据,Go 1.26.11。本机没有 bwrap,用一个只转发命令的测试替身)

  • go build ./... 和 go vet(engine/repo/runner/domain/httpapi/runtime)通过。
  • 下表是 head 与 377db662 对比,失败集合两边逐一相同,都是本机缺 Chromium、Docker 或 CLI 导致的:
包 head 377db662
domain ok ok
repo ok ok
engine 743 通过 / 1 失败 740 通过 / 1 失败
runtime 919 通过 / 9 失败 919 通过 / 9 失败
httpapi 1889 通过 / 2 失败 1889 通过 / 2 失败
runner 5 个失败 5 个失败
  • TestChatClarificationEdgePaths 在两边都不稳定(各跑 10 次,都有 3 到 4 次失败),本 PR 的增量没有改 httpapi,与本 PR 无关。
  • MySQL 8.4.7:TestMySQLNodeArtifactCommit 通过;约 19 MiB 产物的分块写入和读取,以及提示词替换,都通过。
  • 增量相关用例(Prompt、子 SOP、恢复、QueuedSOP)加 -race -count=3 通过。
  • CI 16 项全部成功。

未验证:真实 Runner 跨机文件传输、和旧版 Runner(<0.13.0)混跑,都没有实际部署验证,只有进程内的 Runner 交接测试覆盖。

非阻塞观察:prompt.go 读取产物失败时,占位符会静默替换成空串,不报错,可以考虑至少记一条日志。

PR 仍是 draft。本次审查只覆盖上述 head,不代表代码没有缺陷。

crispinhu27
crispinhu27 previously approved these changes Nov 24, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审 1324e744。上一条 APPROVE 6042827371(针对 c146f081)因为这次推送被 dismiss 了。1324e744 是把 main 177d8815 合进来的提交,上次以来没有其他功能改动。

合并提交审查

  • 合并时有 3 处冲突,都是手工解决的:domain/runner.go、engine/runner_dispatch.go、runner/daemon.go。
  • 手工解决后的结果与自动合并结果逐一比对过:
    • domain/runner.go:同时保留了 RunnerVersionProjectCredentials(0.12.1)和 SupportsProjectCredentials,也保留了本 PR 的 RunnerVersionArtifactTransfer(0.13.0)。
    • runner/daemon.go:runnerVersion 取 0.13.0。0.13.0 高于 0.12.1,所以项目凭据的版本检查照样能通过。
    • engine/runner_dispatch.go:脚本派发保留了 main 新增的 task.ProjectCredentialIDs,并改用本 PR 的 validateRunnerArtifactPayload。
  • main 里给 task.ProjectCredentialIDs 赋值的 3 处(agent、script、conversation 派发)在合并后都还在。

验证(隔离环境,最小环境变量,不含凭据,Go 1.26.11。本机没有 bwrap,用一个只转发命令的测试替身)

  • go build ./... 和 go vet(engine/repo/runner/domain/httpapi/runtime)通过。
  • domain、repo、runner、engine、httpapi、runtime 全量测试,与 main 177d8815 对比,失败集合完全一致(各 17 项,都是本机缺 Chromium、Docker 或 CLI 导致的),没有新增失败:
包 1324e744 main 177d8815
engine 744 通过 / 1 失败 739 通过 / 1 失败
httpapi 1900 / 2 1899 / 2
runner 263 / 5 262 / 5
runtime 925 / 9 925 / 9
repo 615 / 0 614 / 0
domain 318 / 0 318 / 0
  • TestChatClarificationEdgePaths 两边都跳过了,原因是它在合并前的两个基线上就不稳定(见上一条 review)。
  • 之前那条 [P2] 的复现测试在 1324e744 上重跑仍然通过:SQLite 1 MiB+ 分块产物,以及 MySQL 8.4.7 约 19 MiB 的产物,下游提示词都替换出了完整正文。TestMySQLNodeArtifactCommit 和 TestDownstreamPromptRendersArtifactBody 也通过。
  • CI:16 项的 conclusion 都是 success。其中 curl-install 查询时 status 还显示 in_progress,但 conclusion 已经是 success。

状态提醒:main 现在已经前进到 c3dd1b4d,本 PR 显示和 main 有冲突(dirty),需要再合一次 main,合完后按复审处理。

未验证:真实 Runner 跨机文件传输,以及和旧版 Runner(<0.13.0)混跑,都没有实际部署验证。

PR 仍是 draft。本次审查只覆盖上述 head,不代表代码没有缺陷。

# Conflicts:
#	docs/deployment.md
crispinhu27
crispinhu27 previously approved these changes Nov 24, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审 head 0b6a4430(合并 main c3dd1b4d)。上次 APPROVE 时的 head 是 1324e744,base 是 177d8815。

合并核对:把 git diff 177d8815 1324e744 和 git diff c3dd1b4d 0b6a4430 的 +/- 行逐行比对,结果完全一致(都是 46 个文件,+2016/-282),PR 的净改动没有变化。唯一手工解决的冲突在 docs/deployment.md,PR 的 20 MiB 交付物 / Runner 0.13.0 段落和 main 的 Shared projects 段落都保留了。#1304 的 041 升级流程和本 PR 的 artifact-migration(042,放在 platform 之前执行)顺序兼容。#1285 在 runner_dispatch.go 里的执行机共享改动和本 PR 的产物输入改动互不影响。

历史问题:下游提示词里 {{artifact.<节点>.<产物>}} 被替换成空串的 [P2],在当前 head 上复测仍为 FIXED(TestDownstreamPromptRendersArtifactBody 的 inline 和分块两个子用例都通过)。

验证:

  • go build ./... 和 go vet ./... 通过。
  • go test ./...:27 个包通过。engine/httpapi/runner/runtime 中失败的用例和 main c3dd1b4d 上的失败集合一致,都是本机缺 Docker、浏览器或 bwrap 导致的。
  • 产物提交失败、可选产物失败后仍可审批、分块上传中断重启、Runner 产物交接一直走到审批完成等用例都通过。
  • MariaDB 上跑了 TestMySQLNodeArtifactCommit:65535/65536 字节边界、042 重复执行、20 MiB 和 20 MiB+1 都符合预期。
  • webtest 285/285,scripts/test-install.py 通过,CI 16 项全绿。

没做的验证:本机没有 Docker,没有实跑 Compose 升级(041→042 串联),也没有在 MySQL 8 上验证,这两项以 CI first-run 和静态核对为准。

注意:main 已前进到 f3d4f41a(#1284),本 PR 现在和 main 有冲突(internal/domain/runner.go、internal/engine/node_execute.go、internal/repo/runs.go、internal/runner/daemon.go)。这个 APPROVE 只针对 0b6a4430,作者合完 main 后按复审处理。

Co-Authored-By: Claude Code <noreply@anthropic.com>

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

CR + 部署实测:功能实测通过;CI 未过,暂不能合入(head 437eb251)

这个 head 是 0b6a443 合并 main 7bebfa5 的结果。我核对了冲突处的解法:

  • node_execute.go:runnerID/runner 在前面已经取过,stagingCheckout = !UsesConversationWorkspace() && !runner.SupportsIntegrate() 和 main(#1284)的语义一致。
  • RunState 改成 RunProgress 后,DeleteRun 同时清理新加的两张 blob 表,并保留 main 新加的「工作区有关联 SOP 运行时不能删除」检查。
  • domain/runner.go 里两个版本门槛(0.13.0 产物传输、0.12.3 会话工作区)都保留了。

合并后的结果没有发现问题。

❗ 阻塞:CI browser / platform-required 失败

  • 失败任务:https://github.com/Tencent/LoopForge/actions/runs/45469840030/job/138714492631
  • 报错:e2e route coverage: 348/410 = 84.9%,FAIL: route coverage 84.9% is below 85%。main 7bebfa5 上是 346/406 = 85.2%。
  • 原因:本 PR 新加了 4 条路由,其中 GET /api/runners/tasks/:id/input-file 和 PUT /api/runners/tasks/:id/output-file 在 e2e 里没有被访问到(在 uncovered 列表里),/runners/tasks/:id/... 那两条已覆盖。需要补 e2e 去访问这两条路由(或者用别的办法把覆盖率拉回 85%)。已告知负责修这个 PR 的会话。

部署实测(本机原生部署 MySQL 8.4.7,旧库由 main 建表)

场景 main 本 PR
旧 TEXT 列 + 64 KiB 产物(旧执行流程) 报 MySQL 1406,节点一直卡在 running(150 秒以上) 节点 failed,原因写明「保存节点终态和产物失败:…Error 1406…」。main 上卡住的那个运行,换成本 PR 的平台启动后也正确收尾为 failed
042 迁移连跑两次 — 两次都成功;列变为 mediumtext utf8mb4 utf8mb4_0900_ai_ci NULL,字符集、排序规则、可空属性都保留
迁移后重试上面那个失败节点 — 第 2 次尝试成功,下游 sha256 校验一致,进入人工审批
新执行机器 0.13.0:必需 5 MiB + 可选 21 MiB — 5 MiB 分 2 块存进 run_artifact_blob_chunks;下游从 .agentflow/inputs/produce/plan.md 读到的 sha256 和生成的一致;可选文件提示「跳过可选产物 opt(opt.bin):超过产物大小上限 20 MiB」;审批后运行 succeeded
新执行机器:必需文件正好 20 MiB — 通过,sha256 一致
新执行机器:必需文件 20 MiB+1 — 第 1 次尝试就 failed:「artifact contract: plan (plan.md): 超过产物大小上限 20 MiB」,下游审批没有启动
旧执行机器 0.12.4:64 KiB + 1 KiB 两个内联文件 — 通过,sha256 一致,审批后 succeeded
旧执行机器:必需文件 1 MiB+1 — failed:「超过旧版执行机器的 1 MiB 单文件回传限制,请将执行机器升级到 0.13.0」

产物由真实 Claude Code(deepseek-flash)在执行机器上生成,下游校验用的是 shell 脚本节点。

测试

  • 本机通过:go test ./internal/repo、./internal/engine -run 'Artifact|Handoff|Approval|RunState|Terminal|Legacy'、./internal/httpapi -run 'Artifact|Runner';go vet ./... 干净。
  • ./internal/runner 只有 TestRunnerStartsPanelBrowserInRunSandbox 失败,main 上同样失败,原因是本机没有 Chromium,不是本 PR 引入的。

把 CI 的路由覆盖率修好后可以合入。

A legacy runner receives its input files inline, so a queued task payload
can carry more than a megabyte. Sorting whole runner_tasks rows then
exceeds MySQL's default 256 KiB sort buffer (error 1038), every claim for
that provider fails and the SOP stays queued. Claims and the task list
now sort only narrow columns and load payloads by ID.

The route sweep also covers the /api aliases of the Runner file transfer
endpoints, which keeps e2e route coverage above the 85% gate.

Co-Authored-By: Claude Code <noreply@anthropic.com>

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

CR + 部署实测:LGTM,可以合入(head 8bca19b5)

接着上一条对 437eb25 的评审,这一轮复审新提交 8bca19b(领任务时不再对整行 payload 排序;e2e 补了两条路由)。

代码

  • ClaimRunnerTask 加锁查询只取 id, attempt 两列来排序,ORDER BY created_at LIMIT 1 的排序行里不再带 payload。更新成功后再用 takeRunnerTask 按主键取整行,加锁和条件更新的语义没有变。
  • RunnerTasks 先按 created_at DESC 取前 200 个 id,再按 id IN 取整行,最后按 id 原顺序重新排好,返回顺序和以前一致。
  • runner_tasks 上的其他查询要么只选 id(HasQueuedRunnerTask),要么不排序,没有同样的风险。
  • 90-route-sweep 补了 GET /api/runners/tasks/:id/input-file 和 PUT /api/runners/tasks/:id/output-file,覆盖两种情况:没有会话时返回 401,有会话但任务不存在时返回 4xx。

部署实测(MySQL 8.4.7,sort_buffer_size 为默认的 256 KiB)

  • 在 437eb25 上复现:用旧执行机器 0.12.4 跑「必需 1 MiB + 可选 64 KiB」。上游节点成功,下游节点的输入会内联进任务 payload,领任务一直报 Error 1038 (HY001): Out of sort memory,运行卡住不动。这个场景我上一轮没测到。
  • 平台换成 8bca19b、执行机器不动:卡住的运行被自动领走,下游读到 1,048,576 字节,sha256 和生成的一致,批准后运行 succeeded,平台日志里不再出现 1038。
  • 回归:新执行机器 0.13.0 跑「必需 5 MiB + 可选 21 MiB」,sha256 一致,可选文件按超限被跳过,进入审批。GET /api/runners/tasks 返回 200。
  • 测试:新加的 TestMySQLRunnerTaskClaimWithLargePayload 在本 head 上通过;把这个测试放到 437eb25 上跑会失败(task list omitted large tasks),说明它能测出这个问题。./internal/repo 全部通过,其他 MySQL 领任务测试也都通过。
  • CI:当前 head 全部 16 项检查通过,包括 browser(路由覆盖率)、core 和 platform-required。

437eb25 那条评审里提到的阻塞问题(路由覆盖率不到 85%)已在这个 head 上解决。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

CR + 部署实测:实测通过,CI 全绿,可以合入(head 8bca19b5)

和上一轮 437eb25 相比,这个 head 新增了一个提交 8bca19b,修了两件事:

1. 修复:执行机器领取任务时报 MySQL 1038(部署实测中发现)

  • 现象:旧执行机器 0.12.4 以内联方式回传 1 MiB 文本产物时,下游任务把 1 MiB 内容内联进了 payload。ClaimRunnerTask 是带着整行 payload 做 ORDER BY created_at 的,这会撞上 MySQL 8.4 默认的 sort_buffer_size(256 KiB),报 Error 1038: Out of sort memory,执行机器一直领不到任务,运行卡住。领取路径在 main 上就有这个问题,这个 PR 支持大产物后才更容易触发。
  • 修法:ClaimRunnerTask 先只 SELECT id, attempt 排序取最早一条,再按 id 读整行。RunnerTasks() 列表也改为先按 created_at DESC 取 200 个 id,再用 id IN ? 读出整行,在 Go 里排好顺序。
  • 回归测试:TestMySQLRunnerTaskClaimWithLargePayload。两个排队任务各带 2 MiB prompt,要求列表能列出来,并且领到最早的那个,租约和 payload 都完整。修复前失败,修复后通过。
  • 实测:卡住的那次运行,在换上新二进制后被自动领取并跑完;旧执行机器回传 1 MiB 文本产物成功,下游 sha256 一致。

2. 修复 CI:路由覆盖率 84.9% < 85%

  • e2e/api/90-route-sweep.test.mjs 增加了对 GET /api/runners/tasks/:id/input-file 和 PUT /api/runners/tasks/:id/output-file 的访问:未登录时期望 401,已登录时访问不存在的任务期望 400/403/404/409。
  • CI 结果:e2e route coverage: 350/410 = 85.4%,16 项检查全部通过。

部署实测汇总(本机原生部署,MySQL 8.4.7;agent 节点用 CodeBuddy deepseek-v4.1-flash)

场景 结果
平台原生执行:64 KiB plan + 1 MiB 二进制 + 21 MiB 可选文件 可选文件被跳过并给出原因,下游 sha256 一致,agent 读到输入,审批后 succeeded
平台原生执行:正好 20 MiB / 20 MiB+1 20 MiB 成功;20 MiB+1 以「超过产物大小上限 20 MiB」失败,下游不启动
执行机器 0.13.0:20 MiB + agent 通过 input-file/output-file 接口传输,succeeded
旧执行机器 0.12.4:1 MiB+1 失败,并提示升级执行机器
旧执行机器 0.12.4:1 MiB 文本 修复前因 1038 卡住,修复后成功
main:同样的大产物 复现原问题:1406 报错后节点一直停在 running
未迁移的 TEXT 列 + 本 PR 二进制 节点以清楚的 1406 原因失败;042 连跑两次都成功,列变成 MEDIUMTEXT,重试节点后成功
e2e API 全套(本地,不配模型) 182 项:164 通过、0 失败、16 跳过,和 main 一致

已知问题(不阻塞)

  • 旧执行机器回传 1 MiB 随机二进制时,JSON 会把非法 UTF-8 展开,请求被以 400 拒绝,节点要等租约过期才结束。这是旧版执行机器原来就有的行为,升级到 0.13.0 就没有这个问题。
  • 迁移号:本 PR 用的是 042_run_artifacts_content_mediumtext.sql。main 上已经有两个 042,#1303 和 #1306 也用了 042,合入时请维护者统一调整编号。

@Robert0622
Robert0622 marked this pull request as ready for review November 24, 2026 20:33
crispinhu27
crispinhu27 previously approved these changes Nov 24, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审 head 8bca19b51a752a5eb2941487828687b522892a49(base main 7bebfa50)。上一份 APPROVE 6044721573 审的是 0b6a4430,之后作者推送新提交,那份 APPROVE 被 dismiss。本次审查范围是增量 0b6a4430..8bca19b5:

  • 437eb251:合并 main 7bebfa50
  • 8bca19b5:领取任务时不再按整行排序;e2e 补了两条路由

历史问题

  • [P2](下游提示词里 {{artifact.<节点>.<产物>}} 被替换成空串):在当前 head 上复测仍为 FIXED。TestDownstreamPromptRendersArtifactBody 的 inline 和 chunked 两个子用例都通过。

合并核对(437eb251)

  • 把 git diff c3dd1b4d 0b6a4430 和 git diff 7bebfa50 437eb251 的 +/- 行逐行比对,只有两处上下文不同,都是 main 那边带来的:
    • node_execute.go:stagingCheckout 复用前面已经取过的 runnerID/runner,和 main(#1284)语义一致。
    • runner/daemon.go:被替换的旧值从 RunnerVersionProjectCredentials 变成了 main 的 RunnerVersionGitPlainHTTP(0.12.4)。PR 用的 RunnerVersionArtifactTransfer(0.13.0)比它高,版本门槛不受影响。
  • PR 的净改动没有其他变化。

8bca19b5

  • ClaimRunnerTask 的加锁查询只选 id, attempt,加锁强度、条件更新、attempt+1 都没变,更新后再用 takeRunnerTask 按主键读整行。
  • RunnerTasks 先取 200 个 id,再按 id IN 读整行,并按原来的 created_at DESC 顺序重排。
  • runner_tasks 上没有其他对整行排序的查询。

验证(隔离环境,单独用户,最小环境变量,不含任何凭据;Go 1.26.11,MySQL 8.4.7 默认 sort_buffer_size=262144)

  • go build ./... 和 go vet(repo、engine、runner、httpapi、domain)通过。
  • TestMySQLRunnerTaskClaimWithLargePayload 对照:
    • head 上通过。
    • 把这个测试放到 437eb251 和 main 7bebfa50 上,两边都失败,RunnerTasks() 返回空列表。
    • 结论:1038 这个问题 main 上原来就有,这个提交修复了它。
  • 临时并发测试(没有推送):12 个 goroutine 同时领取 6 个 1 MiB payload 的任务。
    • head:没有 1038,没有重复领取,attempt=1,payload 完整,列表顺序为 DESC。
    • 437eb251:每次领取都报 Error 1038 (HY001): Out of sort memory。
    • 同一测试换成小 payload,在 main 和 head 上的表现一致:单次并发会有领取方暂时拿不到任务,这是 FOR UPDATE 原有的行为,不是本 PR 引入的。
  • MySQL 下 internal/repo 全量测试(head 和 main 各用一个新库):只有 TestMySQLGitSSHCredentialLifecycle、TestMySQLReadsObserveExternalChangesWithoutReload 失败,main 上也同样失败,没有新增失败。SQLite 下 internal/repo 全部通过,领取相关用例 -count=5 也通过。
  • internal/engine 的 TestNodeArtifactCommitFailure,以及在 MySQL 8.4.7 上跑的 TestMySQLNodeArtifactCommit,都通过。
  • internal/httpapi -run Runner 通过。
  • internal/runner 全量测试:head 和 main 的失败集合完全一致,只有 TestRunnerConversationWorkspaceCLIAuthentication 和 TestRunnerStartsPanelBrowserInRunSandbox 两个,都是本机环境原因(没有 Chromium 和 CLI 登录环境)。
  • CI 在 8bca19b5 上 16/16 通过,browser 的 e2e 路由覆盖率为 350/410 = 85.4%,达到 85% 门槛。

未验证

  • 容器不支持 bwrap,engine 和 runner 测试用的是只转发命令的替身。
  • 没有在真实 0.12.4 Runner 上跑端到端的大文件内联领取。
  • 没有在生产规模的 runner_tasks 上看查询计划和性能。

本次复审没有发现需要阻塞合并的问题,不代表代码一定没有缺陷。

Resolve conflicts with Tencent#1327 and Tencent#1323: runState reads the header and nodes through main's RunWithNodes, and the Runner reports 0.13.0 (artifact transfer), which also covers 0.12.5 privileged sandboxes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Resolve internal/runner/daemon.go: report Runner 0.13.0 (artifact
transfer), which is newer than main's 0.12.6 Docker sandbox limits gate.

Co-Authored-By: Claude Code <noreply@anthropic.com>
crispinhu27
crispinhu27 previously approved these changes Nov 25, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审结论:APPROVE(head 9b9b1976)

范围:上次 APPROVE(8bca19b5)之后只多了合并提交 9b9b1976,把 main cb78a499 合了进来。这次审查了合并结果,以及 main 在 7bebfa50..cb78a499 之间引入的改动和本 PR 逻辑之间的相互影响。

合并核对:PR 的净改动在合并前后一致,都是 49 个文件。合并前按 7bebfa50..8bca19b5 统计为 +2098/−287,合并后按 cb78a499..9b9b1976 统计为 +2097/−287。差异只有两处冲突解决,都合理:

  • internal/repo/runs.go 的 runState 改用 main 新增的 RunWithNodes,查不到或出错时仍返回 false,语义等价;
  • internal/runner/daemon.go 中 runnerVersion 的旧值换成了 main 的版本号,最终值仍是 RunnerVersionArtifactTransfer(0.13.0)。

迁移 042 号重复是 main 上原有的情况,compose 和 dev.sh 按文件名执行,不会因此出错。

隔离验证:使用隔离用户和合成数据,环境为 Go 1.26.11、MySQL 8.4.7,与 main cb78a499 对照。

  • go build ./...、go vet ./... 通过。
  • 六个包(domain/repo/runtime/runner/engine/httpapi)的失败集合与 main 一致,共有的 24 项是环境原因(Chromium、网络、沙箱配置)。另有 TestEnsureHostBrowserWithFakeChromium 在两边各偶发失败一次,单独重跑 25 次全部通过。
  • TestMySQLRunnerTaskClaimWithLargePayload 在 head 上通过;拷到 main 上跑会失败(task list omitted large tasks)。
  • TestDownstreamPromptRendersArtifactBody(历史 P2)通过,inline 和 chunked 两种方式都覆盖了。
  • TestMySQLNodeArtifactCommit、产物提交失败相关测试、TestStageArchivedArtifact*、TestArtifactBlobInterruptedUpload* 均通过。
  • TestSOPRunnerArtifactHandoff* 用转发型 bwrap 替身时通过,不代表验证了 bwrap 隔离本身。
  • scripts/test-install.py 结果与 main 一致。
  • 组合场景(临时测试,未提交):先让产物写入失败,再触发闲置回收,然后去掉故障并重试。SQLite 和 MySQL 各测 100 B 与 2 MiB 两种大小,4/4 通过,产物正文一致。
  • 真实平台升级:同一个 MySQL 库先起 main 平台、再起 head 平台,/api/health 都正常。042 连跑两次都成功,content 列变为 mediumtext。
  • CI 16/16 通过。

未覆盖:真实 bwrap/Docker 沙箱内的执行、compose 的 artifact-migration 容器、Runner 模式下的组合场景、-race。

需要作者处理:PR 目前和最新 main 11e75217(#1329)冲突,GitHub 显示不可合并。冲突只在 internal/runner/daemon.go 的 runnerVersion 一行:main 是 RunnerVersionDockerSandboxLimits(0.12.6),本 PR 是 RunnerVersionArtifactTransfer(0.13.0),应保留 0.13.0。我们按这个方式在本地模拟合并,go build ./... 通过,runner/engine/httpapi/domain 的 vet 和筛选测试也通过。作者合入 main、产生新 head 后,需要按复审再核对一次。

roberttwang and others added 2 commits November 25, 2026 10:39
Deliverables can now be 20 MiB, but the preview dialogs read the whole
body into the page and render it as text. A 20 MiB binary froze the run
page for about 34 seconds, and the download button re-encoded the
decoded text, so binary files were corrupted.

Show a download hint instead of a preview for binary types and files
above 5 MiB, and download the original bytes through the artifact URL.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The artifact response named every non-Markdown and non-JSON deliverable
.txt, so a binary file published by a SOP was saved as a text file. Name
it after the source path and fall back to the artifact name.

Co-Authored-By: Claude Code <noreply@anthropic.com>
roberttwang and others added 2 commits November 25, 2026 11:09
The preview dialog's download control became a link, which broke its
button role and the focus order the approvals queue test relies on. Keep
the button and download the original bytes from the artifact URL.

Co-Authored-By: Claude Code <noreply@anthropic.com>
A deliverable declared without a media type is stored as text/markdown,
so a small zip or other binary file was still rendered as garbage. Check
the body instead of the declared type: NUL bytes or a mostly undecodable
start show the download hint, while text types such as NDJSON keep
previewing.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

Fixes for the 00e49e77 reviews (head 07590d0c)

Both review findings are fixed. There are two commits on top of 00e49e77.

[P1] browser check failed because the download control was a link (f5085f6e)

  • In both the preview dialog and the download-only view, "⬇ 下载文件" is a <button> again. So e2e/ui/02-interactions.spec.mjs:199 (getByRole('button', { name: /下载文件/ })) and the Shift+Tab focus order work unchanged. The e2e test is not modified.
  • Clicking it creates a temporary <a download> on the artifact URL. The original bytes are downloaded, so the binary corruption fixed in ec7cdb3e does not come back. The file name is the last segment of the artifact path.
  • webtest asserts that the control is a BUTTON and that clicking it downloads /api/runs/:id/artifacts/:id as report.md / model.bin.

[P3] Binary content declared without mediaType was rendered as text (07590d0c)

  • The run page preview and the chatbot ArtifactPreview now decide from the body instead of the declared type. If it contains NUL bytes, or more than 10% of the first 64 KiB fails to decode, only the download hint is shown. Files over 5 MiB still are not fetched at all.
  • I did not change the server-side default (text/markdown when mediaType is empty, internal/engine/artifacts.go:318). The media type also decides the extension of the downstream input file (extensionFor). Inferring it from the path would move existing SOP inputs from .agentflow/inputs/<node>/<name>.md to .txt.
  • Tests: webtest covers an undeclared pkg.zip (download only, pkg.zip) and application/x-ndjson (still previewed). chatbot has a new case for a binary body declared as text/markdown.

Verification

Local deployment from this head: MySQL 8.4.7, native sandbox via a forwarding bwrap stand-in, Chromium.

  • The P3 reproduction: a node writes a 2 MiB random out/pkg.zip with no mediaType, plus notes.md and rows.ndjson.
    • pkg.zip shows "此文件不在页面内预览" ("this file is not previewed in the page") in about 0.3 s.
    • notes.md renders as Markdown and rows.ndjson shows its source.
  • Earlier artifacts: 1 MiB and 3 MiB text preview in 0.3–0.4 s; the 20 MiB binary shows the download hint.
  • Downloads: s1m.txt 1,048,576 B, s3m.txt 3,145,728 B and big.bin 20,971,520 B. All sha256 values match the platform metadata.
  • Playwright UI suite:
    • On f5085f6e: 24 passed, 2 skipped.
    • On 07590d0c: 23 passed, 2 skipped, 1 failed. The failure was personal credentials timing out on a click. It is unrelated to this change and passed on rerun.
  • webtest 292/292, chatbot vitest 496/496, check-public passed.
  • The 4 sandbox-dependent Go tests added by this PR pass with the bwrap stand-in, and so does TestArtifactFileNameKeepsTheDeliverableExtension.
  • Artifact scenarios from the previous round passed again on the fixed build, both locally and on Runner 0.13.0:
    • 10 B to 20 MiB handoffs, compared by sha256
    • over-limit required and optional artifacts
    • missing required artifact
    • rework
    • e2e/api/30-runs and 35-runner-mode

CI on 07590d0c: 16/16 passed. Trial merge with the latest main 1f10ccf7 (#1340): no conflicts; go build, go vet, webtest 292/292 and the artifact, handoff and credential-related Go tests pass.

The token belongs to the PR author, so this is a comment, not an approval. The pre-existing note on the duplicate migration number 042 is still for maintainers.

crispinhu27
crispinhu27 previously approved these changes Nov 25, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审 head 07590d0c(base main 11e75217)。上次 REQUEST CHANGES 6056422211 的 [P1] 已 FIXED,验证结果见原线程:f5085f6e 把下载控件改回 <button>,用产物 URL 下载原始字节,browser 在 07590d0c 上通过。

增量审查:07590d0c 把二进制判定改为按内容(含 NUL,或开头 64 KiB 里替换字符超过 10%),超过 5 MiB 只提供下载;chatbot ArtifactPreview 同步;字段与 domain.Artifact 的 JSON 一致。00e49e77 的 artifactFileName 仍走 %q 转义,没有头注入。

非阻塞观察:取消了按 mediaType 的提前短路,声明为二进制但小于 5 MiB 的产物仍会先整份 fetch 再判定,最坏约 5 MiB 文本解码,比 ec7cdb3e 略退,但远好于原先 20 MiB 整页渲染,可不阻塞。

验证:chatbot npm test 496/496、vite build 通过(在 07590d0c 上重跑);go test ./internal/httpapi -run 'Artifact|Deliverable' 通过;CI 16 项全绿。

未覆盖:没有在真实浏览器里手工测 20 MiB 二进制产物的交互,这部分依赖 webtest 与 CI 覆盖。

本次审查只覆盖上述 head,不代表代码没有缺陷。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

CR + 部署实测 07590d0c:LGTM,两条修复都生效

范围:00e49e77..07590d0c 有 2 个提交,改了 web/app/runs.js、chatbot/src/RichContent.jsx 和对应测试。

  • f5085f6e:「⬇ 下载文件」改回 <button type="button">,点击时临时建一个 <a download> 去拿产物 URL 的原始字节。
  • 07590d0c:去掉按 mediaType 判断能否预览的 artifactPreviewable。现在只有 >5 MiB 直接给下载;其余先取正文,含 NUL 或开头 64 KiB 里超过 10% 是 U+FFFD 的,就当二进制,只给下载。chatbot 端加了同样的 looksBinary。

单测(本机合入 main 1f10ccf7 后构建):chatbot 496/496,webtest 292/292。CI 16/16 通过。

部署实测:MySQL 8.4.7 全新库,native 沙箱。一个脚本节点产出 9 个交付物,用 Chromium 在运行页逐个打开预览,再点「下载文件」,拿下载到的文件和接口返回的字节比 sha256。

交付物 声明类型 页面表现 下载
zh.md 中文 + emoji,11 KB text/markdown 渲染预览,有「复制内容」,没有乱码 ✅ 文件名 zh.md,字节一致 ✅
plain.txt UTF-8 中文,13 KB 未声明(存成 text/markdown) 正常预览,没有误判成二进制 ✅ 一致 ✅
report.json 51 B application/json 源码预览 ✅ 一致 ✅
undeclared.bin 2 MiB 随机字节 未声明 只给下载,「此文件不在页面内预览」(上一轮的 P3 已修)✅ undeclared.bin,一致 ✅
noznul.bin 292 KB 不含 NUL 的随机字节 未声明 靠 U+FFFD 比例判成二进制,只给下载 ✅ 一致 ✅
data.bin 1 MiB application/octet-stream 只给下载 ✅ 一致 ✅
chart.png 6 KB image/png 只给下载 ✅ 一致 ✅
big.md 6.1 MB text/markdown 没请求正文,直接给下载 ✅ 一致 ✅
gbk.txt GBK 编码中文,8 KB 未声明 只给下载(见下面第 2 条) 一致 ✅

9 个下载控件都是 BUTTON type=button,页面没有 JS 报错。

不阻塞的建议(P3)

  1. 声明了二进制类型的小文件现在也会先整份拉下来再判断。00e49e77 里 application/octet-stream、image/png 这类按 mediaType 直接给下载,不请求正文;现在 ≤5 MiB 的都会 fetch + res.text() 一次。实测 data.bin(1 MiB)和 chart.png 打开预览时都多了一次产物请求,最坏情况每次打开要读 5 MiB。chatbot 端的 ArtifactPreview 仍然保留 readable 判断(按 mimeType,不拉二进制),两端不一致。建议 web 端也保留按类型的快速判断:明确不是文本的类型(image/*、application/octet-stream、zip、pdf 等)直接给下载,只对未声明或文本类型按内容嗅探。
  2. GBK 等非 UTF-8 的文本(未声明类型)会被判成二进制,只给下载,提示是「文件较大或为二进制内容」,而这个文件只有 8 KB。00e49e77 上这类文件会直接显示乱码,现在只给下载其实更好,只是提示文字有点误导,可以改成「无法按文本显示,请下载后查看」之类。

结论:LGTM,可以合。token 是作者本人的账号,只评论,不点 Approve。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

关于 #issuecomment-7162195208 的两条 P3:本 PR 先不改,合入后另提 PR 处理。

  • 两条都核对过,属实,但都不影响正确性。第 1 条是 ≤5 MiB 的二进制类型产物打开预览时会多读一次正文,两端判断方式也不一致。第 2 条是 GBK 文本会被当成二进制处理,只给下载,提示文字有误导。下载出来的字节和文件名都是对的,实测 9 种交付物全部一致。
  • 现在推新提交会让 crispinhu27 刚给的 APPROVED 失效,PR 又得等重新批准,为了两条 P3 不划算。
  • 后续 PR 的改法:web 端恢复按类型的快速判断,明确不是文本的类型(image/*、application/octet-stream、zip、pdf 等)直接给下载,只对未声明类型或文本类型按内容判断,和 chatbot 的 ArtifactPreview 保持一致;提示改成「无法按文本显示,请下载后查看」,大文件仍提示「文件较大」。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

本轮增量(07590d0c..967edee)

只审新增提交 967edee1:nodeFailedAt 把终态写入包成 storeFailure,用 updateRunErr 写,遇到 MySQL 1213 重试(最多再试 2 次,退避 5ms/10ms),每次重试前重置 shouldReject;单测新增 TestNodeArtifactCommitFailureRetriesTerminalDeadlock(注入一次 1213)。

CR 结论

思路对:每次重试都经过 updateRunAtErr 重新加载 run,租约/代际/attempt 校验仍然生效;只重试 1213,不做无限重试;shouldReject 每轮先清零,成功后才决定打回,避免用被回滚那一轮的中间状态。没有阻塞问题。

P3:

  1. internal/engine/node_outcome.go:88-99:1213 重试全部用尽后直接 return,该节点既没落 failed 也没落 pending,run 会一直停在 running,只能等租约过期后的恢复流程兜底。SUPERSEDE 前的行为同样如此,不算回归,但如果想「失败也要有终态」,可以在放弃重试时打一条 node.failed 级别的日志或事件,方便定位。
  2. 重试参数和仓库里已有的 internal/repo/dbtime.go:63 retryBotDeadlock 不一致(那里 6 次、5–160ms)。同一种 deadlock 处理出现两套预算,后续容易各改各的,建议复用或抽出公共 helper。

部署实测

  • 环境:本机 MariaDB 11.8,平台 127.0.0.1:18101(本 PR 分支独立编译,未对 Tencent/LoopForge 做操作)。
  • 单测:go test ./internal/engine -run TestNodeArtifactCommit -v 两条全过(首次在容器里因缺 bwrap 失败,装测试替身后通过)。
  • 失败节点常规路径:仅有 exit 7 的脚本节点,run 3s 内落到 failed,节点 attempt=1、错误 Run: exit status 7,无重复失败事件。
  • 1213 注入(在 run_nodes 上加 BEFORE UPDATE 触发器,status='failed' 时 SIGNAL 1213,模拟死锁牺牲者):
    • 只注入一次时:平台日志 put run ...: run_nodes write: Error 1213 (40001) 出现 3 次 = 首写 + 2 次重试,随后正常收敛;
    • 持续注入(每次都 1213):run 停在 running、节点停在 running,符合上面的 P3-1,没有出现半写状态或重复事件。
    • 注:触发器里的计数写入会被同一条 SIGNAL 回滚,所以「只注入一次」需要把计数放到不回滚的表里;这不影响结论,只是复现时注意。

复现脚本:files/loopforge-pr-review-robert0622-1125-2100/inject-deadlock.mjs。


loopforge-pr-review:967edee1

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审 a85d6d3c(上一次 APPROVE 是在 07590d0c,之后被新推送撤销):REQUEST_CHANGES,1 条 P2,见行内评论。

审查范围

  • 967edee1:nodeFailedAt 在 MySQL 死锁(1213)时重试写入 failed 状态,并补了测试。
  • 7e94be25:合入 main 058a530b,internal/engine/run_recovery.go 和 internal/repo/runs.go 的冲突处理已核对:保留了 main 的 promoteQueuedRuns(),persistRun 末尾调用 writeRunArtifacts。
  • a85d6d3c:只改了 scripts/test-install.py 的测试夹具。
  • node_outcome.go 在 967edee1 和 a85d6d3c 之间没有变化。

已验证、没有问题的部分

  • 死锁重试本身有效。
    • 在真实 MySQL 8.4.7 上,用两个事务按相反顺序加锁,造出真实的 Error 1213:967edee1 上节点正确变为 failed,node.failed 事件只有 1 条,连续 3 次通过;07590d0c 上节点卡在 running。
    • 每次重试都会重新读取 run,lease、generation 和 attempt 的检查都会重新做。errors.As 能拿到 *mysql.MySQLError。连续注入两次 1213 后,事件和 run_events 都只有 1 条,没有重复副作用。
  • 新测试 TestNodeArtifactCommitFailureRetriesTerminalDeadlock 在 a85d6d3c 通过;放到 07590d0c 上会失败,说明它确实测到了这次修复。
  • go build ./... 和 go vet ./internal/engine/... 通过。internal/engine、internal/repo、internal/httpapi 全量测试的失败集合与 07590d0c 一致,只有缺 Chromium 和 git 全局身份导致的 5 个环境失败。

验证说明:容器里没有可用的 bwrap,engine 测试是用一个只用于审查的假 bwrap(不做隔离、直接执行命令)跑的,两个版本条件相同。

非阻塞观察(不要求在本 PR 处理)

  • 如果 3 次都撞上 1213,节点仍会停在 running。
  • waitApproval 的写入仍然忽略错误。
  • updateRunAtErr 在 PutRun 失败时不会把已取出的 pending telemetry 放回队列。死锁重试后 node.commit.failed 这条 telemetry 会丢失(5/5 复现);07590d0c 也同样会丢,不是本次引入的。

Comment thread internal/engine/node_outcome.go Resolved
roberttwang and others added 2 commits November 25, 2026 14:07
Only a lost or held run lease skips the auto-reject now. Other write
errors (lock wait timeout, transient store failures, an exhausted
deadlock budget) still call Reject, which reloads the run and resets the
node with its upstream, so the run no longer hangs in running with
nobody executing the node. Deadlock retries reuse the repo's
six-attempt RetryDeadlock budget.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

修复 + 部署实测:4cadb274(基于 a85d6d3c:975355fe 是本会话的修复,4cadb274 是作者在其上的补充)

处理 crispinhu27 的 [P2]:非 1213 的写入错误跳过了自动打回,run 一直卡在 running。

  • nodeFailedAt:只有 lease 丢失或被别的实例持有时才返回;其他写入失败继续调用 Reject。Reject 会重新读 run,把本节点和上游一起重置。
  • 1213 用 repo.RetryDeadlock(6 次,5–160ms),1205 再多重试一轮。Reject 带 NodeExpectation,节点已经变了就不打回。

部署实测(本机平台 + MariaDB 11.8 新库,合成数据,没有对 Tencent/LoopForge 做部署测试)。工作流是 repair(script) → verify(script,第一次 exit 3,rejectTo: repair)。在 run_nodes 上加 BEFORE INSERT/UPDATE 触发器,verify 写 status=failed 时用 SIGNAL 注入错误,次数由一张不随事务回滚的 Aria 表控制:

场景 注入 4cadb274 a85d6d3c(对照)
正常打回 无 succeeded,repair rework=1 succeeded
锁等待超时 1205 ×1 succeeded,rework=1 running 卡住(45s 超时)
其他 DB 错误 1105 ×1 succeeded,rework=1 running 卡住
死锁一次 1213 ×1 succeeded succeeded
死锁用尽重试 1213 ×6(实际命中 6 次) succeeded,rework=1 running 卡住(只重试 3 次)
无 rejectTo 正常失败 无 failed(exit 4) failed
无 rejectTo + 1205 ×1 1205 ×1 failed(第二轮重试写成功) running 卡住
  • 单测:TestNodeFailureWriteErrorKeepsAutoReject(3 个子例)、TestNodeArtifactCommitFailure*(含作者新增的 1205 用例)全过。go test ./internal/engine/... ./internal/repo/... ./internal/httpapi/... 只失败 5 个环境用例(缺 Chromium、git 全局身份),a85d6d3c 上是同样 5 个。
  • e2e:API 166 过、0 失败、16 跳过。UI 24 过,失败 2 个,a85d6d3c 以外的其他分支(main 系的 test: repair main platform CI for Runner selection and run evaluation #1345、Rename SOP to LOOP across LoopForge #1286)本机也是这 2 个:会话改名是 MariaDB 不支持 CAST(... AS JSON) 返回 500;凭据向导用例在负载下超时,单独重跑能过。CI 上用的是 MySQL,browser 作业已经通过。

仍然存在(之前就有,不阻塞):节点没有 rejectTo、并且 1213 连续 6 次以上都失败时,节点还是会停在 running,a85d6d3c 上也一样。

CI:除 core 还在跑,其余都过了。需要 crispinhu27 重新审一下。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

CR + 部署实测 4cadb274:LGTM,crispinhu27 在 a85d6d3c 上提的 P2 已修复

范围:上次 LGTM 的是 967edee1,这次看 967edee1..4cadb274:

  • 04e06a4d:已知是二进制的产物不再拉取预览
  • 7e94be25:合入 main 058a530b
  • a85d6d3c:调整安装脚本的测试夹具
  • 975355fe:修复会话提交
  • 4cadb274:作者提交

[P2] 写入失败节点终态时,如果不是 1213 错误就直接 return,跳过了自动打回 → 已修复

  • 先在 a85d6d3c 上独立复现了这个问题。用的是一个只在本地用的临时测试(没有提交):工作流是 repair(script) → verify(mock [[mock:gate=rework,pass]],RejectTo: repair),用 gorm callback 让 verify 写 failed 时报错。结果见下表。
  • 修复读下来没问题:
    • 现在只有 ErrRunLeaseLost、ErrRunLeaseHeld 时才 return。这两种情况下 run 已经不归本 worker 管,直接返回是对的。其他错误都会继续自动打回。
    • 1213 改成用 repo.RetryDeadlock 重试(6 次,退避 5–160ms),和 retryBotDeadlock 用的是同一套预算,上一轮我提的 P3-2 也一起解决了。1205 会再额外重试一轮。
    • Reject 带上了 NodeExpectation:写入成功时期望节点状态是 failed,写入失败时期望是写入前的状态(running)。这样如果这段时间里有别的操作改了这个节点,就不会被误打回。
    • updateRunAtErr 在 PutRun 遇到 1205/1213 时,把已经取出来的 pending telemetry 放回队列最前面。crispinhu27 提到 node.commit.failed 会丢,这里也修了,新单测检查了这条只出现 1 次。
注入的写入错误 a85d6d3c 07590d0c(合入前) 4cadb274
1205 ×1 ❌ 15s 内没结束,run/verify 一直 running ✅ succeeded,rework=1 ✅ succeeded,rework=1
普通 error ×1 ❌ 同上 ✅ ✅
1213 ×3(超过 a85 的重试预算) ❌ 同上 ✅ ✅
1213 ×7 / ×20(超过 6 次预算) — — ✅ 重试 6 次后仍然打回,succeeded
1205 ×20 — — ✅ 重试 2 次后打回,succeeded
ErrRunLeaseLost — — ✅ 不打回(rework=0),等租约恢复流程接管
1213 ×1 ✅ ✅ ✅

单测(4cadb274)

  • TestNodeFailureWriteErrorKeepsAutoReject 3 个子用例、TestNodeArtifactCommit* 3 条(包括新增的 1205 用例)全部通过。上表的临时复现测试 8 个子用例也全部通过。
  • go vet ./internal/engine ./internal/repo 通过。chatbot 533/533 通过(a85d6d3c 之后没有改过 chatbot)。
  • go test ./internal/engine ./internal/repo ./internal/httpapi:repo 全部通过。engine 和 httpapi 共有 5 条失败,都是本机环境问题:3 条是 Chromium 沙箱不可用,2 条是本机注入的 git 作者身份覆盖了测试里设置的身份。这 5 条和 975355fe 上失败的完全一样,crispinhu27 在 07590d0c 上也报过同样的环境失败。发评论时 CI 只剩 core 还在跑,其余检查都已通过。

部署实测(本机 MariaDB 11.8 全新库,用 4cadb274 构建平台,native 沙箱,用真实的 MariaDB 触发器注入错误:在 run_nodes 上建 BEFORE INSERT 触发器,node_id='verify' AND status='failed' 时 SIGNAL ... MYSQL_ERRNO=<n>,注入次数存在 MyISAM 计数表里,这样计数不会跟着事务回滚。没有对 Tencent/LoopForge 做部署实测)

工作流是 repair(shell) → verify(shell,第一次 exit 3,第二次通过,rejectTo: repair,maxReworks: 2):

场景 结果
1205 ×1 run succeeded,2s;repair rework=1,verify attempt=2 ✅
1105(普通错误)×1 succeeded,rework=1 ✅
1213 ×1 succeeded,rework=1 ✅
1213 ×10 succeeded,rework=1,用掉 6 次注入(剩 4 次)✅
没有 rejectTo 的节点 + 1205 ×1 重试后正常落到 failed ✅
没有 rejectTo 的节点 + 1105 ×1 节点和 run 一直停在 running(见下面的非阻塞项)
真实模型:上面的工作流后面接一个 Agent 节点 report(Cursor CLI grok-4.7 effort high,必须产出 report.md),注入 1205 ×1 46s 后 succeeded;打回后 repair 跑了 2 次,模型写出的 report.md 内容是 # Report / repair.log has 2 lines,和实际一致。run_artifacts 写进了 report(32 B),通过产物接口下载到的内容一样 ✅

非阻塞(以前就有,不是本 PR 引入的):节点没有配置 rejectTo,写 failed 又遇到不能重试的错误(比如 1105)时,节点会一直停在 running,只能等租约过期后由恢复流程处理。合入前的 07590d0c 也是这样。真想消除这种情况,可以以后单独处理。

结论:LGTM。推送后 crispinhu27 的 REQUEST_CHANGES 需要他复核后解除,并由非作者重新批准。token 是作者本人的账号,所以只评论,不点 Approve。

复现测试、部署脚本和日志在评审会话的归档目录里,没有往仓库推任何东西。

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

复审 head 4cadb274(base main 058a530b,a85d6d3c 上的 REQUEST_CHANGES 6058871172 之后的增量是 975355fe、4cadb274)。结论:APPROVE。

历史问题

  • [P2] 非死锁写入错误时跳过自动打回、run 卡在 running:FIXED,已在 head 上实测,证据见原线程。

增量审查(node_outcome.go、run_state.go、repo/dbtime.go 和测试)

  • 重试有上限:RetryDeadlock 每轮最多 6 次带退避,1205 只多加一轮。
  • 每次重试都会重新读取 run,并重新检查 lease、generation 和 attempt。
  • lease 丢失或被别的实例持有时仍然直接返回,不会打回。
  • 打回前会检查节点的状态、attempt 和返工次数,不会重复打回,也不会打回过期的节点。
  • 1205 / 1213 回滚后,会把待写的 telemetry 放回队列,不会重复记录。
  • RetryDeadlock 和原来的 retryBotDeadlock 行为一致。

验证(隔离环境,合成数据,执行 PR 代码时没有 GitHub 凭据)

  • go build ./... 通过;go vet 对 engine / repo / httpapi / runner / runtime 通过。
  • 在 head 和 base 上用相同条件跑测试,对比失败的用例:
    • internal/engine:两边都是同样 3 个,原因是缺 Chromium 和 git 全局身份。
    • internal/repo:两边都没有失败。
    • internal/httpapi:两边都是同样 2 个浏览器用例。
    • 接 MySQL 8.4.7 跑:internal/repo 两边都是同样 6 个,TestMySQLNodeArtifactCommit 在 head 上通过。
    • 说明:main 058a530b 的 engine 测试本身编译不过(sop_executors_test.go 用的是旧签名),对照时在本地临时补了参数。
  • CI:16/16 通过。
  • 容器里没有 bwrap,engine 测试是用只用于审查的假 bwrap(不做隔离)跑的,head 和 base 条件相同。

非阻塞观察(07590d0c / base 上同样存在,不是本 PR 引入的,不要求在本 PR 处理)

  • 锁等待超过重试和 Reject 自身写入的总时长时,节点仍会停在 running。真实 MySQL 上锁住 6 秒时,head 和 07590d0c 都会这样。
  • 没有 RejectTo 的节点、重试分支和等待审批分支,遇到持续的非 1205/1213 写入错误时,仍会停在 running。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

叠合并实测:#1332 合入后,本 PR 会和它冲突(解法已验证)

本轮所有 Robert0622 的 PR 都没有新提交,各自对 main 058a530b 都是 mergeable、CI 全绿。这次补的是PR 之间的检查:在 main 上按顺序叠合并 #1345 → #1332 → #1223 → #1301,结果:

组合 结果
#1345 / #1332 / #1223 两两组合 无冲突
#1301 + #1332 冲突:internal/httpapi/runs.go、chatbot/src/RichContent.jsx
#1286 + #1332 / #1223 冲突 6 处(App.jsx、ArtifactPanel.jsx、SopRunPanel.jsx、web/app/runs.js、conversation_workspace.go、sop_idle_reclaim_test.go),按原计划最后合

建议合并顺序:#1345 → #1332 → #1223 → #1301(合 main 解冲突)→ #1286。#1301 本身还挂着 REQUEST_CHANGES、需要重新批准,让它来解冲突,就不会让 #1332 已经拿到的批准失效。

冲突解法(两边都保留)

验证(叠合并栈 = main + #1345 + #1332 + #1223 + #1301,本机 MariaDB 11.8,native 沙箱,没有对 Tencent/LoopForge 做部署实测)

  • go build、go vet、chatbot vitest 538/538、webtest 306/306、check-public 全部通过。
  • go test ./...:在干净的 git 环境下重跑失败用例,栈上剩 9 条,和 main+test: repair main platform CI for Runner selection and run evaluation #1345 上失败的完全是同样 9 条(Chromium 沙箱、bwrap、sd_notify 这类本机环境问题)。
  • e2e:API 187 条,169 过 / 0 失败 / 16 跳过;UI 25 过、1 失败(会话改名,是 main 上就有的 MariaDB CAST('true' AS JSON) 问题,CI 用 MySQL 不会出现)、2 跳过;路由覆盖 357/418 = 85.4%。
  • 产物下载(9 种产物):字节 sha256 和 Content-Length 都对得上;text/* 带 charset,octet-stream/png 不带;每个产物都有 CSP sandbox;中文名下载为 filename*=utf-8''%E4%B8%AD…说明.md;.bin/.png 扩展名保留;直接打开 page.html 时脚本不运行,localStorage 会报 SecurityError。
  • 审阅页产物侧栏(Chromium):zh.md 渲染成 Markdown,JSON 格式化显示,CSV 显示成表格;GBK 文本和未声明类型的 .bin 都提示「此类型文件可通过右上角下载查看」,不会显示成「文件为空」;octet-stream 和 6.3 MB 的 big.md 不会去拉取(后者提示「文件较大」);HTML 放在 sandbox="allow-scripts" 的 iframe 里;PNG 正常显示;页面没有报错;点「通过并继续」后运行 succeeded。
  • Prevent SOP runs from hanging after artifact write failures #1301 写入失败注入(run_nodes 触发器):1205×1、1105×1、1213×1、1213×6 都能正常打回并 succeeded(rework=1);没有配置打回的节点(无注入,或 1205×1)正常落到 failed。
  • 真实模型(Cursor CLI grok-4.7、effort high):Agent 节点 36s 写出 summary.md(内容 # 周报 / 编号:CODE-5521),在审阅侧栏里按 Markdown 预览;在节点会话里问编号,27s 答出 CODE-5521,运行仍停在人工审核;批准后 succeeded。
大文件不拉取 GBK 提示下载 Markdown 预览 节点会话(grok-4.7)

这次没有往本分支推提交:现在推只能把 #1332 整个带进来。等 #1332 合入后,git merge origin/main,两个冲突文件按上面的方法解决,再改一下 run_artifact_name_test.go 里的调用就行。合并结果已经在本地模拟过,和上面实测的栈逐字节一致。

@Robert0622
Robert0622 merged commit 6f3f0b8 into Tencent:main Nov 25, 2026
16 checks passed
Robert0622 pushed a commit that referenced this pull request Nov 25, 2026
Resolve conflicts with #1301 (artifact streaming):
- internal/httpapi/runs.go: stream the artifact body from OpenArtifactContent
  with charset only for text/*, keep this branch's CSP sandbox header and
  RFC 2231 Content-Disposition via runArtifactFilename (artifact name + source
  extension). Main's artifactFileName test now exercises runArtifactFilename;
  every main case keeps the same expected file name.
- chatbot/src/RichContent.jsx: keep this branch's loaded-state preview and add
  main's 5 MiB oversized guard and binary detection.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Robert0622 pushed a commit that referenced this pull request Nov 25, 2026
Four user-visible errors that arrived with main (#1342 work branch naming,
#1343/#1348 runner auto-assign, #1301 child artifacts) still said SOP.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Robert0622 added a commit that referenced this pull request Nov 26, 2026
* feat: rename SOP to LOOP across LoopForge

* Apply LOOP terminology to copy merged from main and fix CHANGELOG anchor

Rename the user-visible SOP copy that main added for the enterprise IM
channels, observability dashboard and docs, following the same rules as
the rest of this branch (routes, JSON fields and identifiers unchanged).

Keep accepting the old wording where it can still arrive: notification
cards skip both LOOP and SOP header lines, chat drafts recognise both
(LOOP:…) and (SOP:…) notes, and the clarification command accepts
"保存并启动 LOOP" as well as "保存并启动 SOP".

Point the CHANGELOG link at #updating-existing-public-loops.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Renumber the LOOP terminology migration to 043 and re-apply the rename to main's new copy

main added 042_project_credentials.sql and 042_skill_bodies_to_files.sql,
so the terminology migration becomes 043_loop_terminology.sql; the
installer, its test and the deployment guide follow.

Rename the user-visible SOP copy from #1264, #1294, #1295, #1296 and
#1298 (project roles, join requests, project credentials, workspace
preview messages) with the same rules as the rest of the branch.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Restore the legacy (SOP:…) draft note check clobbered by the rename sweep

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(chatbot): recognize proposal receipts saved before the LOOP rename

Conversations saved before the rename still hold the SOP wording of the
declined and timed-out proposal receipts. The chat matched only the new
LOOP text, so these internal resume turns showed up as user messages.
Accept both wordings.

Rooms also parse LOOP「…」 authors with the correct length and keep
recognizing legacy SOP「…」 authors.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Apply LOOP terminology to the chat attribution copy merged from main

#1300 added a clarification test that expects the bot reply "已启动 SOP" and a comment that says "a SOP started". This branch already renders "已启动 LOOP", so the test failed after merging main.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Resume paused children marked before the LOOP rename

The child-resume marker merged from #1327 now reads "等待继续子 LOOP". A parent paused on a build that stored "等待继续子 SOP" still resumes its child after admission.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* test: cover run evaluation before approval

* test: exercise five previously uncovered platform routes

* fix: translate LOOP evaluation and runner allocation messages

* fix(engine): name LOOP in the remaining auto-assign errors

The default-executor fallback label and the no-compatible-sandbox
error still said SOP after the main merge.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix: name LOOP in errors merged from main

Four user-visible errors that arrived with main (#1342 work branch naming,
#1343/#1348 runner auto-assign, #1301 child artifacts) still said SOP.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(migrations): preserve customized LOOP template copy

* test(install): copy migration 043 into the live install fixture

install-schema-extensions.sh now replays migrations/043_loop_terminology.sql,
but test-install-live.sh only copied 001/033/038/042 into its trimmed
fixture, so every live install identity stopped at the first install with
'cat: migrations/043_loop_terminology.sql: No such file or directory'.

Copy 043 as well, and add a test-install.py check that every migration the
installer replays is in the live fixture's copy list, so CI catches the
next one.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Name LOOP in comments and test copy merged from main

The merge of main kept the product copy for requirements without a LOOP,
but comments, test fixtures and failure messages around #1411's sopMode
still said SOP. Use the LOOP terminology there too; protocol values such as
sopMode none/sop and Go identifiers keep their names.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: roberttwang <roberttwang@tencent.com>
Co-authored-by: roberttwang <u_dc6754cd1ee5@users.noreply.local>
Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: Codex <codex@users.noreply.github.com>
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.

3 participants