Skip to content

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

Open
Robert0622 wants to merge 9 commits into
Tencent:mainfrom
Robert0622:codex/fix-sop-artifact-terminal-write
Open

Robert0622 wants to merge 9 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 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 上看查询计划和性能。

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

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