19 Commits
Author SHA1 Message Date
xiaoheiandClaude Opus 4.8 435f720cfb fix(agent): 注入目标文件完整原文 + 强令最小改动(修整文件重写噪声)
CI / guardrails (push) Successful in 5s
CI / guardrails (pull_request) Successful in 7s
CI / tests (push) Successful in 48s
CI / tests (pull_request) Successful in 41s
根因:agent 无本地读文件工具,只拿到 workspace 的截断采样,被要求"输出完整文件"
时只能凭残缺采样+自身知识重构整个文件 → 丢行/重排/改注释/版权头 → 巨噪声 diff,
要么 apply 不上,要么 apply 了破坏无关测试(SWE-bench Pro 两臂 0/10 的主因)。

修法:
- _load_exact_target_files():从子任务描述正则提取目标文件路径,注入其**完整未截断**
  的磁盘原文(上限6文件/各120KB,超限留给采样)。
- 执行 prompt 新增 "EXACT CURRENT CONTENT" 段 + 强令:返回内容必须是该原文逐字节保留、
  仅施加任务所需最小编辑,禁止 reformat/reorder/rename/clean-up 无关行。
- 强化原 full-file 输出说明。

目的:让 diff 只含必要行,救回 NodeBB 296/300、ansible 171/175 这类"差几个测试"的近失题。
契约测试全绿(runtime-contract/merge-smoke/workflow-e2e/contract-freeze)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 09:47:35 +00:00
xiaoheiandClaude Opus 4.8 cdb17a0d73 fix(agent+orchestrator): 关 qwen 思考模式出干净 JSON + 修 bounce 死锁
CI / guardrails (push) Successful in 6s
CI / tests (push) Successful in 45s
CI / guardrails (pull_request) Successful in 8s
CI / tests (pull_request) Successful in 43s
BUG-A: qwen3.7-max 默认思考模式,重 impl 子任务把预算花在 reasoning_content
上不出最终 content JSON → json.loads("") 失败。task_executor._complete 两处
chat.completions.create 注入 extra_body={"enable_thinking": False}(env
AGENT_ENABLE_THINKING=1 可opt-in)。对齐 Qwen 官方结构化输出用法。

BUG-B: bounce 仅重开含 impl 文件的任务;impl 失败(0文件)+test成功时
reopens=0 → run 永远 running 空转。加兜底:reopens==0 时重开 FAILED 任务
(受 MAX_REVIEW_CYCLES 约束);仍无可重开则 accept_no_rework 走正常收敛终结。

契约测试全绿(runtime-contract/merge-smoke/workflow-e2e/contract-freeze)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 05:44:00 +00:00
gongzhiyongandClaude Opus 4.8 c4c2116122 fix(agent): content 为空时回退 reasoning_content(修思考模型空响应)
CI / guardrails (push) Successful in 6s
CI / tests (push) Successful in 44s
CI / guardrails (pull_request) Successful in 5s
CI / tests (pull_request) Successful in 39s
qwen3.7-max 思考模型常返回空 message.content、答案在 reasoning_content。原代码只读
content → 拿到 "" → json.loads("") → "Expecting value: line 1 column 1 (char 0)" → 任务失败。
新增 _message_text():content → reasoning_content(attr 或 OpenAI SDK model_extra)回退,
_complete 两个返回点都用它。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 03:39:06 +08:00
gongzhiyongandClaude Opus 4.8 c5595cf344 fix(agent): 执行 max_tokens 4000→65535 + 明确全仓已本地 clone(修两个执行 bug)
CI / guardrails (push) Successful in 4s
CI / tests (push) Successful in 41s
#1 全量重写文件的 files JSON 远超 4000 token → JSON 中途截断("Unterminated string")
   → 任务失败。提到 qwen3.7-max 输出上限 65535,env AGENT_EXEC_MAX_TOKENS 可调。
#2 prompt 明确:完整仓库已 clone 在 {workspace_dir}(base_commit),上面列出的文件只是
   片段,绝不能因没列出就当文件/目录缺失(之前 LLM 误判 qutebrowser/utils 不存在 → 联网)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 03:19:19 +08:00
gongzhiyongandClaude Opus 4.8 770adcd8d7 fix(agent): 分解提示词改为蜂群模式 — 按文件归属的代码改动,非过程步骤
CI / guardrails (push) Successful in 8s
CI / tests (push) Successful in 1m1s
CI / guardrails (pull_request) Successful in 13s
CI / tests (pull_request) Successful in 41s
根因:旧提示词"task planning assistant + actionable subtasks + estimated_time"诱导
模型产出人类项目计划式步骤(探索/跑测试/移动文件/复审),而执行端只能"输出完整文件
内容"→ 这些步骤必然失败 → 0 patch。

