Skip to content

fix(codex): warn when codex-shim install cannot prove routing - #1169

Closed
TyroneXie wants to merge 1 commit into
lidge-jun:devfrom
TyroneXie:agent/codex-shim-readiness-warning
Closed

fix(codex): warn when codex-shim install cannot prove routing#1169
TyroneXie wants to merge 1 commit into
lidge-jun:devfrom
TyroneXie:agent/codex-shim-readiness-warning

Conversation

@TyroneXie

@TyroneXie TyroneXie commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • ocx codex-shim install now reports a warning instead of a clean green success when the launcher is installed but Codex routing is not provably pointed at OpenCodex: an external model_provider, a user-owned local/remote gateway, or unverifiable routing.
  • It also warns when outbound proxy variables exist only in the current process while config.proxy is unset or unresolved, because Codex launchers and background services (for example launchd) may not inherit that environment. Proxy values are never printed.
  • The change is advisory-only: install still succeeds with the same exit code, and the shim still fail-open execs the real Codex launcher.

Verification

  • bun test tests/codex-shim-readiness.test.ts — 5 pass, including a real CLI install in isolated CODEX_HOME/OPENCODEX_HOME directories asserting that no proxy URL or credential is printed.
  • bun run typecheck — pass.
  • git diff --check — pass.
  • The full suite was attempted; unrelated sandbox-environment failures (EADDRINUSE on port-0 test listeners and EPERM on test temp directories) prevented a clean full-suite run in this environment. Focused tests and typecheck are green.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed (English and zh-CN CLI lifecycle docs).
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults (no proxy values or credentials are logged).

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • New Features
    • Added post-install readiness checks for Codex routing and proxy configuration.
    • Warns about external, custom, unknown, or unverifiable routes and mismatched proxy settings.
    • Proxy values are redacted, and checks are read-only.
    • Installation reports warnings while preserving existing success and failure behavior.
  • Documentation
    • Documented routing and proxy readiness warnings in English and Chinese CLI guides.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

ocx codex-shim install now checks routing and proxy readiness after a healthy installation. It reports warnings for external, custom, unverifiable, or process-only proxy configurations. The checks are read-only and redact proxy values.

Changes

Codex shim readiness

