Skip to content

Commit b034527

Browse files
committed
merge: bound meeting audio lifecycle (#117733)
* commit '9931d8b9aaaea02b6083dbfce73689f4e5497b10': fix(meeting-bot): keep configured host options internal docs(changelog): note meeting audio bounds fix(meeting-bot): preserve node host SDK surface fix(meeting-bot): break node host import cycle refactor(meeting-bot): split configured host wrapper fix(meeting-bot): fence terminal audio teardown fix(meeting-bot): preserve graceful capture flush fix(meeting-bot): type optional input drain stream fix(meeting-bot): bound terminal audio drain refactor(meeting-bot): simplify terminal audio cleanup fix(meeting-bot): drain capture stdout before close fix(meeting-bot): drain terminal node audio fix(meeting-bot): harden node audio teardown fix(meeting-bot): bound node host audio retention test(meeting-bot): cover node audio retention limits
2 parents 12a8d80 + 9931d8b commit b034527

6 files changed

Lines changed: 853 additions & 163 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Docs: https://docs.openclaw.ai
7070
- **macOS remote tunnel lifecycle:** prevent cancelled or superseded restart backoffs from recreating SSH tunnels, and join a tunnel create that another caller started while the actor was suspended.
7171
- **macOS location permission requests:** coalesce concurrent prompts so every caller resumes, and stop cancelled timeouts from opening Settings or completing a newer request.
7272
- **macOS Voice Wake cancellation:** stop superseded silence, capture, and recognizer-restart timers immediately so cancelled work cannot restart the microphone pipeline or keep stale monitor loops alive.
73+
- **Meeting node audio retention:** bound captured audio and terminal retention for Google Meet, Teams, and Zoom node-host sessions, make close idempotent, and force stalled bridge processes down after the graceful shutdown window.
7374
- **Control UI update reconciliation:** preserve an unresolved managed-update request across disconnects, accept the replacement Gateway version when it proves success, and otherwise show explicit recovery guidance instead of trusting an unrelated cached update result or failing silently. Fixes #116075. Thanks @shakkernerd.
7475
- **Control UI model readiness:** put AI setup first when no model is selectable, distinguish signed-in credentials from ready providers, and route accounts with no exposed models directly to provider recovery instead of leading with disabled default controls.
7576
- **Control UI Talk session isolation:** stop active realtime Talk media and retire its callbacks before chat session changes, Gateway disconnects, or pane disposal so previous-session audio, transcript, camera, and status updates cannot leak into the next view. Thanks @shakkernerd.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { spawnSync } from "node:child_process";
2+
import { asRecord } from "@openclaw/normalization-core/record-coerce";
3+
import { createMeetingNodeHost, type MeetingNodeHostOptions } from "./node-host.js";
4+
5+
type MeetingConfiguredNodeHostOptions = Omit<MeetingNodeHostOptions, "assertAudioAvailable"> & {
6+
meetingLabel: string;
7+
outputMentionsAudioDevice(output: string): boolean;
8+
sharePrerequisiteDeadline: boolean;
9+
systemProfilerCommand: string;
10+
};
11+
12+
function readSetupCommand(params: Record<string, unknown>, name: string): string[] {
13+
const value = params[name];
14+
if (
15+
!Array.isArray(value) ||
16+
value.length === 0 ||
17+
value.some((entry) => typeof entry !== "string")
18+
) {
19+
throw new Error(`${name} must be a non-empty string array.`);
20+
}
21+
return value as string[];
22+
}
23+
24+
function isSpawnSyncTimeout(error: unknown): boolean {
25+
return error instanceof Error && "code" in error && error.code === "ETIMEDOUT";
26+
}
27+
28+
export function createMeetingConfiguredNodeHost(options: MeetingConfiguredNodeHostOptions) {
29+
const probeCommand = (command: string, timeoutMs: number): "found" | "missing" | "timed-out" => {
30+
const result = spawnSync("/bin/sh", ["-lc", 'command -v "$1" >/dev/null 2>&1', "sh", command], {
31+
encoding: "utf8",
32+
timeout: timeoutMs,
33+
});
34+
if (isSpawnSyncTimeout(result.error)) {
35+
return "timed-out";
36+
}
37+
return result.status === 0 ? "found" : "missing";
38+
};
39+
const assertAudioAvailable = (
40+
timeoutMs: number,
41+
commands: readonly (readonly string[])[] = [
42+
options.defaultAudioInputCommand,
43+
options.defaultAudioOutputCommand,
44+
],
45+
) => {
46+
if (process.platform !== "darwin") {
47+
throw new Error(`${options.meetingLabel} talk-back with BlackHole 2ch is macOS-only`);
48+
}
49+
const deadline = Date.now() + timeoutMs;
50+
const commandTimeout = () =>
51+
options.sharePrerequisiteDeadline ? Math.max(1, deadline - Date.now()) : timeoutMs;
52+
const result = spawnSync(options.systemProfilerCommand, ["SPAudioDataType"], {
53+
encoding: "utf8",
54+
timeout: commandTimeout(),
55+
});
56+
if (isSpawnSyncTimeout(result.error)) {
57+
throw new Error(`${options.meetingLabel} audio prerequisite check timed out on the node.`);
58+
}
59+
const stderr =
60+
result.stderr ??
61+
(result.error
62+
? result.error instanceof Error
63+
? result.error.message
64+
: String(result.error)
65+
: "");
66+
const output = `${result.stdout ?? ""}\n${stderr}`;
67+
if (
68+
(typeof result.status === "number" ? result.status : result.error ? 1 : 0) !== 0 ||
69+
!options.outputMentionsAudioDevice(output)
70+
) {
71+
throw new Error("BlackHole 2ch audio device not found on the node.");
72+
}
73+
const commandNames = new Set<string>();
74+
for (const argv of commands) {
75+
const command = argv[0];
76+
if (!command) {
77+
throw new Error(`Configured audio command not found on the node: ${command || "<empty>"}`);
78+
}
79+
commandNames.add(command);
80+
}
81+
for (const command of commandNames) {
82+
if (options.sharePrerequisiteDeadline && Date.now() >= deadline) {
83+
throw new Error(`${options.meetingLabel} audio prerequisite check timed out on the node.`);
84+
}
85+
const probeResult = probeCommand(command, commandTimeout());
86+
if (probeResult === "timed-out") {
87+
throw new Error(`${options.meetingLabel} audio prerequisite check timed out on the node.`);
88+
}
89+
if (probeResult === "missing") {
90+
throw new Error(`Configured audio command not found on the node: ${command}`);
91+
}
92+
}
93+
};
94+
const host = createMeetingNodeHost({ ...options, assertAudioAvailable });
95+
96+
return async (paramsJSON?: string | null): Promise<string> => {
97+
if (paramsJSON) {
98+
let raw: unknown;
99+
try {
100+
raw = JSON.parse(paramsJSON) as unknown;
101+
} catch {
102+
throw new Error(`${options.displayName} node host received malformed params JSON.`);
103+
}
104+
const params = asRecord(raw);
105+
if (params.action === "setup") {
106+
const commands = [
107+
readSetupCommand(params, "audioInputCommand"),
108+
readSetupCommand(params, "audioOutputCommand"),
109+
];
110+
if (params.bargeInInputCommand !== undefined) {
111+
commands.push(readSetupCommand(params, "bargeInInputCommand"));
112+
}
113+
assertAudioAvailable(10_000, commands);
114+
return JSON.stringify({ ok: true });
115+
}
116+
}
117+
return await host.handleCommand(paramsJSON);
118+
};
119+
}

0 commit comments

Comments
 (0)