Repository navigation
feat(agents): Swarm core β collector spawn, agents_wait, structured output, caps (gated) - #110932
Conversation
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86814ac270
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ([, candidate]) => | ||
| !candidate.collectorCompletion || | ||
| candidate.collectorLaunchCleanupPending === true || | ||
| candidate.archiveAtMs === undefined || |
There was a problem hiding this comment.
Assign an archive deadline to default collector runs
When callers use the normal sessions_spawn({ collect: true }) form without specifying cleanup, the tool defaults to cleanup="keep" (src/agents/tools/sessions-spawn-tool.ts:341-343), and registration consequently leaves archiveAtMs undefined (src/agents/subagent-registry-run-manager.ts:790-795). This new group guard therefore prevents every default collector group from ever being archived, retaining its registry/SQLite records indefinitely and causing reused explicit groups to remain permanently subject to maxTotalPerGroup; collector runs need a group-retention deadline independent of session cleanup mode.
Useful? React with πΒ / π.
86814ac to
e9921b9
Compare
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9921b9fe9
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const persistedCollectorSession = | ||
| !collectorSession && requestSessionKey && isSubagentSessionKey(requestSessionKey) | ||
| ? loadSessionEntry({ |
There was a problem hiding this comment.
Avoid opening the session DB for every subagent request
For every ordinary request whose sessionKey is a subagent key, collectorSession is absent, so this condition invokes loadSessionEntry even when the session has never been a collector. That function opens the per-agent SQLite database synchronously (src/config/sessions/session-accessor.sqlite-entry.ts:76-79), adding a writable DB open/read to every normal subagent dispatch and resume despite the comment claiming ordinary traffic avoids it. Restrict this fallback to the startup window or maintain a process-level index of persisted collector session keys.
Useful? React with πΒ / π.
|
Codex review: needs real behavior proof before merge. Reviewed July 19, 2026, 1:41 AM ET / 05:41 UTC. Summary Reproducibility: yes. from source: complete a collector with a terminal provider/runtime error before an assistant result is captured, then call Review metrics: 3 noteworthy metrics.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Return a stable terminal diagnostic or dedicated error field from Do we have a high-confidence way to reproduce the issue? Yes, from source: complete a collector with a terminal provider/runtime error before an assistant result is captured, then call Is this the best way to solve the issue? No: the current status-only fallback is not the best solution because it discards an existing terminal outcome; preserve a stable error field or terminal diagnostic in the waiter result. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 30e2129ace2e. Label changesLabel justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (9 earlier review cycles; latest 8 shown)
|
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57448bd6f7
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const response = await subagentRegistryDeps.callGateway({ | ||
| method: "agent", | ||
| params: launch.request, | ||
| timeoutMs: launch.timeoutMs, | ||
| }); | ||
| const gatewayRunId = readGatewayRunId(response) ?? runId; | ||
| try { | ||
| if (!startQueuedSubagentRun(runId, gatewayRunId)) { |
There was a problem hiding this comment.
Reconcile queued launches before replaying them
If the gateway exits after this agent call is accepted but before startQueuedSubagentRun persists the running transition, the durable row remains queued; restoration therefore sends the same launch request again. The Gateway idempotency cache is only the process-local Map at src/gateway/server-runtime-state.ts:141, so it cannot deduplicate this replay after restart, allowing the collector task and any pre-crash side effects to execute twice. Persist a launch-in-flight state that restoration reconciles against the child session, or use durable request deduplication, rather than unconditionally replaying queued work.
Useful? React with πΒ / π.
57448bd to
c7325cd
Compare
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7595ded42
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const snapshot = subagentRegistryDeps.getSubagentRunsSnapshotForRead(subagentRuns); | ||
| const byId = new Map<string, SubagentRunRecord>(); | ||
| for (const entry of snapshot.values()) { |
There was a problem hiding this comment.
Avoid rebuilding the full registry on every wait poll
While any requested collector remains pending, agents_wait polls every 25 ms (src/agents/tools/agents-wait-tool.ts:105-120), and each poll reaches this function, which merges the persisted/in-memory registry and then scans every retained run to rebuild byId. With multiple groups or long-retained collector records, one wait therefore performs thousands of full-registry scans and periodically reloads the entire SQLite table during a 600-second call; use a maintained stable-swarm-id index or targeted lookup instead.
Useful? React with πΒ / π.
| const gatewayRunId = readGatewayRunId(response) ?? runId; | ||
| try { | ||
| if (!startQueuedSubagentRun(runId, gatewayRunId)) { | ||
| throw new Error( | ||
| "collector registry row could not transition from queued to running", | ||
| ); | ||
| } |
There was a problem hiding this comment.
Emit start hooks after restoring a queued collector
When the gateway restarts while a collector is queued, this restored scheduler callback accepts the child and marks it running but never emits subagent_progress(phase="started") or subagent_spawned. The normal queued-launch callback explicitly calls emitSpawnLifecycleHooks after the same transition (src/agents/subagent-spawn.ts:1777-1789), so restart-launched collectors disappear from hook-backed progress and lifecycle integrations even though their eventual ended hook still fires.
Useful? React with πΒ / π.
β¦lector start lifecycle hooks Autoreview findings: replace the per-request full registry scan with an index-maintaining run map and gate the persisted-store fallback behind isSubagentSessionKey; emit subagent_progress/subagent_spawned from the swarm scheduler start callback so collector children produce balanced plugin lifecycle events.
β¦ executor return
β¦nabled fact resolveSwarmConfig value-import in tool-catalog dragged the server graph into the Control UI bundle via tool-policy-shared (UNLOADABLE_DEPENDENCY on subpath aliases). Catalog stays pure; the gateway tools-catalog handler resolves the gate and passes the boolean.
defa451 to
70f23bb
Compare
|
Merged via squash.
|
β¦utput, caps (gated) (openclaw#110932) * docs: add Swarm implementation spec * feat(agents): Swarm core β collector spawn, agents_wait, structured output, fastMode, caps Implements docs/plan/swarms.md Β§4-6: tools.swarm config gate (default off), collector-mode sessions_spawn (collect/outputSchema/fastMode/groupId), fail-closed child approvals, agents_wait race-semantics tool, per-group FIFO scheduler with maxConcurrent/maxChildrenPerGroup/maxTotalPerGroup caps, additive registry and state-schema columns (no schema-version bump), and colocated tests. Part of openclaw#110325 * fix(agents): rebase reconciliation β preserve swarm state columns * fix(agents): O(1) collector session index, cheap-first preflight, collector start lifecycle hooks Autoreview findings: replace the per-request full registry scan with an index-maintaining run map and gate the persisted-store fallback behind isSubagentSessionKey; emit subagent_progress/subagent_spawned from the swarm scheduler start callback so collector children produce balanced plugin lifecycle events. * chore(protocol): regenerate Swift gateway models for swarm fields * fix(agents): lint cleanup β typed catch, explicit microtask flush, no executor return * fix(agents): knip/test-support/max-lines cleanup for swarm surfaces * fix(agents): keep tool-catalog ui-safe β callers pass prepared swarmEnabled fact resolveSwarmConfig value-import in tool-catalog dragged the server graph into the Control UI bundle via tool-policy-shared (UNLOADABLE_DEPENDENCY on subpath aliases). Catalog stays pure; the gateway tools-catalog handler resolves the gate and passes the boolean. * fix(agents): reconcile swarm spawn pipeline * fix(agents): refresh swarm tool metadata * fix(apps): sync swarm tool localization * style(agents): compact tool display metadata * fix(plugin-sdk): account for swarm config surface
β¦utput, caps (gated) (openclaw#110932) * docs: add Swarm implementation spec * feat(agents): Swarm core β collector spawn, agents_wait, structured output, fastMode, caps Implements docs/plan/swarms.md Β§4-6: tools.swarm config gate (default off), collector-mode sessions_spawn (collect/outputSchema/fastMode/groupId), fail-closed child approvals, agents_wait race-semantics tool, per-group FIFO scheduler with maxConcurrent/maxChildrenPerGroup/maxTotalPerGroup caps, additive registry and state-schema columns (no schema-version bump), and colocated tests. Part of openclaw#110325 * fix(agents): rebase reconciliation β preserve swarm state columns * fix(agents): O(1) collector session index, cheap-first preflight, collector start lifecycle hooks Autoreview findings: replace the per-request full registry scan with an index-maintaining run map and gate the persisted-store fallback behind isSubagentSessionKey; emit subagent_progress/subagent_spawned from the swarm scheduler start callback so collector children produce balanced plugin lifecycle events. * chore(protocol): regenerate Swift gateway models for swarm fields * fix(agents): lint cleanup β typed catch, explicit microtask flush, no executor return * fix(agents): knip/test-support/max-lines cleanup for swarm surfaces * fix(agents): keep tool-catalog ui-safe β callers pass prepared swarmEnabled fact resolveSwarmConfig value-import in tool-catalog dragged the server graph into the Control UI bundle via tool-policy-shared (UNLOADABLE_DEPENDENCY on subpath aliases). Catalog stays pure; the gateway tools-catalog handler resolves the gate and passes the boolean. * fix(agents): reconcile swarm spawn pipeline * fix(agents): refresh swarm tool metadata * fix(apps): sync swarm tool localization * style(agents): compact tool display metadata * fix(plugin-sdk): account for swarm config surface
What Problem This Solves
OpenClaw has no way to orchestrate many subagents deterministically β no awaitable spawn, no structured child output, no fan-out caps. This is the core lane of the Swarm program (#110325).
Why This Change Was Made
Per the frozen spec (
docs/plan/swarms.md, lands with this PR): one canonical, harness-agnostic owner of spawn/complete/settle semantics that both the QuickJS code-mode surface and the Codex-harness projection build on. Fully gated behind newtools.swarmconfig (default off) β with the gate closed, the only behavior change is param rejection with a clear error.User Impact
Gated (off by default). When
tools.swarm.enabled:sessions_spawngainscollect(waitable completion record instead of announce/steering),outputSchema(validated structured output via injectedstructured_outputtool, one nudge retry,schemaErrorfallback),fastMode,groupId; child identity defaults totools.swarm.defaultAgentId(validated against the existing target allowlist).agents_waittool: first-completion race semantics, bounded timeout, idempotent re-reads, spawner-chain ownership.maxConcurrent/maxChildrenPerGroup/maxTotalPerGroup; collector children run approvals-fail-closed (denials reported in results, no operator prompts).Evidence
node scripts/run-vitest.mjs β¦, 2 shards).isSubagentSessionKey-gated store fallback;subagent_progress/subagent_spawnedemitted from the scheduler start callback). Round 2: one finding rejected as factually incorrect βresolveRealalready maps only ENOENT to null and rethrows otherwise, so non-ENOENT realpath failures returnfalse(subagent-registry-helpers.ts:189-216).agents.runsurface (in flight), dots widget, event-driven wait (replacing the bounded 25ms in-memory poll),agents.session.