Skip to content

Commit 8668aeb

Browse files
fix(discord): bind transcript capture to source account [AI] (#118579)
* fix(discord): bind transcript capture to source account * style(agents): keep transcript tool wiring compact * fix(transcripts): declare account binding channels * fix(transcripts): report effective capture account * fix(transcripts): enforce account lifecycle ownership * fix(transcripts): preserve cross-surface control * fix(copilot): preserve transcript channel context * fix(transcripts): fail closed for legacy channel owners * fix(transcripts): add trusted legacy recovery * fix(transcripts): preserve auto-start cleanup ownership * fix(transcripts): reject untrusted account starts * fix(transcripts): keep persisted ownership authoritative * fix(transcripts): harden legacy recovery * fix(transcripts): preserve agent ownership boundary * fix(transcripts): scope account binding to source channel * fix(transcripts): preserve unattributed owner isolation * fix(transcripts): own configured captures by account * docs(plugins): clarify transcript auto-start ownership * test(transcripts): cover account-less recovery * docs(transcripts): scope legacy recovery by provider * fix(discord): reuse eligible account ordering for transcripts * test(discord): use neutral transcript account fixtures * fix(transcripts): keep accountless recovery local * fix(discord): resolve transcript accounts by voice capability * fix(transcripts): bound account resolution failures * fix(transcripts): bound account tool output * fix(transcripts): honor unresolved provider accounts * fix(transcripts): preserve binding when providers are missing * fix(transcripts): fail closed on unknown binding provenance * fix(transcripts): qualify account lifecycle capability * fix(transcripts): normalize provable legacy owners * fix(transcripts): bind scheduled capture to caller authority * fix(transcripts): preserve scheduled caller identity tuple * fix(transcripts): preserve channel-less scheduled authority * fix(plugin-sdk): publish transcript provider types * fix(transcripts): use exact lifecycle ownership tokens * fix(transcripts): preserve local ownerless lifecycle access * fix(transcripts): allow local configured capture control * fix(transcripts): preserve scheduled caller channel * fix(transcripts): retain named-agent legacy recovery * fix(transcripts): deny unrelated remote channels * fix(doctor): validate transcript owner inference * fix(transcripts): restrict legacy remote recovery * fix(ci): align transcript Doctor checks * fix(transcripts): require Doctor-owned legacy metadata * fix(transcripts): reject unowned remote capture starts * fix(transcripts): reject unbound Discord lifecycle calls * fix(transcripts): distinguish legacy owner rows * test(discord): keep unavailable account fixture typed * fix(transcripts): mark current imports for Doctor * fix(transcripts): complete account ownership validation * fix(discord): restore transcript package boundary * fix(discord): preserve bundled transcript entry boundary * docs(transcripts): clarify Discord auto-start account * fix(transcripts): bind account-owned imports * fix: preserve transcript and cron policy state * fix(cron): preserve scheduled transcript authority * fix(discord): keep legacy transcript rows local * fix(transcripts): narrow account ownership boundary * fix(transcripts): preserve trusted caller ownership * fix(discord): enforce transcript source authorization * fix(ci): bound Control UI gzip build variance * test(qa): align transcript scenario contracts * fix(agents): repair rebased caller context * fix(discord): restore rebased account ownership * test(discord): restore voice account fixtures --------- Co-authored-by: joshavant <[email protected]>
1 parent dbc2356 commit 8668aeb

89 files changed

Lines changed: 4382 additions & 424 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.

‎docs/cli/transcripts.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ Use `path <session> --transcript` to inspect the raw append-only transcript,
112112
or run the `transcripts` tool's `summarize` action to regenerate the Markdown
113113
summary.
114114

115+
Historical sessions without complete account-owner metadata remain on a local
116+
recovery path. Recover an agent-owned row with a local turn for that agent; a row
117+
with no agent attribution requires a local main-agent turn. Sources without
118+
account binding retain main-agent access across their normal surfaces. Missing
119+
providers, partial owner metadata, and accountless historical sources also stay
120+
on this local recovery path.
121+
122+
```bash
123+
openclaw agent --agent <owning-agent-or-main> --local --message \
124+
"Use transcripts summarize for session <session>."
125+
```
126+
115127
## Upgrading the legacy file store
116128

117129
OpenClaw releases that predate the SQLite store wrote canonical runtime state
@@ -147,7 +159,11 @@ Meeting transcript capture is enabled by default. To opt out globally:
147159
Configure auto-start sources with `transcripts.autoStart`. Each entry is
148160
enabled by being present; omit an entry to disable that source. `discord-voice`
149161
is the bundled auto-start-capable source and requires `guildId` and
150-
`channelId`:
162+
`channelId`. When exactly one configured Discord account has credentials and
163+
voice enabled, OpenClaw selects it automatically. When multiple accounts are
164+
voice-capable, OpenClaw selects a capable `channels.discord.defaultAccount`.
165+
Otherwise, set `accountId` to the corresponding key under
166+
`channels.discord.accounts`; an omitted account is rejected as ambiguous:
151167

152168
```json
153169
{
@@ -156,6 +172,7 @@ Meeting transcript capture is enabled by default. To opt out globally:
156172
"autoStart": [
157173
{
158174
"providerId": "discord-voice",
175+
"accountId": "work",
159176
"guildId": "1234567890",
160177
"channelId": "2345678901"
161178
}

‎docs/concepts/qa-e2e-automation.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,12 @@ Discord YAML module scenarios (`qa/scenarios/channels/discord-*.yaml`):
614614
Discord voice state is the target voice/stage channel. Convex Discord
615615
credentials may include optional `voiceChannelId`; otherwise the runner
616616
adapter discovers the first visible voice/stage channel in the guild.
617+
- `discord-transcripts-voice-authorization` - opt-in live-model scenario. A
618+
real driver-bot message first proves a sender excluded from the target voice
619+
channel receives a visible transcript-tool denial without a join. The same
620+
sender is then allowlisted and must start, stop, and leave live capture. The
621+
scenario writes redacted JSON evidence and deletes its known Discord
622+
messages during cleanup.
617623
- `discord-status-reactions-tool-only` - opt-in Mantis scenario. Runs by
618624
itself because it switches the SUT to always-on, tool-only guild replies
619625
with `messages.statusReactions.enabled=true`, then captures a REST
@@ -631,6 +637,16 @@ pnpm openclaw qa discord \
631637
--provider-mode mock-openai
632638
```
633639

640+
Run the transcript authorization scenario with a Convex lease:
641+
642+
```bash
643+
pnpm openclaw qa discord \
644+
--scenario discord-transcripts-voice-authorization \
645+
--provider-mode live-frontier \
646+
--credential-source convex \
647+
--credential-role maintainer
648+
```
649+
634650
Run the Mantis status-reaction scenario explicitly:
635651

636652
```bash
@@ -1077,7 +1093,8 @@ sutAuthTag?: string }` - `relayUrl` must use `wss://`, with `ws://` allowed only
10771093
for loopback relays; `roomId` must be a channel UUID, and the identities must
10781094
be distinct.
10791095
- Discord (`kind: "discord"`): `{ guildId: string, channelId: string,
1080-
driverBotToken: string, sutBotToken: string, sutApplicationId: string }`.
1096+
driverBotToken: string, sutBotToken: string, sutApplicationId: string,
1097+
voiceChannelId?: string }`.
10811098
- Telegram (`kind: "telegram"`): `{ groupId: string, driverToken: string,
10821099
sutToken: string }` - `groupId` must be a numeric chat-id string.
10831100
- Telegram real user (`kind: "telegram-user"`): `{ groupId: string, sutToken:

‎docs/plugins/sdk-overview.md‎

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,39 @@ and external URLs. Registering another provider replaces the current provider.
9696

9797
### Capability registration
9898

99-
| Method | What it registers |
100-
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
101-
| `api.registerProvider(...)` | Text inference (LLM) |
102-
| `api.registerWorkerProvider(...)` | Cloud-worker lifecycle leases |
103-
| `api.registerModelCatalogProvider(...)` | Model catalog rows for text and media generation |
104-
| `api.registerAgentHarness(...)` | [Experimental](/plugins/sdk-agent-harness) native agent executor (Codex, Copilot) |
105-
| `api.registerCliBackend(...)` | Local CLI inference backend |
106-
| `api.registerChannel(...)` | Messaging channel |
107-
| `api.registerEmbeddingProvider(...)` | Reusable vector embedding provider |
108-
| `api.registerSpeechProvider(...)` | Text-to-speech / STT synthesis |
109-
| `api.registerRealtimeTranscriptionProvider(...)` | Streaming realtime transcription |
110-
| `api.registerRealtimeVoiceProvider(...)` | Duplex realtime voice sessions |
111-
| `api.registerMediaUnderstandingProvider(...)` | Image/audio/video analysis |
112-
| `api.registerTranscriptSourceProvider(...)` | Live or imported meeting transcript source; meeting plugins can use `createMeetingTranscriptSourceProvider` from `plugin-sdk/transcripts` |
113-
| `api.registerImageGenerationProvider(...)` | Image generation |
114-
| `api.registerMusicGenerationProvider(...)` | Music generation |
115-
| `api.registerVideoGenerationProvider(...)` | Video generation |
116-
| `api.registerWebFetchProvider(...)` | Web fetch / scrape provider |
117-
| `api.registerWebSearchProvider(...)` | Web search |
118-
| `api.registerCompactionProvider(...)` | Pluggable transcript-compaction backend |
99+
| Method | What it registers |
100+
| ------------------------------------------------ | --------------------------------------------------------------------------------- |
101+
| `api.registerProvider(...)` | Text inference (LLM) |
102+
| `api.registerWorkerProvider(...)` | Cloud-worker lifecycle leases |
103+
| `api.registerModelCatalogProvider(...)` | Model catalog rows for text and media generation |
104+
| `api.registerAgentHarness(...)` | [Experimental](/plugins/sdk-agent-harness) native agent executor (Codex, Copilot) |
105+
| `api.registerCliBackend(...)` | Local CLI inference backend |
106+
| `api.registerChannel(...)` | Messaging channel |
107+
| `api.registerEmbeddingProvider(...)` | Reusable vector embedding provider |
108+
| `api.registerSpeechProvider(...)` | Text-to-speech / STT synthesis |
109+
| `api.registerRealtimeTranscriptionProvider(...)` | Streaming realtime transcription |
110+
| `api.registerRealtimeVoiceProvider(...)` | Duplex realtime voice sessions |
111+
| `api.registerMediaUnderstandingProvider(...)` | Image/audio/video analysis |
112+
| `api.registerTranscriptSourceProvider(...)` | Live or imported meeting transcript source |
113+
| `api.registerImageGenerationProvider(...)` | Image generation |
114+
| `api.registerMusicGenerationProvider(...)` | Music generation |
115+
| `api.registerVideoGenerationProvider(...)` | Video generation |
116+
| `api.registerWebFetchProvider(...)` | Web fetch / scrape provider |
117+
| `api.registerWebSearchProvider(...)` | Web search |
118+
| `api.registerCompactionProvider(...)` | Pluggable transcript-compaction backend |
119+
120+
Transcript source providers that share an account namespace with an inbound
121+
channel declare an `accountOwnership` descriptor with that channel id and a
122+
canonical account resolver. OpenClaw then
123+
ignores model-selected account ids for same-channel capture, binds the trusted
124+
inbound account, and records it as the session owner for later lifecycle
125+
actions. The resolver also selects an omitted account before OpenClaw starts or
126+
persists live capture. It validates an already-bound trusted account without
127+
redirecting it and returns an actionable typed error when no unique capable
128+
account exists. Configured auto-start must supply a nonempty source account or
129+
resolve one with this descriptor. OpenClaw rejects ambiguous or unresolved ownership before it
130+
persists the start or invokes the provider. Provider aliases are lookup names
131+
only and must not be used for this declaration.
119132

120133
Worker providers must also declare their id in `contracts.workerProviders`.
121134
Core persists durable intent before `provision(profile, operationId)`. Providers validate settings before external allocation and throw `WorkerProviderError` for permanent profile rejection. `provision` must adopt the same lease when the operation id repeats. Providers whose provisioning can legitimately exceed core's five-minute default may return a positive millisecond budget from `resolveProvisionTimeoutMs(profile)`; include acquisition, provider-owned setup, and cleanup in that bound.

‎extensions/copilot/src/tool-bridge.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,29 @@ describe("createCopilotToolBridge", () => {
714714
expect(getOpts().messageProvider).toBe("telegram");
715715
});
716716

717+
it("preserves the Discord channel separately from the voice provider", async () => {
718+
const { createOpenClawCodingTools, getOpts } = captureCall();
719+
720+
await createCopilotToolBridge({
721+
agentId: "agent-1",
722+
attemptParams: {
723+
agentAccountId: "account-a",
724+
messageChannel: "discord",
725+
messageProvider: "discord-voice",
726+
} as never,
727+
createOpenClawCodingTools,
728+
modelId: "gpt-4o",
729+
modelProvider: "github-copilot",
730+
sessionId: "session-1",
731+
});
732+
733+
expect(getOpts()).toMatchObject({
734+
agentAccountId: "account-a",
735+
messageChannel: "discord",
736+
messageProvider: "discord-voice",
737+
});
738+
});
739+
717740
it("forwards authProfileStore, runId, config, and run hooks (onToolOutcome) from attemptParams", async () => {
718741
const { createOpenClawCodingTools, getOpts } = captureCall();
719742
const authProfileStore = { kind: "fake-store" } as never;

‎extensions/copilot/src/tool-bridge.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ function buildOpenClawCodingToolsOptions(
409409
elevated: a.bashElevated,
410410
},
411411
messageProvider: a.messageProvider ?? a.messageChannel,
412+
messageChannel: a.messageChannel,
412413
toolBindings: a.toolBindings,
413414
chatType: a.chatType,
414415
agentAccountId: a.agentAccountId,

‎extensions/discord/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";
33
import { registerDiscordActivities } from "./activities-api.js";
44
import { registerDiscordSubagentHooks } from "./subagent-hooks-api.js";
5-
import { discordVoiceTranscriptsSourceProvider } from "./transcripts-source-api.js";
5+
import { registerDiscordTranscriptSourceProvider } from "./transcripts-source-api.js";
66

77
export default defineBundledChannelEntry({
88
id: "discord",
@@ -26,6 +26,6 @@ export default defineBundledChannelEntry({
2626
registerDiscordSubagentHooks(api);
2727
},
2828
registerCapabilities(api) {
29-
api.registerTranscriptSourceProvider(discordVoiceTranscriptsSourceProvider);
29+
registerDiscordTranscriptSourceProvider(api);
3030
},
3131
});

‎extensions/discord/src/accounts.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {
1111
} from "openclaw/plugin-sdk/channel-config-helpers";
1212
import { resolveAccountEntry } from "openclaw/plugin-sdk/routing";
1313
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
14-
import type { DiscordAccountConfig, DiscordActionConfig, OpenClawConfig } from "./runtime-api.js";
14+
import {
15+
resolveConfiguredFromCredentialStatuses,
16+
type DiscordAccountConfig,
17+
type DiscordActionConfig,
18+
type OpenClawConfig,
19+
} from "./runtime-api.js";
1520
import { selectDiscordRuntimeConfig } from "./runtime-config.js";
1621
import { resolveDiscordToken, type DiscordCredentialStatus } from "./token.js";
1722

@@ -189,3 +194,23 @@ export function listEnabledDiscordAccounts(cfg: OpenClawConfig): ResolvedDiscord
189194
.map((accountId) => resolveDiscordAccount({ cfg, accountId }))
190195
.filter((account) => isDiscordAccountEnabledForRuntime(account, cfg));
191196
}
197+
198+
export function listDiscordStartupAccountIds(cfg: OpenClawConfig): string[] {
199+
const startupAccountIds = listEnabledDiscordAccounts(cfg)
200+
.filter(
201+
(candidate) =>
202+
resolveConfiguredFromCredentialStatuses(candidate) ??
203+
Boolean(normalizeOptionalString(candidate.token)),
204+
)
205+
.map((candidate) => candidate.accountId);
206+
const defaultAccountId = resolveDefaultDiscordAccountId(cfg);
207+
// Promote only a gateway-eligible account; otherwise a disabled or unconfigured
208+
// default would waste the immediate startup slot while a real bot waits.
209+
if (!startupAccountIds.includes(defaultAccountId)) {
210+
return startupAccountIds;
211+
}
212+
return [
213+
defaultAccountId,
214+
...startupAccountIds.filter((candidateId) => candidateId !== defaultAccountId),
215+
];
216+
}

‎extensions/discord/src/channel.ts‎

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import {
2424
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
2525
import { resolveTargetsWithOptionalToken } from "openclaw/plugin-sdk/target-resolver-runtime";
2626
import {
27-
listEnabledDiscordAccounts,
28-
resolveDefaultDiscordAccountId,
27+
listDiscordStartupAccountIds,
2928
resolveDiscordAccount,
3029
resolveDiscordAccountAllowFrom,
3130
type ResolvedDiscordAccount,
@@ -231,28 +230,8 @@ const discordMessageActions = {
231230
},
232231
};
233232

234-
function resolveDiscordStartupAccountIds(cfg: OpenClawConfig): string[] {
235-
const startupAccountIds = listEnabledDiscordAccounts(cfg)
236-
.filter(
237-
(candidate) =>
238-
resolveConfiguredFromCredentialStatuses(candidate) ??
239-
Boolean(normalizeOptionalString(candidate.token)),
240-
)
241-
.map((candidate) => candidate.accountId);
242-
const defaultAccountId = resolveDefaultDiscordAccountId(cfg);
243-
// Promote only a gateway-eligible account; otherwise a disabled or unconfigured
244-
// default would waste the immediate startup slot while a real bot waits.
245-
if (!startupAccountIds.includes(defaultAccountId)) {
246-
return startupAccountIds;
247-
}
248-
return [
249-
defaultAccountId,
250-
...startupAccountIds.filter((candidateId) => candidateId !== defaultAccountId),
251-
];
252-
}
253-
254233
function resolveDiscordStartupDelayMs(cfg: OpenClawConfig, accountId: string): number {
255-
const startupAccountIds = resolveDiscordStartupAccountIds(cfg);
234+
const startupAccountIds = listDiscordStartupAccountIds(cfg);
256235
const startupIndex = startupAccountIds.findIndex((candidateId) => candidateId === accountId);
257236
return startupIndex <= 0 ? 0 : startupIndex * DISCORD_ACCOUNT_STARTUP_STAGGER_MS;
258237
}

‎extensions/discord/src/doctor.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,4 +689,46 @@ describe("discord doctor", () => {
689689

690690
expect(collectDiscordMissingEnvTokenWarnings({ cfg, env: {} })).toStrictEqual([]);
691691
});
692+
693+
it("warns when Discord transcript auto-start cannot choose between voice accounts", async () => {
694+
const cfg = {
695+
transcripts: {
696+
autoStart: [
697+
{
698+
providerId: "discord-voice",
699+
guildId: "guild-1",
700+
channelId: "channel-1",
701+
},
702+
{
703+
providerId: "discord-voice",
704+
accountId: "alpha",
705+
guildId: "guild-1",
706+
channelId: "channel-2",
707+
},
708+
{ providerId: "meeting", meetingUrl: "https://meet.example.test/standup" },
709+
],
710+
},
711+
channels: {
712+
discord: {
713+
accounts: {
714+
alpha: { token: "alpha-token", voice: { enabled: true } },
715+
bravo: { token: "bravo-token", voice: { enabled: true } },
716+
},
717+
},
718+
},
719+
} as unknown as OpenClawConfig;
720+
721+
const warnings =
722+
(await discordDoctor.collectPreviewWarnings?.({
723+
cfg,
724+
doctorFixCommand: "openclaw doctor --fix",
725+
env: {},
726+
})) ?? [];
727+
728+
expect(warnings).toHaveLength(1);
729+
expect(warnings[0]).toContain("transcripts.autoStart[0]");
730+
expect(warnings[0]).toContain("Multiple Discord accounts are enabled for voice");
731+
expect(warnings[0]).toContain("transcripts.autoStart[0].accountId");
732+
expect(warnings[0]).toContain("channels.discord.defaultAccount");
733+
});
692734
});

0 commit comments

Comments
 (0)