perf: short-circuit model list via bridge (−34s startup)#1304
Conversation
fe18ecf to
236cac8
Compare
Intercept list-models-for-host calls in the renderer inject script and return model names from the Codex++ bridge (<1ms) instead of waiting for the app-server RPC (~34s). Inspired by PR BigPizzaV3#620 by @congxb.
236cac8 to
ae721e0
Compare
There was a problem hiding this comment.
Pull request overview
该 PR 在 Codex 渲染器的注入脚本中拦截 list-models-for-host 请求:当 Codex++ bridge 已能提供模型目录时,直接用 bridge 的模型名构造返回值,从而跳过首次启动时耗时很长的 app-server RPC 往返(PR 描述中约 34s),以显著降低启动阶段模型列表可用的等待时间。
Changes:
- 在
client.sendRequest的补丁中对list-models-for-host增加短路逻辑:优先从/codex-model-catalog加载/读取模型名并立即返回 - 当 bridge 模型名不可用时保持原行为:回退到原始
sendRequest(app-server RPC)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
想确认一下这个优化的基准:原始 能否补一下测量方式/日志,例如:
另外短路后模型列表完全依赖 Codex++ catalog。这里是否验证过官方账号模式下不会丢掉 app-server 实时返回的模型差异?如果 bridge catalog 为空会 fallback 原请求,这点我看到了;主要想确认 catalog 非空但过旧/不完整时的行为。 |
- Extract reqMethod to variable (avoid double call)
- Add sendCodexPlusDiagnostic('model_list_shortcut', ...) on hit
- Add sendCodexPlusDiagnostic('model_list_rpc_timing', ...) on fallback
- Remove ambiguous '~34s' from comment
感谢 review,很好的两个问题。 1. 基准数据标题里写的"~34s"不够精确。该数值来源于 @congxb 的 PR #620 端到端测量(Windows Store Codex + agnes-ai provider),是 CDP 轮询优化 + 模型列表短路的叠加收益,不是 list-models-for-host RPC 单独耗时。 已在最新 commit(ad20656)补充了两处诊断日志,运行后可在 sendCodexPlusDiagnostic 事件中查看:
这样不管在什么环境下启动、切换提供商、打开模型选择器,都能看到准确数字。 2. Catalog 过期风险分析了一下短路前后的数据流: 短路前(原始逻辑): 短路后(PR #1304): 两种情况下的最终模型列表来源相同(都是 bridge catalog)。非短路路径下 RPC 结果也会被 bridge catalog 覆盖掉,所以短路不引入新的数据风险——bridge catalog 已经是模型列表的 source of truth,无论走不走短路都一样。
3. 更新ad20656 已推送到 perf/model-shortcut 分支,PR 已自动更新。 |
|
我又对照了一下本机 Codex 解包代码,这里确实还有一个数据风险,建议这个 PR 先不要按当前实现合。 解包里 app-server 连接的模型列表入口是: async listModels(e) {
await this.ensureReady();
let t = `model/list:${randomUUID()}`;
let n = await this.sendInternalRequest({ id: t, method: `model/list`, params: e });
if (n.error) throw Error(n.error.message ?? `Failed to read available models`);
return n.result;
}也就是说官方账号模式下,原始 当前主线的 Codex++ patch 行为是:先等原始 RPC 返回,再 但 #1304 命中短路后直接: return patchAppServerModelResult("list-models-for-host", { data: [] });这会跳过官方 因此如果官方账号/app-server 返回了 catalog 里没有的模型,或者返回了更完整的 metadata(displayName、reasoning/speed tier、隐藏/可用状态等),短路路径会丢失这些原始信息。 我建议改成其中一种策略:
这样可以保留性能优化空间,但不会让官方账号模式的模型列表退化。 |
Per BigPizzaV3's review: patchModelArray appends catalog models to the
official RPC result (data: [] causes replace, not merge). Removing the
short-circuit block while retaining model_list_rpc_timing diagnostic.
After this change:
- list-models-for-host always goes through original RPC (safe)
- sendCodexPlusDiagnostic('model_list_rpc_timing') records real latency
- reqMethod extraction refactor from ad20656 preserved
|
你的 review 是对的。我重新查了代码确认 已修正,commit a7772e4:
当前 PR diff(vs upstream/main):+10 行诊断 + reqMethod 提取,-0 短路。 关于后续优化方向:
|
Summary
Intercept
list-models-for-hostcalls in the renderer inject script and return model names from the Codex++ bridge (<1ms) instead of waiting for the app-server RPC (~34s).Inspired by PR #620 by @congxb.
How it works
list-models-for-host, intercept and check bridgepatchAppServerModelResult— skip the full app-server roundtripVerification