Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
daemon(batch-reset): machine:reset_all case — loop existing runRestartCommand
Gus491f060488d1
diff --git a/src/daemon/src/manager/agentRouter.test.ts b/src/daemon/src/manager/agentRouter.test.tsindex b969db0e6..440bc80f2 100644--- a/src/daemon/src/manager/agentRouter.test.ts+++ b/src/daemon/src/manager/agentRouter.test.ts@@ -1,5 +1,5 @@import { describe, it, expect } from "vitest";-import { AgentRouter, UnknownRuntimeError } from "./agentRouter";+import { AgentRouter, UnknownRuntimeError, UnknownBotError } from "./agentRouter";import type { AgentProcessManager } from "./managerRuntime";import type { HostControlChannel, HostCommand, SessionErrorFrame } from "../server/contract";import type { Logger } from "../logger";@@ -298,6 +298,81 @@ describe("AgentRouter — agent:reset", () => {});});+describe("AgentRouter — machine:reset_all (batch reset)", () => {+ const CFG = { version: 1 as const, runtime: "mock", model: { kind: "default" as const }, mode: { kind: "default" as const } };++ it("loops resetSession over every entry in the resets array (all agents reset, in order)", async () => {+ const { mgr, resets, order } = fakeManager();+ const { ch, fire } = fakeChannel();+ const before: string[] = [];+ const router = new AgentRouter({+ manager: mgr, channel: ch, runtimeReport: [{ id: "mock" }],+ onBeforeAgent: async (id) => { before.push(id); },+ });+ await router.start();++ await fire({ type: "machine:reset_all", resets: [+ { agentId: "a1", config: CFG, launchId: "l1" },+ { agentId: "a2", config: CFG, launchId: "l2" },+ { agentId: "a3", config: CFG, launchId: "l3" },+ ] });++ // Every entry reset, once each; onBeforeAgent ran for each (gate inherited).+ expect(resets.map((r) => r.agentId)).toEqual(["a1", "a2", "a3"]);+ expect(before).toEqual(["a1", "a2", "a3"]);+ // Each agent's before precedes its reset (same orchestration as single reset).+ expect(order.indexOf("reset:a2")).toBeGreaterThan(order.indexOf("reset:a1"));+ expect(router.buildReady().runningAgents).toEqual(expect.arrayContaining(["a1", "a2", "a3"]));+ });++ it("a foreign/unknown agentId (onBeforeAgent throws) is NOT reset, but the batch continues (per-entry independence + inherited ownership gate)", async () => {+ const { mgr, resets } = fakeManager();+ const { ch, wakeAcks, fire } = fakeChannel();+ const logger = stubLogger();+ const router = new AgentRouter({+ manager: mgr, channel: ch, runtimeReport: [{ id: "mock" }], logger,+ // Mirror createDaemon's onBeforeAgent botsById gate: a2 is not bound here.+ onBeforeAgent: async (id) => { if (id === "a2") throw new UnknownBotError(id); },+ });+ await router.start();++ await fire({ type: "machine:reset_all", resets: [+ { agentId: "a1", config: CFG, launchId: "l1" },+ { agentId: "a2", config: CFG, launchId: "l2" }, // foreign → gated+ { agentId: "a3", config: CFG, launchId: "l3" },+ ] });++ // a2 gated out (never reset); a1 + a3 reset — one bad entry doesn't abort batch.+ expect(resets.map((r) => r.agentId)).toEqual(["a1", "a3"]);+ // a2 gets a negative ack (bot_unknown), not silent.+ expect(wakeAcks).toContainEqual(expect.objectContaining({ agentId: "a2", status: "error" }));+ expect(router.buildReady().runningAgents).not.toContain("a2");+ });++ it("one entry's resetSession throwing doesn't abort the rest (per-entry try/catch)", async () => {+ const resets: string[] = [];+ const mgr = {+ resetSession: async (agentId: string) => {+ if (agentId === "a2") throw new Error("boom");+ resets.push(agentId);+ },+ liveSessionReports: () => [],+ } as unknown as AgentProcessManager;+ const { ch, wakeAcks, fire } = fakeChannel();+ const router = new AgentRouter({ manager: mgr, channel: ch, runtimeReport: [{ id: "mock" }], logger: stubLogger() });+ await router.start();++ await fire({ type: "machine:reset_all", resets: [+ { agentId: "a1", config: CFG, launchId: "l1" },+ { agentId: "a2", config: CFG, launchId: "l2" }, // throws+ { agentId: "a3", config: CFG, launchId: "l3" },+ ] });++ expect(resets).toEqual(["a1", "a3"]); // a2 failed, a1 + a3 still ran+ expect(wakeAcks).toContainEqual(expect.objectContaining({ agentId: "a2", status: "error" }));+ });+});+describe("AgentRouter — agent:nap", () => {const CFG = { version: 1 as const, runtime: "mock", model: { kind: "default" as const }, mode: { kind: "default" as const } };diff --git a/src/daemon/src/manager/agentRouter.ts b/src/daemon/src/manager/agentRouter.tsindex c718d62a9..edf350231 100644--- a/src/daemon/src/manager/agentRouter.ts+++ b/src/daemon/src/manager/agentRouter.ts@@ -502,6 +502,28 @@ export class AgentRouter {}),);break;+ case "machine:reset_all":+ // Batch reset every agent the server packed into `resets` (the machine's+ // full binding set — see the server-side enumerate; NOT filtered to+ // running, so bound-but-idle agents get cold-started). Each entry runs+ // through the SAME `runRestartCommand` path as a single `agent:reset`,+ // so it inherits (a) the `onBeforeAgent` botsById ownership gate — a+ // foreign/cross-owner agentId throws UnknownBotError → that entry gets a+ // `bot_unknown` ack and is NOT reset — and (b) per-entry try/catch, so+ // one failure never aborts the rest of the batch. Sequential await keeps+ // the restart orchestration (stop→forget→respawn) from interleaving+ // across agents. One frame, not fan-out (owner-triggered "reset this+ // machine"). See plans/daemon-batch-reset.md.+ for (const r of cmd.resets) {+ await this.runRestartCommand(r.agentId, r.launchId, "agent:reset", () =>+ this.opts.manager.resetSession(r.agentId, {+ runtimeConfig: r.config,+ launchId: r.launchId,+ rewakePrompt: REWAKE_PROMPT,+ }),+ );+ }+ break;case "agent:nap":// Self-initiated twin of agent:reset — same enroll → forget-session →// fresh-rewake orchestration and `nap` timeline barrier; the only