Layer / File(s) Summary
Readiness warning evaluation
src/cli/codex-shim-readiness.ts
Defines readiness inputs, classifies routing states, detects proxy environment mismatches, and collects current configuration and routing state.
Install reporting and validation
src/cli/index.ts, tests/codex-shim-readiness.test.ts, docs-site/src/content/docs/reference/cli/lifecycle.md, docs-site/src/content/docs/zh-cn/reference/cli/lifecycle.md
The install command prints readiness warnings after healthy installation. Tests cover routing, proxy mismatch, redaction, and CLI output. English and Chinese documentation describe the checks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: lidge-jun, wibias

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant codexShimInstall
  participant diagnoseCodexShim
  participant ReadinessCollector
  participant CLIOutput
  User->>codexShimInstall: run install
  codexShimInstall->>diagnoseCodexShim: verify installed shim
  codexShimInstall->>ReadinessCollector: collect routing and proxy warnings
  ReadinessCollector-->>codexShimInstall: return warnings
  codexShimInstall->>CLIOutput: print success or warning status
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the Codex shim change and the new warning behavior when routing cannot be verified.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ All CI tests are green on my local testing.
  • ⬜ I pushed my PR to the latest dev commit.
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@github-actions github-actions Bot added the bug Something isn't working label Aug 7, 2026
@TyroneXie
TyroneXie marked this pull request as ready for review August 7, 2026 05:43
@github-actions
github-actions Bot marked this pull request as draft August 7, 2026 05:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/codex-shim-readiness.ts`:
- Around line 61-68: Update collectCodexShimReadinessWarnings to catch failures
from currentExternalCodexModelProvider and pass externalProvider: null so
readiness collection remains advisory when the Codex config is unreadable or
removed. Add a regression test covering that read failure and verify the
unresolved-routing warning is returned instead of throwing.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c0a63ab5-1167-442f-a412-dc3bf2a7eeda

📥 Commits

Reviewing files that changed from the base of the PR and between f2e5a88 and d8968b7.

📒 Files selected for processing (5)
  • docs-site/src/content/docs/reference/cli/lifecycle.md
  • docs-site/src/content/docs/zh-cn/reference/cli/lifecycle.md
  • src/cli/codex-shim-readiness.ts
  • src/cli/index.ts
  • tests/codex-shim-readiness.test.ts

Comment on lines +61 to +68
export function collectCodexShimReadinessWarnings(): string[] {
const config = loadConfig();
return codexShimReadinessWarnings({
routingKind: getCodexRoutingKind(),
externalProvider: currentExternalCodexModelProvider(),
processProxyEnvPresent: PROXY_ENV_KEYS.some(key => Boolean(process.env[key]?.trim())),
configuredProxyResolved: Boolean(resolveEnvValue(config.proxy)?.trim()),
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Keep readiness collection advisory when Codex config reads fail.

Line 64 fails closed to "unknown" when Codex config cannot be read. Line 65 then calls currentExternalCodexModelProvider(), whose upstream implementation reads the same file without a catch. If the file is unreadable or changes between the existence check and read, codex-shim install throws instead of reporting the unresolved-routing warning.

Catch this read failure and use externalProvider: null. Add a regression test for an unreadable or removed Codex config.

Proposed fix
 export function collectCodexShimReadinessWarnings(): string[] {
   const config = loadConfig();
+  const routingKind = getCodexRoutingKind();
+  let externalProvider: string | null = null;
+  try {
+    externalProvider = currentExternalCodexModelProvider();
+  } catch {
+    // Routing is already classified as unknown when config cannot be read.
+  }
+
   return codexShimReadinessWarnings({
-    routingKind: getCodexRoutingKind(),
-    externalProvider: currentExternalCodexModelProvider(),
+    routingKind,
+    externalProvider,
     processProxyEnvPresent: PROXY_ENV_KEYS.some(key => Boolean(process.env[key]?.trim())),
     configuredProxyResolved: Boolean(resolveEnvValue(config.proxy)?.trim()),
   });
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function collectCodexShimReadinessWarnings(): string[] {
const config = loadConfig();
return codexShimReadinessWarnings({
routingKind: getCodexRoutingKind(),
externalProvider: currentExternalCodexModelProvider(),
processProxyEnvPresent: PROXY_ENV_KEYS.some(key => Boolean(process.env[key]?.trim())),
configuredProxyResolved: Boolean(resolveEnvValue(config.proxy)?.trim()),
});
export function collectCodexShimReadinessWarnings(): string[] {
const config = loadConfig();
const routingKind = getCodexRoutingKind();
let externalProvider: string | null = null;
try {
externalProvider = currentExternalCodexModelProvider();
} catch {
// Routing is already classified as unknown when config cannot be read.
}
return codexShimReadinessWarnings({
routingKind,
externalProvider,
processProxyEnvPresent: PROXY_ENV_KEYS.some(key => Boolean(process.env[key]?.trim())),
configuredProxyResolved: Boolean(resolveEnvValue(config.proxy)?.trim()),
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/codex-shim-readiness.ts` around lines 61 - 68, Update
collectCodexShimReadinessWarnings to catch failures from
currentExternalCodexModelProvider and pass externalProvider: null so readiness
collection remains advisory when the Codex config is unreadable or removed. Add
a regression test covering that read failure and verify the unresolved-routing
warning is returned instead of throwing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8968b7e6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const warnings: string[] = [];
const provider = externalProviderLabel(inputs.externalProvider);

if (inputs.routingKind === "unknown") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prioritize external providers selected through profiles

When config.toml selects an external provider through profile = "work" and [profiles.work].model_provider, currentExternalCodexModelProvider() returns that provider, but getCodexRoutingKind() only classifies root routing and can return native or opencodex-local; this function consequently returns no warning. The shim's subsequent ensure also preserves that external route, so installation appears green even though Codex requests bypass OpenCodex. Check externalProvider independently before accepting a routing kind as ready, and add a focused profile-selector regression test.

AGENTS.md reference: AGENTS.md:L228-L230

Useful? React with 👍 / 👎.

