Skip to content

Commit e980537

Browse files
committed
Add safe upstream URL updates
1 parent 6e423d4 commit e980537

5 files changed

Lines changed: 520 additions & 32 deletions

File tree

.codex/SET_UPSTREAM.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# codex-fast-proxy upstream URL change for Codex
2+
3+
Use these instructions when an engineer asks Codex to change the provider URL used by an already
4+
enabled Codex Fast proxy.
5+
6+
Do not edit the active provider `base_url` in `~/.codex/config.toml` directly while the proxy is
7+
enabled. That field should keep pointing to the local proxy. API keys, model, reasoning, and other
8+
Codex settings can still be edited in `config.toml` as usual.
9+
10+
If the user did not provide the new upstream URL, ask for it. Do not guess provider URLs.
11+
12+
If the Codex environment uses sandbox or approval controls, request approval/escalation because this
13+
flow may write under `%USERPROFILE%\.codex`, edit `%USERPROFILE%\.codex\hooks.json`, restart the
14+
background proxy, and update the uninstall recovery baseline.
15+
16+
Run this block after replacing `<UPSTREAM_BASE_URL>` with the user-provided URL:
17+
18+
```powershell
19+
$statusJson = python -m codex_fast_proxy status
20+
$status = $statusJson | ConvertFrom-Json
21+
if ($status.config_matches -ne $true) {
22+
$statusJson
23+
throw 'Codex config no longer points to the recorded local proxy. Review ~/.codex/config.toml before changing upstream.'
24+
}
25+
26+
$resultJson = python -m codex_fast_proxy set-upstream --upstream-base '<UPSTREAM_BASE_URL>'
27+
$resultJson
28+
python -m codex_fast_proxy status
29+
```
30+
31+
Report the set-upstream JSON and the final status JSON. The key fields are `provider`, `base_url`,
32+
`previous_upstream_base`, `upstream_base`, `config_matches`, `restart_required`, and `start_result`.
33+
34+
Do not use `--restart` unless the user explicitly accepts that restarting the proxy can interrupt
35+
current proxy-backed Codex sessions. If `restart_required=true`, tell the user to restart Codex App,
36+
open a new CLI process, or run `python -m codex_fast_proxy start` later to apply the new upstream.
37+
38+
If the user also changed API key environment variables, model, reasoning, or other Codex config, tell
39+
them to restart Codex App or open a new CLI process so Codex reloads those settings.

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Local Fast proxy for Codex App and Codex CLI. It lets Codex use providers that
66
support `service_tier="priority"` even when the official Codex App does not send
77
that field.
88

