Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(orca): 避免 Lead 主动等待 Worker (#3558)
fmfsaisaib7837c744f0a
diff --git a/docs/dev-rules/orca-team-architecture.md b/docs/dev-rules/orca-team-architecture.mdindex ed6b0d7415..6554bb2e43 100644--- a/docs/dev-rules/orca-team-architecture.md+++ b/docs/dev-rules/orca-team-architecture.md@@ -219,7 +219,10 @@ Worktree 现状:Orca 与普通 session 对齐,worktree 是可选项,不强Lead 汇总前必须按执行该任务的同一通道确认真实终态,并逐项标明`Orca Worker` 或 `native subagent`。原生 subagent 由 Codex`collabAgentToolCall`/Claude Agent/Task 任务卡展示标识、任务和终态,但不得写入 Orca- Worker 状态,也不得触发 Orca Worker 完成提醒。实现指针:+ Worker 状态,也不得触发 Orca Worker 完成提醒。native subagent lifecycle tools(包括+ `wait_agent` 或等价能力)只能管理用户明确要求的 native subagent,不得用来等待或管理+ Orca Worker。部分 Worker 报告先到时,Lead 只处理当前报告与必要追问,不主动等待仍在+ 工作的 Worker;后续报告会作为新消息自动唤醒 Lead。实现指针:`packages/orca-workflow/src/orca-bridge-prompt.ts` 的`renderOrcaLeadSystemPrompt`,以及 `packages/maker-core/src/agents/codex/translator.ts`的 `handleCollabAgentToolCall`。diff --git a/packages/orca-workflow/src/__tests__/orca-bridge-prompt.test.ts b/packages/orca-workflow/src/__tests__/orca-bridge-prompt.test.tsindex b7f2b84e3f..835e637fd5 100644--- a/packages/orca-workflow/src/__tests__/orca-bridge-prompt.test.ts+++ b/packages/orca-workflow/src/__tests__/orca-bridge-prompt.test.ts@@ -40,43 +40,61 @@ describe('renderOrcaLeadSystemPrompt', () => {expect(prompt.indexOf(workerRoutingRule)).toBeLessThan(prompt.indexOf(nativeSubagentBoundary));});- it('forbids substituting an Orca Worker for a subagent, and demands honesty when the harness has none', () => {- // Orca Worker 是 session 级协同者,subagent 是 agent 内部的一次性执行体 —— 两者- // 不可互换。此前引导只写了「native subagent 不满足 Orca 派单」这一半,缺了反方向,- // 且只列举 Codex / Claude Code 两家机制;没有原生机制的 harness(如 pi)因此被推向- // 它唯一看得见的 Orca 工具,表现为「误开协同模式」。+ it('forbids substituting an Orca Worker for a subagent or improvising one', () => {+ // Orca Worker 是 session 级协同者,subagent 是 agent 内部的一次性执行体;+ // 两者不可互换,也不允许自己起进程冒充任一执行通道。const prompt = renderOrcaLeadSystemPrompt(null);expect(prompt).toContain('An Orca Worker is NEVER a substitute for a subagent.');- expect(prompt).toContain(- 'If you have no native subagent mechanism, say so plainly and ask the user how to proceed',- );- expect(prompt).toContain('do NOT open or reuse an Orca Worker to satisfy a subagent request');- // 兜底路径也不许自己起进程冒充 subagent。+ expect(prompt).toContain('Do NOT open or reuse an Orca Worker to satisfy a subagent request');expect(prompt).toContain('do NOT improvise one by spawning processes yourself');+ expect(prompt).not.toContain('If you have no native subagent mechanism');});it('requires execution-channel disclosure and terminal-state verification', () => {const prompt = renderOrcaLeadSystemPrompt(null);- expect(prompt).toContain(- 'Show the native subagent identifier, assigned task, and actual terminal status',- );expect(prompt).toContain('A native subagent result is not evidence that an Orca Worker ran or completed.',);expect(prompt).toContain(channelDisclosureRule);+ expect(prompt).not.toContain(+ 'Show the native subagent identifier, assigned task, and actual terminal status',+ );});- it('requires Lead review without prescribing a harness-specific simplify command', () => {+ it('keeps native subagent lifecycle tools away from Orca Workers', () => {const prompt = renderOrcaLeadSystemPrompt(null);+ expect(prompt).toContain('Orca Workers are not native subagents');+ expect(prompt).toContain('native subagent lifecycle tools');+ expect(prompt).toContain('wait_agent or equivalents');+ expect(prompt).toContain('wait for or manage Orca Workers');+ expect(prompt).toContain('Orca reports arrive automatically as new messages');expect(prompt).toContain(- 'review the output, then synthesize the final report for the user.',+ 'Use those lifecycle tools only for native subagents that the user explicitly requested',);+ expect(prompt).toContain('If other Orca Workers are still working, do not wait for them');expect(prompt).not.toContain('/simplify');});+ it('preserves async delivery, terminal routing, and emergency diagnostics boundaries', () => {+ const prompt = renderOrcaLeadSystemPrompt(null);++ expect(prompt).toContain(+ '(worker_status and read_worker also exist but are for emergency diagnostics only — do NOT use them for normal polling.)',+ );+ expect(prompt).toContain(+ 'You will be automatically woken up when the worker responds — you do NOT need to check on it.',+ );+ expect(prompt).toContain(+ 'For a single-role request, after create_worker, send_to_worker, or interrupt_worker returns with the concrete dispatch signals above, your turn is OVER. Produce ZERO output',+ );+ expect(prompt).toContain(+ 'Produce the final summary only after every relevant task has a terminal result from its own execution channel (rule 8).',+ );+ });+it('declares create_workers while preserving batch result reporting boundaries', () => {const prompt = renderOrcaLeadSystemPrompt(null);@@ -152,7 +170,7 @@ describe('renderOrcaLeadSystemPrompt', () => {describe('renderOrcaWorkerSystemPrompt', () => {const subagentHint =- 'If the user asks for a "subagent" / "子代理", use your own native subagent mechanism (for example Codex spawn_agent, or the Claude Code Agent/Task tool) to handle it yourself — do NOT escalate to the lead for it, and do NOT call start_team / create_worker (you cannot create Orca workers). If you have no native subagent mechanism, tell the user so instead of substituting an Orca Worker or spawning processes yourself; an Orca Worker is never a substitute for a subagent.';+ 'If the user asks for a "subagent" / "子代理", use your own native subagent mechanism (for example Codex spawn_agent, or the Claude Code Agent/Task tool) to handle it yourself — do NOT escalate to the lead for it, and do NOT call start_team / create_worker (you cannot create Orca workers). An Orca Worker is never a substitute for a subagent.';const workerSubagentReportingBoundary ='If you use native subagents, have them return findings only to you. Never tell them to contact the Lead or call send_to_lead; aggregate their results and report to the Lead yourself.';@@ -190,13 +208,13 @@ describe('renderOrcaWorkerSystemPrompt', () => {expect(prompt).toContain(subagentHint);});- it('tells a worker without a native subagent mechanism to be honest rather than substitute Orca', () => {- // worker 侧同规:没有原生机制时如实告知,不拿 Orca 顶替、不自己起进程。+ it('keeps the Worker rule concise without the unreachable fallback', () => {const prompt = renderOrcaWorkerSystemPrompt(workerMeta);- expect(prompt).toContain(- 'If you have no native subagent mechanism, tell the user so instead of substituting an Orca Worker or spawning processes yourself',+ expect(prompt).toContain('An Orca Worker is never a substitute for a subagent');+ expect(prompt).not.toContain('If you have no native subagent mechanism');+ expect(prompt).not.toContain(+ 'Show the native subagent identifier, assigned task, and actual terminal status',);- expect(prompt).toContain('an Orca Worker is never a substitute for a subagent');});});diff --git a/packages/orca-workflow/src/orca-bridge-prompt.ts b/packages/orca-workflow/src/orca-bridge-prompt.tsindex a61eca5998..bb2a2cb47c 100644--- a/packages/orca-workflow/src/orca-bridge-prompt.ts+++ b/packages/orca-workflow/src/orca-bridge-prompt.ts@@ -26,8 +26,8 @@ export function renderOrcaLeadSystemPrompt(initialWorker?: OrcaInitialWorkerRef'You are the lead agent in an Orca multi-agent workflow. Prefer delegating implementation work to workers via tools instead of doing it yourself.','An assignment to an Orca Worker MUST use the Orca tools below. This includes tasks addressed to an existing worker by role or label, explicit requests to open new Orca workers, requests for the Lead to delegate to workers, and parallel role assignments while an Orca team is active. Native subagents do not satisfy an Orca Worker assignment.','Use your own native subagent mechanism (for example Codex spawn_agent, or the Claude Code Agent/Task tool) only when the user explicitly asks for a "subagent" / "子代理" without assigning the task to an Orca Worker, or explicitly says not to use Orca Workers. A generic role name or a request to delegate in collaboration mode is not permission to switch execution channels.',- 'An Orca Worker is NEVER a substitute for a subagent. The two are different things: an Orca Worker is a session-level collaborator (its own persistent session, visible in the UI), a subagent is an ephemeral subtask executor inside your own agent. If you have no native subagent mechanism, say so plainly and ask the user how to proceed — do NOT open or reuse an Orca Worker to satisfy a subagent request, and do NOT improvise one by spawning processes yourself.',- 'If a native subagent is used, explicitly tell the user that the task did not use an Orca Worker. Show the native subagent identifier, assigned task, and actual terminal status, and never report its result as an Orca Worker completion.',+ 'An Orca Worker is NEVER a substitute for a subagent. The two are different things: an Orca Worker is a session-level collaborator (its own persistent session, visible in the UI), a subagent is an ephemeral subtask executor inside your own agent. Do NOT open or reuse an Orca Worker to satisfy a subagent request, and do NOT improvise one by spawning processes yourself.',+ 'Orca Workers are not native subagents. Never use native subagent lifecycle tools — including wait_agent or equivalents — to wait for or manage Orca Workers. Orca reports arrive automatically as new messages. Use those lifecycle tools only for native subagents that the user explicitly requested.','','Tools: get_workspace_info, create_worker, create_workers, send_to_worker, interrupt_worker, get_worker_queue_status, update_queued_message, cancel_queued_message, merge_queued_messages.','(worker_status and read_worker also exist but are for emergency diagnostics only — do NOT use them for normal polling.)',@@ -72,7 +72,7 @@ export function renderOrcaLeadSystemPrompt(initialWorker?: OrcaInitialWorkerRef'If get_workspace_info shows queued_count > 0 or queue_paused=true, call get_worker_queue_status first, then revise or withdraw one pending message, merge related messages, or send a separate task.','Never simulate an interrupt or merge with multiple stop, update, cancel, or send calls because the queue may advance between calls.','5. CRITICAL: Silence is tied to the concrete dispatch signals above, not merely to calling a tool. For a fully resolved multi-role request, issue all required Orca dispatches together in the one parallel tool-call batch described above; after its results, follow the single combined-report rule and call nothing else. For a single dispatched create_worker, send_to_worker, or interrupt_worker result, end immediately with no output or further tool calls. For any error or no-dispatch result, report it immediately and never sleep, wait, or poll for a worker response that was not scheduled.',- '6. When a worker report arrives (prefixed with [From Orca Worker]), review the output, then synthesize the final report for the user.',+ '6. When a worker report arrives (prefixed with [From Orca Worker]), review it and handle any immediate follow-up. If other Orca Workers are still working, do not wait for them; their reports will arrive as new messages. Produce the final summary only after every relevant task has a terminal result from its own execution channel (rule 8).','7. If you see "[Auto-bridged: ...]" in a worker message, it means the worker finished but forgot to call send_to_lead — the system bridged its output for you. Treat it the same as a normal worker report.','8. Before saying that all tasks are complete, verify every task from the terminal state reported by the same execution channel that ran it. A native subagent result is not evidence that an Orca Worker ran or completed.','9. In the final summary, label every delegated task with its actual execution channel: Orca Worker or native subagent.',@@ -110,7 +110,7 @@ export function renderOrcaWorkerSystemPrompt(meta: OrcaWorkerPromptMeta): string'7. When you need a response from the lead, explicitly include "please reply via send_to_worker" in your send_to_lead message. Otherwise the lead may not know to reply.','8. Do not commit changes unless the lead explicitly asks you to. Leave diffs for lead/user review.','9. When first created, wait for the lead to assign a task. Do not proactively message the lead.',- '10. If the user asks for a "subagent" / "子代理", use your own native subagent mechanism (for example Codex spawn_agent, or the Claude Code Agent/Task tool) to handle it yourself — do NOT escalate to the lead for it, and do NOT call start_team / create_worker (you cannot create Orca workers). If you have no native subagent mechanism, tell the user so instead of substituting an Orca Worker or spawning processes yourself; an Orca Worker is never a substitute for a subagent.',+ '10. If the user asks for a "subagent" / "子代理", use your own native subagent mechanism (for example Codex spawn_agent, or the Claude Code Agent/Task tool) to handle it yourself — do NOT escalate to the lead for it, and do NOT call start_team / create_worker (you cannot create Orca workers). An Orca Worker is never a substitute for a subagent.','11. An [Orca UI Assignment] may include a Lead session id and snapshot_before_ms because the Lead did not compose the assignment. If the task depends on current work, continuing work, this PR, or other relative context, use read_lead_history to inspect the owning Lead transcript before acting; pass snapshot_before_ms as from_ms when present. This read is scoped to your Lead and does not wake it. If the task is self-contained, proceed without reading history.',];