Skip to content

feat: support WMA, A2A agents, and OpenSandbox runners - #1469

Open
Robert0622 wants to merge 3 commits into
mainfrom
codex/agent-execution-providers
Open

Robert0622 wants to merge 3 commits into
mainfrom
codex/agent-execution-providers

Conversation

@Robert0622

@Robert0622 Robert0622 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

LOOP roles can invoke a published WorkBuddy Managed Agent session or an external A2A v0.3 Agent. A2A supports a service on a user's personal Runner and a project-scoped HTTPS service. Each managed turn publishes a text artifact through the existing LOOP handoff.

Deployments can assign a project workspace to an OpenSandbox Docker or Kubernetes backend. The run freezes its backend and uses a dedicated Runner for the shared workspace. The server signs Runner registration and releases the sandbox after completion. A create request can use the full startup budget for cold images.

Scope

  • Platform core / API / runner
  • Public adapter / deployment

Compatibility

The integrations use opt-in deployment bindings. For OpenSandbox, select a native LOOP profile and assign a backend to the project. The dedicated Runner executes within the assigned container. The new run and role fields are optional JSON fields. See Architecture for configuration.

Validation

  • Real WorkBuddy hy4flash streamed a response through the Tencent Cloud control plane and ACP. The public branch ran a mixed LOOP on OpenSandbox 1.2.0 on both Docker and Kind Kubernetes 1.32.2. Two downstream steps consumed the artifact and reused the workspace. Both backends released the sandbox.
  • Live A2A adapter smoke tests exercised a personal Runner with DeepSeek V4 Flash and a separate HTTPS service with GLM-4.7-Flash. Public-branch integration tests covered both targets, project sharing, executor readiness, and persisted text artifacts.
  • bash scripts/build-chatbot.sh built the app and passed 535 Chat tests. npm run coverage in webtest passed 387 tests with 85.95% line coverage. Public Playwright acceptance passed 28 tests and skipped 3 opt-in model tests.
  • Focused Go integration tests, go vet ./..., python3 scripts/check-public.py, and bash scripts/scan-secrets.sh passed.
  • Local full Go runs hit native mount and Chromium startup errors. Isolated reruns passed the affected execution and control-plane browser cases. The existing TestRunnerStartsPanelBrowserInRunSandbox startup error also reproduces on public main on this host.

Safety

  • Configuration examples use placeholders and public endpoints.
  • The diff is based on public main and contains only the execution integration.

@Robert0622
Robert0622 marked this pull request as ready for review November 26, 2026 19:39

@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.

初审 c0d3e7c5:BLOCKED(运行时验证未完成)

审查版本:head c0d3e7c5(base main be6918d7)。上游 34f1c341 新增 WMA/A2A/OpenSandbox 三条执行路径(44 文件 +2937/−37),c0d3e7c5 在此基础上将 OpenSandbox POST 超时从 20s 增到 2 分钟(Docker 拉镜像场景),新增 TestCreateAllowsColdImageStartup 覆盖,并简化 TestExternalA2ASOP 改用 Artifact 断言。

审查范围

  • 核心协议层:internal/managedagent/(a2a.go、wma.go、acp.go、tencent.go,含测试)
  • 执行引擎层:internal/engine/managed_agent.go、opensandbox.go、opensandbox_test.go、node_execute.go、sop_executors.go、run_start.go
  • Runner 层:internal/runner/external_agent.go、external_agent_test.go、opensandbox_test.go
  • OpenSandbox 客户端:internal/opensandbox/client.go、client_test.go
  • 配置入口:cmd/agentflow/optional_execution.go、cmd/agentflow-runner/a2a_config.go
  • 前端:web/app/agents.js、web/app/runners.js、web/index.html
  • 文档:docs/architecture.md

静态分析结果

安全控制:

  • A2A NewA2A 验证 endpoint scheme/hostname/User/Fragment/RawQuery;loopback 模式严格调用 net.ParseIP + IsLoopback();non-loopback 只允许 HTTPS。
  • WMA NewWMA 验证 HTTPS origin;API key 要求 ck_ 或 pt_ 前缀;TencentCloud 和 OpenAPI 两种模式互斥。
  • Bootstrap token:WorkspaceFromBootstrap 验证前缀 + base64 格式 + safeID 正则;ValidBootstrap 使用 hmac.Equal 时序安全比对,signing key 至少 32 字节。
  • OpenSandbox 配置:拒绝通配符 "*"、空 project ID 和重复绑定;binding() 对 scope/workspace 做 SHA-256 截断存 Kubernetes label,满足 63 字符限制。

