feat: 文档/图片工具进任务镜像 + 结果截断从截断 JSON 改为提取 text 上限 20000 字

This commit is contained in:
host committed 2026-10-30 02:03:14 +08:00
1 parent 9ac0199eba
commit c1d25d11b1
4 files changed
+93 -13

No files matched your search

+12 -4
View File
@@ -714,7 +714,8 @@ class Worker:
"""pick_next 的输入:只取 queued/completed/merged 三类任务。
旧实现是 SELECT * 全表:prompt/result_text/error_text
(后两者各可达 4000 字)全量进内存,且每轮 poll 都来一次;
(result_text 可达 21000 字、error_text 可达 4000 字)
全量进内存,且每轮 poll 都来一次;
任务表随时间变大后这是纯浪费。pick_next 只需要 queued
任务和已完成 id(依赖判断),running/failed/interrupted
的任务对它既不是就绪、也不是已完成,排除它们不影响结果。
@@ -1467,7 +1468,7 @@ class Worker:
" turn_id = COALESCE(?, turn_id),"
" root_turn_id = COALESCE(?, root_turn_id),"
" updated_at = ? WHERE id = ?" + status_clause,
((result_text or "")[:4000] if result_text else None,
((result_text or "")[:21000] if result_text else None,
(error_text or "")[:4000] if error_text else None,
actual_model, started_at, finished_at,
turn_id, root_turn_id,
@@ -1481,7 +1482,7 @@ class Worker:
" turn_id = COALESCE(?, turn_id),"
" root_turn_id = COALESCE(?, root_turn_id),"
" updated_at = ? WHERE id = ?" + status_clause,
((result_text or "")[:4000] if result_text else None,
((result_text or "")[:21000] if result_text else None,
(error_text or "")[:4000] if error_text else None,
actual_model, started_at, finished_at, child_pid,
turn_id, root_turn_id,
@@ -3893,7 +3894,8 @@ class Worker:
超时用统一的超时文本;runner 异常用异常文本;同步路径的
stdout 是 host.py 的 JSON 时取它的 text 字段(比整段 JSON
可读);最后退到 host_status token 或通用文本。绝不返回
可读),执行器已提取出 text 时直接用该文本;最后退到
host_status token 或通用文本。绝不返回
任何密钥(stdout 里本就不应含密钥,text 字段同样不含)。
"""
if result is not None and result.get("status") == "timeout":
@@ -3922,6 +3924,12 @@ class Worker:
stderr = (result or {}).get("stderr", "") or ""
if not stdout.strip() and stderr.strip():
return stderr.strip()[-1000:]
# 执行器现在返回的是解析出的 text(不再是整段 JSON):
# JSON 解析失败且 stdout 非空时,stdout 本身就是报错
# 文本,绝不能丢掉它退到 host_status=404 这种代号
# (2026-10-30 全量因此丢了 "primary 404 boom")。
if stdout.strip():
return stdout.strip()[:1000]
if token is not None:
return "host_status=%s" % token
return stdout.strip() or "host execution failed"