Skip to content

Commit e9770a7

Browse files
committed
fix(doctor): repair keyed multi-agent rosters without ownership
1 parent bacc134 commit e9770a7

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎docs/concepts/multi-agent.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ Bindings are deterministic and most-specific wins. See [Channel routing](/channe
234234

235235
For existing multi-agent configs, `openclaw doctor --fix` materializes legacy ambient default routing into channel-wide bindings plus explicit heartbeat, Custodian, and Talk targets. Single-agent configs are unchanged.
236236

237+
For a multi-agent roster defined directly in the main config file without a
238+
legacy `default: true` marker, Doctor adds `agents.ownership: "explicit"` for
239+
both keyed `agents.entries` and older `agents.list` rosters, including with
240+
`--fix --non-interactive`. Existing bindings and per-surface owners remain
241+
unchanged; Doctor does not choose an agent for unowned surfaces.
242+
237243
## Multiple accounts / phone numbers
238244

239245
Channels that support multiple accounts (e.g. WhatsApp) use `accountId` to identify each login. Each `accountId` routes to its own agent, so one server can host multiple phone numbers without mixing sessions.

‎src/commands/doctor-config-flow.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { homedir } from "node:os";
22
/** Main doctor config flow: preflight, migrations, previews, repairs, and final write decision. */
33
import path from "node:path";
44
import { note } from "../../packages/terminal-core/src/note.js";
5-
import { readAgentRosterProperty, tryResolveSoleAgentId } from "../agents/agent-scope-config.js";
5+
import {
6+
listAgentEntries,
7+
readAgentRosterProperty,
8+
tryResolveSoleAgentId,
9+
} from "../agents/agent-scope-config.js";
610
import { resolveAgentWorkspaceDir } from "../agents/agent-scope.js";
711
import { formatCliCommand } from "../cli/command-format.js";
812
import { withProgress } from "../cli/progress.js";
@@ -239,7 +243,9 @@ export async function loadAndMaybeMigrateDoctorConfig(params: {
239243
.filter((source) => source !== undefined)
240244
.map((source) => migratePersistedImplicitMainRoster(source));
241245
const rosterMigrations = rawRosterMigrations.filter((migration) => migration.changed);
242-
const rosterMigrationNeeded = rosterMigrations.length > 0;
246+
const rosterMigrationNeeded =
247+
rosterMigrations.length > 0 ||
248+
(baseCfg.agents?.ownership === undefined && listAgentEntries(baseCfg).length > 1);
243249
const legacyDefaultAgentId = rawRosterMigrations
244250
.map((migration) => migration.retainedLegacyDefaultAgentId)
245251
.find((agentId) => agentId !== undefined);

‎src/commands/doctor-config-flow.workspace-persistence.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,44 @@ describe("Doctor workspace persistence", () => {
5454
closeOpenClawStateDatabaseForTest();
5555
});
5656

57+
it.each(["entries", "list"])(
58+
"persists explicit ownership for a markerless multi-agent %s roster",
59+
async (shape) => {
60+
await withTempHome(async (home) => {
61+
await withEnvOverride({ OPENCLAW_DISABLE_BUNDLED_PLUGINS: "1" }, async () => {
62+
const entries = {
63+
ops: { workspace: path.join(home, "ops") },
64+
research: { workspace: path.join(home, "research") },
65+
};
66+
const configPath = await writeOpenClawConfig(home, {
67+
agents:
68+
shape === "entries"
69+
? { entries }
70+
: {
71+
list: Object.entries(entries).map(([id, entry]) => ({
72+
id,
73+
workspace: entry.workspace,
74+
})),
75+
},
76+
gateway: { mode: "local" },
77+
plugins: { enabled: false },
78+
});
79+
expect((await readConfigFileSnapshot()).valid).toBe(false);
80+
81+
const ctx = await prepareDoctorContext(configPath);
82+
await runInitialConfigWriteHealth(ctx);
83+
84+
const saved = JSON.parse(await fs.readFile(configPath, "utf-8"));
85+
expect(saved.agents).toEqual({ ownership: "explicit", entries });
86+
expect((await readConfigFileSnapshot()).valid).toBe(true);
87+
expect((await prepareDoctorContext(configPath)).configResult.shouldWriteConfig).toBe(
88+
false,
89+
);
90+
});
91+
});
92+
},
93+
);
94+
5795
it.each(["entries", "list", "noncanonical list"])(
5896
"repairs workspace and heartbeat values from %s through snapshot, doctor, and write",
5997
async (shape) => {

0 commit comments

Comments
 (0)