Skip to content

Commit c3ff7f9

Browse files
steipeteyu-xin-c
andauthored
feat(buzz): preserve bot identities when adding named accounts (#132226)
* feat(buzz): preserve root identity across named account setup Keep named credentials, rooms, lifecycle, and setup writes account-owned; preserve static root-layout policy through Doctor without importing disabled plugin runtimes. Fixes #130062. Co-authored-by: yu-xin-c <[email protected]> * fix(buzz): resolve setup credentials without disabling accounts Preserve authored secret references and reject unavailable credentials without saving account changes. Require an authorized room selection to finish setup. Co-authored-by: yu-xin-c <[email protected]> * fix(channels): distinguish preserved roots from empty promotion Keep ordinary env-only account promotion seeding accounts.default while an explicit preserve-root owner keeps its root intact, including empty roots. Use one canonical promotion result and remove the unused keys-only wrapper. Co-authored-by: yu-xin-c <[email protected]> * fix(outbound): resolve local account defaults before formatting Carry one locally resolved account through prefixing, target resolution and delivery. Preserve explicit, host and binding precedence, and keep omitted account input absent when delegating to a remote Gateway. Co-authored-by: yu-xin-c <[email protected]> * fix(buzz): report the selected account's missing room path Use the canonical account configuration path in startup recovery guidance. Cover missing, empty and disabled room lists for implicit root, named and explicit-default identities before opening a relay or recovery store. Co-authored-by: yu-xin-c <[email protected]> * fix(buzz): settle account work before scoped reloads Keep sibling identities connected during named-account edits. Fence profile publication after cancellation and join pending profile work after relay close so replacement account lifetimes cannot overlap stale profile effects. Co-authored-by: yu-xin-c <[email protected]> * fix(gateway): reconcile channel lifetimes after secret resolution Route no-op secret publication through the existing reload transaction and merge resolved channel effects with its authored restart scope. Leave cold accounts stopped without masking lifecycle failures or undoing manual stops. Preserve shared-auth generation ownership across provider-only changes. Discovered while verifying Buzz multiaccount setup and isolated recovery. Co-authored-by: yu-xin-c <[email protected]> * fix(buzz): align setup reload policy and account guidance Declare isolated named-account reloads on the standalone setup descriptor. Cover both public descriptors and document nested room and auth-tag paths, including the implicit-root-only environment fallback. Co-authored-by: yu-xin-c <[email protected]> --------- Co-authored-by: yu-xin-c <[email protected]>
1 parent ffdc6c1 commit c3ff7f9

58 files changed

Lines changed: 3055 additions & 730 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/assertion-safety-baseline.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ extensions/buzz/src/inbound.ts 1
133133
extensions/buzz/src/message-event.ts 2
134134
extensions/buzz/src/qa/adapter.runtime.ts 2
135135
extensions/buzz/src/room-membership.ts 2
136-
extensions/buzz/src/setup-core.ts 1
137-
extensions/buzz/src/setup-surface.ts 1
138136
extensions/buzz/src/setup-verify.ts 5
139137
extensions/buzz/src/types.ts 2
140138
extensions/byteplus/video-generation-provider.ts 1

‎docs/channels/buzz.md‎

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,29 @@ openclaw channels add --channel buzz
7676

7777
The setup flow walks through the following steps:
7878

79-
1. Enter the Buzz relay URL if one is not already configured.
80-
2. OpenClaw reuses the configured bot identity or generates one automatically.
81-
3. If the bot does not have room access yet, give the displayed public key to a
79+
1. Choose an existing Buzz account or add a named account.
80+
2. Enter the Buzz relay URL if one is not already configured for that account.
81+
3. OpenClaw reuses that account's bot identity or generates one automatically.
82+
4. If the bot does not have room access yet, give the displayed public key to a
8283
Buzz room owner or admin.
83-
4. OpenClaw waits for Buzz to confirm the **Bot** role and continues
84+
5. OpenClaw waits for Buzz to confirm the **Bot** role and continues
8485
automatically. If the automatic wait expires, retry authenticated discovery
8586
or go back without changing the generated identity.
86-
5. If Buzz returns one room, OpenClaw selects it. If Buzz returns several,
87+
6. If Buzz returns one room, OpenClaw selects it. If Buzz returns several,
8788
select the rooms to use and the default outbound room.
88-
6. OpenClaw saves the configuration and silently verifies the authenticated
89+
7. OpenClaw saves the configuration and silently verifies the authenticated
8990
room when the Gateway is running.
9091

9192
Fresh setup accepts normal messages from current members of the configured
9293
rooms without requiring a composer mention. Existing explicit mention and
9394
sender-allowlist settings are preserved when setup is rerun.
9495

96+
Setup resolves the selected account's `privateKey` and `authTag` SecretRefs
97+
without replacing the references in your configuration. If a configured secret
98+
is unavailable, setup reports the error without saving account changes. Make
99+
the secret available and rerun setup; existing accounts are not disabled.
100+
Select at least one authorized room to complete setup, or go back to leave it.
101+
95102
The automatic room-access wait is bounded. If access is not granted in time,
96103
setup remains open and offers authenticated Retry/Back controls. Every retry
97104
reuses the same relay and bot identity; the timeout does not disable Buzz or
@@ -126,12 +133,16 @@ preserves an existing agent-directory profile and channel-add policy; for a new
126133
profile it allows authorized Buzz users to add the identity. This lets Buzz
127134
assign the **Bot** role when the identity is invited to additional rooms
128135
instead of treating it as a normal member. OpenClaw still receives messages
129-
only from rooms explicitly selected in `channels.buzz.groups`.
136+
only from rooms explicitly selected in that account's `groups`: use
137+
`channels.buzz.groups` for the implicit root identity or
138+
`channels.buzz.accounts.<id>.groups` for a nested identity.
130139

131140
Buzz displays `owner unavailable` when the bot profile has no valid NIP-OA
132-
owner attestation. This does not mean room access failed. When
133-
`channels.buzz.authTag` is configured, OpenClaw includes that attestation in the
134-
published profile so Buzz can show the verified human owner.
141+
owner attestation. This does not mean room access failed. Configure the selected
142+
identity's `authTag` at `channels.buzz.authTag` for the implicit root identity or
143+
`channels.buzz.accounts.<id>.authTag` for a nested identity. OpenClaw includes
144+
that attestation in the published profile so Buzz can show the verified human
145+
owner.
135146

136147
While the Gateway is connected, OpenClaw publishes and refreshes the bot's
137148
ephemeral Buzz presence every 30 seconds. Buzz removes the presence when the
@@ -457,18 +468,71 @@ example `"[Support]"`. Use `"auto"` for the routed agent's identity name,
457468
`"[{model}]"` for its selected model, or `""` to disable an inherited global
458469
prefix. Explicit `message` tool and CLI text sends also apply literal and
459470
identity prefixes; see [shared prefix behavior](/concepts/messages#prefixes-threading-and-replies)
460-
for model-dependent templates. Buzz uses one account per Gateway, so there is
461-
no nested `accounts` override.
471+
for model-dependent templates. A named account can override the root prefix
472+
with `channels.buzz.accounts.<id>.responsePrefix`.
473+
CLI sends that omit `--account` use the selected default account's prefix too;
474+
an account-level `""` suppresses the inherited root prefix.
475+
476+
### Multiple bot identities
477+
478+
One Gateway can run independent Buzz accounts, each with its own relay, bot key,
479+
authorization value, and selected rooms. Run `openclaw channels add --channel buzz`
480+
and choose a new account to configure it interactively. Adding a named account
481+
does not move or replace the existing root identity.
482+
483+
```json5
484+
{
485+
channels: {
486+
buzz: {
487+
relayUrl: "wss://buzz.example.com",
488+
privateKey: { source: "env", provider: "default", id: "BUZZ_ROOT_KEY" },
489+
groupPolicy: "allowlist",
490+
groups: { "7c4a6d2a-2ed9-4b4e-a5e2-4d705ee9b34c": {} },
491+
accounts: {
492+
ada: {
493+
name: "Ada",
494+
relayUrl: "wss://buzz.example.com",
495+
privateKey: { source: "env", provider: "default", id: "BUZZ_ADA_KEY" },
496+
groups: { "940d0c32-4eb7-46d7-9d5b-d975aaef87f7": {} },
497+
},
498+
},
499+
},
500+
},
501+
}
502+
```
503+
504+
Named accounts inherit root policy and delivery settings, but never root
505+
`name`, `relayUrl`, `privateKey`, `authTag`, `groups`, or `defaultTo`. Set those
506+
identity and room fields on each account. An explicit `accounts.default` also
507+
owns a complete identity and replaces the implicit root identity; it does not
508+
borrow root credentials or `BUZZ_*` environment variables.
509+
510+
Set `defaultAccount` to select the account used when a command omits `--account`.
511+
Otherwise the implicit root/default identity is preferred, then the first
512+
configured account in sorted order. Account keys use lowercase letters, digits,
513+
hyphens, and underscores, start with a letter or digit, and are at most 64
514+
characters; `constructor` and `prototype` are reserved.
515+
516+
Use `--account ada` with message and directory commands, and add `accountId: "ada"`
517+
to a binding's `match` object when routing that bot to an agent. Set
518+
`channels.buzz.accounts.ada.enabled: false` to disable only Ada;
519+
`channels.buzz.enabled: false` disables all Buzz accounts. Buzz does not yet
520+
support account disabling or deletion through `channels remove`.
521+
522+
Editing an existing named account reloads only that account, leaving healthy
523+
sibling accounts connected. Changes to shared Buzz settings, `accounts.default`,
524+
or removed accounts reload the whole channel. Account shutdown waits for admitted
525+
message work and pending profile synchronization before starting a replacement.
462526

463527
### Bot key storage
464528

465529
The default guided path reuses the current bot identity or generates a private
466-
key and stores it in `channels.buzz.privateKey`, following OpenClaw's current
530+
key and stores it in the selected account's `privateKey`, following OpenClaw's current
467531
plaintext config convention.
468532

469533
For an existing key, setup can use plaintext or an existing `env`, `file`, or
470534
`exec` SecretRef. See [Secrets management](/gateway/secrets) for provider setup.
471-
The default account can also read:
535+
The implicit root default identity can also read:
472536

473537
```bash
474538
export BUZZ_RELAY_URL="wss://buzz.example.com"
@@ -487,7 +551,10 @@ command saves credentials and settings; use guided setup to discover and select
487551
rooms before starting a new bot.
488552

489553
If a hosted workspace operator gives you an identity authorization value, set
490-
`channels.buzz.authTag` or `BUZZ_AUTH_TAG`. It can use the same plaintext or
554+
the selected identity's `authTag`. The implicit root identity uses
555+
`channels.buzz.authTag` and can fall back to `BUZZ_AUTH_TAG`. Nested identities,
556+
including `accounts.default`, use `channels.buzz.accounts.<id>.authTag` and
557+
never borrow that environment fallback. The field accepts the same plaintext or
491558
SecretRef forms as the private key. Treat this delegated, reusable value as a
492559
secret: keep it out of logs, screenshots, chat, and source control, and prefer a
493560
SecretRef for persistent deployments. Request a replacement and revoke the old

‎docs/gateway/secrets.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Plaintext credentials remain agent-readable when they sit in files the agent can
2424
- Secrets resolve into an in-memory runtime snapshot, eagerly during activation, not lazily on request paths.
2525
- Cold Gateway startup isolates a retryable SecretRef failure to a known non-Gateway owner when that owner supports isolation. Mapped owner classes include model providers and skills, media/TTS/cron providers, eligible auth profiles, per-agent memory, sandbox SSH, channel accounts, and manifest-declared plugin routes. The Gateway starts, records the owner as configured-unavailable, and emits a redacted degradation warning. Gateway ingress auth, structurally invalid refs or resolved values, fail-closed owners, and refs whose runtime owner is not mapped still fail startup.
2626
- Reload validates each mapped owner independently, then publishes one atomic snapshot. Healthy owners refresh. An eligible failed owner keeps its last-known-good value and becomes stale only when its ref identities, provider definitions, and complete non-secret owner contract are unchanged; a changed or new failed owner becomes cold. A strict failure rejects the reload and preserves the active snapshot.
27+
- Config reload also reconciles channel connections when a secret-provider edit changes resolved credentials. Plugins that support account-scoped reload restart only the affected named accounts; shared, default, removed, or unresolved account changes use the plugin's whole-channel restart policy. Cold accounts stop, eligible stale accounts keep using their last-known-good credentials, and recovery preserves manual stops.
2728
- Policy violations (for example an OAuth-mode auth profile combined with SecretRef input) fail activation before the runtime swap.
2829
- Runtime requests read only the active in-memory snapshot. Model-provider SecretRef credentials pass through auth storage and stream options as process-local sentinels until egress. Outbound delivery paths (Discord reply/thread delivery, Telegram action sends) also read that snapshot and do not re-resolve refs per send.
2930
- Read-only channel capability discovery evaluates accounts independently. A configured-but-unavailable account does not hide healthy sibling accounts' message actions, while direct sends through the unavailable account still fail closed.

‎docs/plugins/sdk-setup.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,17 @@ When a channel upgrades from a single-account top-level config to `channels.<id>
437437

438438
Every channel plugin can extend or narrow that promotion through its setup adapter:
439439

440+
- `configPromotion: "preserve-root"`: keep all root values in place, including common name, policy, and delivery fields; the plugin owns its account layout
440441
- `singleAccountKeysToMove`: extra top-level keys that should move into the promoted account
441442
- `namedAccountPromotionKeys`: when named accounts already exist, only these keys move into the promoted account; shared policy/delivery keys stay at the channel root
442443
- `resolveSingleAccountPromotionTarget(...)`: choose which existing account receives promoted values
443444

444-
The presence of `singleAccountKeysToMove` marks the promotion contract complete. Declare the field even when it is an empty array to opt out of legacy key promotion. Adapters that omit the field retain a reader-backed pre-declaration promotion tier for already-published plugins. The 2026-07-22 registry sweep removed 23 keys with no published dependents and retained six common keys plus the setup-only `rooms` key. Each retained key is deleted as soon as its published readers migrate to declarations; no version boundary is required.
445+
The presence of `singleAccountKeysToMove` marks the promotion contract complete. Declare the field even when it is an empty array to opt out of legacy key promotion; an empty array does not suppress common fields. Adapters that omit the field retain a reader-backed pre-declaration promotion tier for already-published plugins. The 2026-07-22 registry sweep removed 23 keys with no published dependents and retained six common keys plus the setup-only `rooms` key. Each retained key is deleted as soon as its published readers migrate to declarations; no version boundary is required.
445446

446447
Declare `openclaw.setupFeatures.configPromotion: true` in the plugin package manifest when doctor must load these declarations from the lightweight bundled setup artifact. The setup-only plugin surface and the full channel plugin must expose the same declarations.
447448

449+
For a plugin-owned root layout, also declare `openclaw.setupFeatures.configPromotion: "preserve-root"` in `package.json`. Doctor reads this static declaration for installed and bundled plugins, including disabled plugins, without executing their runtime. Omitting the declaration or using `false` does not opt out of promotion. The runtime declaration belongs on the adapter passed to `defineChannelSetupContract`, and covers shared CLI, declarative wizard, and policy-writer promotion. It does not change helpers that explicitly migrate a base name; use a selected-account writer when the root remains an implicit identity. Buzz is an example of this layout.
450+
448451
When calling `moveSingleAccountChannelSectionToDefaultAccount(...)` with an already resolved plugin, pass its setup adapter as `setupSurface`. Caller-supplied setup surfaces take precedence over loaded and bundled lookup, which keeps scoped or setup-only plugins independent of global registration.
449452

450453
<Note>

‎docs/reference/secretref-credential-surface.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ Source generation fails if a present channel secret-contract artifact cannot loa
9090
- `channels.sms.accounts.*.authToken`
9191
- `channels.buzz.authTag`
9292
- `channels.buzz.privateKey`
93+
- `channels.buzz.accounts.*.authTag`
94+
- `channels.buzz.accounts.*.privateKey`
9395
- `channels.clickclack.token`
9496
- `channels.clickclack.accounts.*.token`
9597
- `channels.discord.token`

‎docs/reference/secretref-user-supplied-credentials-matrix.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@
5252
"optIn": true,
5353
"notes": "Compatibility exception: sibling ref field remains canonical."
5454
},
55+
{
56+
"id": "channels.buzz.accounts.*.authTag",
57+
"configFile": "openclaw.json",
58+
"path": "channels.buzz.accounts.*.authTag",
59+
"secretShape": "secret_input",
60+
"optIn": true
61+
},
62+
{
63+
"id": "channels.buzz.accounts.*.privateKey",
64+
"configFile": "openclaw.json",
65+
"path": "channels.buzz.accounts.*.privateKey",
66+
"secretShape": "secret_input",
67+
"optIn": true
68+
},
5569
{
5670
"id": "channels.buzz.authTag",
5771
"configFile": "openclaw.json",

‎extensions/buzz/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"./index.ts"
2929
],
3030
"setupEntry": "./setup-entry.ts",
31+
"setupFeatures": {
32+
"configPromotion": "preserve-root"
33+
},
3134
"channel": {
3235
"id": "buzz",
3336
"configuredState": {
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { mkdtempSync, rmSync } from "node:fs";
2+
import { tmpdir } from "node:os";
3+
import path from "node:path";
4+
import { finalizeEvent, getPublicKey, type Event } from "nostr-tools";
5+
import { afterEach, beforeEach, vi } from "vitest";
6+
import { sendBuzzTextOneShot, startBuzzBus, type BuzzBus } from "./buzz-bus.js";
7+
import { relayMocks } from "./buzz-bus.test-helpers.js";
8+
9+
const PRIVATE_KEY = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f";
10+
const SENDER_PRIVATE_KEY = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20";
11+
const ACCOUNT_ID = "default";
12+
const CHANNEL_ID = "7c4a6d2a-2ed9-4b4e-a5e2-4d705ee9b34c";
13+
const BOT_PUBLIC_KEY = getPublicKey(Uint8Array.from(Buffer.from(PRIVATE_KEY, "hex")));
14+
const SENDER_PUBLIC_KEY = getPublicKey(Uint8Array.from(Buffer.from(SENDER_PRIVATE_KEY, "hex")));
15+
const SENDER_SECRET_KEY = Uint8Array.from(Buffer.from(SENDER_PRIVATE_KEY, "hex"));
16+
const RELAY_PUBLIC_KEY = "f".repeat(64);
17+
const tempDirs = new Set<string>();
18+
let previousStateDir: string | undefined;
19+
let stateDir: string;
20+
21+
function startTestBus(
22+
overrides: Partial<Parameters<typeof startBuzzBus>[0]> = {},
23+
): Promise<BuzzBus> {
24+
return startBuzzBus({
25+
accountId: ACCOUNT_ID,
26+
relayUrl: "wss://buzz.example.com",
27+
privateKey: PRIVATE_KEY,
28+
channelIds: [CHANNEL_ID],
29+
onMessage: async () => {},
30+
...overrides,
31+
});
32+
}
33+
34+
function sendTestTextOneShot(
35+
overrides: Partial<Parameters<typeof sendBuzzTextOneShot>[0]> = {},
36+
): Promise<string> {
37+
return sendBuzzTextOneShot({
38+
relayUrl: "wss://buzz.example.com",
39+
privateKey: PRIVATE_KEY,
40+
channelId: CHANNEL_ID,
41+
text: "hello",
42+
...overrides,
43+
});
44+
}
45+
46+
function signSenderEvent(template: Parameters<typeof finalizeEvent>[0]): Event {
47+
return finalizeEvent(template, SENDER_SECRET_KEY);
48+
}
49+
50+
function subscriptionIncludesKind(
51+
subscription: (typeof relayMocks.subscriptions)[number],
52+
kind: number,
53+
): boolean {
54+
return subscription.filters.some((filter) => filter.kinds?.includes(kind));
55+
}
56+
57+
export function useBuzzBusLifecycleFixture() {
58+
beforeEach(() => {
59+
previousStateDir = process.env.OPENCLAW_STATE_DIR;
60+
// openclaw-temp-dir: allow extension tests cannot import root test helpers.
61+
stateDir = mkdtempSync(path.join(tmpdir(), "openclaw-buzz-dedupe-"));
62+
tempDirs.add(stateDir);
63+
process.env.OPENCLAW_STATE_DIR = stateDir;
64+
vi.clearAllMocks();
65+
relayMocks.subscriptions.length = 0;
66+
relayMocks.profileEvents = [];
67+
relayMocks.roomMetadataEvents = [];
68+
relayMocks.roomHistoryEvents = [];
69+
relayMocks.beforeRoomHistoryEvent = undefined;
70+
relayMocks.membershipEvents = [
71+
{
72+
id: "membership-1",
73+
kind: 39002,
74+
pubkey: RELAY_PUBLIC_KEY,
75+
created_at: 1_700_000_000,
76+
content: "",
77+
sig: "e".repeat(128),
78+
tags: [
79+
["d", CHANNEL_ID],
80+
["p", BOT_PUBLIC_KEY, "", "bot"],
81+
["p", SENDER_PUBLIC_KEY, "", "member"],
82+
],
83+
},
84+
];
85+
relayMocks.connect.mockResolvedValue();
86+
relayMocks.auth.mockRejectedValue(new Error("auth rejected"));
87+
relayMocks.publish.mockResolvedValue("");
88+
relayMocks.send.mockResolvedValue();
89+
relayMocks.connected = true;
90+
relayMocks.stallProfileQueryEose = false;
91+
relayMocks.stallRoomEoseChannelId = undefined;
92+
vi.stubGlobal(
93+
"fetch",
94+
vi.fn(async () =>
95+
Response.json({
96+
self: RELAY_PUBLIC_KEY,
97+
software: "https://github.com/block/buzz",
98+
}),
99+
),
100+
);
101+
});
102+
103+
afterEach(() => {
104+
vi.useRealTimers();
105+
if (previousStateDir === undefined) {
106+
delete process.env.OPENCLAW_STATE_DIR;
107+
} else {
108+
process.env.OPENCLAW_STATE_DIR = previousStateDir;
109+
}
110+
for (const tempDir of tempDirs) {
111+
rmSync(tempDir, { recursive: true, force: true });
112+
}
113+
tempDirs.clear();
114+
});
115+
return {
116+
PRIVATE_KEY,
117+
ACCOUNT_ID,
118+
CHANNEL_ID,
119+
BOT_PUBLIC_KEY,
120+
SENDER_PUBLIC_KEY,
121+
RELAY_PUBLIC_KEY,
122+
startTestBus,
123+
sendTestTextOneShot,
124+
signSenderEvent,
125+
subscriptionIncludesKind,
126+
};
127+
}

0 commit comments

Comments
 (0)