惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
博客园 - 司徒正美
Martin Fowler
Martin Fowler
T
Tailwind CSS Blog
B
Blog RSS Feed
Vercel News
Vercel News
博客园 - 聂微东
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
GbyAI
GbyAI
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
B
Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: harden realtime voice setup (#70764) · openclaw/open...
steipete · 2026-04-24 · via Recent Commits to openclaw:main

@@ -124,6 +124,7 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

124124125125

private ws: WebSocket | null = null;

126126

private connected = false;

127+

private sessionConfigured = false;

127128

private intentionallyClosed = false;

128129

private reconnectAttempts = 0;

129130

private pendingAudio: Buffer[] = [];

@@ -133,6 +134,7 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

133134

private lastAssistantItemId: string | null = null;

134135

private toolCallBuffers = new Map<string, { name: string; callId: string; args: string }>();

135136

private readonly flowId = randomUUID();

137+

private sessionReadyFired = false;

136138137139

constructor(private readonly config: OpenAIRealtimeVoiceBridgeConfig) {}

138140

@@ -143,7 +145,7 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

143145

}

144146145147

sendAudio(audio: Buffer): void {

146-

if (!this.connected || this.ws?.readyState !== WebSocket.OPEN) {

148+

if (!this.connected || !this.sessionConfigured || this.ws?.readyState !== WebSocket.OPEN) {

147149

if (this.pendingAudio.length < 320) {

148150

this.pendingAudio.push(audio);

149151

}

@@ -172,7 +174,7 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

172174

}

173175174176

triggerGreeting(instructions?: string): void {

175-

if (!this.connected || !this.ws) {

177+

if (!this.isConnected() || !this.ws) {

176178

return;

177179

}

178180

this.sendEvent({

@@ -209,18 +211,37 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

209211

close(): void {

210212

this.intentionallyClosed = true;

211213

this.connected = false;

214+

this.sessionConfigured = false;

212215

if (this.ws) {

213216

this.ws.close(1000, "Bridge closed");

214217

this.ws = null;

215218

}

216219

}

217220218221

isConnected(): boolean {

219-

return this.connected;

222+

return this.connected && this.sessionConfigured;

220223

}

221224222225

private async doConnect(): Promise<void> {

223226

await new Promise<void>((resolve, reject) => {

227+

let connectTimeout: ReturnType<typeof setTimeout>;

228+

let settled = false;

229+

const settleResolve = () => {

230+

if (settled) {

231+

return;

232+

}

233+

settled = true;

234+

clearTimeout(connectTimeout);

235+

resolve();

236+

};

237+

const settleReject = (error: Error) => {

238+

if (settled) {

239+

return;

240+

}

241+

settled = true;

242+

clearTimeout(connectTimeout);

243+

reject(error);

244+

};

224245

const { url, headers } = this.resolveConnectionParams();

225246

const debugProxy = resolveDebugProxySettings();

226247

const proxyAgent = createDebugProxyWebSocketAgent(debugProxy);

@@ -229,13 +250,16 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

229250

...(proxyAgent ? { agent: proxyAgent } : {}),

230251

});

231252232-

const connectTimeout = setTimeout(() => {

233-

reject(new Error("OpenAI realtime connection timeout"));

253+

connectTimeout = setTimeout(() => {

254+

if (!this.connected && !this.intentionallyClosed) {

255+

this.ws?.terminate();

256+

settleReject(new Error("OpenAI realtime connection timeout"));

257+

}

234258

}, OpenAIRealtimeVoiceBridge.CONNECT_TIMEOUT_MS);

235259236260

this.ws.on("open", () => {

237-

clearTimeout(connectTimeout);

238261

this.connected = true;

262+

this.sessionConfigured = false;

239263

this.reconnectAttempts = 0;

240264

captureWsEvent({

241265

url,

@@ -248,11 +272,7 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

248272

},

249273

});

250274

this.sendSessionUpdate();

251-

for (const chunk of this.pendingAudio.splice(0)) {

252-

this.sendAudio(chunk);

253-

}

254-

this.config.onReady?.();

255-

resolve();

275+

settleResolve();

256276

});

257277258278

this.ws.on("message", (data: Buffer) => {

@@ -287,8 +307,7 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

287307

},

288308

});

289309

if (!this.connected) {

290-

clearTimeout(connectTimeout);

291-

reject(error);

310+

settleReject(error instanceof Error ? error : new Error(String(error)));

292311

}

293312

this.config.onError?.(error instanceof Error ? error : new Error(String(error)));

294313

});

@@ -302,7 +321,9 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

302321

reasonBuffer,

303322

});

304323

this.connected = false;

324+

this.sessionConfigured = false;

305325

if (this.intentionallyClosed) {

326+

settleResolve();

306327

this.config.onClose?.("completed");

307328

return;

308329

}

@@ -406,6 +427,20 @@ class OpenAIRealtimeVoiceBridge implements RealtimeVoiceBridge {

406427407428

private handleEvent(event: RealtimeEvent): void {

408429

switch (event.type) {

430+

case "session.created":

431+

return;

432+433+

case "session.updated":

434+

this.sessionConfigured = true;

435+

for (const chunk of this.pendingAudio.splice(0)) {

436+

this.sendAudio(chunk);

437+

}

438+

if (!this.sessionReadyFired) {

439+

this.sessionReadyFired = true;

440+

this.config.onReady?.();

441+

}

442+

return;

443+409444

case "response.audio.delta": {

410445

if (!event.delta) {

411446

return;