幂等与并发:

  • ManagedPromptAttempt fence 在 dispatch 前写库,重启后不会重发同一 attempt。
  • provisionOpenSandbox 先写 ExecutionResourcePending 再 POST,重启后只做 Find,幂等正确。
  • OpenSandbox Runner 注册路径:OpenSandboxRegistrant 在批准前验证 token 仍绑定存活 workspace,防止旧 token 重用。

sop_executors.go:seen 由 bool 改为 int(索引),多节点复用同一 managed executor 时取 AND 合并 Configured,逻辑正确。

ACP SSE 流:readEvents 用 bufio.Scanner + 1 MiB limit,空行分隔事件,prompt() cancel 时发 session/cancel cleanup,逻辑完整。

CI 结果

  • core 全部步骤通过(含 Non-browser Go tests、Real-browser Go tests、Coverage gate、Browser-free UI tests),审查版本 c0d3e7c5。
  • 其余 14 项 checks 全部 success,无失败项。

UNVERIFIED(阻塞 Approve 的原因)
本次审查未能在真实后端上执行以下端到端路径,缺少外部凭据:

  1. WMA ACP SSE 连接与 session/prompt 完整对话(需要真实 WorkBuddy Managed Agent session)。
  2. A2A remote HTTPS 端点(ExternalAgentRemote 路径,需要真实 A2A 服务)。
  3. OpenSandbox Docker/Kubernetes 后端生命周期(provision → sandbox Running → Runner 注册 → release,需要真实 OpenSandbox 服务)。

上述验证需作者或部署方提供环境凭据后完成,TestOpenSandboxMixedSOP 和 TestExternalA2ASOP 的真实后端路径(LF_WMA_E2E_SESSION_ID、LF_OPENSANDBOX_E2E_URL)均已在测试中预留。

结论:无已确认阻塞缺陷;但必要运行时验证尚未完成,暂无法 Approve。待上述三条路径在真实环境完成端到端验证后可提交 Approve。

🤖 Generated with Claude Code

@Robert0622

Copy link
Copy Markdown
Collaborator Author

本轮 CR 结论:LGTM,可以合入

head: c0d3e7c5,CI 16/16 ✅,mergeable=MERGEABLE(BLOCKED — 尚无 Review,未触碰代码问题),未发现需要改动的地方。


代码审查(45 个文件,+2979/−37)

PR 新增三大集成能力,全部通过 opt-in 配置开关,不改动现有执行路径:

1. WorkBuddy Managed Agent(WMA)+ A2A 外部 Agent

  • internal/managedagent/(新包):WMA 通过 ACP/SSE + Tencent Cloud TC3-HMAC-SHA256 对接;A2A 实现 JSON-RPC 2.0 协议,支持 loopback(个人 Runner)和 remote(HTTPS 服务)两种目标;取消请求能正确发 tasks/cancel。
  • internal/domain/agent.go:新增 WMAExecutorID / A2AExecutorID 常量和 ValidateManagedExecutor(),拒绝托管 Agent 与 loop/artifacts/verification 组合(这些需要 CLI);externalAgentTarget 仅限 A2A 角色且值只能是 runner 或 remote。
  • internal/engine/managed_agent.go(新文件):executeManagedAgentNode() 在分发前用幂等写法写入 ManagedPromptAttempt,防止恢复时重复发起;dispatchExternalAgent() 以 sha256 派生稳定的任务 ID,保证 A2A 任务唯一性。
  • internal/engine/node_execute.go:在已有路径前插入托管 Agent 检测,不影响其他节点类型。

