BigPizzaV3/CodexPlusPlus · error
Codex 状态 API 不可用 ( )
Error message
Codex 状态 API 不可用 (${errors.join("; ")}) What it means
codexStateApi() memoizes a one-shot async probe that tries to obtain Codex's state/call export (the bridge for invoking app-server JSON-RPC methods like codexStateCall) across all known asset prefixes. If every probe fails — the state export is missing or throws — the aggregated per-prefix errors are joined into this thrown message, and the memoized promise rejects for all subsequent callers.
Solutions
- Update the inject script's assetPrefix list and export names to match the installed Codex build (inspect the joined per-prefix error messages).
- Reset the memoized promise and retry probing after a delay so lazy chunks can load.
- Align Codex and inject script versions (pin or update one to match the other).
- Add a fallback bridge (e.g. postMessage to a background/agent layer) if the in-page export is gone.
Example fix
// before
const call = await codexStateApi();
// after
let call;
try { call = await codexStateApi(); }
catch (e) {
resetCodexStateApi(); // clear memoized rejected promise
await new Promise(r => setTimeout(r, 1500));
call = await codexStateApi();
} Defensive patterns
Strategy: retry
Validate before calling
let available = true; try { await codexStateApi(); } catch { available = false; } if (!available) { /* disable state-dependent UI and prompt update */ } Type guard
function isStateApi(call) { return typeof call === "function"; } Try / catch
try { const call = await codexStateApi(); } catch (e) { resetCodexStateApi(); await sleep(1500); return codexStateApi().catch(() => notifyUser("Codex 状态接口不可用")); } Prevention
- Clear the memoized rejected promise before retrying, or it will fail forever.
- Update assetPrefix/export names whenever Codex internals change.
- Probe once at startup and degrade UI features gracefully instead of failing per-call.
When it happens
Trigger: Any codexStateCall(method, params) invocation when the probe found no callable state export: Codex updated and renamed the state module, the chunk hosting it isn't loaded yet, or the inject script's assetPrefix list is outdated. Once rejected, the memoized promise keeps failing.
Common situations: Codex renderer upgrade changed internal exports; inject script version mismatch; probe raced ahead of lazy chunk loading; bundler hash changes invalidated the module lookup paths.
Related errors
- Codex setting-storage 接口不可用
- 当前 Codex 版本的后台整理接口尚未适配,请在设置中使用外接 API 整理
- API 未能生成本批整理结果
- API 输出达到长度上限,本批未提交;请使用输出容量更大的模型
- API 未返回有效的 choices[0].message.content,请确认兼容 Chat Completions
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/ef503cb068db5fc8.
Report an issue: GitHub.
Appendix: source
Thrown at assets/inject/renderer-inject.js:6469
return typeof module?.qut === "function" ? module.qut : null;
}
return null;
}
async function codexStateApi() {
codexStateApiPromise = codexStateApiPromise || (async () => {
const errors = [];
for (const assetPrefix of ["vscode-api-", "app-initial-"]) {
try {
const api = await loadCodexAppModule(assetPrefix);
const call = codexStateApiFromModule(api, assetPrefix);
if (typeof call === "function") return call;
errors.push(`${assetPrefix}: state export unavailable`);
} catch (error) {
errors.push(`${assetPrefix}: ${error?.message || String(error)}`);
}
}
throw new Error(`Codex 状态 API 不可用 (${errors.join("; ")})`);
})();
return await codexStateApiPromise;
}
async function codexStateCall(method, params) {
const call = await codexStateApi();
return await call(method, params);
}
async function getCodexGlobalState(key) {
const result = await codexStateCall("get-global-state", { params: { key } });
return result && Object.prototype.hasOwnProperty.call(result, "value") ? result.value : result;
}
async function setCodexGlobalState(key, value) {
return await codexStateCall("set-global-state", { params: { key, value } });
}
View on GitHub (pinned to b1ed92e5e4)