9-
[中文说明](#中文说明) · [Install](#install) · [Update](#update) · [Uninstall](#uninstall) · [Safety](#safety-model) · [Sponsor](#sponsor)
9+
[中文说明](#中文说明) · [Install](#install) · [Change Upstream](#change-upstream) · [Update](#update) · [Uninstall](#uninstall) · [Safety](#safety-model) · [Sponsor](#sponsor)
1010

1111
## What It Does
1212

@@ -123,6 +123,29 @@ provider accepted the wire parameter, and `observed_priority_effective=true` mea
123123
workload was materially faster. `provider_confirmed_priority=true` is extra response metadata when a
124124
provider exposes it, but many providers do not echo that field.
125125

126+
## Change Upstream
127+
128+
After the proxy is enabled, the active provider's `base_url` in `~/.codex/config.toml` is owned by
129+
the local proxy. If you only change API keys, model, reasoning, or other Codex settings, edit
130+
`config.toml` as usual. If you want to change the provider URL, update the saved upstream instead:
131+
132+
```powershell
133+
python -m codex_fast_proxy set-upstream --upstream-base https://api.example.com/v1
134+
```
135+
136+
Or ask Codex:
137+
138+
```text
139+
把 Codex Fast proxy 的上游切到 https://api.example.com/v1
140+
```
141+
142+
`set-upstream` refuses to run if the recorded provider no longer points to the local proxy. When it
143+
succeeds, it keeps Codex config pointed at the local proxy and updates the uninstall baseline so a
144+
later uninstall restores to the new upstream URL. If the proxy is already running, the default is
145+
safe for the current conversation: it records the new upstream and leaves the current process alone.
146+
Restart Codex App, open a new CLI process, or run `python -m codex_fast_proxy start` later to apply
147+
the new upstream. Use `--restart` only when interrupting current proxy-backed sessions is acceptable.
148+
126149
## Update
127150

128151
Paste this into Codex:
@@ -170,6 +193,7 @@ Agents should run the manager as the source of truth:
170193
```powershell
171194
python -m codex_fast_proxy doctor
172195
python -m codex_fast_proxy install --start
196+
python -m codex_fast_proxy set-upstream --upstream-base https://api.example.com/v1
173197
python -m codex_fast_proxy status
174198
python -m codex_fast_proxy benchmark
175199
python -m codex_fast_proxy autostart --quiet
@@ -199,6 +223,10 @@ Default paths:
199223
write autostart log entries.
200224
- Plain `install` refuses to switch config without a running proxy.
201225
- If startup or config switching fails, the manager restores the backed-up config.
226+
- `set-upstream` changes only the saved upstream URL for the recorded provider. It does not edit API
227+
keys, model, reasoning, tools, or prompts, and it refuses to run if config no longer points to the
228+
local proxy. By default it does not restart a running proxy, so the current response is not cut off;
229+
the next Codex startup hook or manual `start` applies the new upstream.
202230
- Running Codex processes do not hot-switch provider config. Restart Codex App and return to the
203231
same conversation, or open a new CLI process.
204232
- `stop` refuses to stop while Codex config still points to the proxy unless `--force` is explicit.
@@ -322,6 +350,27 @@ Codex CLI/app-server 流量作为可重复的 A/B 路径,并在结果里标出
322350
接受了这个 wire 参数,`observed_priority_effective=true` 表示完整任务实测明显变快。
323351
`provider_confirmed_priority=true` 只是供应商响应里额外回显的证据,很多供应商不会返回这个字段。
324352

353+
### 更换上游 URL
354+
355+
启用 proxy 后,当前 provider 的 `base_url` 会由本地 proxy 接管。如果只是改 API key、model、
356+
reasoning 或其它 Codex 配置,仍然可以按原来的方式改 `config.toml`。如果要更换供应商 URL,不要
357+
直接改这个 `base_url`,而是更新 proxy 保存的 upstream:
358+
359+
```powershell
360+
python -m codex_fast_proxy set-upstream --upstream-base https://api.example.com/v1
361+
```
362+
363+
也可以直接对 Codex 说:
364+
365+
```text
366+
把 Codex Fast proxy 的上游切到 https://api.example.com/v1
367+
```
368+
369+
`set-upstream` 只在当前 provider 仍指向本地 proxy 时执行;成功后会更新卸载恢复基线,后续卸载会
370+
恢复到新的 upstream URL。如果 proxy 已经在运行,默认不会立刻重启,避免打断当前对话;重启
371+
Codex App、新开 CLI,或之后运行 `python -m codex_fast_proxy start` 会应用新的 upstream。只有在
372+
接受打断当前 proxy 会话时才使用 `--restart`
373+
325374
### 更新
326375

327376
把这句话贴给 Codex:
@@ -367,6 +416,8 @@ Fetch and follow instructions from https://raw.githubusercontent.com/gaoguobin/c
367416
- dashboard 只读取最近一次 benchmark 的脱敏摘要,不提供会消耗 quota 的启动按钮。
368417
- 浏览器打开 `http://127.0.0.1:8787/v1` 时显示只读本地状态页;API 请求仍按原逻辑转发。
369418
- provider 通用:自动读取当前 active provider 的原始 `base_url` 作为 upstream。
419+
- 更换供应商 URL 时使用 `set-upstream` 更新 proxy 保存的 upstream;key/model 等其它配置仍由用户
420+
直接维护 `config.toml`。默认延期重启运行中的 proxy,避免打断当前响应。
370421
- 启用后写入 Codex `SessionStart` hook;hook 使用当前 Python 可执行文件运行 autostart。后续 Codex
371422
App/CLI 新建或恢复会话时,如果配置仍指向本地 proxy,会自动启动或刷新代理。用户手动改回直连时
372423
hook 会静默跳过,正常 no-op 不写日志。

skills/codex-fast-proxy/SKILL.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: codex-fast-proxy
3-
description: Installs, enables, checks, benchmarks, stops, or uninstalls Codex App Fast proxy. Use when the user asks for Codex App Fast, priority service_tier, PackyAPI Fast, provider acceleration, Fast/Priority A/B benchmark, or says phrases like "启用 Codex Fast proxy", "让 Codex App 使用 Fast", "跑 Fast proxy benchmark", "验证供应商是否支持 Fast", "查看 Fast proxy 状态", or "停止 Codex Fast proxy".
3+
description: Installs, enables, checks, benchmarks, changes upstream URL, stops, or uninstalls Codex App Fast proxy. Use when the user asks for Codex App Fast, priority service_tier, PackyAPI Fast, provider acceleration, Fast/Priority A/B benchmark, or says phrases like "启用 Codex Fast proxy", "让 Codex App 使用 Fast", "跑 Fast proxy benchmark", "验证供应商是否支持 Fast", "把 Codex Fast proxy 的上游切到", "查看 Fast proxy 状态", or "停止 Codex Fast proxy".
44
---
55

66
Use this skill when the user wants Codex to manage the local Fast proxy for Codex App.
@@ -11,6 +11,7 @@ Use this skill when the user wants Codex to manage the local Fast proxy for Code
1111
- App Fast requests such as `让 Codex App 使用 Fast`
1212
- Provider-specific requests such as `PackyAPI 开 Fast`
1313
- Benchmark requests such as `跑 Fast proxy benchmark`, `验证供应商是否支持 Fast`, `Fast 模式有没有变快`
14+
- Upstream URL changes such as `把 Codex Fast proxy 的上游切到 https://api.example.com/v1`
1415
- Maintenance requests such as `查看 Fast proxy 状态`, `停止 Fast proxy`, `卸载 Fast proxy`
1516

1617
## How to execute
@@ -20,6 +21,7 @@ Run the manager as the source of truth:
2021
```powershell
2122
python -m codex_fast_proxy doctor
2223
python -m codex_fast_proxy install --start
24+
python -m codex_fast_proxy set-upstream --upstream-base https://api.example.com/v1
2325
python -m codex_fast_proxy status
2426
python -m codex_fast_proxy benchmark
2527
python -m codex_fast_proxy autostart --quiet
@@ -41,6 +43,14 @@ python -m codex_fast_proxy uninstall
4143
each new or resumed session; `autostart --quiet` does not log normal no-op checks.
4244
- Do not run plain `install` to enable the proxy; the manager rejects config switching without `--start`.
4345
- If proxy startup or config switching fails, the manager restores the backed-up config before returning.
46+
- Use `set-upstream --upstream-base <url>` when the user wants to change the provider URL while the
47+
proxy is already enabled. It must keep Codex config pointed at the local proxy, update the saved
48+
upstream and uninstall baseline, and refuse to run if config no longer points to the recorded proxy.
49+
Do not pass `--restart` unless the user explicitly accepts that restarting the proxy can interrupt
50+
current proxy-backed Codex sessions. Without `--restart`, tell the user to restart Codex App, open a
51+
new CLI process, or run `start` later to apply the new upstream.
52+
- Do not edit the active provider `base_url` directly while the proxy is enabled. API key, model,
53+
reasoning, and other Codex config fields can still be edited directly by the user or agent.
4454
- Running Codex processes do not hot-switch provider config. After enable, restart Codex App and resume the same conversation if desired, or open a new CLI process.
4555
- If the current process is already using the proxy, stopping the proxy can interrupt the conversation. Disable with `uninstall --defer-stop`, tell the user to restart Codex App or open a new CLI process, then run uninstall again to finish cleanup.
4656
- Uninstall removes only the `codex-fast-proxy` hook and must preserve unrelated hooks.
@@ -82,6 +92,9 @@ Use `--provider <name>` only when the user names a provider or when `doctor` rep
8292

8393
Use `--upstream-base <url>` only when Codex config does not contain a usable provider `base_url` or the user explicitly wants a different upstream.
8494

95+
For upstream URL changes after enable, prefer `set-upstream --upstream-base <url>` over rerunning
96+
`install --start --upstream-base <url>`.
97+
8598
## Result handling
8699

87100
- Treat the JSON output as the source of truth.
@@ -104,6 +117,10 @@ Use `--upstream-base <url>` only when Codex config does not contain a usable pro
104117
- `install --start` backs up `~/.codex/config.toml`.
105118
- The selected provider's original `base_url` becomes `upstream_base`.
106119
- The selected provider's `base_url` becomes `http://127.0.0.1:8787/v1`.
120+
- `set-upstream` updates the saved `upstream_base` and uninstall recovery baseline without changing
121+
model, reasoning, tools, input, or API key settings. It applies immediately only when the proxy is
122+
not running or the user explicitly accepted `--restart`; otherwise it defers restarting a running
123+
proxy to avoid cutting off the current response.
107124
- A `SessionStart` hook calls the current Python executable with
108125
`-m codex_fast_proxy autostart --quiet` on future Codex sessions.
109126
- The proxy only injects `service_tier="priority"` into `POST /v1/responses` when that field is absent.

0 commit comments

Comments
 (0)