新提示词按去中心化蜂群运作约束重写:仓库已在本地 base_commit、agent 唯一产物=完整
文件内容、子任务并行自选无共享 FS、产物按路径合并。要求:每个子任务=按文件归属的具体
代码改动(互斥,避免并行覆盖)、最小改动(可单文件就一个)、明确 FORBIDDEN 过程/元步骤。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 01:39:41 +08:00
gongzhiyongandClaude Opus 4.8 b53e32be78 fix(agent): 约束 jina 工具用法,不关闭搜索
- jina 工具砍到 allowlist(默认 search_web,read_url),21→2;其余工具不暴露,
  减少 prompt 膨胀与误用(env JINA_TOOL_ALLOWLIST 可调)。
- prompt 加 workspace/tool 边界:本地 base_commit 代码是唯一真源,本地读改;
  web 搜索/read_url 仅用于外部知识(库文档/语言特性/报错查证),严禁取本仓源码
  (web 版本≠本地 base_commit,会污染 patch);read_url 不接受 file:// 本地路径。

搜索作为模型验证/补能手段保留,仅约束调用边界。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 01:01:36 +08:00
gongzhiyongandClaude Opus 4.8 fb1eeeebfa fix(swebench): 真实仓 patch 捕获 + agent 稳定性
#1 稳定性:HEARTBEAT_TIMEOUT 30→120(可配 AGENT_HEARTBEAT_TIMEOUT)——真实仓 clone/长
模型调用不再误杀 agent。
#2 正确性/忠实度:
- 透传 GIT_BASE_COMMIT;agent clone 改为浅 fetch+checkout 该 commit(在正确基线上读/改,
  且大仓也快);emit_patch 持久化 base_commit + _git_diff 对 SHA 走浅 fetch。
- agent 读文件预算可配并调大(AGENT_CTX_MAX_FILES=40/BYTES=40000),LLM 看到完整文件,
  避免全量重写截断 → diff 失真。launcher 透传这些 env 给 agent pod。

import + runtime-contract/result-aggregator/security-boundary 测试全绿。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 00:25:38 +08:00
gongzhiyong 5c1ff0ef58 feat(agent): 任务执行加结构化日志(LLM推理/tool调用query与返回/产出)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 099f270cc2a092a4eae7e5d06d99c4d7e076465e)
2026-06-21 20:45:56 +08:00
gongzhiyong e263dae115 feat(agent): Jina 搜索改用标准 MCP SDK 接入
- agent/task_executor.py: Jina 搜索从手搓 httpx 改为官方 mcp SDK
  (streamablehttp_client + ClientSession);工具经 OpenAI function-calling 暴露给模型
- agent/requirements.txt: +mcp==1.28.0;pydantic 2.9.2->2.13.4(mcp 要求 >=2.11)
- orchestrator/agent_launcher.py: JINA_API_KEY 经 per-swarm Secret 透传给 agent pod
  (SENSITIVE_ENV_KEYS),不内联 PodSpec
- k8s/orchestrator-local.yaml: 本地部署清单(默认 in-pod 沙箱评估开关 + JINA_API_KEY)

沙箱保持默认 in-pod 方案,未引入 OpenSandbox。
影响范围: agent_swarm(agent/orchestrator) + Agent(新增 Jina MCP 工具)。
密钥经 k8s Secret 注入无明文。不影响 Manager 契约/计费/审计/发布链路。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit deb984ac38)
2026-06-21 20:45:56 +08:00
gongzhiyongandClaude Opus 4.8 1288fd19d7 feat(swarm): 协作聚合收敛取代蜂后选优 + sandbox 用 pytest 验证
CI / tests (push) Failing after 15m3s
CI / guardrails (push) Failing after 15m3s
按 juejin 协作聚合模型重构收敛(取代 best-of-N 选优):
- 删蜂后选优(queen.py/test-queen.py)
- 新增聚合节点 result_aggregator.py:共享池收集→同文件 LLM/AST 整合→沙箱验证→单次落 main
- 质量驱动闭环:不达标打回迭代(AGGREGATE_ACCEPTANCE_THRESHOLD + MAX_REVIEW_CYCLES)
- agent 停 git 工作分支,产出走 task.result.files 共享池(AGENT_GIT_PUSH_ENABLED 默认 false)
- sandbox_runner 改用 pytest(原生支持 pytest 风格 class),修 stdlib runner 收集失败
- 文档同步重写为协作聚合模型

