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

  1. Update the inject script's assetPrefix list and export names to match the installed Codex build (inspect the joined per-prefix error messages).
  2. Reset the memoized promise and retry probing after a delay so lazy chunks can load.
  3. Align Codex and inject script versions (pin or update one to match the other).
  4. 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

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


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)