const config = loadConfig();
return codexShimReadinessWarnings({
routingKind: getCodexRoutingKind(),
externalProvider: currentExternalCodexModelProvider(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Catch readiness probe failures after installing the shim

If config.toml exists but cannot be read, is replaced between the existence check and read, or is a directory, currentExternalCodexModelProvider() throws because unlike getCodexRoutingKind() it does not catch readFileSync failures. This happens after installCodexShim() has already modified the launcher, so an advisory probe turns a successful installation into an uncaught non-zero CLI failure without printing the install result. Treat probe errors as unverifiable routing and emit the warning instead of allowing them to escape.

Useful? React with 👍 / 👎.

}

export function collectCodexShimReadinessWarnings(): string[] {
const config = loadConfig();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the advertised readiness check read-only

loadConfig() is a mutating loader: it hardens directory and secret permissions and, when an invalid configuration cannot be repaired, writes a timestamped .invalid-* backup. Consequently, every fresh ocx codex-shim install process can create another copy of an invalid configuration—including any credentials it contains—even though the newly added lifecycle documentation says these readiness checks are read-only. Use the existing observe-only readConfigDiagnostics() path to inspect config.proxy without altering the user's configuration state.

AGENTS.md reference: docs-site/AGENTS.md:L7-L10

Useful? React with 👍 / 👎.

routingKind: getCodexRoutingKind(),
externalProvider: currentExternalCodexModelProvider(),
processProxyEnvPresent: PROXY_ENV_KEYS.some(key => Boolean(process.env[key]?.trim())),
configuredProxyResolved: Boolean(resolveEnvValue(config.proxy)?.trim()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Warn when config.proxy depends on the current environment

When config.proxy is an environment reference such as ${HTTPS_PROXY}, this check treats it as persistent merely because it resolves in the installer process. If Codex is later launched from a desktop session or another shell that does not inherit that variable, the shim-started proxy loads the same reference as unresolved and loses outbound connectivity, yet installation was reported green; generated background-service environments likewise do not preserve arbitrary proxy variables. Distinguish a literal persisted proxy from an environment reference whose value exists only now, and add focused coverage for this handoff case.

AGENTS.md reference: AGENTS.md:L228-L230

Useful? React with 👍 / 👎.

@lidge-jun
lidge-jun marked this pull request as ready for review August 8, 2026 09:16
@github-actions
github-actions Bot marked this pull request as draft August 8, 2026 09:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8968b7e6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +64 to +65
routingKind: getCodexRoutingKind(),
externalProvider: currentExternalCodexModelProvider(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check project-local provider overrides before reporting ready

When installation runs inside, or globally trusts, a repository whose .codex/config.toml selects an external provider, these probes inspect only the global CODEX_CONFIG_PATH, so a native or OpenCodex-managed global route produces no warning even though Codex's merged project configuration bypasses the proxy. The repository already models this concrete override in collectProjectCodexConfigWarnings() and analyzeProjectCodexConfig(); include those diagnostics in readiness and add a focused project-config regression test before printing green.

AGENTS.md reference: src/AGENTS.md:L24-L26

Useful? React with 👍 / 👎.

@lidge-jun

Copy link
Copy Markdown
Owner

@TyroneXie Republished this on current dev as #1289 — your branch was 335 commits behind. The rebase was clean and the commit is yours via Co-authored-by.

A green "installed" message when routing can't actually be proven is the kind of success report that costs someone an afternoon, so this is worth landing. I re-verified on the rebased head rather than trusting the old run: full suite 9994 pass / 0 fail, your 5 readiness tests pass, privacy:scan green, and diagnoseCodexShim still exists at src/codex/shim.ts:1179, so the new call site in src/cli/index.ts resolves against today's dev and not just your original base.

I'll close this once #1289 lands. Nothing needed from you.

lidge-jun added a commit that referenced this pull request Aug 8, 2026
…#1289)

`ocx codex-shim install` reported a clean green success even when the
launcher was installed but Codex routing was not provably pointed at
OpenCodex — an external `model_provider`, a user-owned local or remote
gateway, or routing that cannot be verified. It now reports a warning for
those cases.

It also warns when outbound proxy variables exist only in the current
process while `config.proxy` is unset or unresolved, because Codex launchers
and background services such as launchd may not inherit that environment.
Proxy values are never printed.

The change is advisory only: install still succeeds with the same exit code,
and the shim still fail-open execs the real Codex launcher.

Republished from #1169 by TyroneXie, whose branch was 335 commits behind dev.
Rebased onto f5147cb with no conflicts; authorship preserved below.

Co-authored-by: TyroneXie <328347833@qq.com>
@lidge-jun

Copy link
Copy Markdown
Owner

Landed on dev as 5aa1971 via #1289, with your Co-authored-by trailer intact through the squash — the commit is credited to you in the repository history.

Closing this as superseded rather than stale. Thanks for catching it; a green success message that can't actually prove routing is exactly the kind of thing that wastes someone's afternoon.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants