Skip to content

launcher: 将本地代理注入改为显式开启#82

Open
wanpan11 wants to merge 1 commit into
BigPizzaV3:mainfrom
wanpan11:agents/create-pull-request
Open

launcher: 将本地代理注入改为显式开启#82
wanpan11 wants to merge 1 commit into
BigPizzaV3:mainfrom
wanpan11:agents/create-pull-request

Conversation

@wanpan11
Copy link
Copy Markdown
Contributor

@wanpan11 wanpan11 commented May 14, 2026

变更摘要

  • 新增 --proxy 启动参数,使本地代理自动探测改为显式开启
  • 将新的 auto_proxy 配置贯穿到 launcher 的启动与注入流程
  • 更新 launcher 相关测试,并修复 Windows installer 测试中的跨平台断言

变更原因

默认自动注入探测到的本地代理,会在用户未明确要求时修改 Codex 启动进程的环境变量。此次调整后,只有在用户显式传入 --proxy 时,才会启用代理自动注入。

评审说明

  • 默认启动流程现在会保持当前环境不变,不再额外注入代理变量
  • 启用 --proxy 后,若环境中已显式设置代理,仍会优先沿用已有配置;只有未设置时才会回退到本地代理自动探测

Add a --proxy flag so Codex launch only auto-injects a detected local proxy when explicitly requested.
Update launcher tests for the new opt-in behavior and fix the Windows installer test to assert the current interpreter path across platforms.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 14, 2026 02:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Makes local proxy auto-detection/injection opt-in for launcher-driven Codex starts, to avoid unexpectedly mutating the launched process environment unless explicitly requested.

Changes:

  • Add a --proxy CLI flag and thread auto_proxy through launch_and_injectlaunch_codex_appcodex_process_environment.
  • Update launcher tests to validate opt-in proxy behavior, and broaden monkeypatched call signatures to accept new kwargs.
  • Fix Windows installer test expectations to assert the actual default interpreter path used in generated scripts.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
codex_session_delete/launcher.py Adds auto_proxy plumbing and gates local proxy injection behind an opt-in flag.
codex_session_delete/cli.py Introduces --proxy flag and passes it through to the launcher entrypoint.
tests/test_launcher_cli.py Updates/extends tests for opt-in proxy behavior and adjusts mocks for new kwargs.
tests/test_windows_installer.py Adjusts assertion to match the installer’s computed default Python executable path.
Comments suppressed due to low confidence (1)

codex_session_delete/launcher.py:166

  • has_proxy_environment() treats empty-string proxy variables as “not set”, but env.setdefault(...) will not overwrite an existing key whose value is ''. If a user has HTTP_PROXY/HTTPS_PROXY exported as empty and runs with --proxy, local proxy auto-detection will still not inject anything. Consider explicitly setting the keys when the current value is falsy (or deleting empty keys) so --proxy consistently enables injection.
def codex_process_environment(auto_proxy: bool = False) -> dict[str, str]:
    env = os.environ.copy()
    if not auto_proxy:
        return env
    if has_proxy_environment(env):
        return env
    proxy = local_proxy_url()
    if proxy:
        env.setdefault("HTTP_PROXY", proxy)
        env.setdefault("HTTPS_PROXY", proxy)
        env.setdefault("ALL_PROXY", proxy)
    return env

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 17 to 24
def add_launch_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument("--app-dir", type=Path, default=None)
parser.add_argument("--db", type=Path, default=Path.home() / ".codex" / "state_5.sqlite", help="SQLite database path for local deletion fallback")
parser.add_argument("--backup-dir", type=Path, default=Path.home() / ".codex-session-delete" / "backups")
parser.add_argument("--debug-port", type=int, default=9229)
parser.add_argument("--helper-port", type=int, default=57321)
parser.add_argument("--proxy", action="store_true", default=False, help="Auto-detect and inject local proxy into Codex process environment")

@wanpan11 wanpan11 changed the title launcher: make local proxy injection opt-in launcher: 将本地代理注入改为显式开启 May 14, 2026
@BigPizzaV3
Copy link
Copy Markdown
Owner

原来的自动探测有什么问题

@wanpan11
Copy link
Copy Markdown
Contributor Author

wanpan11 commented May 14, 2026

原来的自动探测有什么问题

会话无法正常链接 一直重试直到失败 使用的 V2rayU

#82 (comment)

@wanpan11 wanpan11 marked this pull request as draft May 14, 2026 03:34
@wanpan11 wanpan11 marked this pull request as ready for review May 14, 2026 03:46
@wanpan11
Copy link
Copy Markdown
Contributor Author

image

不行 加上本次才能正常回复

@BigPizzaV3 BigPizzaV3 closed this May 18, 2026
@BigPizzaV3 BigPizzaV3 reopened this May 18, 2026
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.

3 participants