本地验证:产物仓单分支 main + 三函数完整 + pytest 12/12 pass_rate=100 一次达标。
影响:Swarm 收敛/聚合层;Manager/客户端契约不变(artifact字段/sequence/状态机;契约测试全过)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 22:03:00 +08:00
FastheiandClaude Opus 4.8 f9df550ac9 fix(agent/#75): 落地 agent 侧自底向上分解(#7 task_proposal)+ _parse_task 健壮化
修 #75:蜂群单任务铺不到多 agent。两层根因 + 对应修复(均经本地 k8s 端到端验证):

1) 真实 agent 执行器从未实现 #7「自主分解提案」(autonomous-task-generation.md §4 标为
   「后续」;此前只有 stub_agent 演示)。编排器侧 handle_task_proposal 早已就绪,缺 agent 侧出口。
   - agent/main.py: 新增 propose_task()(发 WS task_proposal,字段对齐 handle_task_proposal);
     execute_task 传入 proposal_callback;control_messages 接受 task_proposal_ack。
   - agent/task_executor.py: 新增 _maybe_propose_subtasks() —— 执行顶层种子时用 _parse_task 拆分,
     把每个子任务经 proposal_callback 提案入池(由编排器 review→create_task→其他 agent 自选)。
     仅顶层种子提案(parent 为空、source 非 agent_proposed/dynamic_handoff),子任务不再递归提案,无环。
     env ENABLE_AUTONOMOUS_PROPOSALS(默认 on)可关。