2. OpenSandbox(Docker/Kubernetes 工作区)

  • internal/opensandbox/client.go(新包):Create/Inspect/Find/Release 生命周期,POST 允许最多 2 分钟(冷镜像), 认证,ErrNotFound 显式区分 404。
  • internal/engine/opensandbox.go(新文件):创建意图先落库再 POST,防止响应丢失时重复创建;releaseOpenSandbox() 在 20 秒内完成清理;多后端绑定通过 openSandboxProjects map 路由,同一项目不能绑两个后端(有重复检查)。
  • internal/httpapi/runners.go:OpenSandbox 注册令牌前缀识别;保留 sandbox-workspace-<runID> 命名空间给 OpenSandbox,普通 Runner 不能注册该 ID;OpenSandbox Runner 只能看到自己 ID 对应的任务(runnerMaySeeTask 过滤)。

3. 前端 + API 层

  • web/app/agents.js:增加 managedAgentExecutors 常量,WMA/A2A 进入 executorOptions 下拉,isManagedAgentExecutor 时隐藏模型选择器、显示外部 Agent target 字段;externalAgentTarget 保存到 PUT body。
  • internal/httpapi/executor_models.go:当 engine 配置了 WMA/A2A 时向 /api/executor-models 注入 {configured:true}。
  • internal/httpapi/catalog.go:在 validateCatalogAgentExecutor 里调用 ValidateManagedExecutor,API 层拦截非法组合。

代码逻辑整体清晰,安全设计合理(opt-in、API key 头、签名、runner ID 命名空间隔离)。测试覆盖了所有新 HTTP 客户端、取消路径、A2A 端点策略和 OpenSandbox 后端绑定。


部署实测(本机 MariaDB + c0d3e7c5 二进制)

API 验证

  • PUT /api/agents(executorId=wma + loop.enabled=true)→ 400「托管 Agent 角色仅支持文本结果。工作区产物、门禁和自修正需要 CLI」✅
  • PUT /api/agents(executorId=wma,仅文本配置)→ 201 保存成功 ✅
  • PUT /api/agents(executorId=a2a,externalAgentTarget=remote)→ 201 保存成功 ✅
  • PUT /api/agents(executorId=wma,externalAgentTarget=runner)→ 400「externalAgentTarget 仅适用于 A2A 角色」✅
  • PUT /api/agents(executorId=a2a,externalAgentTarget=invalid-value)→ 400 ✅

Go 单元测试

  • internal/managedagent:TestA2AEndpointPolicy、TestA2ATaskCancellation、TestWMATencentControl、TestWMATextAndCancellation (cancel=false/true)、TestWMARefusesUntrustedACPOrigin — 全部 PASS(1.016s)
  • internal/opensandbox:TestCreateAllowsColdImageStartup — PASS(创建预算在 1–2 分钟之间 ✅)
  • internal/engine:TestOpenSandboxBackendBinding — PASS(同项目不能绑两个后端、runner 跟随固化后端 ✅)
  • internal/domain:TestIsAgentCLIKindMatchesCaseInsensitivelyAfterTrim 等域测试全部 PASS
  • internal/repo:TestRunnerTaskClaimIsExclusive、TestRunnerTaskClaimRespectsProviderAndTargeting 等 runner 任务测试全部 PASS

webtest(node --test 子集)

  • tests/assets-agents.test.mjs(含新增「LOOP role editor saves an external Agent target and preserves CLI model controls」)
  • tests/projects-repos.test.mjs(含「AI branch naming offers only CLIs configured for the user」)
  • 16/16 通过

与 #1470 的交叉改动说明

两个 PR 都修改了 internal/engine/node_execute.go,位置不重叠:

后合入的一方只需解 node_execute.go 这一处,不涉及语义冲突。

没有发现代码问题,不需要改动。

…utcome

- A WMA/A2A node interrupted mid-turn (control-plane restart) hit the
  dispatch fence on recovery, but shouldRetryFailedAttempt treated that error
  as retryable, so with maxAttempts>=2 attempt N+1 sent the same prompt again.
  The fence now returns errManagedTurnUnknown, which is never retried
  automatically.
- The fenced attempt kept the "执行实例退出,等待恢复" activity, so an explicit
  retry continued the same attempt and hit the fence forever. The fence now
  clears that marker so a retry starts a new attempt.
- A WMA/A2A turn that runs past the 5-minute budget reports
  "<provider> Agent 未在 5m0s 内完成本轮,已请求取消" instead of a bare
  "context deadline exceeded"; run cancellation keeps the plain error.
- Document both behaviours in docs/architecture.md.

Co-Authored-By: Claude Code <noreply@anthropic.com>
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