Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
build(model-hub): adopt CPA v8.0.30 as model-hub-engine-v8.0.30-1 (#2831)
Call White8c1f008d786b
diff --git a/docs/plans/model-hub-cpa-dependency.md b/docs/plans/model-hub-cpa-dependency.mdindex 11af29e5f..60097e796 100644--- a/docs/plans/model-hub-cpa-dependency.md+++ b/docs/plans/model-hub-cpa-dependency.md@@ -64,11 +64,11 @@ SHA-256, and extracted binary SHA-256. The verified upstream bytes are publishedpublication. A scheduled guard verifies that release and preserves amanifest-keyed backup that can restore missing assets without overwriting amismatched asset. For this change,-the reviewed target is Avibe-owned CLIProxyAPI `v8.0.23` at source commit-`d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5`, built with Go 1.26.9 for+the reviewed target is Avibe-owned CLIProxyAPI `v8.0.30` at source commit+`5be2cdab0869cbaa3d401891f740aebf7e15aa99`, built with Go 1.26.9 fordarwin-arm64, darwin-x64, linux-amd64, linux-arm64, windows-amd64 andwindows-arm64. The release assets are built from that exact upstream source-with the patches in `patches/model-hub-cpa-v8.0.23/`, applied in the order the+with the patches in `patches/model-hub-cpa-v8.0.30/`, applied in the order themanifest's `build.patches` records; the packaged manifest records the resultingarchive and binary digests. Rolling back means reverting the whole adoptionchange, which restores the previous patch directory and manifest together.diff --git a/docs/plans/model-hub-e2e-test-plan.md b/docs/plans/model-hub-e2e-test-plan.mdindex b4c291fee..7c2d3bd8c 100644--- a/docs/plans/model-hub-e2e-test-plan.md+++ b/docs/plans/model-hub-e2e-test-plan.md@@ -68,10 +68,10 @@ Out of scope (documented, not dropped silently):|---|---|---|---|| D1 | add api_key source first, subscription-class source second | the subscription is placed ahead of the key (decision D-1, #2156); a contract test owns it, since adding a subscription hermetically is impossible (a takeover validates its grant with the provider) | contract || D2 | turn with hop0 healthy | served; provenance records hop; usage metered | assert |-| D3 | hop0 → 429 before first output | same-turn failover to hop1; `switch` event; hop0 initial local cooldown 60–72s; chat copy unchanged (silent) | assert |+| D3 | hop0 → 429 before first output | same-turn failover to hop1; `switch` event; hop0 cools for the later of its initial local backoff (60–72s) and a valid Retry-After that survives the managed engine (D-4); chat copy unchanged (silent) | assert || D4 | hop0 → quota (`insufficient_quota`) | fallback, cooldown 300s | assert || D5 | hop0 → 401 (api_key, non-refreshable) | `credential_revoked` needs_action; UI shows repair action; no mid-turn refresh attempt | assert |-| D6 | hop0 → 5xx | source backoff with positive bounded jitter; later valid Retry-After survives the managed engine and takes precedence | xfail: the engine never forwards an upstream error's headers (its status errors carry none, with or without `passthrough-headers`), so upstream advice never arrives |+| D6 | hop0 → 5xx | source backoff with positive bounded jitter; later valid Retry-After survives the managed engine and takes precedence | assert || D7 | stream interrupt after first output | terminal frame injected per protocol; **no replay/failover**; source still settles; next turn resolves hop1 (takeover pill visible) | assert || D8 | cooldown `retry_at` elapses | hop0 becomes eligible; only recognized output or valid empty completion clears its state and emits `recover` | unit/loopback covered; local Incus outstanding || D9 | all temporary hops keep failing | one closed recovery-exhausted result (Codex 400, Claude/OpenCode 424); localized final copy and original upstream provenance | gateway/scenario covered; local Incus outstanding |diff --git a/docs/plans/model-hub-inference-deadlines.md b/docs/plans/model-hub-inference-deadlines.mdindex ff96f0665..0dddabe37 100644--- a/docs/plans/model-hub-inference-deadlines.md+++ b/docs/plans/model-hub-inference-deadlines.md@@ -273,7 +273,7 @@ even an opt-in HTTP/2 health check. Its maintainers closedrouter-for-me/CLIProxyAPI#6534 as not planned: timeouts and cancellation belongto the downstream client. For the engine that client is this gateway.-Engine patches 4 and 5 (`patches/model-hub-cpa-v8.0.23/README.md`) are carried+Engine patches 4 and 5 (`patches/model-hub-cpa-v8.0.30/README.md`) are carriedby design and turn a dead network path into an error in about 45 s. They cannotsee a relay that stays alive while its own upstream is stuck: the relay answersPINGs and keeps writing `: keep-alive` comments, and the engine holdsdiff --git a/patches/model-hub-cpa-v8.0.23/README.md b/patches/model-hub-cpa-v8.0.23/README.mddeleted file mode 100644index b768313c5..000000000--- a/patches/model-hub-cpa-v8.0.23/README.md+++ /dev/null@@ -1,255 +0,0 @@-# Avibe-owned CPA v8.0.23 compatibility patches--This directory records the source patches carried by Avibe's-`model-hub-engine-v8.0.23-3` build. Each patch applies independently to the-pinned source; the build applies them in the order the manifest's-`build.patches` records.--Base:--- Repository: `router-for-me/CLIProxyAPI`-- Release: `v8.0.23`-- Source commit: `d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5`--## `openai-compat-native-token-field.patch`--Avibe owns the OpenAI-compatible Source boundary. When an incoming Chat-request contains `max_completion_tokens`, or `max_tokens`, the engine must-preserve that caller-selected field unless Avibe explicitly selects the-`use-max-completion-tokens` compatibility mode for a model. The stock-default rewrites the former field to the latter, which breaks upstreams that-accept only the native field.--The patch therefore makes the stock `false` path a preservation path. The-existing explicit `true` path still canonicalizes to-`max_completion_tokens`. Avibe does not set the option today, so both-buffered and streaming requests retain their native token-limit field.--The patch is limited to the helper used by both OpenAI Chat execution paths-(`openai_compat_executor.go`, buffered and streaming). The helper is-byte-identical between v8.0.20 and v8.0.23 and differs from v7.3.16 only in-its module import path, outside the patched hunk.--The patch also updates the three `useMaxCompletionTokens=false` cases of-upstream's `TestNormalizeOpenAIMaxTokens`, which asserted the stock rewrite,-to assert this contract: the payload, including a `null` limit, is returned-unchanged. It updates the four `use-max-completion-tokens=false` chat cases of-upstream's executor-level `TestOpenAICompatExecutor_MaxTokensNormalization`-and `TestOpenAICompatExecutor_MaxTokensNormalizationStream` the same way: the-request keeps `max_completion_tokens`, including `null`, and gains no-`max_tokens`. With all patches applied, `go test ./internal/runtime/executor/`-and `go test ./internal/runtime/executor/helps/` pass. The test changes do not-alter the engine binary.--## `oauth-callback-forwarder-loopback.patch`--Avibe starts every redirect-based subscription login (Claude, Codex,-Antigravity) with `is_webui=true`. The engine then starts a callback forwarder-on the vendor's fixed redirect port (54545, 1455 or 51121) that relays the-browser's redirect to the management callback. Stock CPA binds that forwarder-on `0.0.0.0` and aborts the login with a 500 when the bind fails.--The patch binds the forwarder on `127.0.0.1` only, because the redirect always-comes from a browser on the same machine. A wildcard bind exposed the port to-the network and, on Windows, raised a Defender Firewall prompt for the engine.-A failed bind (the port is in use, or reserved by Hyper-V, WSL or Docker) is-logged and no longer aborts the login: Avibe's Web UI still accepts the pasted-callback URL, which reaches the same session through `POST /oauth-callback`.--A container deployment that publishes the callback ports to reach a browser-outside the container loses the automatic callback, since the forwarder no-longer listens on the container's external interface. The pasted callback URL-completes the login there.--Go's wildcard listen is dual-stack, so the stock forwarder also accepted-`[::1]`; the patched one accepts 127.0.0.1 only. The vendors' redirect URIs-name `localhost`, and a browser that tries `::1` first is refused at once and-falls back to 127.0.0.1, as mainstream browsers do. Where one does not, the-pasted callback URL still completes the login. Revisit this if anyone reports-a refused connection to `localhost` at the OAuth callback.--## `antigravity-static-catalog-until-probe.patch`--Avibe ships Gemini subscriptions through Antigravity OAuth grants and routes-to them as soon as the engine has loaded a grant: right after every engine-start and right after a new login. Since v8.0.14 the stock engine registers no-Antigravity models until its per-account entitlement probe-(`/v1internal:fetchAvailableModels`) answers. Until then a request gets-`model_not_found` and model discovery sees an empty catalog; when the probe-fails, the account stays unroutable until a backed-off retry succeeds-(1-2 minutes at first, up to 30 minutes).--The patch registers the static Antigravity catalog while no entitlement hints-are cached. The probe that registration already queues narrows the catalog-through the fenced `ReplaceClientModels` when it answers; a failed probe leaves-the static catalog in place. This is the pre-v8.0.14 startup behavior plus-the later narrowing. The patch also rewrites upstream's-`TestAntigravityModelRegistration_AsyncNonBlocking`, which asserted the stock-behavior, to assert this contract: the static catalog is registered before the-probe answers, then narrowed to the entitled set. With both patches applied,-`go test -run Antigravity ./sdk/cliproxy/` passes.--Drop the patch once router-for-me/CLIProxyAPI#6531 is fixed upstream.--## `codex-utls-h2-ping-health-check.patch`--Codex subscription requests to `https://chatgpt.com` go through a dedicated-Chrome uTLS connection per request. When ALPN selects HTTP/2, stock CPA wraps-that connection in a zero-value `http2.Transport{}`: no PING health check, no-client timeout, nothing that bounds the body read. A path that stops-delivering packets without a FIN or RST reaching the engine, which a NAT or a-TCP-terminating proxy can leave behind and TCP keepalive cannot see past,-therefore blocks the stream until the caller gives up. Avibe's turns then-waited out their 600-second bound with no byte and no error. The same code is-in v7.3.16, so this is not a v8 regression.--The patch sets `ReadIdleTimeout` 30 s and `PingTimeout` 15 s on that-connection's `http2.Transport` only. After 30 s without a frame the transport-sends one PING and closes the connection when no ACK arrives within 15 s, so-the stream fails with an in-stream `request_timeout` error at about 45 s.-Model Hub's recovery then retries on a new connection. A live upstream that-is silent, for example during a long reasoning phase, acknowledges the PING-and is not cut; an active stream sends no PING. The shared transports, the-proxy transports, the HTTP/1.1 Claude round tripper and the WebSocket path-are untouched. The patch adds `utls_client_health_test.go`: a dead path fails-the stream, and a silent healthy stream survives ten idle periods.--Measured on the shipped v8.0.23 engine on the uTLS HTTP/2 path through a-black-holing CONNECT proxy: stock sent no byte and no error for 9 min 38 s,-until it was killed; patched sent `event: error` (`request_timeout`) at-45.0 s. A live stream silent for 120 s completed on both.--Upstream declined the health check. router-for-me/CLIProxyAPI#6534 was-closed as not planned: by the project's design policy CPA sets no timeout-once an upstream connection is established, HTTP/2 health checks and stream-read deadlines included, not even as an opt-in setting, and leaves timeouts-and cancellation to the downstream client. The opt-in pull request,-router-for-me/CLIProxyAPI#6535, was closed unmerged. Avibe therefore carries-this patch by design as its client-side transport bound for this connection.-No drop is planned; re-evaluate only if upstream changes its post-connect-timeout policy. The cost is that every CPA upgrade must rebase this patch and-`fallback-transport-h2-ping-health-check.patch`.--## `fallback-transport-h2-ping-health-check.patch`--Patch 4 covers only the dedicated uTLS connection to `https://chatgpt.com`.-Every other upstream request on an HTTP client from-`internal/runtime/executor/helps` ran on `http.DefaultTransport`, or on a-per-request proxy transport, without an HTTP/2 health check. That covers-API-key relays and OpenAI-compatible providers. The same dead-path failure-therefore reached Avibe through API-key relays: a turn on an HTTP/2 relay-whose path went dead waited out the 600-second bound with no byte and no-error.--The patch gives those requests one shared clone of `http.DefaultTransport`,-created on first use, with `HTTP2Config{SendPingTimeout: 30s, PingTimeout:-15s}`, the same timings as patch 4, as constants. It is used:--- as `NewUtlsHTTPClient`'s standard fallback for hosts other than chatgpt.com- and api.anthropic.com (the Codex and Claude executors);-- by the OpenAI-compatible executor, through `WithUpstreamFallbackTransport`,- which sets it only when `NewProxyAwareHTTPClient` left the transport nil.--`buildProxyTransport` sets the same health check on proxy transports.-`http.DefaultTransport` itself is not modified, and `NewProxyAwareHTTPClient`-still returns a nil transport when no proxy and no injected RoundTripper-apply, because the Antigravity executor reads that as "direct" and installs-its own HTTP/1.1 pool. The injected context RoundTripper is untouched, as in-patch 4. The health check only sets HTTP/2 timings: protocol selection-(`ForceAttemptHTTP2`, `Protocols`, `TLSNextProto`, ALPN) is unchanged, and a-transport that did not opt into HTTP/2 still speaks HTTP/1.1.--Avibe renders `proxy-url: ""` and no per-Source proxy, so its Sources take the-shared clone. Coverage by Avibe Source kind:--| Source | CPA path | Covered |-| --- | --- | --- |-| `openai_responses` API key (OpenAI and xAI relays) | `codex-api-key`, `NewUtlsHTTPClient` fallback | yes |-| `anthropic` API key on a non-Anthropic host | `claude-api-key`, `NewUtlsHTTPClient` fallback | yes |-| `openai_chat` API key | `openai-compatibility`, `WithUpstreamFallbackTransport` | yes |-| `anthropic` API key on `api.anthropic.com` | HTTP/1.1 Claude round tripper | no: PING is HTTP/2 only |-| ChatGPT subscription | patch 4's uTLS connection | patch 4 |--An HTTP/1.1 upstream has no PING, so a silent HTTP/1.1 body is still bounded-only by the caller. The patch adds `upstream_transport_test.go`:--- a dead path fails the stream;-- a silent healthy stream survives ten idle periods;-- the shared transport is wired into both clients and the proxy transports;-- protocol selection is unchanged.--Upstream: the same failure mode as router-for-me/CLIProxyAPI#6534, declined-under the same policy (see `codex-utls-h2-ping-health-check.patch`), so no-upstream follow-up is pending. Avibe carries this patch by design as its-client-side transport bound for these transports. No drop is planned;-re-evaluate only if upstream changes its post-connect timeout policy. Every-CPA upgrade must rebase it together with that patch.--## `codex-sse-per-event-parsing.patch`--The Codex executor read upstream SSE line by line and took every `data:` line-as a whole event. In SSE an event's data may span several `data:` lines,-joined with `\n`. On such a split, lenient `gjson` read `"type":-"response.completed"` from the first fragment, the executor took its-terminal path, and the rest of the event was never read. The handler's-validator then failed the stream with `invalid SSE data JSON (len=<first-fragment>)`, the error Avibe saw from an API-key relay after a turn's full-output had streamed.--The patch reads the stream through `codexSSEScanner`, which keeps-`bufio.Scanner`'s interface. It is used by both `ExecuteStream` and the-non-stream `Execute`. Every event on this path is one JSON value, so:--- A data line that is complete JSON, or cannot start JSON (an empty value,- `[DONE]`), is delivered byte-for-byte as before, with no lookahead. This- keeps upstreams that send no blank line between events working as stock- does; upstream tests cover that framing.-- A data line that starts an object or array it does not complete collects- the following data lines until:- - their joined value closes its outermost object or array, tracked- incrementally so validation stays linear;- - a blank line ends the event;- - the stream ends;- - a data line that is a complete object of its own starts the next event;- - or the collected bytes would exceed the scanner's 50 MB line limit.-- A completed multi-line event is delivered compacted onto one line.-- One that never becomes valid JSON is delivered as the same multi-line data- field, so it still fails downstream as before. One warning then records its- framing: the data line count, each line's length and whether it is valid on- its own, the joined length, and the JSON error offset. It records no data- bytes.-- Field and comment lines inside an event follow its data line.-- An event left unterminated at the end of the stream is still delivered.--The patch adds `codex_sse_events.go` and `codex_sse_events_test.go`. They-cover:--- the minimal two-line repro and CRLF;-- blank-less framing, also after a split;-- invalid fragments, and the warning's contents;-- the 50 MB bound, and a 2,000-line event under a time bound;-- `[DONE]` and empty data lines;-- equivalence with `bufio.Scanner` on well-formed streams;-- the split event through `ExecuteStream`, with and without bootstrap- buffering, and through `Execute`.--Upstream: the line-based parsing is unchanged on CPA `main` (v8.0.27) and-`dev`. Drop this patch once a tagged CPA release Avibe adopts parses Codex-SSE per event.--## Rebuild--The repository-owned release path checks out `source_sha`, applies the-recorded patches, builds every supported target with `CGO_ENABLED=0`,-packages deterministic archives, and verifies the generated bytes against the-checked-in manifest before publication:--```sh-python3 scripts/model_hub_engine_release_guard.py fetch-source \- --output-dir /tmp/model-hub-engine-patched-```--The same command is available from the manual Model Hub release-guard-workflow. Its uploaded artifact is the source-built publication input; the-runtime manifest is updated only after the generated bytes and release assets-have been reviewed.diff --git a/patches/model-hub-cpa-v8.0.23/codex-sse-per-event-parsing.patch b/patches/model-hub-cpa-v8.0.23/codex-sse-per-event-parsing.patchdeleted file mode 100644index 46d6f52c1..000000000--- a/patches/model-hub-cpa-v8.0.23/codex-sse-per-event-parsing.patch+++ /dev/null@@ -1,595 +0,0 @@-diff --git a/internal/runtime/executor/codex_executor_execute.go b/internal/runtime/executor/codex_executor_execute.go-index f5afac2f..77190003 100644---- a/internal/runtime/executor/codex_executor_execute.go-+++ b/internal/runtime/executor/codex_executor_execute.go-@@ -128,11 +128,12 @@ func (e *CodexExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, re- data, errRead := io.ReadAll(httpResp.Body)- helps.AppendAPIResponseChunk(ctx, e.cfg, data)--- lines := bytes.Split(data, []byte("\n"))-+ events := newCodexSSEScanner(ctx, bytes.NewReader(data), len(data)+1)- outputItemsByIndex := make(map[int64][]byte)- var outputItemsFallback [][]byte- sawOutputDelta := false-- for _, line := range lines {-+ for events.Scan() {-+ line := events.Bytes()- if !bytes.HasPrefix(line, dataTag) {- continue- }-diff --git a/internal/runtime/executor/codex_executor_stream.go b/internal/runtime/executor/codex_executor_stream.go-index 7c9fef29..4b8985d0 100644---- a/internal/runtime/executor/codex_executor_stream.go-+++ b/internal/runtime/executor/codex_executor_stream.go-@@ -1,7 +1,6 @@- package executor-- import (-- "bufio"- "bytes"- "context"- "io"-@@ -145,8 +144,7 @@ func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au- bootstrapStart = nowCodexBootstrap()- }--- scanner := bufio.NewScanner(httpResp.Body)-- scanner.Buffer(nil, 52_428_800) // 50MB-+ scanner := newCodexSSEScanner(ctx, httpResp.Body, 52_428_800) // 50MB- claudeInputTokens := helps.NewClaudeInputTokenState(from, to, responseFormat, originalPayload)- var param any- outputItemsByIndex := make(map[int64][]byte)-diff --git a/internal/runtime/executor/codex_sse_events.go b/internal/runtime/executor/codex_sse_events.go-new file mode 100644-index 00000000..48bb5e49---- /dev/null-+++ b/internal/runtime/executor/codex_sse_events.go-@@ -0,0 +1,212 @@-+package executor-+-+import (-+ "bufio"-+ "bytes"-+ "context"-+ "encoding/json"-+ "errors"-+ "io"-+ "strconv"-+ "strings"-+-+ "github.com/router-for-me/CLIProxyAPI/v8/internal/runtime/executor/helps"-+)-+-+// codexSSEDiagnosticLines caps how many data lines one invalid-event diagnostic describes.-+const codexSSEDiagnosticLines = 8-+-+// codexSSEScanner reads an upstream Responses SSE stream line by line, as bufio.Scanner does, but-+// delivers an event whose data an upstream split across several "data:" lines as one "data:" line.-+// In SSE an event's data may span several data lines, joined with "\n". Taking each data line as a-+// whole event instead cuts such an event: on a split response.completed the stream ends at the-+// first fragment and the rest is never read.-+//-+// Every event this path carries is one JSON value, so a data line that is complete JSON on its own,-+// or cannot start JSON at all (an empty value, [DONE]), is delivered byte-for-byte as read with no-+// lookahead; this also keeps upstreams that omit the blank line between events working as before.-+// A data line that starts a JSON object or array but is not yet complete JSON starts an event that-+// collects the following data lines until their joined value closes its outermost object or array,-+// a blank line ends the event, the stream ends, a data line that is a complete JSON object on its own starts the next-+// event, or the collected bytes would exceed the scanner's line limit. A completed event is-+// delivered compacted onto one line. One that never becomes valid JSON is delivered as the same-+// multi-line data field, so it still fails downstream, and one warning describes its framing-+// without any of its bytes. Other lines pass through in order.-+type codexSSEScanner struct {-+ ctx context.Context-+ lines *bufio.Scanner-+ maxBytes int-+ queue [][]byte-+ current []byte-+}-+-+func newCodexSSEScanner(ctx context.Context, r io.Reader, maxBytes int) *codexSSEScanner {-+ lines := bufio.NewScanner(r)-+ lines.Buffer(nil, maxBytes)-+ return &codexSSEScanner{ctx: ctx, lines: lines, maxBytes: maxBytes}-+}-+-+// Scan advances to the next line, or to the next assembled event data line.-+func (s *codexSSEScanner) Scan() bool {-+ if len(s.queue) > 0 {-+ s.current, s.queue = s.queue[0], s.queue[1:]-+ return true-+ }-+ if !s.lines.Scan() {-+ return false-+ }-+ line := s.lines.Bytes()-+ if !bytes.HasPrefix(line, dataTag) || !codexSSEIncompleteJSON(bytes.TrimSpace(line[len(dataTag):])) {-+ s.current = line-+ return true-+ }-+ // An incomplete event: collect its continuation. The underlying scanner reuses its buffer, so keep copies.-+ data := [][]byte{bytes.Clone(line)}-+ joined := bytes.Clone(codexSSEValue(line))-+ var nesting codexJSONNesting-+ closed := nesting.feed(joined)-+ var rest [][]byte-+ size := len(line)-+ for !closed && s.lines.Scan() {-+ next := s.lines.Bytes()-+ if len(next) == 0 {-+ rest = append(rest, []byte{})-+ break-+ }-+ if size+len(next) > s.maxBytes {-+ // Bounded like a single line: stop collecting and let the next line be read on its own.-+ rest = append(rest, bytes.Clone(next))-+ break-+ }-+ size += len(next)-+ if !bytes.HasPrefix(next, dataTag) {-+ rest = append(rest, bytes.Clone(next))-+ continue-+ }-+ if value := bytes.TrimSpace(next[len(dataTag):]); bytes.HasPrefix(value, []byte("{")) && json.Valid(value) {-+ // A complete object of its own is the next event of an upstream that sends no blank lines.-+ rest = append(rest, bytes.Clone(next))-+ break-+ }-+ data = append(data, bytes.Clone(next))-+ value := codexSSEValue(next)-+ joined = append(append(joined, '\n'), value...)-+ closed = nesting.feed([]byte{'\n'}) || nesting.feed(value)-+ }-+ s.current = s.assemble(data, joined)-+ s.queue = rest-+ return true-+}-+-+// codexSSEValue is one data line's value: the text after "data:" without the one leading space.-+func codexSSEValue(line []byte) []byte {-+ return bytes.TrimPrefix(line[len(dataTag):], []byte(" "))-+}-+-+// codexSSEClosed reports whether joined event data is complete JSON. Only a value that now ends-+// with a closing bracket can have become complete, so other values are not re-validated.-+func codexSSEClosed(joined []byte) bool {-+ trimmed := bytes.TrimRight(joined, " \t\r\n")-+ if len(trimmed) == 0 || (trimmed[len(trimmed)-1] != '}' && trimmed[len(trimmed)-1] != ']') {-+ return false-+ }-+ return json.Valid(joined)-+}-+-+// codexSSEIncompleteJSON reports whether one data line's value starts a JSON object or array that-+// it does not complete. Values that cannot start JSON, such as an empty value or [DONE], are not.-+func codexSSEIncompleteJSON(value []byte) bool {-+ if len(value) == 0 || (value[0] != '{' && value[0] != '[') || bytes.Equal(value, []byte("[DONE]")) {-+ return false-+ }-+ return !codexSSEClosed(value)-+}-+-+// codexJSONNesting follows the nesting of a JSON text fed in pieces, so an event split across many-+// data lines is validated once, when its outermost object or array closes, not after every piece.-+type codexJSONNesting struct {-+ depth int-+ inString bool-+ escaped bool-+}-+-+// feed consumes p and reports whether the outermost object or array closed within it.-+func (n *codexJSONNesting) feed(p []byte) bool {-+ for _, c := range p {-+ switch {-+ case n.inString:-+ switch {-+ case n.escaped:-+ n.escaped = false-+ case c == '\\':-+ n.escaped = true-+ case c == '"':-+ n.inString = false-+ }-+ case c == '"':-+ n.inString = true-+ case c == '{' || c == '[':-+ n.depth++-+ case c == '}' || c == ']':-+ n.depth---+ if n.depth <= 0 {-+ return true-+ }-+ }-+ }-+ return false-+}-+-+// Bytes returns the current line. It stays valid until the next call to Scan.-+func (s *codexSSEScanner) Bytes() []byte { return s.current }-+-+// Err returns the error that stopped the scan, as bufio.Scanner does.-+func (s *codexSSEScanner) Err() error { return s.lines.Err() }-+-+func (s *codexSSEScanner) assemble(lines [][]byte, joined []byte) []byte {-+ if len(lines) == 1 {-+ s.diagnose(lines, bytes.TrimSpace(joined))-+ return lines[0]-+ }-+ if json.Valid(joined) {-+ var compacted bytes.Buffer-+ compacted.Grow(len(dataTag) + 1 + len(joined))-+ compacted.Write(dataTag)-+ compacted.WriteByte(' ')-+ if errCompact := json.Compact(&compacted, joined); errCompact == nil {-+ return compacted.Bytes()-+ }-+ }-+ s.diagnose(lines, joined)-+ return bytes.Join(lines, []byte("\n"))-+}-+-+// diagnose logs one bounded warning when an event's data is not valid JSON: how many data lines-+// carried it, each line's length and whether it is valid on its own, and where the joined data-+// fails to parse. It never logs data bytes.-+func (s *codexSSEScanner) diagnose(lines [][]byte, data []byte) {-+ if len(data) == 0 || bytes.Equal(data, []byte("[DONE]")) || json.Valid(data) {-+ return-+ }-+ offset := int64(-1)-+ var syntaxErr *json.SyntaxError-+ if errors.As(json.Unmarshal(data, new(json.RawMessage)), &syntaxErr) {-+ offset = syntaxErr.Offset-+ }-+ shown := min(len(lines), codexSSEDiagnosticLines)-+ lengths := make([]string, shown)-+ valid := make([]string, shown)-+ for i := range shown {-+ value := bytes.TrimSpace(lines[i][len(dataTag):])-+ lengths[i] = strconv.Itoa(len(value))-+ valid[i] = strconv.FormatBool(json.Valid(value))-+ }-+ more := ""-+ if len(lines) > shown {-+ more = ",+" + strconv.Itoa(len(lines)-shown)-+ }-+ helps.LogWithRequestID(s.ctx).Warnf(-+ "codex executor: upstream SSE event data is not valid JSON: data_lines=%d line_bytes=[%s%s] lines_valid=[%s%s] data_bytes=%d json_error_offset=%d",-+ len(lines), strings.Join(lengths, ","), more, strings.Join(valid, ","), more, len(data), offset,-+ )-+}-diff --git a/internal/runtime/executor/codex_sse_events_test.go b/internal/runtime/executor/codex_sse_events_test.go-new file mode 100644-index 00000000..47711d2b---- /dev/null-+++ b/internal/runtime/executor/codex_sse_events_test.go-@@ -0,0 +1,330 @@-+package executor-+-+import (-+ "bufio"-+ "context"-+ "encoding/json"-+ "fmt"-+ "strings"-+ "testing"-+ "time"-+-+ "github.com/router-for-me/CLIProxyAPI/v8/internal/config"-+ cliproxyauth "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/auth"-+ cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/executor"-+ sdktranslator "github.com/router-for-me/CLIProxyAPI/v8/sdk/translator"-+ log "github.com/sirupsen/logrus"-+ logtest "github.com/sirupsen/logrus/hooks/test"-+)-+-+func captureCodexSSEWarnings(t *testing.T) *logtest.Hook {-+ t.Helper()-+ hook := new(logtest.Hook)-+ log.StandardLogger().AddHook(hook)-+ t.Cleanup(func() { log.StandardLogger().ReplaceHooks(make(log.LevelHooks)) })-+ return hook-+}-+-+func scanCodexSSE(t *testing.T, stream string) []string {-+ t.Helper()-+ scanner := newCodexSSEScanner(context.Background(), strings.NewReader(stream), 1<<20)-+ var lines []string-+ for scanner.Scan() {-+ lines = append(lines, string(scanner.Bytes()))-+ }-+ if errScan := scanner.Err(); errScan != nil {-+ t.Fatalf("scan error: %v", errScan)-+ }-+ return lines-+}-+-+func TestCodexSSEScannerAssemblesEventData(t *testing.T) {-+ const marker = "body-bytes-must-not-be-logged"-+ cases := []struct {-+ name string-+ stream string-+ want []string-+ warnings int-+ }{-+ {-+ name: "one-line events pass through as read",-+ stream: "event: response.created\ndata: {\"type\":\"response.created\"}\n\n: keep-alive\n\ndata: {\"type\":\"x\",\"v\":\"a b\"}\n\n",-+ want: []string{"event: response.created", `data: {"type":"response.created"}`, "", ": keep-alive", "", `data: {"type":"x","v":"a b"}`, ""},-+ },-+ {-+ name: "CRLF line endings",-+ stream: "event: a\r\ndata: {\"type\":\"a\"}\r\n\r\n",-+ want: []string{"event: a", `data: {"type":"a"}`, ""},-+ },-+ {-+ name: "data lines of one event are joined and compacted",-+ stream: "event: response.completed\ndata: {\"type\":\"response.completed\",\ndata: \"response\":{\"id\":\"r\",\"output\":[]}}\n\n",-+ want: []string{"event: response.completed", `data: {"type":"response.completed","response":{"id":"r","output":[]}}`, ""},-+ },-+ {-+ name: "joined CRLF event",-+ stream: "data: {\"a\":\r\ndata: [1,\r\ndata: 2]}\r\n\r\n",-+ want: []string{`data: {"a":[1,2]}`, ""},-+ },-+ {-+ name: "comment and field lines inside an event follow its data",-+ stream: "data: {\"a\":\n: keep-alive\nid: 7\ndata: 1}\n\n",-+ want: []string{`data: {"a":1}`, ": keep-alive", "id: 7", ""},-+ },-+ {-+ name: "unterminated one-line event at end of stream",-+ stream: "data: {\"type\":\"response.completed\"}",-+ want: []string{`data: {"type":"response.completed"}`},-+ },-+ {-+ name: "unterminated multi-line event at end of stream",-+ stream: "data: {\"type\":\ndata: \"response.completed\"}\n",-+ want: []string{`data: {"type":"response.completed"}`},-+ },-+ {-+ name: "complete events without blank separators stay separate",-+ stream: "data: {\"a\":1}\ndata: {\"b\":2}\n",-+ want: []string{`data: {"a":1}`, `data: {"b":2}`},-+ },-+ {-+ name: "split event followed by an event without a blank separator",-+ stream: "data: {\"a\":\ndata: 1}\ndata: {\"b\":2}\n",-+ want: []string{`data: {"a":1}`, `data: {"b":2}`},-+ },-+ {-+ name: "invalid fragment followed by a complete event without a blank separator",-+ stream: "data: {\"a\":\"" + marker + "\ndata: {\"b\":2}\n\n",-+ want: []string{`data: {"a":"` + marker, `data: {"b":2}`, ""},-+ warnings: 1,-+ },-+ {-+ name: "unterminated incomplete event at end of stream is still delivered",-+ stream: "data: {\"type\":\"response.completed\",\"t\":\"" + marker + "\",",-+ want: []string{`data: {"type":"response.completed","t":"` + marker + `",`},-+ warnings: 1,-+ },-+ {-+ name: "empty and non-JSON data lines take the stock path",-+ stream: "data:\n\ndata: \n\ndata: ping\n\n",-+ want: []string{"data:", "", "data: ", "", "data: ping", ""},-+ },-+ {-+ name: "done sentinel",-+ stream: "data: [DONE]\n\n",-+ want: []string{"data: [DONE]", ""},-+ },-+ {-+ name: "invalid one-line event passes through with one warning",-+ stream: "data: {\"type\":\"response.completed\",\"t\":\"" + marker + "\",\n\n",-+ want: []string{`data: {"type":"response.completed","t":"` + marker + `",`, ""},-+ warnings: 1,-+ },-+ {-+ name: "event split inside a string stays invalid and keeps its data lines",-+ stream: "data: {\"t\":\"" + marker + "\ndata: " + marker + "\"}\n\n",-+ want: []string{`data: {"t":"` + marker + "\ndata: " + marker + `"}`, ""},-+ warnings: 1,-+ },-+ }-+ for _, tc := range cases {-+ t.Run(tc.name, func(t *testing.T) {-+ hook := captureCodexSSEWarnings(t)-+ got := scanCodexSSE(t, tc.stream)-+ if fmt.Sprintf("%q", got) != fmt.Sprintf("%q", tc.want) {-+ t.Fatalf("lines = %q\nwant %q", got, tc.want)-+ }-+ if len(hook.AllEntries()) != tc.warnings {-+ t.Fatalf("warnings = %d, want %d", len(hook.AllEntries()), tc.warnings)-+ }-+ for _, entry := range hook.AllEntries() {-+ message, errMessage := entry.String()-+ if errMessage != nil {-+ t.Fatal(errMessage)-+ }-+ if entry.Level != log.WarnLevel || strings.Contains(message, marker) || !strings.Contains(message, "data_lines=") || !strings.Contains(message, "json_error_offset=") {-+ t.Fatalf("diagnostic = %q, want a bounded warning without data bytes", message)-+ }-+ }-+ })-+ }-+}-+-+func TestCodexSSEScannerBoundsAnEventToTheLineLimit(t *testing.T) {-+ hook := captureCodexSSEWarnings(t)-+ // Each fragment fits the 64-byte limit; together they do not.-+ stream := "data: {\"a\":\"" + strings.Repeat("x", 40) + "\ndata: " + strings.Repeat("y", 40) + "\ndata: " + strings.Repeat("z", 40) + "\"}\n\ndata: {\"b\":2}\n\n"-+ scanner := newCodexSSEScanner(context.Background(), strings.NewReader(stream), 64)-+ var got []string-+ for scanner.Scan() {-+ got = append(got, string(scanner.Bytes()))-+ }-+ if errScan := scanner.Err(); errScan != nil {-+ t.Fatalf("scan error: %v", errScan)-+ }-+ // The collected fragment is flushed as an invalid event; the lines after it are read as stock reads them.-+ want := []string{-+ "data: {\"a\":\"" + strings.Repeat("x", 40),-+ "data: " + strings.Repeat("y", 40),-+ "data: " + strings.Repeat("z", 40) + "\"}",-+ "",-+ `data: {"b":2}`,-+ "",-+ }-+ if fmt.Sprintf("%q", got) != fmt.Sprintf("%q", want) {-+ t.Fatalf("lines = %q\nwant %q", got, want)-+ }-+ if len(hook.AllEntries()) != 1 {-+ t.Fatalf("warnings = %d, want 1 for the flushed invalid event", len(hook.AllEntries()))-+ }-+}-+-+func TestCodexSSEScannerAssemblesAnEventOfThousandsOfLinesQuickly(t *testing.T) {-+ // A 2 MB response.completed whose upstream wrapped it into 2,000 data lines between array-+ // elements. Every line ends with "}", so only nesting, not the last byte, tells the event apart-+ // from a finished one.-+ item := func(i int) string {-+ return fmt.Sprintf(`{"type":"message","content":[{"type":"output_text","text":"%s"}]}`, strings.Repeat(string(rune('a'+i%26)), 960))-+ }-+ head := `{"type":"response.completed","response":{"id":"resp_big","output":[`-+ var payload, stream strings.Builder-+ payload.WriteString(head + item(0))-+ stream.WriteString("data: " + head + item(0) + "\n")-+ for i := 1; i < 2000; i++ {-+ payload.WriteString("," + item(i))-+ stream.WriteString("data: ," + item(i) + "\n")-+ }-+ payload.WriteString("]}}")-+ stream.WriteString("data: ]}}\n\n")-+ started := time.Now()-+ scanner := newCodexSSEScanner(context.Background(), strings.NewReader(stream.String()), 52_428_800)-+ var got []string-+ for scanner.Scan() {-+ got = append(got, string(scanner.Bytes()))-+ }-+ elapsed := time.Since(started)-+ if len(got) != 2 || got[0] != "data: "+payload.String() {-+ t.Fatalf("assembled %d lines, want the event on one line and its blank line", len(got))-+ }-+ if elapsed > 2*time.Second {-+ t.Fatalf("assembling 2,001 data lines took %v; validation must not grow with every line", elapsed)-+ }-+}-+-+func TestCodexSSEScannerDiagnosticDescribesFraming(t *testing.T) {-+ hook := captureCodexSSEWarnings(t)-+ // A split inside a string: each fragment is invalid on its own, and so is their SSE join.-+ scanCodexSSE(t, "data: {\"type\":\"response.completed\",\"t\":\"abc\ndata: def\"}\n\n")-+ entries := hook.AllEntries()-+ if len(entries) != 1 {-+ t.Fatalf("warnings = %d, want 1", len(entries))-+ }-+ message := entries[0].Message-+ for _, want := range []string{"data_lines=2", "line_bytes=[37,5]", "lines_valid=[false,false]", "data_bytes=43", "json_error_offset=38"} {-+ if !strings.Contains(message, want) {-+ t.Fatalf("diagnostic %q lacks %q", message, want)-+ }-+ }-+}-+-+func codexStreamChunks(t *testing.T, stream string, buffered bool) []string {-+ t.Helper()-+ cfg := &config.Config{}-+ cfg.Codex.StreamBootstrapBuffering = buffered-+ executor := NewCodexExecutor(cfg)-+ ctx := context.WithValue(t.Context(), "cliproxy.roundtripper", codexAllocationTransport{stream: stream})-+ auth := &cliproxyauth.Auth{Attributes: map[string]string{"api_key": "test"}}-+ result, err := executor.ExecuteStream(ctx, auth, cliproxyexecutor.Request{Model: "gpt-5.4", Payload: []byte(`{"model":"gpt-5.4","input":"hello"}`)},-+ cliproxyexecutor.Options{Stream: true, SourceFormat: sdktranslator.FormatOpenAIResponse})-+ if err != nil {-+ t.Fatal(err)-+ }-+ var chunks []string-+ for chunk := range result.Chunks {-+ if chunk.Err != nil {-+ t.Fatalf("stream error: %v", chunk.Err)-+ }-+ if len(chunk.Payload) > 0 {-+ chunks = append(chunks, string(chunk.Payload))-+ }-+ }-+ return chunks-+}-+-+func TestCodexExecuteStreamTreatsAnEventSplitAcrossDataLinesAsOneEvent(t *testing.T) {-+ completed := `{"type":"response.completed","response":{"id":"resp_split","model":"gpt-5.4","status":"completed","output":[{"id":"msg_1","type":"message","role":"assistant","content":[{"type":"output_text","text":"hi"}]}],"usage":{"input_tokens":5,"output_tokens":1,"total_tokens":6}}}`-+ cut := strings.Index(completed, `"output":`)-+ created := "event: response.created\ndata: {\"type\":\"response.created\",\"response\":{\"id\":\"resp_split\",\"model\":\"gpt-5.4\"}}\n\n"-+ oneLine := created + "event: response.completed\ndata: " + completed + "\n\n"-+ split := created + "event: response.completed\ndata: " + completed[:cut] + "\ndata: " + completed[cut:] + "\n\n"-+ for _, buffered := range []bool{false, true} {-+ t.Run(fmt.Sprintf("buffered=%t", buffered), func(t *testing.T) {-+ want := codexStreamChunks(t, oneLine, buffered)-+ got := codexStreamChunks(t, split, buffered)-+ if fmt.Sprintf("%q", got) != fmt.Sprintf("%q", want) {-+ t.Fatalf("split event chunks = %q\nwant the one-line chunks %q", got, want)-+ }-+ if terminal := want[len(want)-1]; !strings.Contains(terminal, `"response.completed"`) || !json.Valid([]byte(strings.TrimPrefix(terminal, "data: "))) {-+ t.Fatalf("last chunk = %q, want a valid response.completed", terminal)-+ }-+ })-+ }-+}-+-+func TestCodexSSEScannerMatchesBufioScannerOnWellFormedStreams(t *testing.T) {-+ stream := codexAllocationStream(6, 64) + "data: {\"type\":\"x\"}\ndata: {\"type\":\"y\"}\n: trailing comment\n\nevent: done\ndata: [DONE]\n\n"-+ for _, newline := range []string{"\n", "\r\n"} {-+ input := strings.ReplaceAll(stream, "\n", newline)-+ t.Run(fmt.Sprintf("newline=%q", newline), func(t *testing.T) {-+ stock := bufio.NewScanner(strings.NewReader(input))-+ var want []string-+ for stock.Scan() {-+ want = append(want, stock.Text())-+ }-+ got := scanCodexSSE(t, input)-+ if fmt.Sprintf("%q", got) != fmt.Sprintf("%q", want) {-+ t.Fatalf("lines = %q\nwant bufio.Scanner's %q", got, want)-+ }-+ })-+ }-+}-+-+func TestCodexExecuteStreamPassesADoneSentinelAfterTheCompletedEvent(t *testing.T) {-+ hook := captureCodexSSEWarnings(t)-+ stream := codexAllocationStream(2, 16) + "data: [DONE]\n\n"-+ chunks := codexStreamChunks(t, stream, false)-+ sawCompleted := false-+ for _, chunk := range chunks {-+ if strings.Contains(chunk, `"response.completed"`) {-+ sawCompleted = true-+ }-+ }-+ if !sawCompleted {-+ t.Fatalf("chunks = %q, want the completed event", chunks)-+ }-+ for _, entry := range hook.AllEntries() {-+ if strings.Contains(entry.Message, "SSE event data") {-+ t.Fatalf("unexpected framing warning: %s", entry.Message)-+ }-+ }-+}-+-+func TestCodexExecuteNonStreamReadsAnEventSplitAcrossDataLines(t *testing.T) {-+ completed := `{"type":"response.completed","response":{"id":"resp_split","object":"response","model":"gpt-5.4","status":"completed","output":[{"id":"msg_1","type":"message","role":"assistant","content":[{"type":"output_text","text":"hi"}]}],"usage":{"input_tokens":5,"output_tokens":1,"total_tokens":6}}}`-+ cut := strings.Index(completed, `"output":`)-+ stream := "event: response.completed\r\ndata: " + completed[:cut] + "\r\ndata: " + completed[cut:] + "\r\n\r\n"-+ executor := NewCodexExecutor(&config.Config{})-+ ctx := context.WithValue(t.Context(), "cliproxy.roundtripper", codexAllocationTransport{stream: stream})-+ auth := &cliproxyauth.Auth{Attributes: map[string]string{"api_key": "test"}}-+ resp, err := executor.Execute(ctx, auth, cliproxyexecutor.Request{Model: "gpt-5.4", Payload: []byte(`{"model":"gpt-5.4","input":"hello"}`)},-+ cliproxyexecutor.Options{SourceFormat: sdktranslator.FormatOpenAIResponse})-+ if err != nil {-+ t.Fatalf("Execute error: %v", err)-+ }-+ var got struct {-+ ID string `json:"id"`-+ Output []json.RawMessage `json:"output"`-+ }-+ if errDecode := json.Unmarshal(resp.Payload, &got); errDecode != nil || got.ID != "resp_split" || len(got.Output) != 1 {-+ t.Fatalf("payload = %s (decode error %v), want the completed response", resp.Payload, errDecode)-+ }-+}diff --git a/patches/model-hub-cpa-v8.0.30/README.md b/patches/model-hub-cpa-v8.0.30/README.mdnew file mode 100644index 000000000..884c9f1f7--- /dev/null+++ b/patches/model-hub-cpa-v8.0.30/README.md@@ -0,0 +1,402 @@+# Avibe-owned CPA v8.0.30 compatibility patches++This directory records the source patches carried by Avibe's+`model-hub-engine-v8.0.30-1` build. The build applies them with+`git apply --whitespace=error`, in the order the manifest's `build.patches`+records; each one applies on top of the ones before it.++Base:++- Repository: `router-for-me/CLIProxyAPI`+- Release: `v8.0.30`+- Source commit: `5be2cdab0869cbaa3d401891f740aebf7e15aa99`++Carried over from the v8.0.28 set: patches 1 to 5, byte-identical; they apply+to v8.0.30 with hunk offsets only. New in this set: patch 6, the xAI over-limit+item IDs; patches 7 and 8, private copies of router-for-me/CLIProxyAPI#6701+and #6700, carried until upstream releases them; and patch 9, upstream's own+fix a43026d7 from v8.0.33, backported. Patches 7, 8 and 9 are+`git format-patch` output; `git apply` reads them as the diffs they contain.++Each contract was re-measured on v8.0.30: the stock engine fails the check the+patch exists for, and the patched engine passes it.++## `openai-compat-native-token-field.patch`++Avibe owns the OpenAI-compatible Source boundary. When an incoming Chat+request contains `max_completion_tokens`, or `max_tokens`, the engine must+preserve that caller-selected field unless Avibe explicitly selects the+`use-max-completion-tokens` compatibility mode for a model. The stock+default rewrites the former field to the latter, which breaks upstreams that+accept only the native field.++The patch therefore makes the stock `false` path a preservation path. The+existing explicit `true` path still canonicalizes to+`max_completion_tokens`. Avibe does not set the option today, so both+buffered and streaming requests retain their native token-limit field.++The patch is limited to the helper used by both OpenAI Chat execution paths+(`openai_compat_executor.go`, buffered and streaming). The helper and its call+sites are unchanged from v8.0.23 to v8.0.30; stock v8.0.30 still rewrites the+field (upstream's `TestNormalizeOpenAIMaxTokens` passes unpatched).++The patch also updates the three `useMaxCompletionTokens=false` cases of+upstream's `TestNormalizeOpenAIMaxTokens`, which asserted the stock rewrite,+to assert this contract: the payload, including a `null` limit, is returned+unchanged. It updates the four `use-max-completion-tokens=false` chat cases of+upstream's executor-level `TestOpenAICompatExecutor_MaxTokensNormalization`+and `TestOpenAICompatExecutor_MaxTokensNormalizationStream` the same way: the+request keeps `max_completion_tokens`, including `null`, and gains no+`max_tokens`. With all patches applied, `go test ./internal/runtime/executor/`+and `go test ./internal/runtime/executor/helps/` pass. The test changes do not+alter the engine binary.++## `oauth-callback-forwarder-loopback.patch`++Avibe starts every redirect-based subscription login (Claude, Codex,+Antigravity) with `is_webui=true`. The engine then starts a callback forwarder+on the vendor's fixed redirect port (54545, 1455 or 51121) that relays the+browser's redirect to the management callback. Stock CPA binds that forwarder+on `0.0.0.0` and aborts the login with a 500 when the bind fails.++The patch binds the forwarder on `127.0.0.1` only, because the redirect always+comes from a browser on the same machine. A wildcard bind exposed the port to+the network and, on Windows, raised a Defender Firewall prompt for the engine.+A failed bind (the port is in use, or reserved by Hyper-V, WSL or Docker) is+logged and no longer aborts the login: Avibe's Web UI still accepts the pasted+callback URL, which reaches the same session through `POST /oauth-callback`.++A container deployment that publishes the callback ports to reach a browser+outside the container loses the automatic callback, since the forwarder no+longer listens on the container's external interface. The pasted callback URL+completes the login there.++Go's wildcard listen is dual-stack, so the stock forwarder also accepted+`[::1]`; the patched one accepts 127.0.0.1 only. The vendors' redirect URIs+name `localhost`, and a browser that tries `::1` first is refused at once and+falls back to 127.0.0.1, as mainstream browsers do. Where one does not, the+pasted callback URL still completes the login. Revisit this if anyone reports+a refused connection to `localhost` at the OAuth callback.++Measured on stock v8.0.30 with+`test_oauth_callback_forwarder_is_loopback_only_and_optional`+(`AVIBE_E2E_ISOLATED_NETWORK=1`): the Codex forwarder listens on `::`; with the+patch it listens on `127.0.0.1` and a taken Anthropic port is non-fatal.++## `antigravity-static-catalog-until-probe.patch`++Avibe ships Gemini subscriptions through Antigravity OAuth grants and routes+to them as soon as the engine has loaded a grant: right after every engine+start and right after a new login. Since v8.0.14 the stock engine registers no+Antigravity models until its per-account entitlement probe+(`/v1internal:fetchAvailableModels`) answers. Until then a request gets+`model_not_found` and model discovery sees an empty catalog; when the probe+fails, the account stays unroutable until a backed-off retry succeeds+(1-2 minutes at first, up to 30 minutes).++The patch registers the static Antigravity catalog while no entitlement hints+are cached. The probe that registration already queues narrows the catalog+through the fenced `ReplaceClientModels` when it answers; a failed probe leaves+the static catalog in place. This is the pre-v8.0.14 startup behavior plus+the later narrowing. The patch also rewrites upstream's+`TestAntigravityModelRegistration_AsyncNonBlocking`, which asserted the stock+behavior, to assert this contract: the static catalog is registered before the+probe answers, then narrowed to the entitled set. With both patches applied,+`go test -run Antigravity ./sdk/cliproxy/` passes.++Upstream closed router-for-me/CLIProxyAPI#6531 with v8.0.24 (091ff27f), which+persists the probe's entitlement hints in the auth file and seeds them at the+next start. That covers a restart after one successful probe only: a new login,+and every grant written by an older engine on its first start, still register+nothing until the probe answers, and a failed probe leaves them unroutable for+the backoff. Measured on stock v8.0.28, and again on stock v8.0.30, with a synthetic grant: `model_not_found`+from the first request and an empty listing, nothing at all while the probe+fails, and an immediate Source refresh refused. Keep this patch until upstream+registers a catalog while no hints exist; where persisted hints exist the patch+never runs, because `hints.ModelIDs` is set.++v8.0.29 (08e5762a) fences model registration with epochs; the static catalog+this patch registers goes through the same fenced path, and the probe still+narrows it.++## `codex-utls-h2-ping-health-check.patch`++Codex subscription requests to `https://chatgpt.com` go through a dedicated+Chrome uTLS connection per request. When ALPN selects HTTP/2, stock CPA wraps+that connection in a zero-value `http2.Transport{}`: no PING health check, no+client timeout, nothing that bounds the body read. A path that stops+delivering packets without a FIN or RST reaching the engine, which a NAT or a+TCP-terminating proxy can leave behind and TCP keepalive cannot see past,+therefore blocks the stream until the caller gives up. Avibe's turns then+waited out their 600-second bound with no byte and no error. The same code is+in v7.3.16, so this is not a v8 regression.++The patch sets `ReadIdleTimeout` 30 s and `PingTimeout` 15 s on that+connection's `http2.Transport` only. After 30 s without a frame the transport+sends one PING and closes the connection when no ACK arrives within 15 s, so+the stream fails with an in-stream `request_timeout` error at about 45 s.+Model Hub's recovery then retries on a new connection. A live upstream that+is silent, for example during a long reasoning phase, acknowledges the PING+and is not cut; an active stream sends no PING. The shared transports, the+proxy transports, the HTTP/1.1 Claude round tripper and the WebSocket path+are untouched. The patch adds `utls_client_health_test.go`: a dead path fails+the stream, and a silent healthy stream survives ten idle periods.++Measured on the shipped v8.0.23 engine on the uTLS HTTP/2 path through a+black-holing CONNECT proxy: stock sent no byte and no error for 9 min 38 s,+until it was killed; patched sent `event: error` (`request_timeout`) at+45.0 s. A live stream silent for 120 s completed on both. Re-measured on v8.0.28+through the same kind of path: stock silent until the client's 120 s bound,+patched `request_timeout` at 45.06 s, and a live stream silent for 90 s+completed on both. Re-measured on v8.0.30: stock silent until the client's 120 s+bound, patched `request_timeout` at 45.02 s, a 90 s silent stream completed.+v8.0.29 (345cc9d5, b3dc6c3f) added an opt-in uTLS handshake timeout+(`tls-handshake-timeout-seconds`, default off); it bounds the handshake only,+not an established connection, so this patch stays.++Upstream declined the health check. router-for-me/CLIProxyAPI#6534 was+closed as not planned: by the project's design policy CPA sets no timeout+once an upstream connection is established, HTTP/2 health checks and stream+read deadlines included, not even as an opt-in setting, and leaves timeouts+and cancellation to the downstream client. The opt-in pull request,+router-for-me/CLIProxyAPI#6535, was closed unmerged. Avibe therefore carries+this patch by design as its client-side transport bound for this connection.+No drop is planned; re-evaluate only if upstream changes its post-connect+timeout policy. The cost is that every CPA upgrade must rebase this patch and+`fallback-transport-h2-ping-health-check.patch`. A dead path is this patch's+case; a live relay whose own upstream is stuck answers PINGs, so Avibe's+gateway bounds that case instead (the 120 s stream idle bound,+`docs/plans/model-hub-inference-deadlines.md`, "Stream idle bound", #2538).++## `fallback-transport-h2-ping-health-check.patch`++Patch 4 covers only the dedicated uTLS connection to `https://chatgpt.com`.+Every other upstream request on an HTTP client from+`internal/runtime/executor/helps` ran on `http.DefaultTransport`, or on a+per-request proxy transport, without an HTTP/2 health check. That covers+API-key relays and OpenAI-compatible providers. The same dead-path failure+therefore reached Avibe through API-key relays: a turn on an HTTP/2 relay+whose path went dead waited out the 600-second bound with no byte and no+error.++The patch gives those requests one shared clone of `http.DefaultTransport`,+created on first use, with `HTTP2Config{SendPingTimeout: 30s, PingTimeout:+15s}`, the same timings as patch 4, as constants. It is used:++- as `NewUtlsHTTPClient`'s standard fallback for hosts other than chatgpt.com+ and api.anthropic.com (the Codex and Claude executors);+- by the OpenAI-compatible executor, through `WithUpstreamFallbackTransport`,+ which sets it only when `NewProxyAwareHTTPClient` left the transport nil.++`buildProxyTransport` sets the same health check on proxy transports.+`http.DefaultTransport` itself is not modified, and `NewProxyAwareHTTPClient`+still returns a nil transport when no proxy and no injected RoundTripper+apply, because the Antigravity executor reads that as "direct" and installs+its own HTTP/1.1 pool.++v8.0.28 added a request-scoped transport decorator (`sdk/httptransport`):+`NewProxyAwareHTTPClient` now ends by wrapping its transport, or+`http.DefaultTransport` when it has none, in any decorator the context carries.+Wrapping the helper's client with the fallback afterwards would then find a+non-nil transport and skip the health check. The OpenAI-compatible executor+therefore builds its client through `NewUpstreamHTTPClient`: the helper runs+with `WithoutDecorator`, the shared transport fills the empty slot, and+`Decorate` is applied once at the end, the same order upstream uses for the+Antigravity executor's own pool. Stock CPA sets no decorator, so this changes+nothing today; it keeps the contract if one is ever set. The injected context RoundTripper is untouched, as in+patch 4. The health check only sets HTTP/2 timings: protocol selection+(`ForceAttemptHTTP2`, `Protocols`, `TLSNextProto`, ALPN) is unchanged, and a+transport that did not opt into HTTP/2 still speaks HTTP/1.1.++Avibe renders `proxy-url: ""` and no per-Source proxy, so its Sources take the+shared clone. Coverage by Avibe Source kind:++| Source | CPA path | Covered |+| --- | --- | --- |+| `openai_responses` API key (OpenAI and xAI relays) | `codex-api-key`, `NewUtlsHTTPClient` fallback | yes |+| `anthropic` API key on a non-Anthropic host | `claude-api-key`, `NewUtlsHTTPClient` fallback | yes |+| `openai_chat` API key | `openai-compatibility`, `WithUpstreamFallbackTransport` | yes |+| `anthropic` API key on `api.anthropic.com` | HTTP/1.1 Claude round tripper | no: PING is HTTP/2 only |+| ChatGPT subscription | patch 4's uTLS connection | patch 4 |++An HTTP/1.1 upstream has no PING, so a silent HTTP/1.1 body is still bounded+only by the caller. The patch adds `upstream_transport_test.go`:++- a dead path fails the stream;+- a silent healthy stream survives ten idle periods;+- the shared transport is wired into both clients and the proxy transports;+- a request-scoped decorator wraps the health-checked transport, not+ `http.DefaultTransport`;+- protocol selection is unchanged.++Measured on v8.0.28 with a black-holing middlebox in front of an HTTP/2+relay: stock stayed silent until the client's 120 s bound on both the+`codex-api-key` and the `openai-compatibility` path; patched failed the stream+at 45.04 s and 45.05 s. A live stream silent for 90 s completed on both.+Re-measured on v8.0.30: stock silent until 120 s on both paths; patched failed+at 45.02 s (`request_timeout`, `codex-api-key`) and 45.01 s (`http2: client+connection lost`, `openai-compatibility`); a 90 s silent stream completed.++Upstream: the same failure mode as router-for-me/CLIProxyAPI#6534, declined+under the same policy (see `codex-utls-h2-ping-health-check.patch`), so no+upstream follow-up is pending. Avibe carries this patch by design as its+client-side transport bound for these transports. No drop is planned;+re-evaluate only if upstream changes its post-connect timeout policy. Every+CPA upgrade must rebase it together with that patch. A live relay that answers+PINGs while its own upstream is stuck is bounded by Avibe's gateway instead+(the 120 s stream idle bound, `docs/plans/model-hub-inference-deadlines.md`,+"Stream idle bound", #2538).++## `codex-compat-upstream-item-ids.patch`++Avibe renders `is-compat: true` on the `codex-api-key` models of an xAI Source (#2620), so the codex+executor stops deleting xAI's envelope-less reasoning `encrypted_content` and `id` on replay. A second+rule still rewrote xAI's own item IDs. `SanitizeCodexInputItemIDs` enforces OpenAI's 64-rune input-ID+limit: it removes an encrypted reasoning item whose ID is longer, and shortens any other long ID to+47 runes plus a hash. xAI issues longer IDs. In the 2026-10-13 spike, tool-call reasoning `tco_…` and+custom tool calls `ctc_…` are 84 runes and share a `<turn>_<call>` suffix, and web search calls `ws_…`+are 83. Its own reasoning `rs_…` (39) and messages `msg_…` (40) are within the limit.++With `is-compat`, an input item ID over the limit is the upstream's own and is kept verbatim: it is+neither prefixed nor shortened, and an encrypted reasoning item carrying one is not removed.+- The rule is the ID's length, so it covers every item type.+- IDs within the limit are normalized exactly as before.+- Without `is-compat` nothing changes. That includes today's removal of over-limit encrypted+ reasoning and the shortening of every other over-limit ID.+- The HTTP executor gets the flag through `cacheHelperWithCompat`; the two WebSocket paths pass it+ directly.++Avibe renders `is-compat` for xAI Sources (#2767), so this patch changes the xAI replay wire: on stock+v8.0.30 under that config the 84-rune `tco_` reasoning is dropped whole and the `ctc_` ID is shortened+(`MH-ENGINE-HOSTED-007` is an expected failure); with the patch both arrive verbatim. For every other+Source the patch changes no byte.++Tests:+- `helps/codex_input_ids_test.go`: one subtest per item type (reasoning, custom_tool_call,+ web_search_call, function_call, message), each with an over-limit ID. With compat the item is kept+ byte for byte. Without compat the result equals `SanitizeCodexInputItemIDs`: encrypted reasoning+ removed, other IDs shortened to 64 runes.+- `codex_executor_signature_test.go`: `ExecuteStream` with a real 84-rune `tco_` reasoning item and+ its 84-rune `ctc_` custom tool call. An `is-compat` model sends both verbatim. A non-compat model+ strips the reasoning and shortens the call ID, as before.+- Mutation checks: disabling the verbatim rule fails both tests. Wiring `ExecuteStream` back to+ `cacheHelper` fails the executor test.++Drop the patch if xAI rejects verbatim long IDs in the live A/B, or once upstream exempts+compatibility models from the Codex ID limit.++## `config-locked-reads.patch`++A private copy of router-for-me/CLIProxyAPI#6701 (Avibe #2686), rebased on+v8.0.30. Avibe hot-reloads the engine with `PUT /v0/management/config.yaml`.+The engine rewrites `config.yaml` in place (the management write, and its own+rewrite of the management secret to bcrypt on every load), while its watcher,+loaders and management reads used a bare `os.ReadFile`, so a reader could see a+truncated or half-written file.++v8.0.30 (1631875b, #6631) already serializes reloads and records the hash of+the bytes each reload parsed. This patch carries only the torn-read fix that+release lacks: `config.ReadConfigFile` and `config.WriteConfigFile` hold one+RWMutex, through which the management write and its GET and v8 reads,+`SaveConfigPreserveComments*`, `PrepareConfigFileForUpload`, the `LoadConfig`+reads and cleanup write, the watcher's reload read, and the management+stale-snapshot check that 1631875b added all go. Writes stay in+place with `fsync`, so the inode of a single-file bind mount is kept. The+watcher is otherwise stock: Avibe writes `config.yaml` only before it starts+the engine and reloads through the management API, never by renaming the file+under a running engine, so the stock file watch is enough (upstream's watcher+work is in #6710, not carried).++Tests: `TestConfigFileReadsAndWritesExcludeEachOther` (a named pipe parks a+read or a write inside the file I/O, so mutual exclusion is checked without+timing), `TestConfigFileCallSitesHoldTheLock` (the same pipe parks each call+site, the watcher reload, the management GET, v8 read, stale-snapshot check+and write, inside its own file I/O while the test checks it holds the lock;+reverting any one to raw file I/O fails its subtest) and+`TestWriteConfigFileKeepsInode`. `fsync` has no unit test.++Drop when upstream merges #6701 and Avibe adopts a release that contains it.++## `claude-retry-headers-on-error-responses.patch`++A private copy of router-for-me/CLIProxyAPI#6700 (Avibe #2666) at its head+860a2f442, rebased on v8.0.30. When Anthropic refuses a request with a rate+limit, its response carries `Retry-After`, `Retry-After-Ms` and the+`Anthropic-Ratelimit-Unified-*` headers. Stock CPA drops them from the error it+returns, so a client cannot tell when to retry.++The Claude executor keeps those headers on its error, the fast-mode decode+path included. `executionErrorMessage`, the only producer of an error+message's headers, owns the policy for every consumer (HTTP writers, the+Responses WebSocket error event, plugin callbacks): it finds the header+carrier through every wrapper (`errors.As`), so retry and Home rounds no+longer lose them; it filters them with `FilterUpstreamHeaders`, as success+responses are; and when CPA has its own `Retry-After` (a Home round delay or+a local cooldown), that value replaces the upstream `Retry-After` and+`Retry-After-Ms`. The headers reach a client only with+`passthrough-headers: true`.++Tests: `TestClaudeExecutor_ErrorCarriesRetryHeaders`,+`TestClaudeExecutorFastHTTPDecodeErrorKeepsRetryHeaders`,+`TestExecutionErrorMessageFindsUpstreamHeadersThroughWrappers`,+`TestExecutionErrorMessageFiltersUpstreamHeadersLikeSuccess` and+`TestExecutionErrorMessageKeepsCPARetryTimingForEveryConsumer`; seven+mutants, all caught. Avibe's D6 (a 5xx's `Retry-After: 600` reaches the+Source cooldown through the real engine) fails on stock v8.0.30 and passes+with the patch.++Drop when upstream merges #6700 and Avibe adopts a release that contains it.++## `gemini-schema-content-keywords.patch`++Upstream's a43026d7 (router-for-me/CLIProxyAPI#6699, first in v8.0.33),+applied as published. Since v8.0.28 (a0fd8448) the Gemini and Antigravity+tool-schema cleaners keep a multi-branch `anyOf`/`oneOf` union instead of+collapsing it to one branch. A `contentMediaType` or `contentEncoding`+annotation that the collapse used to drop now reaches the backend, which+rejects the whole request with 400 `Unknown name "contentMediaType"`. Avibe's+Gemini subscription is an Antigravity grant, and MCP tool schemas carry these+annotations. The patch adds both keywords to the cleaners' unsupported list.++Upstream's `TestCleanJSONSchema_RemovesContentMediaTypeKeyword_Issue6699`+covers every cleaner (Gemini, Gemini JSON schema, Antigravity, its tool,+Claude-tool and response variants): on stock v8.0.30 each keeps both keywords+at the root, in `anyOf[1]` and in a property; with the patch they are+stripped, and properties named after the keywords survive. Dropping+`contentMediaType` from the list fails the test.++Drop at the next bump to v8.0.33 or later, which contains a43026d7.++## Known risk: model registration superseded mid-flight (#6718)++v8.0.29 (08e5762a) fences model registration with epochs. A registration that+is superseded mid-flight by another update of the same auth's attributes, where+that update does not register models itself, leaves the auth with no models+(router-for-me/CLIProxyAPI#6718; reproduced with a synthetic openai-compat+auth). Avibe does not take that path: its prefix PATCH re-registers+synchronously, and config reloads and watcher events each register. Upstream+fixed it in v8.0.33 (f75ea073), a +556/-60 change that does not apply to this+tree; the next bump resolves it. Revisit if Model Hub reports models vanishing+right after a Source edit or an OAuth login.++## Dropped earlier: `codex-sse-per-event-parsing.patch`++Dropped with the v8.0.28 set: upstream's `CodexSSEScanner` (7795de19, v8.0.28)+covers it, and v8.0.30 does not change it.++## Rebuild++The repository-owned release path checks out `source_sha`, applies the+recorded patches, builds every supported target with `CGO_ENABLED=0`,+packages deterministic archives, and verifies the generated bytes against the+checked-in manifest before publication:++```sh+python3 scripts/model_hub_engine_release_guard.py fetch-source \+ --output-dir /tmp/model-hub-engine-patched+```++The same command is available from the manual Model Hub release-guard+workflow. Its uploaded artifact is the source-built publication input; the+runtime manifest is updated only after the generated bytes and release assets+have been reviewed.diff --git a/patches/model-hub-cpa-v8.0.23/antigravity-static-catalog-until-probe.patch b/patches/model-hub-cpa-v8.0.30/antigravity-static-catalog-until-probe.patchsimilarity index 96%rename from patches/model-hub-cpa-v8.0.23/antigravity-static-catalog-until-probe.patchrename to patches/model-hub-cpa-v8.0.30/antigravity-static-catalog-until-probe.patchindex ff82f0e88..95b5d7dac 100644--- a/patches/model-hub-cpa-v8.0.23/antigravity-static-catalog-until-probe.patch+++ b/patches/model-hub-cpa-v8.0.30/antigravity-static-catalog-until-probe.patch@@ -61,10 +61,10 @@ index fe25493e..8d3edee9 100644}diff --git a/sdk/cliproxy/service_models.go b/sdk/cliproxy/service_models.go-index a444b64c..2ea086ef 100644+index 686a0405..82961ea0 100644--- a/sdk/cliproxy/service_models.go+++ b/sdk/cliproxy/service_models.go-@@ -123,6 +123,12 @@ func (s *Service) registerModelsForAuthWithCache(ctx context.Context, a *coreaut+@@ -127,6 +127,12 @@ func (s *Service) registerModelsForAuthWithConfigAndCache(ctx context.Context, cs.asyncProbeAntigravityCapabilities(ctx, a, provider)return}diff --git a/patches/model-hub-cpa-v8.0.30/claude-retry-headers-on-error-responses.patch b/patches/model-hub-cpa-v8.0.30/claude-retry-headers-on-error-responses.patchnew file mode 100644index 000000000..8e2529a12--- /dev/null+++ b/patches/model-hub-cpa-v8.0.30/claude-retry-headers-on-error-responses.patch@@ -0,0 +1,387 @@+From 8709b7563ca1d51aad052397c483584236b71d04 Mon Sep 17 00:00:00 2001+From: cyhhao <[email protected]>+Date: Sat, 17 Oct 2026 13:51:27 +0800+Subject: [PATCH] fix(claude): carry retry headers on upstream error responses++Claude upstream errors dropped Retry-After, Retry-After-Ms and the+Anthropic-Ratelimit-Unified-* headers after using them for cooldowns,+so passthrough-headers never forwarded them on 429/529 responses.+Keep that allow-listed subset on the error. executionErrorMessage, the+only producer of ErrorMessage.Addon, finds header carriers through+execution wrappers with errors.As, filters them like success headers,+and puts CPA's own Retry-After (a Home round delay or a local+cooldown) in place of the upstream's Retry-After and Retry-After-Ms.++Upstream: router-for-me/CLIProxyAPI#6700 at 860a2f442.+---+ .../claude_executor_fast_error_test.go | 52 +++++++++++++++ .../claude_executor_ratelimit_test.go | 65 +++++++++++++++++++ .../executor/claude_executor_request.go | 2 +-+ .../executor/helps/claude_ratelimit.go | 18 ++++++ .../executor/openai_compat_executor.go | 4 +++ .../handlers/handlers_error_response_test.go | 68 ++++++++++++++++++++ sdk/api/handlers/handlers_execution.go | 22 +++++-+ sdk/api/handlers/header_filter.go | 11 ++++ 8 files changed, 238 insertions(+), 4 deletions(-)++diff --git a/internal/runtime/executor/claude_executor_fast_error_test.go b/internal/runtime/executor/claude_executor_fast_error_test.go+index 7024147f2..9fd607890 100644+--- a/internal/runtime/executor/claude_executor_fast_error_test.go++++ b/internal/runtime/executor/claude_executor_fast_error_test.go+@@ -5,8 +5,10 @@ import (+ "compress/gzip"+ "context"+ "errors"++ "fmt"+ "io"+ "net/http"++ "reflect"+ "strings"+ "sync/atomic"+ "testing"+@@ -281,3 +283,53 @@ func TestClaudeExecutorNonFastErrorKeepsCredentialScopedBehavior(t *testing.T) {+ t.Fatalf("upstream attempts = %d, want 1", got)+ }+ }++++func TestClaudeExecutorFastHTTPDecodeErrorKeepsRetryHeaders(t *testing.T) {++ for _, stream := range []bool{false, true} {++ t.Run(fmt.Sprintf("stream=%t", stream), func(t *testing.T) {++ transport := roundTripperFunc(func(req *http.Request) (*http.Response, error) {++ return &http.Response{++ StatusCode: http.StatusTooManyRequests,++ Header: http.Header{++ "Content-Type": []string{"application/json"},++ "Content-Encoding": []string{"gzip"},++ "Retry-After": []string{"30"},++ "Anthropic-Ratelimit-Unified-Status": []string{"rejected"},++ "Anthropic-Organization-Id": []string{"org-1"},++ },++ Body: io.NopCloser(strings.NewReader("not-a-gzip-stream")),++ Request: req,++ }, nil++ })++ ctx := context.WithValue(t.Context(), "cliproxy.roundtripper", http.RoundTripper(transport))++ auth := &cliproxyauth.Auth{++ ID: "fast-decode-error-headers",++ Attributes: map[string]string{"api_key": "sk-ant-oat-fast-decode-error-headers"},++ Metadata: claudeOAuthTestMetadata(),++ }++ request := cliproxyexecutor.Request{++ Model: "claude-opus-5",++ Payload: []byte(`{"model":"claude-opus-5","max_tokens":16,"speed":"fast","messages":[{"role":"user","content":"reply OK"}]}`),++ }++ opts := cliproxyexecutor.Options{Stream: stream, SourceFormat: sdktranslator.FormatClaude, ResponseFormat: sdktranslator.FormatClaude}++ executor := NewClaudeExecutor(&config.Config{})++ var errRun error++ if stream {++ _, errRun = executor.ExecuteStream(ctx, auth, request, opts)++ } else {++ _, errRun = executor.Execute(ctx, auth, request, opts)++ }++ var carrier interface{ Headers() http.Header }++ if !errors.As(errRun, &carrier) {++ t.Fatalf("Fast decode error %T does not carry headers", errRun)++ }++ want := http.Header{++ "Retry-After": {"30"},++ "Anthropic-Ratelimit-Unified-Status": {"rejected"},++ }++ if got := carrier.Headers(); !reflect.DeepEqual(got, want) {++ t.Fatalf("Headers() = %v, want %v", got, want)++ }++ })++ }++}+diff --git a/internal/runtime/executor/claude_executor_ratelimit_test.go b/internal/runtime/executor/claude_executor_ratelimit_test.go+index 444a82654..6f368870e 100644+--- a/internal/runtime/executor/claude_executor_ratelimit_test.go++++ b/internal/runtime/executor/claude_executor_ratelimit_test.go+@@ -6,6 +6,7 @@ import (+ "io"+ "net/http"+ "net/http/httptest"++ "reflect"+ "strconv"+ "strings"+ "sync/atomic"+@@ -792,3 +793,67 @@ func TestClaudeExecutor_AuthManager_MultiModelPoolStreamStopsProbingOn429(t *tes+ t.Fatalf("attempts on cred2 = %d, want 1", got)+ }+ }++++func TestClaudeExecutor_ErrorCarriesRetryHeaders(t *testing.T) {++ cases := []struct {++ name string++ status int++ stream bool++ }{++ {name: "execute 429", status: http.StatusTooManyRequests},++ {name: "stream 429", status: http.StatusTooManyRequests, stream: true},++ {name: "execute 529", status: 529},++ }++ for _, tc := range cases {++ t.Run(tc.name, func(t *testing.T) {++ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {++ w.Header().Set("Content-Type", "application/json")++ w.Header().Set("Retry-After", "30")++ w.Header().Set("Retry-After-Ms", "30000")++ w.Header().Set("Anthropic-Ratelimit-Unified-Status", "rejected")++ w.Header().Set("Anthropic-Ratelimit-Unified-5h-Status", "rejected")++ w.Header().Set("Anthropic-Organization-Id", "org-1")++ w.Header().Set("Request-Id", "req-1")++ w.Header().Set("Set-Cookie", "session=1")++ w.WriteHeader(tc.status)++ _, _ = w.Write([]byte(`{"type":"error","error":{"type":"rate_limit_error","message":"limited"}}`))++ }))++ defer server.Close()++++ executor := NewClaudeExecutor(&config.Config{})++ auth := &cliproxyauth.Auth{++ ID: "claude-auth-1",++ Provider: "claude",++ Attributes: map[string]string{"api_key": "test-key", "base_url": server.URL},++ }++ req := cliproxyexecutor.Request{++ Model: "claude-3-5-sonnet-20241022",++ Payload: []byte(`{"messages":[{"role":"user","content":[{"type":"text","text":"hi"}]}]}`),++ }++ opts := cliproxyexecutor.Options{SourceFormat: sdktranslator.FormatClaude}++ var err error++ if tc.stream {++ _, err = executor.ExecuteStream(context.Background(), auth, req, opts)++ } else {++ _, err = executor.Execute(context.Background(), auth, req, opts)++ }++ if err == nil {++ t.Fatal("expected an error")++ }++++ var carrier interface{ Headers() http.Header }++ if !errors.As(err, &carrier) {++ t.Fatalf("error %T does not carry headers", err)++ }++ want := http.Header{++ "Retry-After": {"30"},++ "Retry-After-Ms": {"30000"},++ "Anthropic-Ratelimit-Unified-Status": {"rejected"},++ "Anthropic-Ratelimit-Unified-5h-Status": {"rejected"},++ }++ if got := carrier.Headers(); !reflect.DeepEqual(got, want) {++ t.Fatalf("Headers() = %v, want %v", got, want)++ }++ })++ }++}+diff --git a/internal/runtime/executor/claude_executor_request.go b/internal/runtime/executor/claude_executor_request.go+index 75a37252b..42b53f687 100644+--- a/internal/runtime/executor/claude_executor_request.go++++ b/internal/runtime/executor/claude_executor_request.go+@@ -717,7 +717,7 @@ func classifyClaudeUpstreamErrorWithCooling(statusCode int, headers http.Header,+ if statusCode == http.StatusTooManyRequests || (statusCode >= 400 && statusCode < 600) {+ retryAfter = helps.ParseClaudeRateLimitReset(headers, time.Now())+ }+- err := statusErr{code: statusCode, msg: string(body), retryAfter: retryAfter}++ err := statusErr{code: statusCode, msg: string(body), retryAfter: retryAfter, headers: helps.ClaudeRetryHeaders(headers)}+ if statusCode == http.StatusTooManyRequests {+ if !modelLevelCooling && helps.ClaudeHeadersIndicateUnifiedRateLimitRejection(headers) {+ return claudeRateLimitError{statusErr: err, credentialScoped: true}+diff --git a/internal/runtime/executor/helps/claude_ratelimit.go b/internal/runtime/executor/helps/claude_ratelimit.go+index e4aa4592c..9b0c550bc 100644+--- a/internal/runtime/executor/helps/claude_ratelimit.go++++ b/internal/runtime/executor/helps/claude_ratelimit.go+@@ -21,6 +21,24 @@ const (+ maxClaudeRateLimitWindow = 7*24*time.Hour + time.Hour+ )+++// ClaudeRetryHeaders returns the upstream headers that tell a client when it may++// retry: Retry-After, Retry-After-Ms and the Anthropic-Ratelimit-Unified-* family.++// It returns nil when none are present.++func ClaudeRetryHeaders(headers http.Header) http.Header {++ var retry http.Header++ for key, values := range headers {++ name := http.CanonicalHeaderKey(key)++ if name != "Retry-After" && name != "Retry-After-Ms" && !strings.HasPrefix(name, "Anthropic-Ratelimit-Unified-") {++ continue++ }++ if retry == nil {++ retry = make(http.Header)++ }++ retry[name] = append(retry[name], values...)++ }++ return retry++}+++ // ClaudeHeadersIndicateUnifiedRateLimitRejection reports whether response headers explicitly+ // declare an Anthropic shared 5h or 7d rate-limit rejection. An overage-only or Fable-only rejection+ // remains model-scoped when shared subscription windows are not rejected (status "allowed", "allowed_warning",+diff --git a/internal/runtime/executor/openai_compat_executor.go b/internal/runtime/executor/openai_compat_executor.go+index b63f1258d..96fe7c3f0 100644+--- a/internal/runtime/executor/openai_compat_executor.go++++ b/internal/runtime/executor/openai_compat_executor.go+@@ -1108,6 +1108,9 @@ type statusErr struct {+ msg string+ retryAfter *time.Duration+ credentialScoped bool++ // headers are upstream response headers that may be forwarded to the client++ // when passthrough-headers is enabled.++ headers http.Header+ }++ func (e statusErr) Error() string {+@@ -1119,6 +1122,7 @@ func (e statusErr) Error() string {+ func (e statusErr) StatusCode() int { return e.code }+ func (e statusErr) RetryAfter() *time.Duration { return e.retryAfter }+ func (e statusErr) IsCredentialScoped() bool { return e.credentialScoped }++func (e statusErr) Headers() http.Header { return e.headers }++ const openAICompatTPMFallbackRetryAfter = time.Minute++diff --git a/sdk/api/handlers/handlers_error_response_test.go b/sdk/api/handlers/handlers_error_response_test.go+index c75481c45..f1d1bc9b7 100644+--- a/sdk/api/handlers/handlers_error_response_test.go++++ b/sdk/api/handlers/handlers_error_response_test.go+@@ -5,6 +5,7 @@ import (+ "context"+ "encoding/json"+ "errors"++ "fmt"+ "net/http"+ "net/http/httptest"+ "net/url"+@@ -946,3 +947,70 @@ func TestWriteErrorResponse_ContextCanceledUses499(t *testing.T) {+ t.Fatalf("status = %d, want %d", recorder.Code, clienterror.StatusClientClosedRequest)+ }+ }++++type upstreamHeaderError struct{ headers http.Header }++++func (e upstreamHeaderError) Error() string { return "upstream rate limit" }++func (e upstreamHeaderError) Headers() http.Header { return e.headers }++++func TestExecutionErrorMessageFindsUpstreamHeadersThroughWrappers(t *testing.T) {++ upstream := upstreamHeaderError{headers: http.Header{"Retry-After": {"30"}}}++ msg := executionErrorMessage(fmt.Errorf("retry round exhausted: %w", upstream))++ if got := msg.Addon.Get("Retry-After"); got != "30" {++ t.Fatalf("Addon Retry-After = %q, want 30 from the wrapped upstream error", got)++ }++}++++func TestExecutionErrorMessageKeepsCPARetryTimingForEveryConsumer(t *testing.T) {++ // A CPA error with its own retry timing around an upstream error with its own.++ upstream := upstreamHeaderError{headers: http.Header{++ "Retry-After": {"30"},++ "Retry-After-Ms": {"30000"},++ "Anthropic-Ratelimit-Unified-Status": {"rejected"},++ }}++ msg := executionErrorMessage(errors.Join(coreauth.NewHomeConcurrencyBusyError("busy", 750*time.Millisecond), upstream))++ msg.StatusCode = http.StatusTooManyRequests++++ check := func(consumer string, headers http.Header) {++ t.Helper()++ if got := headers.Values("Retry-After"); !reflect.DeepEqual(got, []string{"1"}) {++ t.Fatalf("%s Retry-After = %#v, want CPA's own [1]", consumer, got)++ }++ if got := headers.Get("Retry-After-Ms"); got != "" {++ t.Fatalf("%s Retry-After-Ms = %q, want none next to CPA's own Retry-After", consumer, got)++ }++ if got := headers.Get("Anthropic-Ratelimit-Unified-Status"); got != "rejected" {++ t.Fatalf("%s Anthropic-Ratelimit-Unified-Status = %q, want rejected", consumer, got)++ }++ }++ // The Responses WebSocket error event serializes Addon as is.++ check("Addon", msg.Addon)++ check("plugin stream error", modelExecutionStreamErrorFromMessage(msg).Headers)++++ gin.SetMode(gin.TestMode)++ recorder := httptest.NewRecorder()++ c, _ := gin.CreateTestContext(recorder)++ c.Request = httptest.NewRequest(http.MethodGet, "/", nil)++ NewBaseAPIHandlers(&sdkconfig.SDKConfig{PassthroughHeaders: true}, nil).WriteErrorResponse(c, msg)++ check("HTTP response", recorder.Header())++}++++func TestExecutionErrorMessageFiltersUpstreamHeadersLikeSuccess(t *testing.T) {++ // A stream that fails before its first payload carries the upstream's raw headers.++ upstream := upstreamHeaderError{headers: http.Header{++ "Retry-After": {"30"},++ "Set-Cookie": {"session=1"},++ "Transfer-Encoding": {"chunked"},++ "Content-Encoding": {"gzip"},++ }}++ msg := executionErrorMessage(fmt.Errorf("retry round exhausted: %w", upstream))++++ if got := msg.Addon.Get("Retry-After"); got != "30" {++ t.Fatalf("Addon Retry-After = %q, want 30", got)++ }++ for _, name := range []string{"Set-Cookie", "Transfer-Encoding", "Content-Encoding"} {++ if got := msg.Addon.Get(name); got != "" {++ t.Fatalf("Addon %s = %q, want it filtered as on success responses", name, got)++ }++ }++}+diff --git a/sdk/api/handlers/handlers_execution.go b/sdk/api/handlers/handlers_execution.go+index 5e4c1962c..4b3dda404 100644+--- a/sdk/api/handlers/handlers_execution.go++++ b/sdk/api/handlers/handlers_execution.go+@@ -11,6 +11,7 @@ import (+ "github.com/router-for-me/CLIProxyAPI/v8/internal/clienterror"+ "github.com/router-for-me/CLIProxyAPI/v8/internal/interfaces"+ "github.com/router-for-me/CLIProxyAPI/v8/internal/runtime/executor/helps"++ coreauth "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/auth"+ coreexecutor "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/executor"+ coreusage "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/usage"+ "github.com/router-for-me/CLIProxyAPI/v8/sdk/pluginapi"+@@ -388,9 +389,24 @@ func executionErrorMessage(err error) *interfaces.ErrorMessage {+ }+ }+ var addon http.Header+- if he, ok := err.(interface{ Headers() http.Header }); ok && he != nil {+- if hdr := he.Headers(); hdr != nil {+- addon = hdr.Clone()++ // Execution layers wrap upstream errors (retries, Home rounds, fast mode), so++ // look through every wrapper for the headers the upstream error carries. They++ // are filtered here, as on success responses, because every consumer of the++ // error message (HTTP, WebSocket, plugin callbacks) may expose them.++ var he interface{ Headers() http.Header }++ if errors.As(err, &he) && he != nil {++ addon = FilterUpstreamHeaders(he.Headers())++ }++ if addon != nil {++ if own := coreauth.SafeResponseHeaders(err).Values("Retry-After"); len(own) > 0 {++ // CPA's own retry timing (a Home round delay or a local cooldown) is++ // authoritative over the upstream's, for every consumer as well.++ for key := range addon {++ if IsRetryTimingHeader(key) {++ delete(addon, key)++ }++ }++ addon["Retry-After"] = append([]string(nil), own...)+ }+ }+ return &interfaces.ErrorMessage{StatusCode: status, Error: err, Addon: addon}+diff --git a/sdk/api/handlers/header_filter.go b/sdk/api/handlers/header_filter.go+index e72467459..e6e17ad63 100644+--- a/sdk/api/handlers/header_filter.go++++ b/sdk/api/handlers/header_filter.go+@@ -52,6 +52,17 @@ func IsCPAReservedResponseHeader(name string) bool {+ return reserved+ }+++// IsRetryTimingHeader reports whether a response header tells the client when to retry.++// CPA's own retry timing (a Home round delay or a local cooldown) takes precedence over++// the upstream's.++func IsRetryTimingHeader(name string) bool {++ switch http.CanonicalHeaderKey(name) {++ case "Retry-After", "Retry-After-Ms":++ return true++ }++ return false++}+++ // FilterUpstreamHeaders returns a copy of src with hop-by-hop and security-sensitive+ // headers removed. Returns nil if src is nil or empty after filtering.+ func FilterUpstreamHeaders(src http.Header) http.Header {+--+2.50.1 (Apple Git-155)+diff --git a/patches/model-hub-cpa-v8.0.30/codex-compat-upstream-item-ids.patch b/patches/model-hub-cpa-v8.0.30/codex-compat-upstream-item-ids.patchnew file mode 100644index 000000000..0c2aa872e--- /dev/null+++ b/patches/model-hub-cpa-v8.0.30/codex-compat-upstream-item-ids.patch@@ -0,0 +1,289 @@+diff --git a/internal/runtime/executor/codex_executor_execute.go b/internal/runtime/executor/codex_executor_execute.go+index 1cb4da2..34103d0 100644+--- a/internal/runtime/executor/codex_executor_execute.go++++ b/internal/runtime/executor/codex_executor_execute.go+@@ -86,7 +86,7 @@ func (e *CodexExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, re+ }++ url := strings.TrimSuffix(baseURL, "/") + "/responses"+- httpReq, upstreamBody, err := e.cacheHelper(ctx, from, url, req, body, opts.Headers)++ httpReq, upstreamBody, err := e.cacheHelperWithCompat(ctx, from, url, req, body, isCompat, opts.Headers)+ if err != nil {+ return resp, err+ }+@@ -267,7 +267,7 @@ func (e *CodexExecutor) executeCompact(ctx context.Context, auth *cliproxyauth.A+ body, optimizeMultiAgentV2 := helps.OptimizeCodexMultiAgentV2RequestForAuth(ctx, opts.Headers, body, e.cfg, auth, isCompat)++ url := strings.TrimSuffix(baseURL, "/") + "/responses/compact"+- httpReq, upstreamBody, err := e.cacheHelper(ctx, from, url, req, body, opts.Headers)++ httpReq, upstreamBody, err := e.cacheHelperWithCompat(ctx, from, url, req, body, isCompat, opts.Headers)+ if err != nil {+ return resp, err+ }+diff --git a/internal/runtime/executor/codex_executor_request.go b/internal/runtime/executor/codex_executor_request.go+index 43dd89b..d2bff01 100644+--- a/internal/runtime/executor/codex_executor_request.go++++ b/internal/runtime/executor/codex_executor_request.go+@@ -97,6 +97,12 @@ func (e *CodexExecutor) HttpRequest(ctx context.Context, auth *cliproxyauth.Auth+ }++ func (e *CodexExecutor) cacheHelper(ctx context.Context, from sdktranslator.Format, url string, req cliproxyexecutor.Request, rawJSON []byte, headerSets ...http.Header) (*http.Request, []byte, error) {++ return e.cacheHelperWithCompat(ctx, from, url, req, rawJSON, false, headerSets...)++}++++// cacheHelperWithCompat is cacheHelper for a request whose model compatibility mode is++// isCompat, which decides how input item IDs are sanitized.++func (e *CodexExecutor) cacheHelperWithCompat(ctx context.Context, from sdktranslator.Format, url string, req cliproxyexecutor.Request, rawJSON []byte, isCompat bool, headerSets ...http.Header) (*http.Request, []byte, error) {+ var headers http.Header+ if len(headerSets) > 0 {+ headers = headerSets[0]+@@ -139,7 +145,7 @@ func (e *CodexExecutor) cacheHelper(ctx context.Context, from sdktranslator.Form+ if cache.ID != "" {+ rawJSON = helps.SetStringIfDifferent(rawJSON, "prompt_cache_key", cache.ID)+ }+- rawJSON = helps.SanitizeCodexInputItemIDs(rawJSON)++ rawJSON = helps.SanitizeCodexInputItemIDsWithCompat(rawJSON, isCompat)+ rawJSON = helps.FinalizePayload(ctx, rawJSON)+ httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(rawJSON))+ if err != nil {+diff --git a/internal/runtime/executor/codex_executor_signature_test.go b/internal/runtime/executor/codex_executor_signature_test.go+index 9947580..b042ac8 100644+--- a/internal/runtime/executor/codex_executor_signature_test.go++++ b/internal/runtime/executor/codex_executor_signature_test.go+@@ -480,3 +480,71 @@ func TestCodexExecutorDisambiguatesConfigIndex(t *testing.T) {+ t.Fatalf("content text = %q, want keep me", gotText)+ }+ }++++func TestCodexExecutorExecuteStreamKeepsUpstreamIDsOverTheLimitForCompatModel(t *testing.T) {++ // A real xAI X search turn: the tool-call reasoning and its custom tool call share a++ // <turn>_<call> suffix and are 84 runes each, over the Codex ID limit.++ const (++ toolReasoningID = "tco_6b0014d0-e12f-9b38-ac33-4df9412f3045_call-fbb80085-357f-4d3e-b850-0123456789ab"++ customToolID = "ctc_6b0014d0-e12f-9b38-ac33-4df9412f3045_call-fbb80085-357f-4d3e-b850-0123456789ab"++ )++ for _, isCompat := range []bool{true, false} {++ var gotBody []byte++ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {++ body, errRead := io.ReadAll(r.Body)++ if errRead != nil {++ t.Fatalf("read body: %v", errRead)++ }++ gotBody = body++ w.Header().Set("Content-Type", "text/event-stream")++ _, _ = w.Write([]byte("data: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp_1\",\"object\":\"response\",\"created_at\":0,\"status\":\"completed\",\"background\":false,\"error\":null}}\n\n"))++ }))++++ cfg := &config.Config{++ CodexKey: []config.CodexKey{{++ APIKey: "test-api-key",++ BaseURL: server.URL,++ Models: []config.CodexModel{{Name: "grok-4.6", Alias: "grok-4.6", IsCompat: isCompat}},++ }},++ }++ executor := NewCodexExecutor(cfg)++ auth := &cliproxyauth.Auth{++ Provider: "codex",++ Attributes: map[string]string{"base_url": server.URL, "api_key": "test-api-key"},++ }++ payload := []byte(`{"model":"grok-4.6","stream":true,"store":false,"input":[` +++ `{"type":"reasoning","id":"` + toolReasoningID + `","summary":[],"encrypted_content":"xai-opaque-ciphertext"},` +++ `{"type":"custom_tool_call","id":"` + customToolID + `","call_id":"xs_call-1","name":"x_keyword_search","input":"{}"},` +++ `{"role":"user","content":[{"type":"input_text","text":"again"}]}` +++ `]}`)++++ streamResult, err := executor.ExecuteStream(context.Background(), auth, cliproxyexecutor.Request{++ Model: "grok-4.6",++ Payload: payload,++ }, cliproxyexecutor.Options{SourceFormat: sdktranslator.FromString("openai-response"), Stream: true})++ if err != nil {++ t.Fatalf("isCompat=%v: ExecuteStream error: %v", isCompat, err)++ }++ for range streamResult.Chunks {++ }++ server.Close()++++ input := gjson.GetBytes(gotBody, "input").Array()++ if isCompat {++ if len(input) != 3 || input[0].Get("id").String() != toolReasoningID ||++ input[0].Get("encrypted_content").String() != "xai-opaque-ciphertext" ||++ input[1].Get("id").String() != customToolID {++ t.Fatalf("compat model: xAI-issued IDs not replayed verbatim: %s", gotBody)++ }++ continue++ }++ // Without compat: the foreign ciphertext and the overlong reasoning ID go, and the++ // custom tool call's ID is shortened to the Codex limit, as before.++ if len(input) != 3 || input[0].Get("encrypted_content").Exists() || input[0].Get("id").Exists() {++ t.Fatalf("non-compat model: reasoning not stripped as before: %s", gotBody)++ }++ if id := input[1].Get("id").String(); len([]rune(id)) != 64 || id == customToolID {++ t.Fatalf("non-compat model: custom tool call ID = %q, want it shortened to 64 runes", id)++ }++ }++}+diff --git a/internal/runtime/executor/codex_executor_stream.go b/internal/runtime/executor/codex_executor_stream.go+index f468586..3abef56 100644+--- a/internal/runtime/executor/codex_executor_stream.go++++ b/internal/runtime/executor/codex_executor_stream.go+@@ -93,7 +93,7 @@ func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au+ }++ url := strings.TrimSuffix(baseURL, "/") + "/responses"+- httpReq, upstreamBody, err := e.cacheHelper(ctx, from, url, req, body, opts.Headers)++ httpReq, upstreamBody, err := e.cacheHelperWithCompat(ctx, from, url, req, body, isCompat, opts.Headers)+ if err != nil {+ return nil, err+ }+diff --git a/internal/runtime/executor/codex_websockets_execute.go b/internal/runtime/executor/codex_websockets_execute.go+index eed3dc0..ade5dc2 100644+--- a/internal/runtime/executor/codex_websockets_execute.go++++ b/internal/runtime/executor/codex_websockets_execute.go+@@ -95,7 +95,7 @@ func (e *CodexWebsocketsExecutor) Execute(ctx context.Context, auth *cliproxyaut+ if errPromptCache != nil {+ return resp, errPromptCache+ }+- body = helps.SanitizeCodexInputItemIDs(body)++ body = helps.SanitizeCodexInputItemIDsWithCompat(body, isCompat)+ if useSIWC {+ body = applyCodexSIWCWebsocketBodyRules(body, hasExplicitInstructions)+ }+diff --git a/internal/runtime/executor/codex_websockets_stream.go b/internal/runtime/executor/codex_websockets_stream.go+index 99514f3..ff28f8e 100644+--- a/internal/runtime/executor/codex_websockets_stream.go++++ b/internal/runtime/executor/codex_websockets_stream.go+@@ -823,7 +823,7 @@ func (e *CodexWebsocketsExecutor) prepareCodexWebsocketStream(ctx context.Contex+ if errPromptCache != nil {+ return nil, errPromptCache+ }+- body = helps.SanitizeCodexInputItemIDs(body)++ body = helps.SanitizeCodexInputItemIDsWithCompat(body, isCompat)+ if useSIWC {+ body = applyCodexSIWCWebsocketBodyRules(body, hasExplicitInstructions)+ }+diff --git a/internal/runtime/executor/helps/codex_input_ids.go b/internal/runtime/executor/helps/codex_input_ids.go+index 07a925c..d98a7a6 100644+--- a/internal/runtime/executor/helps/codex_input_ids.go++++ b/internal/runtime/executor/helps/codex_input_ids.go+@@ -27,15 +27,28 @@ const (+ // reasoning items whose IDs exceed the Codex limit, and deterministically shortens+ // other overlong input item IDs.+ func SanitizeCodexInputItemIDs(body []byte) []byte {++ return SanitizeCodexInputItemIDsWithCompat(body, false)++}++++// SanitizeCodexInputItemIDsWithCompat is SanitizeCodexInputItemIDs for a model whose++// compatibility mode may be enabled. A compatible upstream issues its own item IDs, and++// some exceed the Codex limit (xAI's tco_, ctc_ and ws_ IDs are 83-84 runes), so with++// isCompat an ID over the limit is the upstream's and is kept verbatim: it is neither++// prefixed nor shortened, and an encrypted reasoning item carrying one is not removed.++func SanitizeCodexInputItemIDsWithCompat(body []byte, isCompat bool) []byte {+ input := util.GetGJSONBytesNoCopy(body, "input")+ if !input.IsArray() {+ return body+ }++ items := input.Array()++ verbatim := func(item gjson.Result) bool {++ itemID := item.Get("id")++ return isCompat && itemID.Type == gjson.String && len([]rune(itemID.String())) > codexInputItemIDLimit++ }+ idStates := make(map[string]uint8, len(items))+ for _, item := range items {+- if shouldDropCodexEncryptedReasoningItem(item) {++ if verbatim(item) || shouldDropCodexEncryptedReasoningItem(item) {+ continue+ }+ itemID := item.Get("id")+@@ -61,6 +74,10 @@ func SanitizeCodexInputItemIDs(body []byte) []byte {+ rebuilt := make([]string, 0, len(items))+ changed := false+ for _, item := range items {++ if verbatim(item) {++ rebuilt = append(rebuilt, item.Raw)++ continue++ }+ if shouldDropCodexEncryptedReasoningItem(item) {+ changed = true+ continue+diff --git a/internal/runtime/executor/helps/codex_input_ids_test.go b/internal/runtime/executor/helps/codex_input_ids_test.go+index c6264f8..422257e 100644+--- a/internal/runtime/executor/helps/codex_input_ids_test.go++++ b/internal/runtime/executor/helps/codex_input_ids_test.go+@@ -316,3 +316,76 @@ func BenchmarkSanitizeCodexInputItemIDsLargeHistory(b *testing.B) {+ benchmarkSanitizeCodexInputItemIDsOutput = SanitizeCodexInputItemIDs(body)+ }+ }++++// xAI issues input item IDs over the Codex limit: in a real X search turn the tool-call++// reasoning (tco_) and custom tool call (ctc_) are 84 runes and share a <turn>_<call> suffix,++// and a web search call (ws_) is 83. A compat model gets every such ID back verbatim; other++// item types are covered too, since the rule is the ID's length, not its type.++var overlongUpstreamItems = []struct {++ name string++ item string++ id string++}{++ {"reasoning", `{"type":"reasoning","id":"%s","summary":[],"encrypted_content":"xai-opaque"}`,++ "tco_6b0014d0-e12f-9b38-ac33-4df9412f3045_call-fbb80085-357f-4d3e-b850-0123456789ab"},++ {"custom_tool_call", `{"type":"custom_tool_call","id":"%s","call_id":"xs_call-1","name":"x_keyword_search","input":"{}"}`,++ "ctc_6b0014d0-e12f-9b38-ac33-4df9412f3045_call-fbb80085-357f-4d3e-b850-0123456789ab"},++ {"web_search_call", `{"type":"web_search_call","id":"%s","status":"completed"}`,++ "ws_6b0014d0-e12f-9b38-ac33-4df9412f3045_call-fbb80085-357f-4d3e-b850-0123456789abc"},++ {"function_call", `{"type":"function_call","id":"%s","call_id":"call_1","name":"read","arguments":"{}"}`,++ "fc_6b0014d0-e12f-9b38-ac33-4df9412f3045_call-fbb80085-357f-4d3e-b850-0123456789abc"},++ {"message", `{"type":"message","id":"%s","role":"assistant"}`,++ "msg_6b0014d0-e12f-9b38-ac33-4df9412f3045_call-fbb80085-357f-4d3e-b850-0123456789ab"},++}++++func overlongUpstreamBody(item, id string) []byte {++ return []byte(`{"input":[` + fmt.Sprintf(item, id) +++ `,{"type":"function_call","id":"call_2","call_id":"call_2","name":"read","arguments":"{}"}]}`)++}++++func TestSanitizeCodexInputItemIDsWithCompatKeepsUpstreamIDsOverTheLimitVerbatim(t *testing.T) {++ for _, tc := range overlongUpstreamItems {++ t.Run(tc.name, func(t *testing.T) {++ if len([]rune(tc.id)) <= codexInputItemIDLimit {++ t.Fatalf("fixture ID is %d runes, want over %d", len([]rune(tc.id)), codexInputItemIDLimit)++ }++ body := overlongUpstreamBody(tc.item, tc.id)++++ got := SanitizeCodexInputItemIDsWithCompat(body, true)++++ items := gjson.GetBytes(got, "input").Array()++ if len(items) != 2 || items[0].Raw != gjson.GetBytes(body, "input.0").Raw {++ t.Fatalf("upstream item not kept verbatim: %s", got)++ }++ // IDs within the limit are normalized as before.++ if actual := items[1].Get("id").String(); actual != "fc_call_2" {++ t.Fatalf("short function_call ID = %q, want fc_call_2", actual)++ }++ })++ }++}++++func TestSanitizeCodexInputItemIDsWithoutCompatIsUnchanged(t *testing.T) {++ for _, tc := range overlongUpstreamItems {++ t.Run(tc.name, func(t *testing.T) {++ body := overlongUpstreamBody(tc.item, tc.id)++++ got := SanitizeCodexInputItemIDsWithCompat(body, false)++++ if string(got) != string(SanitizeCodexInputItemIDs(body)) {++ t.Fatalf("without compat the result differs from SanitizeCodexInputItemIDs:\n%s\n%s", got, SanitizeCodexInputItemIDs(body))++ }++ items := gjson.GetBytes(got, "input").Array()++ if tc.name == "reasoning" {++ if len(items) != 1 {++ t.Fatalf("overlong encrypted reasoning not removed: %s", got)++ }++ return++ }++ actual := items[0].Get("id").String()++ if len([]rune(actual)) != codexInputItemIDLimit || actual == tc.id {++ t.Fatalf("ID = %q, want %q shortened to %d runes", actual, tc.id, codexInputItemIDLimit)++ }++ })++ }++}diff --git a/patches/model-hub-cpa-v8.0.23/codex-utls-h2-ping-health-check.patch b/patches/model-hub-cpa-v8.0.30/codex-utls-h2-ping-health-check.patchsimilarity index 98%rename from patches/model-hub-cpa-v8.0.23/codex-utls-h2-ping-health-check.patchrename to patches/model-hub-cpa-v8.0.30/codex-utls-h2-ping-health-check.patchindex 6dcb0aa44..c5ddba684 100644--- a/patches/model-hub-cpa-v8.0.23/codex-utls-h2-ping-health-check.patch+++ b/patches/model-hub-cpa-v8.0.30/codex-utls-h2-ping-health-check.patch@@ -1,8 +1,8 @@diff --git a/internal/runtime/executor/helps/utls_client.go b/internal/runtime/executor/helps/utls_client.go-index f832748b..0344b41a 100644+index e090491f..f35432d3 100644--- a/internal/runtime/executor/helps/utls_client.go+++ b/internal/runtime/executor/helps/utls_client.go-@@ -29,6 +29,17 @@ type utlsRoundTripper struct {+@@ -30,6 +30,17 @@ type utlsRoundTripper struct {dialer proxy.Dialer}@@ -20,7 +20,7 @@ index f832748b..0344b41a 100644type closeConnectionBody struct {io.ReadClosercloseConnection func() error-@@ -123,7 +134,8 @@ func roundTripUtlsConnection(req *http.Request, tlsConn *tls.UConn) (*http.Respo+@@ -124,7 +135,8 @@ func roundTripUtlsConnection(req *http.Request, tlsConn *tls.UConn) (*http.Respovar err errorswitch protocol := tlsConn.ConnectionState().NegotiatedProtocol; protocol {case "h2":diff --git a/patches/model-hub-cpa-v8.0.30/config-locked-reads.patch b/patches/model-hub-cpa-v8.0.30/config-locked-reads.patchnew file mode 100644index 000000000..e849d9163--- /dev/null+++ b/patches/model-hub-cpa-v8.0.30/config-locked-reads.patch@@ -0,0 +1,544 @@+From a010cf786b688ecbd3715bf290d3ea831dfffc1f Mon Sep 17 00:00:00 2001+From: cyhhao <[email protected]>+Date: Sat, 17 Oct 2026 15:42:59 +0800+Subject: [PATCH] fix(config): stop readers seeing a half-written config++In-process config writers rewrite config.yaml by truncating it and then+writing it, so a concurrent reader (a reload's LoadConfig, the+management config endpoints, the management stale-snapshot check, a+read-modify-write save) could see an empty or partial file. An empty+read loads as defaults: no api-keys and no management secret until the+next event reloads the full file.++Order every in-process config write against those reads with one+RWMutex (config.WriteConfigFile / config.ReadConfigFile). Writes stay in+place, keeping the inode of a mounted config file, and are fsynced. A+call-site test parks each reader and the management write inside its+file I/O on a named pipe and checks that it holds the lock there.++Upstream: router-for-me/CLIProxyAPI#6701 at 0cd78a14a.+---+ .../api/handlers/management/config_basic.go | 17 +--+ internal/api/handlers/management/config_v8.go | 3 +-+ internal/api/handlers/management/handler.go | 5 +-+ internal/config/config_callsite_unix_test.go | 127 +++++++++++++++++++ internal/config/config_load.go | 10 +-+ internal/config/config_write.go | 37 ++++++ internal/config/config_write_test.go | 37 ++++++ internal/config/config_write_unix_test.go | 74 +++++++++++ internal/config/config_yaml.go | 9 +-+ internal/config/export_test.go | 4 ++ internal/watcher/config_reload.go | 3 +-+ 11 files changed, 295 insertions(+), 31 deletions(-)+ create mode 100644 internal/config/config_callsite_unix_test.go+ create mode 100644 internal/config/config_write.go+ create mode 100644 internal/config/config_write_test.go+ create mode 100644 internal/config/config_write_unix_test.go+ create mode 100644 internal/config/export_test.go++diff --git a/internal/api/handlers/management/config_basic.go b/internal/api/handlers/management/config_basic.go+index a6c02c4d6..86035b0b0 100644+--- a/internal/api/handlers/management/config_basic.go++++ b/internal/api/handlers/management/config_basic.go+@@ -110,20 +110,7 @@ func WriteConfig(path string, data []byte) error {+ return err+ }+ }+- data = config.NormalizeCommentIndentation(data)+- f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)+- if err != nil {+- return err+- }+- if _, errWrite := f.Write(data); errWrite != nil {+- _ = f.Close()+- return errWrite+- }+- if errSync := f.Sync(); errSync != nil {+- _ = f.Close()+- return errSync+- }+- return f.Close()++ return config.WriteConfigFile(path, config.NormalizeCommentIndentation(data), 0o644)+ }++ func (h *Handler) PutConfigYAML(c *gin.Context) {+@@ -183,7 +170,7 @@ func (h *Handler) PutConfigYAML(c *gin.Context) {+ // GetConfigYAML returns the raw config.yaml file bytes without re-encoding.+ // It preserves comments and original formatting/styles.+ func (h *Handler) GetConfigYAML(c *gin.Context) {+- data, err := os.ReadFile(h.configFilePath)++ data, err := config.ReadConfigFile(h.configFilePath)+ if err != nil {+ if os.IsNotExist(err) {+ c.JSON(http.StatusNotFound, gin.H{"error": "not_found", "message": "config file not found"})+diff --git a/internal/api/handlers/management/config_v8.go b/internal/api/handlers/management/config_v8.go+index b4b8e4184..d4063d516 100644+--- a/internal/api/handlers/management/config_v8.go++++ b/internal/api/handlers/management/config_v8.go+@@ -4,7 +4,6 @@ import (+ "encoding/json"+ "io"+ "net/http"+- "os"+ "reflect"+ "strings"++@@ -22,7 +21,7 @@ const ConfigV8ContextKey = "management.config-v8"+ func (h *Handler) ConfigV8(c *gin.Context) {+ h.mu.Lock()+ defer h.mu.Unlock()+- data, err := os.ReadFile(h.configFilePath)++ data, err := config.ReadConfigFile(h.configFilePath)+ if err != nil {+ c.JSON(http.StatusInternalServerError, gin.H{"error": "read_failed"})+ return+diff --git a/internal/api/handlers/management/handler.go b/internal/api/handlers/management/handler.go+index c186e75f4..f4c2df15b 100644+--- a/internal/api/handlers/management/handler.go++++ b/internal/api/handlers/management/handler.go+@@ -140,12 +140,13 @@ func (h *Handler) SetConfig(cfg *config.Config) {++ // isStaleConfigFileSnapshotLocked reports whether cfg was parsed from config file+ // bytes that are no longer on disk. Management saves hold h.mu, so none can land+-// during the check. Callers must hold h.mu.++// during the check, and config.ReadConfigFile keeps other in-process writes (such++// as LoadConfig's write-backs) from being read half-done. Callers must hold h.mu.+ func (h *Handler) isStaleConfigFileSnapshotLocked(cfg *config.Config) bool {+ if cfg == nil || cfg.SourceHash == "" || h.configFilePath == "" {+ return false+ }+- data, errRead := os.ReadFile(h.configFilePath)++ data, errRead := config.ReadConfigFile(h.configFilePath)+ if errRead != nil {+ return false+ }+diff --git a/internal/config/config_callsite_unix_test.go b/internal/config/config_callsite_unix_test.go+new file mode 100644+index 000000000..b069194a8+--- /dev/null++++ b/internal/config/config_callsite_unix_test.go+@@ -0,0 +1,127 @@++//go:build unix++++package config_test++++import (++ "bytes"++ "io"++ "net/http"++ "net/http/httptest"++ "os"++ "path/filepath"++ "syscall"++ "testing"++++ "github.com/gin-gonic/gin"++ "github.com/router-for-me/CLIProxyAPI/v8/internal/api/handlers/management"++ "github.com/router-for-me/CLIProxyAPI/v8/internal/config"++ "github.com/router-for-me/CLIProxyAPI/v8/internal/watcher"++)++++// configPipe creates a named pipe where the config file would be. A read or a++// write of it parks inside the file I/O until the test opens the other end.++func configPipe(t *testing.T) string {++ t.Helper()++ path := filepath.Join(t.TempDir(), "config.yaml")++ if err := syscall.Mkfifo(path, 0o600); err != nil {++ t.Fatalf("mkfifo: %v", err)++ }++ return path++}++++// assertReadHoldsLock runs read, which must read the config at path, and checks++// that it holds the config file lock while it reads, so no write can interleave.++func assertReadHoldsLock(t *testing.T, path string, content []byte, read func()) {++ t.Helper()++ done := make(chan struct{})++ go func() {++ defer close(done)++ read()++ }()++ // Opening the write end returns once the reader has opened the pipe, and the++ // reader then waits for data inside its read.++ pipe, err := os.OpenFile(path, os.O_WRONLY, 0)++ if err != nil {++ t.Fatalf("open pipe for writing: %v", err)++ }++ if config.ConfigFileMu.TryLock() {++ config.ConfigFileMu.Unlock()++ t.Error("the config is read without the config file lock")++ }++ if _, err = pipe.Write(content); err != nil {++ t.Fatalf("write pipe: %v", err)++ }++ if err = pipe.Close(); err != nil {++ t.Fatalf("close pipe: %v", err)++ }++ <-done++}++++func managementContext(method, target string) *gin.Context {++ gin.SetMode(gin.TestMode)++ c, _ := gin.CreateTestContext(httptest.NewRecorder())++ c.Request = httptest.NewRequest(method, target, nil)++ return c++}++++func TestConfigFileCallSitesHoldTheLock(t *testing.T) {++ t.Run("watcher reload", func(t *testing.T) {++ path := configPipe(t)++ w, err := watcher.NewWatcher(path, t.TempDir(), nil)++ if err != nil {++ t.Fatalf("NewWatcher: %v", err)++ }++ defer func() {++ if errStop := w.Stop(); errStop != nil {++ t.Errorf("stop watcher: %v", errStop)++ }++ }()++ // Empty bytes end the reload right after its read.++ assertReadHoldsLock(t, path, nil, w.ReloadConfigIfChanged)++ })++ t.Run("management GET config.yaml", func(t *testing.T) {++ path := configPipe(t)++ h := management.NewHandler(&config.Config{}, path, nil)++ assertReadHoldsLock(t, path, []byte("port: 8317\n"), func() {++ h.GetConfigYAML(managementContext(http.MethodGet, "/v0/management/config.yaml"))++ })++ })++ t.Run("management v8 config", func(t *testing.T) {++ path := configPipe(t)++ h := management.NewHandler(&config.Config{}, path, nil)++ assertReadHoldsLock(t, path, []byte("port: 8317\n"), func() {++ h.ConfigV8(managementContext(http.MethodGet, "/v8/management/config"))++ })++ })++ t.Run("management stale-snapshot check", func(t *testing.T) {++ path := configPipe(t)++ h := management.NewHandler(&config.Config{}, path, nil)++ assertReadHoldsLock(t, path, []byte("port: 8317\n"), func() {++ h.SetConfig(&config.Config{SourceHash: "applied"})++ })++ })++ t.Run("management write", func(t *testing.T) {++ path := configPipe(t)++ // More than a pipe buffer holds, so the writer stays inside its write until++ // the test drains the pipe.++ data := append(bytes.Repeat([]byte("# padding\n"), 1<<17), []byte("port: 8317\n")...)++ written := make(chan error, 1)++ go func() { written <- management.WriteConfig(path, data) }()++ pipe, err := os.Open(path)++ if err != nil {++ t.Fatalf("open pipe for reading: %v", err)++ }++ if config.ConfigFileMu.TryRLock() {++ config.ConfigFileMu.RUnlock()++ t.Error("the config is written without the config file lock")++ }++ if _, err = io.Copy(io.Discard, pipe); err != nil {++ t.Fatalf("drain pipe: %v", err)++ }++ if err = pipe.Close(); err != nil {++ t.Fatalf("close pipe: %v", err)++ }++ // A pipe cannot be synced, so the write reports an error after writing.++ <-written++ })++}+diff --git a/internal/config/config_load.go b/internal/config/config_load.go+index 93cc22efb..ac03a338e 100644+--- a/internal/config/config_load.go++++ b/internal/config/config_load.go+@@ -41,7 +41,7 @@ func ComputeSourceHash(data []byte) string {+ // copies stay identical. When the plaintext cannot be removed it returns an error and+ // leaves configFile untouched, so every later attempt refuses the file again.+ func PrepareConfigFileForUpload(configFile string) error {+- data, errRead := os.ReadFile(configFile)++ data, errRead := ReadConfigFile(configFile)+ if errRead != nil {+ return errRead+ }+@@ -52,7 +52,7 @@ func PrepareConfigFileForUpload(configFile string) error {+ if bytes.Equal(prepared, data) {+ return nil+ }+- if errWrite := os.WriteFile(configFile, prepared, 0600); errWrite != nil {++ if errWrite := WriteConfigFile(configFile, prepared, 0o600); errWrite != nil {+ return fmt.Errorf("failed to write prepared config file: %w", errWrite)+ }+ return nil+@@ -156,7 +156,7 @@ func managementSecretKeyPath(data []byte) []string {+ // If optional is true and the file is empty or invalid, it returns an empty Config.+ func LoadConfigOptional(configFile string, optional bool) (*Config, error) {+ // Read the entire configuration file into memory.+- data, err := os.ReadFile(configFile)++ data, err := ReadConfigFile(configFile)+ if err != nil {+ if optional {+ if os.IsNotExist(err) || errors.Is(err, syscall.EISDIR) {+@@ -331,7 +331,7 @@ func LoadConfigOptional(configFile string, optional bool) (*Config, error) {++ // Only conflicting legacy fields are removed on load. A legacy-only document+ // stays legacy until a v8 configuration write explicitly migrates it.+- current, errRead := os.ReadFile(configFile)++ current, errRead := ReadConfigFile(configFile)+ if errRead != nil {+ return nil, errRead+ }+@@ -340,7 +340,7 @@ func LoadConfigOptional(configFile string, optional bool) (*Config, error) {+ return nil, errLayout+ }+ if changed {+- if errWrite := os.WriteFile(configFile, cleaned, 0600); errWrite != nil {++ if errWrite := WriteConfigFile(configFile, cleaned, 0o600); errWrite != nil {+ return nil, fmt.Errorf("clean conflicting config fields: %w", errWrite)+ }+ }+diff --git a/internal/config/config_write.go b/internal/config/config_write.go+new file mode 100644+index 000000000..ea6f7315f+--- /dev/null++++ b/internal/config/config_write.go+@@ -0,0 +1,37 @@++package config++++import (++ "os"++ "sync"++)++++// configFileMu orders config file writes against reads within this process, so++// a reader such as the config watcher never sees a truncated or half-written file.++var configFileMu sync.RWMutex++++// ReadConfigFile reads a config file. It never overlaps a WriteConfigFile call,++// so it returns either the previous or the new content of a concurrent write.++func ReadConfigFile(path string) ([]byte, error) {++ configFileMu.RLock()++ defer configFileMu.RUnlock()++ return os.ReadFile(path)++}++++// WriteConfigFile rewrites a config file and syncs it to disk. The file is++// written in place to keep the inode of a mounted configuration file.++func WriteConfigFile(path string, data []byte, perm os.FileMode) error {++ configFileMu.Lock()++ defer configFileMu.Unlock()++ f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)++ if err != nil {++ return err++ }++ _, err = f.Write(data)++ if err == nil {++ err = f.Sync()++ }++ if errClose := f.Close(); err == nil {++ err = errClose++ }++ return err++}+diff --git a/internal/config/config_write_test.go b/internal/config/config_write_test.go+new file mode 100644+index 000000000..dba45497b+--- /dev/null++++ b/internal/config/config_write_test.go+@@ -0,0 +1,37 @@++package config++++import (++ "os"++ "path/filepath"++ "testing"++)++++func TestWriteConfigFileKeepsInode(t *testing.T) {++ path := filepath.Join(t.TempDir(), "config.yaml")++ if err := os.WriteFile(path, []byte("port: 8001\n"), 0o640); err != nil {++ t.Fatalf("write config: %v", err)++ }++ before, err := os.Stat(path)++ if err != nil {++ t.Fatalf("stat config: %v", err)++ }++++ if err = WriteConfigFile(path, []byte("port: 8002\n"), 0o600); err != nil {++ t.Fatalf("WriteConfigFile: %v", err)++ }++++ after, err := os.Stat(path)++ if err != nil {++ t.Fatalf("stat config: %v", err)++ }++ if !os.SameFile(before, after) {++ t.Fatal("WriteConfigFile replaced the config file")++ }++ data, err := ReadConfigFile(path)++ if err != nil {++ t.Fatalf("read config: %v", err)++ }++ if string(data) != "port: 8002\n" {++ t.Fatalf("config = %q, want the new content", data)++ }++}+diff --git a/internal/config/config_write_unix_test.go b/internal/config/config_write_unix_test.go+new file mode 100644+index 000000000..4dc438b71+--- /dev/null++++ b/internal/config/config_write_unix_test.go+@@ -0,0 +1,74 @@++//go:build unix++++package config++++import (++ "bytes"++ "io"++ "os"++ "path/filepath"++ "syscall"++ "testing"++)++++// A named pipe parks a read or a write inside the file I/O, so the test can check,++// without timing, that the other side cannot start until it finishes.++func TestConfigFileReadsAndWritesExcludeEachOther(t *testing.T) {++ path := filepath.Join(t.TempDir(), "config.yaml")++ if err := syscall.Mkfifo(path, 0o600); err != nil {++ t.Fatalf("mkfifo: %v", err)++ }++++ read := make(chan error, 1)++ go func() {++ _, err := ReadConfigFile(path)++ read <- err++ }()++ // Opening the write end returns once the reader has opened the pipe, and the++ // reader then waits for data inside ReadConfigFile.++ pipe, err := os.OpenFile(path, os.O_WRONLY, 0)++ if err != nil {++ t.Fatalf("open pipe for writing: %v", err)++ }++ if configFileMu.TryLock() {++ configFileMu.Unlock()++ t.Error("a write could start while a read was in progress")++ }++ if _, err = pipe.Write([]byte("port: 8001\n")); err != nil {++ t.Fatalf("write pipe: %v", err)++ }++ if err = pipe.Close(); err != nil {++ t.Fatalf("close pipe: %v", err)++ }++ if err = <-read; err != nil {++ t.Fatalf("ReadConfigFile: %v", err)++ }++++ written := make(chan error, 1)++ // More than a pipe buffer holds, so the writer stays inside WriteConfigFile++ // until the test drains the pipe.++ data := bytes.Repeat([]byte("# padding\n"), 1<<17)++ go func() {++ written <- WriteConfigFile(path, data, 0o600)++ }()++ pipe, err = os.Open(path)++ if err != nil {++ t.Fatalf("open pipe for reading: %v", err)++ }++ if configFileMu.TryRLock() {++ configFileMu.RUnlock()++ t.Error("a read could start while a write was in progress")++ }++ got, err := io.ReadAll(pipe)++ if err != nil {++ t.Fatalf("read pipe: %v", err)++ }++ if err = pipe.Close(); err != nil {++ t.Fatalf("close pipe: %v", err)++ }++ if !bytes.Equal(got, data) {++ t.Fatalf("pipe carried %d bytes, want %d", len(got), len(data))++ }++ // A pipe cannot be synced, so the write reports an error after writing.++ <-written++}+diff --git a/internal/config/config_yaml.go b/internal/config/config_yaml.go+index a915eb074..f5544864a 100644+--- a/internal/config/config_yaml.go++++ b/internal/config/config_yaml.go+@@ -3,7 +3,6 @@ package config+ import (+ "bytes"+ "fmt"+- "os"+ "strings"++ "gopkg.in/yaml.v3"+@@ -17,7 +16,7 @@ func SaveConfigPreserveComments(configFile string, cfg *Config, migrateV8 ...boo+ persistCfg := cfg+ migrating := len(migrateV8) > 0 && migrateV8[0]+ // Load original YAML as a node tree to preserve comments and ordering.+- data, err := os.ReadFile(configFile)++ data, err := ReadConfigFile(configFile)+ if err != nil {+ return err+ }+@@ -113,7 +112,7 @@ func SaveConfigPreserveComments(configFile string, cfg *Config, migrateV8 ...boo+ return fmt.Errorf("decode migrated config: %w", err)+ }+ }+- if err = os.WriteFile(configFile, data, 0600); err != nil {++ if err = WriteConfigFile(configFile, data, 0o600); err != nil {+ return err+ }+ if migrated != nil {+@@ -126,7 +125,7 @@ func SaveConfigPreserveComments(configFile string, cfg *Config, migrateV8 ...boo+ // SaveConfigPreserveCommentsUpdateNestedScalar updates a nested scalar key path like ["a","b"]+ // while preserving comments and positions.+ func SaveConfigPreserveCommentsUpdateNestedScalar(configFile string, path []string, value string) error {+- data, err := os.ReadFile(configFile)++ data, err := ReadConfigFile(configFile)+ if err != nil {+ return err+ }+@@ -134,7 +133,7 @@ func SaveConfigPreserveCommentsUpdateNestedScalar(configFile string, path []stri+ if err != nil {+ return err+ }+- return os.WriteFile(configFile, data, 0600)++ return WriteConfigFile(configFile, data, 0o600)+ }++ // updateNestedScalarYAML returns data with the nested scalar key path like ["a","b"] set to+diff --git a/internal/config/export_test.go b/internal/config/export_test.go+new file mode 100644+index 000000000..578b99224+--- /dev/null++++ b/internal/config/export_test.go+@@ -0,0 +1,4 @@++package config++++// ConfigFileMu exposes the config file lock to call-site tests in this directory.++var ConfigFileMu = &configFileMu+diff --git a/internal/watcher/config_reload.go b/internal/watcher/config_reload.go+index b9d5aabbf..0a8e04a4a 100644+--- a/internal/watcher/config_reload.go++++ b/internal/watcher/config_reload.go+@@ -5,7 +5,6 @@ package watcher+ import (+ "crypto/sha256"+ "encoding/hex"+- "os"+ "reflect"+ "time"++@@ -56,7 +55,7 @@ func (w *Watcher) reloadConfigIfChanged() {+ w.configApplyMu.Lock()+ defer w.configApplyMu.Unlock()++- data, err := os.ReadFile(w.configPath)++ data, err := config.ReadConfigFile(w.configPath)+ if err != nil {+ log.Errorf("failed to read config file for hash check: %v", err)+ return+--+2.50.1 (Apple Git-155)+diff --git a/patches/model-hub-cpa-v8.0.23/fallback-transport-h2-ping-health-check.patch b/patches/model-hub-cpa-v8.0.30/fallback-transport-h2-ping-health-check.patchsimilarity index 86%rename from patches/model-hub-cpa-v8.0.23/fallback-transport-h2-ping-health-check.patchrename to patches/model-hub-cpa-v8.0.30/fallback-transport-h2-ping-health-check.patchindex ee4a9e9f2..4f2f0a2c5 100644--- a/patches/model-hub-cpa-v8.0.23/fallback-transport-h2-ping-health-check.patch+++ b/patches/model-hub-cpa-v8.0.30/fallback-transport-h2-ping-health-check.patch@@ -1,8 +1,8 @@diff --git a/internal/runtime/executor/helps/proxy_helpers.go b/internal/runtime/executor/helps/proxy_helpers.go-index 0c5f6c95..4c15b243 100644+index d98f7d49..aaff4472 100644--- a/internal/runtime/executor/helps/proxy_helpers.go+++ b/internal/runtime/executor/helps/proxy_helpers.go-@@ -153,5 +153,8 @@ func buildProxyTransport(proxyURL string) *http.Transport {+@@ -156,5 +156,8 @@ func buildProxyTransport(proxyURL string) *http.Transport {log.Errorf("%v", errBuild)return nil}@@ -14,16 +14,21 @@ index 0c5f6c95..4c15b243 100644}diff --git a/internal/runtime/executor/helps/upstream_transport.go b/internal/runtime/executor/helps/upstream_transport.gonew file mode 100644-index 00000000..3e2bae5b+index 00000000..d8f22b21--- /dev/null+++ b/internal/runtime/executor/helps/upstream_transport.go-@@ -0,0 +1,57 @@+@@ -0,0 +1,71 @@+package helps++import (++ "context"+ "net/http"+ "sync"+ "time"++++ "github.com/router-for-me/CLIProxyAPI/v8/internal/config"++ cliproxyauth "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/auth"++ "github.com/router-for-me/CLIProxyAPI/v8/sdk/httptransport"+)++// upstreamHTTP2SendPingTimeout and upstreamHTTP2PingTimeout turn on the HTTP/2 health check for@@ -62,6 +67,15 @@ index 00000000..3e2bae5b+ return client+}+++// NewUpstreamHTTPClient is NewProxyAwareHTTPClient with the shared upstream transport as its++// fallback. A request-scoped decorator (sdk/httptransport) is applied once, after that transport is++// chosen, so it wraps the health-checked transport instead of http.DefaultTransport; the Antigravity++// executor decorates its own pool the same way.++func NewUpstreamHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, timeout time.Duration) *http.Client {++ client := WithUpstreamFallbackTransport(NewProxyAwareHTTPClient(httptransport.WithoutDecorator(ctx), cfg, auth, timeout))++ return httptransport.Decorate(ctx, client)++}+++// withUpstreamHTTP2HealthCheck sets the HTTP/2 health check on transport and returns it, keeping any+// other HTTP/2 settings the transport already has.+func withUpstreamHTTP2HealthCheck(transport *http.Transport, sendPingTimeout, pingTimeout time.Duration) *http.Transport {@@ -77,10 +91,10 @@ index 00000000..3e2bae5b+}diff --git a/internal/runtime/executor/helps/upstream_transport_test.go b/internal/runtime/executor/helps/upstream_transport_test.gonew file mode 100644-index 00000000..be953d58+index 00000000..a539360d--- /dev/null+++ b/internal/runtime/executor/helps/upstream_transport_test.go-@@ -0,0 +1,220 @@+@@ -0,0 +1,233 @@+package helps++import (@@ -98,6 +112,7 @@ index 00000000..be953d58+ "time"++ "github.com/router-for-me/CLIProxyAPI/v8/internal/config"++ "github.com/router-for-me/CLIProxyAPI/v8/sdk/httptransport"+ "github.com/router-for-me/CLIProxyAPI/v8/sdk/proxyutil"+)+@@ -227,6 +242,18 @@ index 00000000..be953d58+ if got := WithUpstreamFallbackTransport(NewProxyAwareHTTPClient(context.Background(), direct, nil, 0)).Transport; got != http.RoundTripper(shared) {+ t.Fatalf("WithUpstreamFallbackTransport transport = %T, want the shared upstream transport", got)+ }++ if got := NewUpstreamHTTPClient(context.Background(), direct, nil, 0).Transport; got != http.RoundTripper(shared) {++ t.Fatalf("NewUpstreamHTTPClient transport = %T, want the shared upstream transport", got)++ }++ // A request-scoped decorator wraps the health-checked transport, not http.DefaultTransport.++ var decorated http.RoundTripper++ decoratorCtx := httptransport.WithDecorator(context.Background(), func(next http.RoundTripper) http.RoundTripper {++ decorated = next++ return roundTripperFunc(func(*http.Request) (*http.Response, error) { return nil, errors.New("unused") })++ })++ if client := NewUpstreamHTTPClient(decoratorCtx, direct, nil, 0); decorated != http.RoundTripper(shared) || client.Transport == http.RoundTripper(shared) {++ t.Fatalf("decorator wrapped %T, want the shared upstream transport", decorated)++ }++ proxied := &config.Config{}+ proxied.ProxyURL = "http://127.0.0.1:9"@@ -302,10 +329,10 @@ index 00000000..be953d58+ }+}diff --git a/internal/runtime/executor/helps/utls_client.go b/internal/runtime/executor/helps/utls_client.go-index f832748b..c3417e78 100644+index f35432d3..1782b6d9 100644--- a/internal/runtime/executor/helps/utls_client.go+++ b/internal/runtime/executor/helps/utls_client.go-@@ -405,7 +405,7 @@ func NewUtlsHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyau+@@ -419,7 +419,7 @@ func NewUtlsHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauvar chromeRT http.RoundTripper = newUtlsRoundTripper(proxyURL)var anthropicRT http.RoundTripper = cachedClaudeCodeRoundTripper(proxyURL)@@ -315,7 +342,7 @@ index f832748b..c3417e78 100644if transport := buildProxyTransport(proxyURL); transport != nil {standardTransport = transportdiff --git a/internal/runtime/executor/openai_compat_executor.go b/internal/runtime/executor/openai_compat_executor.go-index b63f1258..47aaa55e 100644+index b63f1258..09fe923c 100644--- a/internal/runtime/executor/openai_compat_executor.go+++ b/internal/runtime/executor/openai_compat_executor.go@@ -81,7 +81,7 @@ func (e *OpenAICompatExecutor) HttpRequest(ctx context.Context, auth *cliproxyau@@ -323,7 +350,7 @@ index b63f1258..47aaa55e 100644return nil, err}- httpClient := helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0)-+ httpClient := helps.WithUpstreamFallbackTransport(helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0))++ httpClient := helps.NewUpstreamHTTPClient(ctx, e.cfg, auth, 0)return httpClient.Do(httpReq)}@@ -332,7 +359,7 @@ index b63f1258..47aaa55e 100644})- httpClient := helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0)-+ httpClient := helps.WithUpstreamFallbackTransport(helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0))++ httpClient := helps.NewUpstreamHTTPClient(ctx, e.cfg, auth, 0)httpClient = reporter.TrackHTTPClient(httpClient)httpResp, err := httpClient.Do(httpReq)if err != nil {@@ -341,7 +368,7 @@ index b63f1258..47aaa55e 100644})- httpClient := helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0)-+ httpClient := helps.WithUpstreamFallbackTransport(helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0))++ httpClient := helps.NewUpstreamHTTPClient(ctx, e.cfg, auth, 0)httpClient = reporter.TrackHTTPClient(httpClient)httpResp, err := httpClient.Do(httpReq)if err != nil {@@ -350,7 +377,7 @@ index b63f1258..47aaa55e 100644})- httpClient := helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0)-+ httpClient := helps.WithUpstreamFallbackTransport(helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0))++ httpClient := helps.NewUpstreamHTTPClient(ctx, e.cfg, auth, 0)// Early role/empty frames are only first-packet fallbacks, not effective tokens.httpClient = reporter.TrackHTTPClientRoundTripOnly(httpClient)httpResp, err := httpClient.Do(httpReq)@@ -359,7 +386,7 @@ index b63f1258..47aaa55e 100644})- httpClient := helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0)-+ httpClient := helps.WithUpstreamFallbackTransport(helps.NewProxyAwareHTTPClient(ctx, e.cfg, auth, 0))++ httpClient := helps.NewUpstreamHTTPClient(ctx, e.cfg, auth, 0)httpClient = reporter.TrackHTTPClient(httpClient)httpResp, err := httpClient.Do(httpReq)if err != nil {diff --git a/patches/model-hub-cpa-v8.0.30/gemini-schema-content-keywords.patch b/patches/model-hub-cpa-v8.0.30/gemini-schema-content-keywords.patchnew file mode 100644index 000000000..a145af64c--- /dev/null+++ b/patches/model-hub-cpa-v8.0.30/gemini-schema-content-keywords.patch@@ -0,0 +1,124 @@+From a43026d751969f0d98b196b3296ff33f2d8df944 Mon Sep 17 00:00:00 2001+From: Luis Pater <[email protected]>+Date: Sat, 17 Oct 2026 14:18:55 +0800+Subject: [PATCH] feat(gemini): strip unsupported contentMediaType and+ contentEncoding JSON schema keywords++- Add `contentMediaType` and `contentEncoding` to the list of schema metadata fields unsupported by Gemini.+- Ensure these keywords are stripped during schema cleaning while preserving valid schema structures and legitimate property names.++Closes: #6699+---+ internal/util/gemini_schema.go | 2 +-+ internal/util/gemini_schema_test.go | 85 ++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-)++diff --git a/internal/util/gemini_schema.go b/internal/util/gemini_schema.go+index 32f1addf..acfe332c 100644+--- a/internal/util/gemini_schema.go++++ b/internal/util/gemini_schema.go+@@ -1512,7 +1512,7 @@ func removeUnsupportedKeywords(jsonStr string, options jsonSchemaCleanOptions) s+ "dependentRequired", "dependentSchemas", "dependencies",+ "if", "then", "else",+ "$comment", "enumDescriptions", "enumTitles", "prefill", "deprecated", "encrypted", "discriminator", // Schema metadata fields unsupported by Gemini+- "additionalItems", "unevaluatedProperties", "unevaluatedItems", "contentSchema",++ "additionalItems", "unevaluatedProperties", "unevaluatedItems", "contentSchema", "contentMediaType", "contentEncoding",+ )+ if options.antigravitySemantics {+ keywords = append(keywords, "not")+diff --git a/internal/util/gemini_schema_test.go b/internal/util/gemini_schema_test.go+index 79f5652d..2dd8721c 100644+--- a/internal/util/gemini_schema_test.go++++ b/internal/util/gemini_schema_test.go+@@ -3708,3 +3708,88 @@ func TestCleanJSONSchema_RemovesDiscriminatorKeyword_Issue6639(t *testing.T) {+ })+ }+ }++++// TestCleanJSONSchema_RemovesContentMediaTypeKeyword_Issue6699 covers Issue #6699:++// JSON Schema Content Vocabulary annotations ("contentMediaType" and "contentEncoding")++// inside nested anyOf/oneOf branches, on property schemas, or at the schema root are++// rejected by the Gemini/Antigravity backend with 400 INVALID_ARGUMENT++// ("Unknown name \"contentMediaType\" ... Cannot find field") and must be stripped++// while preserving the anyOf branches and any legitimate property named++// "contentMediaType" or "contentEncoding".++func TestCleanJSONSchema_RemovesContentMediaTypeKeyword_Issue6699(t *testing.T) {++ input := `{++ "type": "object",++ "contentMediaType": "application/json",++ "contentEncoding": "utf-8",++ "properties": {++ "value": {++ "anyOf": [++ { "type": "object", "properties": {} },++ { "type": "string", "contentMediaType": "application/json", "contentEncoding": "base64" }++ ]++ },++ "directPayload": {++ "type": "string",++ "contentMediaType": "application/json",++ "contentEncoding": "base64"++ },++ "contentMediaType": {++ "type": "string",++ "contentMediaType": "text/plain",++ "description": "Legitimate property named contentMediaType"++ },++ "contentEncoding": {++ "type": "string",++ "contentEncoding": "base64",++ "description": "Legitimate property named contentEncoding"++ }++ }++ }`++++ cleaners := map[string]func(string) string{++ "Antigravity": CleanJSONSchemaForAntigravity,++ "AntigravityTool": func(s string) string { return CleanJSONSchemaForAntigravityTool(s, false) },++ "AntigravityClaudeTool": func(s string) string { return CleanJSONSchemaForAntigravityClaudeTool(s, false) },++ "AntigravityResponse": CleanJSONSchemaForAntigravityResponse,++ "Gemini": CleanJSONSchemaForGemini,++ "GeminiJSONSchema": CleanJSONSchemaForGeminiJSONSchema,++ }++++ for name, clean := range cleaners {++ t.Run(name, func(t *testing.T) {++ got := clean(input)++ parsed := gjson.Parse(got)++++ for _, forbiddenPath := range []string{++ "contentMediaType",++ "contentEncoding",++ "properties.value.anyOf.1.contentMediaType",++ "properties.value.anyOf.1.contentEncoding",++ "properties.directPayload.contentMediaType",++ "properties.directPayload.contentEncoding",++ "properties.contentMediaType.contentMediaType",++ "properties.contentEncoding.contentEncoding",++ } {++ if parsed.Get(forbiddenPath).Exists() {++ t.Errorf("[%s] %s was not removed: %s", name, forbiddenPath, got)++ }++ }++++ if name != "AntigravityClaudeTool" {++ if gotBranches := len(parsed.Get("properties.value.anyOf").Array()); gotBranches != 2 {++ t.Errorf("[%s] properties.value.anyOf branch count = %d, want 2: %s", name, gotBranches, got)++ }++ if gotType := parsed.Get("properties.value.anyOf.1.type").String(); gotType != "string" {++ t.Errorf("[%s] properties.value.anyOf.1.type = %q, want \"string\": %s", name, gotType, got)++ }++ }++++ if !parsed.Get("properties.contentMediaType").Exists() {++ t.Errorf("[%s] legitimate property \"contentMediaType\" was removed: %s", name, got)++ }++ if !parsed.Get("properties.contentEncoding").Exists() {++ t.Errorf("[%s] legitimate property \"contentEncoding\" was removed: %s", name, got)++ }++ })++ }++}+--+2.50.1 (Apple Git-155)+diff --git a/patches/model-hub-cpa-v8.0.23/oauth-callback-forwarder-loopback.patch b/patches/model-hub-cpa-v8.0.30/oauth-callback-forwarder-loopback.patchsimilarity index 97%rename from patches/model-hub-cpa-v8.0.23/oauth-callback-forwarder-loopback.patchrename to patches/model-hub-cpa-v8.0.30/oauth-callback-forwarder-loopback.patchindex 9a05ce3f0..da2db1f3c 100644--- a/patches/model-hub-cpa-v8.0.23/oauth-callback-forwarder-loopback.patch+++ b/patches/model-hub-cpa-v8.0.30/oauth-callback-forwarder-loopback.patch@@ -1,5 +1,5 @@diff --git a/internal/api/handlers/management/auth_files_oauth_callback.go b/internal/api/handlers/management/auth_files_oauth_callback.go-index f33f82e..b1cefdf 100644+index f33f82e1..b1cefdfa 100644--- a/internal/api/handlers/management/auth_files_oauth_callback.go+++ b/internal/api/handlers/management/auth_files_oauth_callback.go@@ -50,7 +50,10 @@ func startCallbackForwarder(port int, provider, targetBase string) (*callbackFor@@ -15,7 +15,7 @@ index f33f82e..b1cefdf 100644if err != nil {return nil, fmt.Errorf("failed to listen on %s: %w", addr, err)diff --git a/internal/api/handlers/management/auth_files_provider_oauth.go b/internal/api/handlers/management/auth_files_provider_oauth.go-index 48fc4ef..cac8253 100644+index 48fc4ef4..cac82532 100644--- a/internal/api/handlers/management/auth_files_provider_oauth.go+++ b/internal/api/handlers/management/auth_files_provider_oauth.go@@ -80,9 +80,9 @@ func (h *Handler) RequestAnthropicToken(c *gin.Context) {diff --git a/patches/model-hub-cpa-v8.0.23/openai-compat-native-token-field.patch b/patches/model-hub-cpa-v8.0.30/openai-compat-native-token-field.patchsimilarity index 100%rename from patches/model-hub-cpa-v8.0.23/openai-compat-native-token-field.patchrename to patches/model-hub-cpa-v8.0.30/openai-compat-native-token-field.patchdiff --git a/tests/e2e/test_model_hub_engine_hosted_passthrough.py b/tests/e2e/test_model_hub_engine_hosted_passthrough.pyindex b99ebbce6..738dd5ec3 100644--- a/tests/e2e/test_model_hub_engine_hosted_passthrough.py+++ b/tests/e2e/test_model_hub_engine_hosted_passthrough.py@@ -475,15 +475,12 @@ async def test_responses_xai_history_replays_in_real_shapes(tmp_path, monkeypatcassert _events(raw) == _events(reply)- strict=True, reason="engine drops/shortens xAI over-64 ids under is-compat; fixed by the id patch in #2780",-)async def test_responses_xai_over_limit_ids_replay_verbatim(tmp_path, monkeypatch) -> None:"""MH-ENGINE-HOSTED-007: xAI's 84-rune tool-call reasoning and call ids reach xAI as it issued them.- Under ``is-compat``, which Avibe renders for xAI, the pinned engine keeps the ``rs_`` reasoning but- drops the ``tco_`` reasoning whole and shortens the ``ctc_`` id to 64 runes. An engine that keeps- them turns this strict expected failure into a failure, so that change must flip the marker.+ Under ``is-compat``, which Avibe renders for xAI, CPA's 64-rune input id limit would drop the+ ``tco_`` reasoning whole and shorten the ``ctc_`` id; the engine's+ ``codex-compat-upstream-item-ids`` patch keeps an upstream's over-limit ids verbatim."""replayed, _raw, _reply = await _replay_xai_turn(tmp_path, monkeypatch)diff --git a/tests/e2e/test_model_hub_routing.py b/tests/e2e/test_model_hub_routing.pyindex 36c800062..8342e3594 100644--- a/tests/e2e/test_model_hub_routing.py+++ b/tests/e2e/test_model_hub_routing.py@@ -971,7 +971,6 @@ def _assert_probe_cooldown_and_next_request_selection(expected_detail: str,expected_reason: str,expected_delay: int,- expected_max_delay: float | None = None,) -> None:first, second = _prepare_probe_chain(app, first_upstream, second_upstream@@ -988,9 +987,8 @@ def _assert_probe_cooldown_and_next_request_selection(assert first_state["status"] == "cooldown"assert first_state["detail_key"] == expected_detailretry_at = datetime.fromisoformat(first_state["retry_at"])- upper = expected_max_delay if expected_max_delay is not None else expected_delayassert before_probe + timedelta(seconds=expected_delay) <= retry_at- assert retry_at <= after_probe + timedelta(seconds=upper)+ assert retry_at <= after_probe + timedelta(seconds=expected_delay)next_probe = _probe(app)next_body = next_probe.json()@@ -1016,6 +1014,8 @@ def test_d3_rate_limit_moves_the_next_api_probe_to_hop_one(gateway credential issued only to a live backend turn."""+ # D-4: the 429's Retry-After: 120 reaches Avibe through the real engine and+ # outlasts the local 60-72 s backoff, so it sets the cooldown.with MockLLMUpstream() as second_upstream:with _engine_app(model_hub_app_factory) as app:_assert_probe_cooldown_and_next_request_selection(@@ -1025,8 +1025,7 @@ def test_d3_rate_limit_moves_the_next_api_probe_to_hop_one(auth_behavior="429",expected_detail="models.source.cooldown.rate_limited",expected_reason="rate_limited",- expected_delay=60,- expected_max_delay=72,+ expected_delay=120,)@@ -1087,11 +1086,6 @@ def test_d5_nonrefreshable_401_marks_the_key_for_repair(assert next_probe.json()["probe"]["source_id"] == second["id"][email protected](strict=True, reason=(- "D-4 gap: the managed engine never forwards an upstream error's headers (its status errors "- "carry none, whatever passthrough-headers says), so Retry-After never reaches Avibe and a "- "5xx cools for the local 30-36 s backoff only (#2666)"-))def test_d6_server_error_preserves_later_retry_after_through_real_engine(model_hub_app_factory,mock_llm_upstream,diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yamlindex 27c491769..1833e0352 100644--- a/tests/scenarios/model_hub/catalog.yaml+++ b/tests/scenarios/model_hub/catalog.yaml@@ -2397,7 +2397,7 @@ scenarios:test: tests/e2e/test_model_hub_routing.py::test_d5_nonrefreshable_401_marks_the_key_for_repair- id: D6name: A server error honors later upstream advice through the real engine- status: xfail+ status: assertkind: failoverlayer: e2e-autotest: tests/e2e/test_model_hub_routing.py::test_d6_server_error_preserves_later_retry_after_through_real_engine@@ -2670,8 +2670,8 @@ scenarios:layer: e2etest: tests/e2e/test_model_hub_engine_hosted_passthrough.py::test_responses_xai_history_replays_in_real_shapes- id: MH-ENGINE-HOSTED-007- name: The real CPA Responses path replays xAI's 84-rune tool-call reasoning with its id and ciphertext, and the 84-rune call id, as xAI issued them (expected to fail until the engine keeps over-limit upstream ids under is-compat)- status: xfail+ name: The real CPA Responses path replays xAI's 84-rune tool-call reasoning with its id and ciphertext, and the 84-rune call id, as xAI issued them+ status: coveredkind: compatibilitylayer: e2etest: tests/e2e/test_model_hub_engine_hosted_passthrough.py::test_responses_xai_over_limit_ids_replay_verbatim@@ -2683,6 +2683,4 @@ next_priority:- B5- B8- B9- - D6- G3- - MH-ENGINE-HOSTED-007diff --git a/tests/test_model_hub_runtime.py b/tests/test_model_hub_runtime.pyindex d804a5bbf..5fd0ddf5f 100644--- a/tests/test_model_hub_runtime.py+++ b/tests/test_model_hub_runtime.py@@ -907,44 +907,44 @@ def test_packaged_manifest_matches_frozen_runtime_dependency_values(assert manifest == {"name": "cliproxyapi","resolution": "resolved",- "version": "v8.0.23",- "source_sha": "d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5",+ "version": "v8.0.30",+ "source_sha": "5be2cdab0869cbaa3d401891f740aebf7e15aa99","assets": [{"platform": "darwin-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_darwin_aarch64.tar.gz",- "size_bytes": 40525867,- "sha256": "094d9fdf61d2de655bd9206190b3688fc0c22d6ef2cda09716c9b004bc15b80d",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_darwin_aarch64.tar.gz",+ "size_bytes": 40998093,+ "sha256": "5350a46bee04f8bde5346f70cd8d5d71cc2bc2e73399f508ee197f9280088aba",},{"platform": "darwin-x64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_darwin_amd64.tar.gz",- "size_bytes": 42988519,- "sha256": "4d4f5c754219cf4173254e98fc8d573fea11cb425b883daeae56d57f0a6e89e4",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_darwin_amd64.tar.gz",+ "size_bytes": 43496850,+ "sha256": "229583a38aeef6f1228aa5ebeaf77f0d9e0cb818163d426c930787fde02fce16",},{"platform": "linux-amd64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_linux_amd64.tar.gz",- "size_bytes": 40946469,- "sha256": "3733df8472813f74530ce7a739a3ebcd091db9c16de815e016ed0de537a2e1c6",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_linux_amd64.tar.gz",+ "size_bytes": 41420943,+ "sha256": "dd7e0c8e1f0464cb4f933b4132005a0390d1c9f3ffcdeaf10dfd73bac5dcd0ae",},{"platform": "linux-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_linux_aarch64.tar.gz",- "size_bytes": 37556916,- "sha256": "0ee21fcb4d7316ebce4a46739df75f83bcd8369b3757e5b539d0080477d396a5",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_linux_aarch64.tar.gz",+ "size_bytes": 38014778,+ "sha256": "e7d2d3ef548769195e8843069435e49dc82cf4ae9777d9f0af8a4dc40057e843",},{"platform": "windows-amd64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_windows_amd64.tar.gz",- "size_bytes": 41463417,- "sha256": "543497b874e9370c85967fd3b5688dbf582cd454b074993af11a90ce41c9c501",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_windows_amd64.tar.gz",+ "size_bytes": 41954382,+ "sha256": "c7ac88680a02476660abf00ee56e07768cb9a859c12c7558cd77fcf9d4919127",},{"platform": "windows-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_windows_aarch64.tar.gz",- "size_bytes": 37817697,- "sha256": "cde450406bc9cbe8a19cb71e75ee959e387abee0173b97700481e0cb289018fc",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_windows_aarch64.tar.gz",+ "size_bytes": 38272453,+ "sha256": "71eba861e9385cdb44bfc7aae5075a49209e3e4dfbc0c7e06255aff1b5d57c64",},],}@@ -1447,45 +1447,45 @@ def test_installing_projection_matches_live_owner_or_resumable_claim("darwin-arm64",False,"darwin-arm64",- 40525867,- "094d9fdf61d2de655bd9206190b3688fc0c22d6ef2cda09716c9b004bc15b80d",- "8a58f862e5a881c58f05aa8bd379418ebca442d0ec1445002c8248d4cf8460a9",+ 40998093,+ "5350a46bee04f8bde5346f70cd8d5d71cc2bc2e73399f508ee197f9280088aba",+ "c10089fd11f03ef8b01dd489da8e2ed6ce0dcc01ef33f795416d489dd0bcdd64","cli-proxy-api",),("darwin-x64",False,"darwin-x64",- 42988519,- "4d4f5c754219cf4173254e98fc8d573fea11cb425b883daeae56d57f0a6e89e4",- "86870b2e96319b421949d1933f10010a8a7c11c1ba787d9d1bcf08a5e00e0f77",+ 43496850,+ "229583a38aeef6f1228aa5ebeaf77f0d9e0cb818163d426c930787fde02fce16",+ "8c16904ea866cd6ee35eec827d4f691c5230c496147725b5e4a19c0e1115f295","cli-proxy-api",),("linux-x64",False,"linux-amd64",- 40946469,- "3733df8472813f74530ce7a739a3ebcd091db9c16de815e016ed0de537a2e1c6",- "2cbf349b79a3026cce551c65df103cf67a0878ad1c195e5087f2c4fab189cc77",+ 41420943,+ "dd7e0c8e1f0464cb4f933b4132005a0390d1c9f3ffcdeaf10dfd73bac5dcd0ae",+ "ca55c3d255b5391d823990ea39dceec596c91c6be5ee80856e174e397e46566b","cli-proxy-api",),("linux-arm64",False,"linux-arm64",- 37556916,- "0ee21fcb4d7316ebce4a46739df75f83bcd8369b3757e5b539d0080477d396a5",- "9c968a791a9fda4f48193fafaf5ae9dc87680225c9697e2a06ba0a94ec42e2e9",+ 38014778,+ "e7d2d3ef548769195e8843069435e49dc82cf4ae9777d9f0af8a4dc40057e843",+ "54f85bc24a68cced977a422c01f9726d4b7c916bc24d2c3465258c1fa1ecce0b","cli-proxy-api",),("win32-x64",False,"windows-amd64",- 41463417,- "543497b874e9370c85967fd3b5688dbf582cd454b074993af11a90ce41c9c501",- "baea8d2f7a0ae9589552f5c98033d47b1710010bfc8ed16a039c237b7292db7e",+ 41954382,+ "c7ac88680a02476660abf00ee56e07768cb9a859c12c7558cd77fcf9d4919127",+ "cb34b4d627efa056bb5b44a1301aad855d2006e350a2b7ed460900ebbcc4428c","cli-proxy-api.exe",),# x64 Python on Windows on Arm still gets the native engine.@@ -1493,18 +1493,18 @@ def test_installing_projection_matches_live_owner_or_resumable_claim("win32-x64",True,"windows-arm64",- 37817697,- "cde450406bc9cbe8a19cb71e75ee959e387abee0173b97700481e0cb289018fc",- "ce589b8ff37d38c1da86847977692c2a21a342ac8391d749c2cf9adb9444844e",+ 38272453,+ "71eba861e9385cdb44bfc7aae5075a49209e3e4dfbc0c7e06255aff1b5d57c64",+ "854351aa7942333c08f52e08139055570dcd7582f732dd8b83ba90a886e5c092","cli-proxy-api.exe",),("win32-arm64",True,"windows-arm64",- 37817697,- "cde450406bc9cbe8a19cb71e75ee959e387abee0173b97700481e0cb289018fc",- "ce589b8ff37d38c1da86847977692c2a21a342ac8391d749c2cf9adb9444844e",+ 38272453,+ "71eba861e9385cdb44bfc7aae5075a49209e3e4dfbc0c7e06255aff1b5d57c64",+ "854351aa7942333c08f52e08139055570dcd7582f732dd8b83ba90a886e5c092","cli-proxy-api.exe",),],diff --git a/vibe/model_hub_runtime/cliproxyapi_manifest.json b/vibe/model_hub_runtime/cliproxyapi_manifest.jsonindex 42f51486e..4065cc8d6 100644--- a/vibe/model_hub_runtime/cliproxyapi_manifest.json+++ b/vibe/model_hub_runtime/cliproxyapi_manifest.json@@ -1,60 +1,60 @@{"schema_version": 1,"name": "cliproxyapi",- "version": "v8.0.23",+ "version": "v8.0.30","source": "router-for-me/CLIProxyAPI",- "source_url": "https://github.com/router-for-me/CLIProxyAPI/tree/d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5",- "source_sha": "d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5",- "release_tag": "v8.0.23",- "asset_release_tag": "model-hub-engine-v8.0.23-3",+ "source_url": "https://github.com/router-for-me/CLIProxyAPI/tree/5be2cdab0869cbaa3d401891f740aebf7e15aa99",+ "source_sha": "5be2cdab0869cbaa3d401891f740aebf7e15aa99",+ "release_tag": "v8.0.30",+ "asset_release_tag": "model-hub-engine-v8.0.30-1","license": "MIT","assets": [{"platform": "darwin-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_darwin_aarch64.tar.gz",- "size_bytes": 40525867,- "sha256": "094d9fdf61d2de655bd9206190b3688fc0c22d6ef2cda09716c9b004bc15b80d",- "binary_sha256": "8a58f862e5a881c58f05aa8bd379418ebca442d0ec1445002c8248d4cf8460a9",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_darwin_aarch64.tar.gz",+ "size_bytes": 40998093,+ "sha256": "5350a46bee04f8bde5346f70cd8d5d71cc2bc2e73399f508ee197f9280088aba",+ "binary_sha256": "c10089fd11f03ef8b01dd489da8e2ed6ce0dcc01ef33f795416d489dd0bcdd64","bin_path": "cli-proxy-api"},{"platform": "darwin-x64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_darwin_amd64.tar.gz",- "size_bytes": 42988519,- "sha256": "4d4f5c754219cf4173254e98fc8d573fea11cb425b883daeae56d57f0a6e89e4",- "binary_sha256": "86870b2e96319b421949d1933f10010a8a7c11c1ba787d9d1bcf08a5e00e0f77",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_darwin_amd64.tar.gz",+ "size_bytes": 43496850,+ "sha256": "229583a38aeef6f1228aa5ebeaf77f0d9e0cb818163d426c930787fde02fce16",+ "binary_sha256": "8c16904ea866cd6ee35eec827d4f691c5230c496147725b5e4a19c0e1115f295","bin_path": "cli-proxy-api"},{"platform": "linux-amd64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_linux_amd64.tar.gz",- "size_bytes": 40946469,- "sha256": "3733df8472813f74530ce7a739a3ebcd091db9c16de815e016ed0de537a2e1c6",- "binary_sha256": "2cbf349b79a3026cce551c65df103cf67a0878ad1c195e5087f2c4fab189cc77",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_linux_amd64.tar.gz",+ "size_bytes": 41420943,+ "sha256": "dd7e0c8e1f0464cb4f933b4132005a0390d1c9f3ffcdeaf10dfd73bac5dcd0ae",+ "binary_sha256": "ca55c3d255b5391d823990ea39dceec596c91c6be5ee80856e174e397e46566b","bin_path": "cli-proxy-api"},{"platform": "linux-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_linux_aarch64.tar.gz",- "size_bytes": 37556916,- "sha256": "0ee21fcb4d7316ebce4a46739df75f83bcd8369b3757e5b539d0080477d396a5",- "binary_sha256": "9c968a791a9fda4f48193fafaf5ae9dc87680225c9697e2a06ba0a94ec42e2e9",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_linux_aarch64.tar.gz",+ "size_bytes": 38014778,+ "sha256": "e7d2d3ef548769195e8843069435e49dc82cf4ae9777d9f0af8a4dc40057e843",+ "binary_sha256": "54f85bc24a68cced977a422c01f9726d4b7c916bc24d2c3465258c1fa1ecce0b","bin_path": "cli-proxy-api"},{"platform": "windows-amd64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_windows_amd64.tar.gz",- "size_bytes": 41463417,- "sha256": "543497b874e9370c85967fd3b5688dbf582cd454b074993af11a90ce41c9c501",- "binary_sha256": "baea8d2f7a0ae9589552f5c98033d47b1710010bfc8ed16a039c237b7292db7e",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_windows_amd64.tar.gz",+ "size_bytes": 41954382,+ "sha256": "c7ac88680a02476660abf00ee56e07768cb9a859c12c7558cd77fcf9d4919127",+ "binary_sha256": "cb34b4d627efa056bb5b44a1301aad855d2006e350a2b7ed460900ebbcc4428c","bin_path": "cli-proxy-api.exe"},{"platform": "windows-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-3/CLIProxyAPI_8.0.23_windows_aarch64.tar.gz",- "size_bytes": 37817697,- "sha256": "cde450406bc9cbe8a19cb71e75ee959e387abee0173b97700481e0cb289018fc",- "binary_sha256": "ce589b8ff37d38c1da86847977692c2a21a342ac8391d749c2cf9adb9444844e",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.30-1/CLIProxyAPI_8.0.30_windows_aarch64.tar.gz",+ "size_bytes": 38272453,+ "sha256": "71eba861e9385cdb44bfc7aae5075a49209e3e4dfbc0c7e06255aff1b5d57c64",+ "binary_sha256": "854351aa7942333c08f52e08139055570dcd7582f732dd8b83ba90a886e5c092","bin_path": "cli-proxy-api.exe"}],@@ -66,28 +66,40 @@"buildvcs": false,"patches": [{- "path": "patches/model-hub-cpa-v8.0.23/openai-compat-native-token-field.patch",+ "path": "patches/model-hub-cpa-v8.0.30/openai-compat-native-token-field.patch","sha256": "15494e9100baad5a0f3c517ce846e59fab0152d667807df4b09c7dc17b3b033f"},{- "path": "patches/model-hub-cpa-v8.0.23/oauth-callback-forwarder-loopback.patch",- "sha256": "bafde5939b84a440908727e098dff29270742f9b3ab425bb9a5e1223a02e770f"+ "path": "patches/model-hub-cpa-v8.0.30/oauth-callback-forwarder-loopback.patch",+ "sha256": "3a7d7f0c99cb0260a80723dc0aeaa86eb750fe89484f264fc0a8cf403b1a79d1"},{- "path": "patches/model-hub-cpa-v8.0.23/antigravity-static-catalog-until-probe.patch",- "sha256": "d6e0c77a0271f5671ba8090e0f14d91bb293a50cfa4d5127dd15e87bd0619d19"+ "path": "patches/model-hub-cpa-v8.0.30/antigravity-static-catalog-until-probe.patch",+ "sha256": "34c31c00ecd0e1844c79cf891223d7aeb5e4befb1e438387a7cfbbf37ed4bdef"},{- "path": "patches/model-hub-cpa-v8.0.23/codex-utls-h2-ping-health-check.patch",- "sha256": "eca61db9f3e29dadb714dc8f7a2c22bc0104216459c37356d59d12ca048c6b74"+ "path": "patches/model-hub-cpa-v8.0.30/codex-utls-h2-ping-health-check.patch",+ "sha256": "af49da073bdd31e381e1b3f2a90f3cab9815858c8c7c50dbd74344103a89464d"},{- "path": "patches/model-hub-cpa-v8.0.23/fallback-transport-h2-ping-health-check.patch",- "sha256": "fb53083be5ee9e17166c6637e414ce8c8dca5aae68bd1ffdab30c8080fca2094"+ "path": "patches/model-hub-cpa-v8.0.30/fallback-transport-h2-ping-health-check.patch",+ "sha256": "bae8cb5cff3f043b10c950d9ff71c768d1e3e877a21ebb543889bf2f00241e4f"},{- "path": "patches/model-hub-cpa-v8.0.23/codex-sse-per-event-parsing.patch",- "sha256": "4fddc8d556650e57e492b769f63600184b9908f31ef4180329e641c3d80b11eb"+ "path": "patches/model-hub-cpa-v8.0.30/codex-compat-upstream-item-ids.patch",+ "sha256": "af8e833aa0f40373b5f078534ecd157bf618ec6e4f71e2bc5a44e03d25b57906"+ },+ {+ "path": "patches/model-hub-cpa-v8.0.30/config-locked-reads.patch",+ "sha256": "8dc04873f0aae6a7d396c9fe60b111ff2a56e6e6ef02ab85094c54045b7c4ed5"+ },+ {+ "path": "patches/model-hub-cpa-v8.0.30/claude-retry-headers-on-error-responses.patch",+ "sha256": "b608c02c576b8437f17b4859dc61d8997599b3444d4c7aca1a31b1bc222ff62d"+ },+ {+ "path": "patches/model-hub-cpa-v8.0.30/gemini-schema-content-keywords.patch",+ "sha256": "57dc0b3eeacb8d74211fbe1bcd27106be5cd3004c389d7bf0719a2300a4849c4"}],"source_date_epoch": 0