2) _parse_task 又脆又静默退化为单任务(原 max_tokens=2000 截断 + 严格 json.loads + except 兜底):
   - max_tokens 可配 AGENT_PLAN_MAX_TOKENS(默认 65536;注:qwen3.7-max 网关上限即 65536,>之 400);
   - 新增 _coerce_subtasks 宽容解析(裸数组 / ``` 围栏 / {"subtasks":[...]} / 从文本抠 [...]);
   - 解析失败重试 1 次再退化;成功打 INFO "Decomposed into N",退化打明确 WARNING(可观测)。

派发:提案子任务 required_capabilities 置空(像种子,任意空闲 agent 可自选)。否则 LLM 给的具体能力
不是固定能力池子集 → can_agent_run_task 永远拒 → 子任务卡 PENDING(本地实测到的死锁)。能力提示保留在
agent_role(不门控派发);能力感知路由(把子任务能力映射到能力池)作为后续增强,见 #75。

本地验证(Docker Desktop k8s,qwen3.7-max,池16):两次 run 复现「种子→拆 6/8 子任务→派给 6/8 个不同
agent 并行执行」,此前恒为单 agent。

测试(本地全过):test-runtime-contract / test-contract-freeze / test-merge-smoke / test-workflow-e2e /
test-autonomous-tasks / test-agent-launcher / test-convergence。

影响:仅 agent/(执行单元);不动 Manager↔Swarm 冻结契约 / 计费 / 审计 / 编排器接口。
Refs #75

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 02:14:18 +08:00
FastheiandClaude Opus 4.8 c38b5fd80d fix(agent/git): seed baseline commit for empty repos so results push back (#73)
Binding an empty repo (no commits) made `git clone` land an unborn HEAD with no
`origin/main`. `add_task_worktree` / `create_result_branch` then fell back to
base_ref=HEAD, and `git worktree add ... HEAD` failed with "invalid reference:
HEAD". The agent silently degraded to "executing on repo root without git push",
so the result branch never reached the remote.

Fix: after clone (and after refreshing an existing checkout), detect an empty
repo via `git rev-parse --verify HEAD` and plant one empty baseline commit on the
configured base branch. Worktree/branch creation and push then work normally and
the result branch is created on the (previously empty) remote.

Adds scripts/test-git-empty-repo.py covering the empty-repo path; existing
scripts/test-git-workflow.py still passes (no regression). Verified end-to-end
against a real empty GitHub repo: result branch pushed successfully.

Impact: Swarm agent git layer only (agent/git_operations.py). No change to
Manager<->Swarm contract, callbacks, billing, secret_ref, or audit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 22:35:27 +08:00
FastheiandClaude Opus 4.8 1edf73aba4 fix(swarm/#70): 任务超时透传+提默认 / 事件时间线降噪 / 失败 termination_reason 准确
真机端到端实测(#70)暴露三问题,本 PR 全部修复(仅 agent + orchestrator,不跨仓):

问题1【阻断】单任务超时只有 60s,生成类任务必挂
- agent/main.py: TASK_TIMEOUT_SECONDS 默认 60→300(仅对外部/独立启动 agent 生效)。
- agent_launcher.py: 新增 DEFAULT_TASK_TIMEOUT_SECONDS=300、_budget_duration_seconds、
  resolve_task_timeout(base=env 默认 300,与 run budget.duration_seconds 取较小);
  plan_launch_specs 把 TASK_TIMEOUT_SECONDS 透传进每个 agent env(非敏感,inline,
  k8s 不进 Secret)。

问题2【体验】事件时间线全是内部噪音(纯附加,未碰冻结契约)
- swarm_runtime.py: is_client_visible(=event_type∈FROZEN_CLIENT_EVENT_TYPES,单一真源);
  emit_event 给 envelope 加 metadata.client_visible 布尔 + 关键客户端事件回填可选
  payload.message(人话进度,仅取已有字段,不伪造)。task.heartbeat/retried/
  deployment.status_changed/timeline/budget 标 client_visible=false,仍持久化+回调
  但客户端据此过滤出时间线。冻结事件集/类型/sequence/artifact 形状一字未动。
- event-schema.md: 文档化两个附加字段 + 新增 §6.1,明确未解冻。

问题3【正确性】失败/超时 termination_reason 仍报 "tasks_completed"
- convergence.py: 新增 TIMEOUT/MAX_RETRIES_EXCEEDED/TASK_FAILED;classify_failure_reason
  按 timeout→max_retries→task_failed 取最具体(仅凭真实 per-task 信号);FAILED 分支
  再不会返回 tasks_completed(该 reason 仅用于成功),budget/rounds 仅在通用失败时才覆盖。
- task_queue.py: fail_task 永久失败时把 reason 落到 task.result({"success":false,"error":reason}),
  不覆盖已有结果,供 convergence 读取。
- main.py: compute_convergence_report 快照补 retry_count/max_retries。

测试:新增 test_resolve_task_timeout、扩 test-convergence(failed_timeout/max_retries/
generic + "FAILED 永不报 tasks_completed"不变量)。本地全过:test-agent-launcher /
test-convergence / test-runtime-contract / test-contract-freeze / test-merge-smoke /
test-workflow-e2e / test-security-boundary。

影响:agent + orchestrator + 文档;不动 Manager↔Swarm 冻结契约字段(问题2 纯附加)。
栈在 #64(agent_swarm git 注入)之上,#64 合并后本 PR base 自动转 main。

Closes #70

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 18:29:39 +08:00
gongzhiyongandClaude Opus 4.8 26a40c7770 fix(agent): failure reason leads with model's diagnosis, not the task prompt
之前聚合用 "<任务描述前80字>: <error>",失败 reason 被整段 prompt 污染,
真正的"看到什么/缺什么"被挤到后面。改为以模型 summary 为主、附上 distinct error,
reason 直接就是诊断本身(例:"No source files found...; only README/jsonl present.
(Required files like src/database/redis/main.js are missing.)")。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 05:23:04 +08:00
gongzhiyongandClaude Opus 4.8 62d6fdf78c fix(agent): per-task git worktree so concurrent tasks each get an isolated repo copy
取代上一版 Option B(执行器共用仓库根 + 串行 1 任务)。每个任务从本 agent 自己的 clone
切出独立 git worktree(完整仓库内容 + 独立分支/索引),执行器在其中读写真实源码,
任务级 GitOperations 在该 worktree 提交/推送结果分支,完成后回收 worktree。

- 单 agent 可并发多任务(MAX_CONCURRENT_TASKS 恢复 4),互不共用 checkout/index
- worktree 置于仓外 /tmp/agent-worktrees(AGENT_WORKTREE_BASE 可配),主 checkout 不受污染
- _git_admin_lock 仅串行 worktree add/remove 等共享 .git plumbing,任务执行仍并行
- 跨 agent 隔离不变:每个 agent 仍各自 clone 一份(各自 pod)
- 根治 "Empty workspace: no files detected"(worktree 自带仓库文件,已端到端验证)

GitOperations 新增 add_task_worktree / remove_task_worktree。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 05:01:25 +08:00
gongzhiyongandClaude Opus 4.8 6152235c96 fix(agent): execute against cloned repo root, not empty per-task subdir
每个 SWE 任务都因 "Empty workspace: no files detected" 失败:仓库 clone 到 /workspace,
但 TaskExecutor 用的是空的 /workspace/.agent_tasks/<task_id> 子目录(从未播种仓库内容),
模型看不到任何源码 → 正确地拒绝执行。

Option B(架构裁定 2026-06-16):TaskExecutor.workspace_dir 改为仓库根 self.workspace_dir,
context.workspace_dir 同步。git(workspace_git 同根)即可 commit/push 真实改动。
MAX_CONCURRENT_TASKS 默认 1:单一 /workspace git checkout 非并发安全,蜂群并行靠多 agent。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 04:52:40 +08:00
gongzhiyongandClaude Opus 4.8 b394ce99d5 fix(swarm): reap orphan agents on terminal run + retry backoff + surface task errors
孤儿 agent 事故修复(2026-06-15 swarm-69e470561bd7-seed 跨 workspace 执行)。
不改去中心化认领逻辑(swarm_dispatch 不动),仅治理 agent pod 生命周期与可观测性:

- B1 终态回收: refresh_swarm_run_status 终态后 best-effort stop_launched 回收 pod+secret
  (此前仅 Manager stop 才回收,自然完成/失败的 run agent 残留 → 孤儿留在共享池抢别的 swarm 任务)
- B2 防驱逐: agent pod 加 karpenter.sh/do-not-disrupt(AGENT_POD_ALLOW_DISRUPTION=1 可关)
- stop_launched: backend=kubernetes 时按标签删,不再被内存集合 _k8s_swarms 门控(跨重启可靠)
- C 重试退避: Task.next_retry_at + fail_task 指数退避 5→30→180s(cap 300, TASK_RETRY_BACKOFF_*),
  is_task_ready 门控;TASK_MAX_RETRIES 可配
- D 错误上浮: task_executor 失败时聚合 subtask error 到顶层 error(根治通用 "Task failed"),
  _execute_subtask 打印 LLM 响应片段
- 配额硬上限 16: _clamp_user_cap

契约测试全过: runtime-contract / merge-smoke / workflow-e2e / contract-freeze /
max-agents-per-user / security-boundary。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 04:33:01 +08:00
Songhaoz666andClaude Opus 4.8 56bff469c1 每用户并发 Agent 上限:MAX_AGENTS_PER_USER 默认 10
需求:限制每个用户在 swarm 中并发的 Agent 数为 10。按「并发 WS 连接数/用户」口径实现,env 可调(默认 10)。

orchestrator/main.py:ConnectionManager 新增 per-user 记账(agent_user / user_agents + user_agent_count / can_bind_user / bind_user / unbind);max_agents_per_user() 读 MAX_AGENTS_PER_USER(默认 10)。WS register 携带 user_id 且该用户已达上限时回 registration_rejected(reason,limit) 并 close(1008),不注册;同 agent_id 重连放行;断开 unbind 释放名额。未带 user_id 的 Agent 为 unbound、不受限。

agent/main.py:新增 user_id 构造参数 + HEICODE_USER_ID 环境回退,并在 register 载荷中带上(仅在设置时)。

测试 scripts/test-max-agents-per-user.py:单元 + WS 集成(MAX_AGENTS_PER_USER=3)。接入 CI。docs/integration/security-boundary.md §6 记录该配额。

影响范围:仅 agent_swarm;不改 Manager↔Swarm 契约、计费、审批链、密钥处理。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 22:01:22 +08:00
Songhaoz666andClaude Opus 4.8 54cb327348 Agent Swarm v6:基准 v2.1、主控 Agent、实质性对等回复、客户端指南
- 基准标准 v2.1:SwarmMetrics(15 字段)、τ/η/P_decision/reward 公式、对称 G_E,c(修正 C_base=1.0 退化)、Σλ=1.0 校验;新增基线对比与运行记录 schema;指标覆盖缺口分析;参考系数暂留为元数据(待量化)。
- 主控 Agent 实体(分解 / 评审决策 / 汇总);事件契约修正(timeline.title、budget.threshold_pct、handoff 角色、task.released)+ 契约校验脚本。
- 实质性 LLM 对等回复(含降级回退);集成契约(runtime / event / usage / audit / frontend / capability / security);CLIENT_GUIDE 客户端指南;CI 工作流;治理与交付文档。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 16:21:18 +08:00