Repository navigation
Conversation
runner 每 3 秒 claim 一次,查询是「status=queued + provider IN (...),
ORDER BY created_at LIMIT 1」,而 gorm 的 Find(&rows) 会把 payload 一起选出来。
payload 是 Task 的完整调用载荷(上游产物契约、提示词),reviewer/deliverer 这类
节点动辄 300 KB 以上;MySQL 的 filesort 会把所选列放进排序缓冲,超过默认
sort_buffer_size(256 KB)就整条 claim 失败:
Error 1038 (HY001): Out of sort memory, consider increasing server sort buffer size
runner 只是每 3 秒重试一次,平台侧看不到任何错误,run 就永久停在那个节点上
(本次实测卡了 24 分钟)。
- claim 查询改成 Select("id","attempt"):排序记录只有 id + attempt + 排序键,
行大小与 payload 无关;锁定的行不变,随后的 takeRunnerTask 仍按 id 读整行。
- 新增 MySQL 回归测试:payload 撑到 360 KB、会话 sort_buffer_size 压到 256 KB,
断言 claim 成功并完整取回 payload。该用例在未改动的 main 上稳定复现
`Error 1038`,改后通过。
pemila
force-pushed
the
fix/runner-claim-sort-buffer
branch
from
November 23, 2026 10:06
601b127 to
d2139d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
现象
SOP 的
review节点下发后,run 停在review = running,24 分钟没有任何进展,页面上看不到错误。执行机器日志(每 3 秒一条):同一时刻队列里:
根因
RunnersRepo.ClaimRunnerTask的领取查询:payload是任务的完整调用载荷(提示词、上游产物契约、资产绑定),reviewer/deliverer 这类节点天然就是几百 KB;ORDER BY created_at走 filesort,MySQL 会把所选列一起放进排序缓冲;sort_buffer_size = 256 KB,一条 298,965 字节的排队任务就让整个 claim 语句报Error 1038。于是 runner 每 3 秒重试、每 3 秒失败,任务永远领不到;平台侧只看到"已下发",run 就永久挂在那个节点(本次 24 分钟,靠人工重启 platform 才救回来),也没有任何可见的错误提示。
改动
锁定的行不变,
rows[0].Attempt仍用于乐观递增,随后takeRunnerTask(tx, taskID)照旧按 id 读整行,所以行为等价,只是排序记录与 payload 大小解耦。(运维侧临时缓解是
SET GLOBAL sort_buffer_size=8M并重连,但那只是把阈值推高,payload 再长仍会踩到;窄投影才是根治。)验证
新增
internal/repo/runner_claim_mysql_test.go(MySQL 专用,AGENTFLOW_RUNNER_CLAIM_TEST_DSN开启,默认 skip):sort_buffer_size = 262144(默认值);ClaimRunnerTask成功,并完整取回 payload。结果(本机 MySQL 8.4):
claim failed on a large queued payload: Error 1038 (HY001): Out of sort memory—— 稳定复现;GOOS=linux go vet ./internal/repo/通过,go test ./internal/repo/ -run "RunnerTask|Claim|Runner"18 个用例通过。备注
顺带说明为什么只有这次踩到:payload 大小随上游产物增长,之前几轮 review 的 payload 在 180–294 KB 之间,勉强低于/贴近阈值;这次上游
design.md变成 ~100 KB(含 v2 存档与 gate 结果)后越过了 256 KB 的排序缓冲。