Skip to content

perf: Prewarm LiveAvatar browser sessions#16

Open
jiejuncai-ly wants to merge 19 commits into
lex-mainfrom
perf/liveavatar-session-prewarm-20260713
Open

perf: Prewarm LiveAvatar browser sessions#16
jiejuncai-ly wants to merge 19 commits into
lex-mainfrom
perf/liveavatar-session-prewarm-20260713

Conversation

@jiejuncai-ly

@jiejuncai-ly jiejuncai-ly commented Jul 14, 2026

Copy link
Copy Markdown

修改内容

  • 新增会话 prewarm API,并抽离可复用的 Agent dispatch 服务。
  • Browser 房间连接后并行启动本地媒体与 Agent dispatch,复用后端预热状态。
  • 将 VAD/ONNX 静态资源路径限定到当前 sandbox session,兼容 gateway 路径前缀。

原因

原流程串行等待媒体与 Agent 初始化,用户进入会话后才能启动关键链路,导致首屏视频和人脸检测就绪偏慢。

验证

  • 本地 browser 链路端到端通过,dispatch 约 1.1 秒。

  • 人脸检测后 face gate 正常解除静音。

  • VAD/ONNX 资源全部加载成功,无网络或控制台错误。

  • 前端测试:140 passed;lint 与 production build 通过。

  • /api/session/prewarm 的每 Session secret 只用于服务端单次授权:执行中或成功后的重复请求返回 409,失败释放 guard 允许 Gateway 重试;测试覆盖消费、并发与失败重试。

  • Browser source 的部署支持范围为 Sandbox Chromium;音频/视频并行 getUserMedia 按该运行环境验证。

  • 常规 dispatch 默认 8 秒是 lex-main 的既有边界,本 PR 未缩短该路径;prewarm 在用户拿到 Session 前运行,worker-ready 与 dispatch 共用总计 20 秒预算,并受 Gateway 30 秒外层超时约束。fake-clock 行为测试分别验证 8 秒和 20 秒,并验证同一 Session 的并发调用共享最长 timeout 预算,包括旧 deadline 查询进行中的延长竞态;session registry 与 in-flight dispatch 状态通过 globalThis 跨 Next.js server chunk 共享。

@jiejuncai-ly
jiejuncai-ly marked this pull request as ready for review July 14, 2026 03:47
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@jiejuncai-ly

Copy link
Copy Markdown
Author

本轮 review 已逐项核对:

  • prewarmRoomSession 等待 room_audio_input / room_video_input 不改。browser 模式仍通过 lex-voice 的 browser profile 启动这两个 Room Input 服务参与者;它们先入房并等待浏览器原始轨道。usesServerRoomInputDevice() 只决定用户启动阶段是否再次要求 video readiness,不能据此推断 browser 模式没有这两个参与者。
  • 本地媒体快速失败仍等待 dispatch 的问题已在 d813831 修复:失败时立即 cancelAgentSessionStart(sessionId),中止 dispatch fetch,再复用原有统一远端清理路径。
  • session identity 的隐式漂移已在 9d160e4 修复:LIVEAVATAR_VOICE_SESSION_ID 进入 appConfig.voiceSessionId,且远端 UI config 不能覆盖。AGENT_NAME 由同一进程 env 同源读取,LiveKit room name 则由 canonical session id 推导,因此不再增加另一套配置入口。

验证:129 tests passed,lint passed,production build passed(仅保留已有 ONNX dynamic-require warning)。真实 cloud template 的 /api/session/prewarm HIL 仍按部署 gate 执行。

@jiejuncai-ly

jiejuncai-ly commented Jul 16, 2026

Copy link
Copy Markdown
Author

更新:routing 已合入,本 PR 已基于最新 lex-main 恢复并完成重新移植与测试;当前分支是正式候选,不再是撤下状态。

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

Claude finished @jiejuncai-ly's task in 1m 27s —— View job


任务清单

  • 拉取 PR diff(origin/lex-main...HEAD
  • 阅读相关约定与既有实现
  • 审查 LiveKit room/track 生命周期与浏览器媒体权限失败路径
  • 审查 React hook 清理、Next.js 客户端/服务端边界
  • 审查环境变量/secret、TypeScript 类型、验证完整性
  • 汇总发现并输出 review 结论

Review 结论

通过

本轮唯一新增 commit 8ffb46bfix: share session coordination across chunks)修复了此前两轮 review 指出的最后一个 P1:session-registry.tssessions/nextGenerationsession-dispatch-service.tsinFlightDispatches 现已按 prewarm-use-guard.ts 的既有模式挂载到 globalThis__liveavatarRoomSessionRegistry / __liveavatarInFlightDispatches),跨 chunk 场景下并发 dispatch 去重、共享 deadline、cancelAgentSessionStart 取消标记等状态不再退化为独立副本。tests/session-registry.test.mjstests/session-prewarm.test.mjs 新增了跨模块实例(?chunk= query)用例验证共享效果,实现与测试一致。

问题及建议

未发现需要阻塞合并的问题。残余风险(沿用前两轮未修复的 P2,不阻塞合并):

  • [P2] hooks/useRoom.ts:275-290:本地媒体与 dispatchAgentSession() 并行失败时仍只 throw localInputResult.reasondispatchResult.reasonconsole.warn,未体现在最终用户提示中,排障时不易定位 dispatch 侧故障。
  • [P2] lib/session-dispatch-readiness.ts:43-54requireRoomInputParticipantsReady && !hasReadyRoomInputParticipants(...) 的判断在 video-ready 的两个分支中重复书写,建议合并简化。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant