feat(tasks): 完整结果另存 result_text_full,详情不再只剩 2000 字

旧链路三层截断:sandbox stdout 截 2000 字、worker 写回截
4000 字,长答案尾部在详情里永远查不到(只把上限调大是
把截断点后移,不是修掉)。修法:截断版保持不变(列表/
摘要用),完整版另存:
- sandbox _result_from_runner/_parse_host_result(local 与
  docker dispatch 路)回包新增 stdout_full(上限 200000 字,
  只防无界增长);goal 路结论在尾部、tail 已保结论,不动。
- worker _write_execution_result 新增 result_text_full 列
  (_ensure_result_columns + server migrate_tasks_table 幂等
  补列),终局与取消分支均透传 stdout_full。
- server:任务 dict 加 result_full_available(不直接塞全文
  进列表负载),新增 GET /tasks/{id}/result-full(read 权限
  同款校验,无完整版时 404,不回摘要冒充完整)。
单测:test_queue_sandbox 45 项(含新增 stdout_full 1 项)、
test_marker_tools 30 项。
This commit is contained in:
host committed 2026-10-30 02:45:51 +08:00
1 parent 276d433da6
commit 92b7f8e8ff
4 files changed
+71 -6

No files matched your search

+18 -6
View File
@@ -1345,7 +1345,8 @@ class Worker:
except Exception:
return
for name, coltype in {
"result_text": "TEXT", "error_text": "TEXT",
"result_text": "TEXT", "result_text_full": "TEXT",
"error_text": "TEXT",
"actual_model": "TEXT", "started_at": "REAL",
"finished_at": "REAL", "child_pid": "INTEGER",
"executor": "TEXT", "pr_url": "TEXT",
@@ -1439,7 +1440,11 @@ class Worker:
error_text=None, actual_model=None,
started_at=None, finished_at=None,
child_pid=None, turn_id=None,
root_turn_id=None, only_if_status=None):
root_turn_id=None, only_if_status=None,
result_full=None):
# result_full:完整 stdout(dispatch/docker 路由 sandbox
# 的 stdout_full);截断版 result_text 保持 4000 不变作
# 摘要,完整版另存 result_text_full 供详情/端点取。
"""把执行结果写进 tasks 新列;老库缺列时先迁移再写。
turn_id/root_turn_id 只在新值非空时覆盖:某轮没产出
@@ -1461,14 +1466,17 @@ class Worker:
if only_if_status is not None:
status_clause = " AND status = ?"
extra = (only_if_status,)
full = (result_full[:200000] if result_full else None)
if child_pid is None:
cur = conn.execute(
"UPDATE tasks SET result_text = ?, error_text = ?,"
"UPDATE tasks SET result_text = ?,"
" result_text_full = ?, error_text = ?,"
" actual_model = ?, started_at = ?, finished_at = ?,"
" turn_id = COALESCE(?, turn_id),"
" root_turn_id = COALESCE(?, root_turn_id),"
" updated_at = ? WHERE id = ?" + status_clause,
((result_text or "")[:21000] if result_text else None,
full,
(error_text or "")[:4000] if error_text else None,
actual_model, started_at, finished_at,
turn_id, root_turn_id,
@@ -1476,13 +1484,15 @@ class Worker:
)
else:
cur = conn.execute(
"UPDATE tasks SET result_text = ?, error_text = ?,"
"UPDATE tasks SET result_text = ?,"
" result_text_full = ?, error_text = ?,"
" actual_model = ?, started_at = ?, finished_at = ?,"
" child_pid = ?,"
" turn_id = COALESCE(?, turn_id),"
" root_turn_id = COALESCE(?, root_turn_id),"
" updated_at = ? WHERE id = ?" + status_clause,
((result_text or "")[:21000] if result_text else None,
full,
(error_text or "")[:4000] if error_text else None,
actual_model, started_at, finished_at, child_pid,
turn_id, root_turn_id,
@@ -5072,7 +5082,8 @@ class Worker:
started_at=started_at, finished_at=time.time(),
turn_id=(result or {}).get("turn_id"),
root_turn_id=(result or {}).get("root_turn_id"),
only_if_status="interrupted")
only_if_status="interrupted",
result_full=(result or {}).get("stdout_full"))
# P1:取消分支先记一条成本再返回(与配额中断收尾
# 同款记账点)。旧版这里直接返回 cost_record_id=None,
# 被取消前已花的模型费用就从账上丢了;取消不等于没
@@ -5160,7 +5171,8 @@ class Worker:
finished_at=finished_at,
turn_id=(result or {}).get("turn_id"),
root_turn_id=(result or {}).get("root_turn_id"),
only_if_status=final)
only_if_status=final,
result_full=(result or {}).get("stdout_full"))
# 附件暂存清理:任务终局后删 bundle 目录(重试走已存在
# 续跑,文件已在 worktree 里,不再需要暂存)。
self._cleanup_task_seed(task)