Skip to content

fix(proxy): make Claude and Codex proxies fail-open and resilient across user environments - #1556

Merged
Juliusolsson05 merged 4 commits into
mainfrom
fix/proxy-resilience
Nov 28, 2026
Merged

Juliusolsson05 merged 4 commits into
mainfrom
fix/proxy-resilience

Conversation

@Juliusolsson05

Copy link
Copy Markdown
Owner

Summary

Makes both the Claude (mitmdump) and Codex (ResponsesProxy) local proxies strictly fail-open and safe across arbitrary user configurations:

  1. Fail-open fallback for both Claude & Codex — If mitmdump or ResponsesProxy fails to resolve, bind, or start for any reason, Agent Code cleans up any partial proxy state, logs a warning + typed transcript-diagnostic, and spawns the CLI directly without the proxy instead of aborting the pane with Claude proxy startup failed….
  2. Claude env & compatibility hygiene (claudeProxyPolicy.ts, claudeSession.ts) — Automatically skips local mitmproxy when corporate HTTPS_PROXY/HTTP_PROXY, Bedrock/Vertex/Foundry, or localhost/HTTP ANTHROPIC_BASE_URL is set; merges localhost,127.0.0.1,::1 into existing NO_PROXY/no_proxy; combines user NODE_EXTRA_CA_CERTS with mitmproxy's CA into a per-run PEM (0o600) instead of clobbering corporate root CAs.
  3. Codex auth & config hygiene (codexProxyPolicy.ts, codexSession.ts) — Honors CODEX_HOME, parses config.toml (@iarna/toml) to respect custom openai_base_url (URL-validated) and skip proxy for non-openai model_provider, profile, chatgpt_base_url, or cli_auth_credentials_store = "keyring"; detects all ChatGPT/Codex-backend auth_mode values and legacy auth.json; skips proxy when auth is indeterminate (Keychain/pre-login) instead of guessing api.openai.com and causing 401s; merges NO_PROXY when proxying.
  4. Skip local proxy for Terminal-mode panes (shouldUseProxyForSession) — Hard Terminal-mode panes render raw PTY output and skip spawning unnecessary local proxies.

Linked Issues

Fixes #1552

Plan & Review Disposition (one round, independent read-only reviewer)

Plan: docs/plans/2026-11-27-proxy-resilience.md

Finding Verdict Disposition
Cancelled CodexSession.start() attempt in catch could clobber a newer generation's proxyServer valid fixed in 1353c026f (stops local proxy + checks isStartAttemptActive(attempt) first)
env.OPENAI_BASE_URL / env.OPENAI_API_KEY inference could misroute Keychain ChatGPT users (Codex TUI doesn't read them) valid fixed in 1353c026f (removed both env branches)
Unvalidated openai_base_url and profile/chatgpt_base_url/keyring in config.toml valid fixed in 1353c026f
Stale comment on ClaudeSessionEvents['transcript-diagnostic'] valid fixed in 1353c026f

Verification

  • npm run typecheck: passed (0 errors).
  • Vitest suites: 14 files / 143 tests passed initially, plus 9 files / 112 tests passed after review fixes (including 16 Claude proxy policy tests, 16 Codex proxy policy tests, and 4 terminal-mode proxy tests).

…ig hygiene

Skip local proxies in incompatible corporate/cloud/custom-provider/indeterminate-auth environments, preserve user NO_PROXY and NODE_EXTRA_CA_CERTS, and fall back to direct spawn on any proxy startup failure instead of aborting session launch.

Refs #1552
Hard terminal-mode panes render the raw provider PTY directly and never mount Agent Code's semantic feed. Pass useProxy: false when the effective view mode (per-pane override or global setting) is 'terminal' across spawn, wake, reload, and rehydrate.

Refs #1552
…nd auth policy

Guard CodexSession's proxy catch block against cancelled start attempts before mutating shared fields or falling through to ptySpawn, stop consulting env.OPENAI_BASE_URL/env.OPENAI_API_KEY that Codex TUI ignores, validate config.toml openai_base_url and skip profile/chatgpt_base_url/keyring configs, update ClaudeSession diagnostic comment, and record review disposition in the plan.

Refs #1552
@Juliusolsson05
Juliusolsson05 merged commit 6b7c325 into main Nov 28, 2026
2 checks passed
@Juliusolsson05
Juliusolsson05 deleted the fix/proxy-resilience branch November 28, 2026 00:47
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.

fix(proxy): make Claude and Codex proxies fail-open and resilient across user environments

1 participant