Skip to content

fix: take 36 upstream CLIProxyAPI bug fixes - #38

Merged
rune-gh merged 60 commits into
mainfrom
fix/upstream-sync-20261202
Dec 3, 2026
Merged

rune-gh merged 60 commits into
mainfrom
fix/upstream-sync-20261202

Conversation

@rune-gh

@rune-gh rune-gh commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Takes 36 bug fixes from upstream CLIProxyAPI that the fork was missing. I skipped feature work that pulls the fork away from its hub role, and reverted two upstream cancellation changes that conflict with the fork's stream-stall handling (0b791f6d1, c857fe122).

Fixes by area:

  • Auth: terminal and disabled states survive model reconciliation and late success; Claude's expired-refresh-token response is terminal; auth files are written atomically; shutdown waits for in-flight refresh saves; backoff for non-refreshing auths.
  • Codex: Retry-After headers preserved on WS, SSE and overload errors; in-stream billing quota errors fail over; nil auth in WS streams; WS read deadline renewed on heartbeats; zero-byte refresh failures handled.
  • Streams: StreamRewriter buffer corruption fixed; canceled and truncated xAI/OpenAI-compatible streams reported as failures; Gemini interactions goroutine leak on disconnect.
  • Antigravity: OAuth refresh transport and User-Agent aligned; 2.37.0 changelist map; post-refresh credit warm bounded.
  • Other: SOCKS5 transports honor cancellation; signature-cache TOCTOU eviction; xAI idle WS state eviction; safety-policy blocks classified as 400.

Depends on #37 (based on the live hub commits).

Testing: go test ./... passes; deployed to the Windows hub on 2026-12-03.

🤖 Generated with Claude Code

rune-gh and others added 30 commits November 29, 2026 04:35
Configured OpenAI-compatible models without a thinking block all got
low/medium/high. For Mistral that is wrong for most models: GLM-5.3 takes
low/high/max and rejects medium, Magistral and Mistral Small take
none/high, and Codestral, Ministral and Large 2512 reject reasoning_effort
entirely. The hub then rewrote "none" to "low" (rejected upstream or
silently run with reasoning on), passed "medium" through to a 400, and
advertised the wrong levels in the OpenCode catalog.

Models on a mistral.ai base URL now take their levels from a table probed
against the API. Known models without reasoning get no thinking support,
so the hub strips reasoning_effort for them. An explicit thinking block in
the config still wins, and unknown models keep the old default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 566ac95)
…ling

A file-backed OAuth credential with a proxy_url built a fresh transport on
every request, so each request paid a new TCP, SOCKS and TLS handshake to
the proxy. Only credentials defined in config could carry the
connection-pool block that enables reuse.

Auth files now accept the same block as proxy_connection_pool (true, false,
or an object with enabled, idle-conn-timeout and max-idle-conns-per-host).
Both file loaders, the plugin auth path and PATCH auth-files/fields apply it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Anthropic answers not_found_error "model: <id>" for a model the
subscription cannot use. The hub suspends that model on the account for
12 hours, so the first request returned the upstream 404 and every later
one returned 503 auth_unavailable "no auth available". Claude Code shows
that as a temporary server problem and keeps retrying (seen with
claude-mythos-5-2, including during context compaction).

When every enabled candidate is suspended for the model by a 404, the
selector now returns a non-retryable 404 model_not_found that keeps the
upstream error as its cause. If any candidate is blocked for another
reason, the retryable error stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Codex usage_limit_reached rejection cools the account down until the reset
time it carries. When OpenAI renewed both accounts early, the hub kept refusing
every Codex model for up to four more days, because no request reaches a cooling
account and the quota-history poll that read 0% used only fed routing order.

When a Claude or Codex usage poll shows allowance in every window, the recorder
now clears quota cooldowns recorded before that poll, the same local reset as
POST /v0/management/reset-quota. Cooldowns that are not about quota, such as a
model the account rejects, stay in place, and nothing is sent upstream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ta blocks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex limit_reached now blocks recovery even when the parsed windows have
room, a lapsed quota left on a model's own live failure no longer hides it,
and the account-level quota is only judged on its own when no model state
carries it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oll time

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	internal/quotahistory/recorder.go
# Conflicts:
#	config.example.yaml
#	docs/t3code.md
#	internal/api/opencode_catalog.go
#	internal/api/opencode_catalog_test.go
#	internal/api/opencode_upstream.go
Upstream: router-for-me/CLIProxyAPI@7df56074b252

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omic

Upstream: router-for-me/CLIProxyAPI@6d703fdf4818

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…keep recovery scheduled

Upstream: router-for-me/CLIProxyAPI@2d992d12e0d9

Also takes the refresh_outcome_unknown/unauthorized notify condition from upstream f48975b that this hunk builds on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…failures

Upstream: router-for-me/CLIProxyAPI@dee47b32c80f

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…down

Upstream: router-for-me/CLIProxyAPI@32c0c459b0bc

Adapted to the fork's UpdateRefreshedAuth/updateInternal path (no updateInternalWithStatus).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…th version floor

Upstream: router-for-me/CLIProxyAPI@f2b003035, 093c7ef, 2d50f31, 54fc8c4, 99bc000 (version file only), 95392e5

Unmapped Hub releases now pin to the highest verified (version, cl) pair
and the reported version never drops below 2.37.0 / CL 1033035865, so the
User-Agent always carries a matching cl=. The proxy-aware updater
restructure from 4ea1527 is not taken; the fork keeps its updater loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…StreamResult

Upstream: router-for-me/CLIProxyAPI@cdd6ae6d9b10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rune-gh and others added 28 commits December 2, 2026 16:27
Upstream: router-for-me/CLIProxyAPI@cec8a7f39003

Only the sdk/proxyutil part is taken (SOCKS5 dials now honor caller cancellation, which matters for the hub's xAI SOCKS egress). The Antigravity project-discovery client change depends on 0861f9e and is not taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream: router-for-me/CLIProxyAPI@679166b87ed4

Tests adapted to the fork's recordTranscriptTurn(requestPayload, ...) signature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream: router-for-me/CLIProxyAPI@335b69879d4a

Applied by hand: the fork's ExecuteStream differs around this hunk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mRewriter

Upstream: router-for-me/CLIProxyAPI@f35943abc4e0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream: router-for-me/CLIProxyAPI@ff09fcb191c5

Tests adapted: the fork's signature cache is not credential-scoped (upstream 8522538 not taken).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…w turns

Upstream: router-for-me/CLIProxyAPI@46c3467a2 (minimal reimplementation)

Upstream Ping/Pong heartbeats now extend the 5-minute idle read deadline
while a response is still in flight, so long silent reasoning phases are
no longer cut off. Activating a reused session and writing a create or
steer on an idle duplex socket start a fresh idle window; outbound writes
never extend an already in-flight silent upstream, and completed-idle
sessions stay subject to the bounded cleanup. Upstream's duplex
pending-create/steer bookkeeping (and its 20df0c2 event-type
prerequisite) is not taken; in-flight is approximated by the active,
non-terminal response state the fork already tracks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ai and openai_compat

Upstream: router-for-me/CLIProxyAPI@27e298cff4a1

Only the xAI and OpenAI-compatible (Mistral) executors are taken; the Meta and Copilot parts and their tests are dropped. The response.done normalization helper comes from upstream db276e8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream: router-for-me/CLIProxyAPI@8bdffcadc1a4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream: router-for-me/CLIProxyAPI@f73b8132d0bc

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ents

Upstream: router-for-me/CLIProxyAPI@e427d6be9b48

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…andling

Upstream: router-for-me/CLIProxyAPI@3ad507bf1d35

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… as 400 request faults

Upstream: router-for-me/CLIProxyAPI@1f76e479c421

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… status

Upstream: router-for-me/CLIProxyAPI@80e8350c954b

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t SSE event types

Upstream: router-for-me/CLIProxyAPI@5a373ede5b2e

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… buffering

Upstream: router-for-me/CLIProxyAPI@b2e331626229

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ons stream

Upstream: router-for-me/CLIProxyAPI@096f77932f34

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cation on late success

Upstream: router-for-me/CLIProxyAPI@29de31a89da5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…onciliation

Upstream: router-for-me/CLIProxyAPI@35afdf07f976

Test adapted to the fork's four-value earliestPoolCooldownForModelAt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream: router-for-me/CLIProxyAPI@14cc6ad1c452

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oldown handling"

Reverts c857fe1 (upstream 3ad507b). Dropping errors that arrive after
client cancellation, and replacing the fork's Claude-specific success
condition with a blanket ctx.Err() check, made conductor failure recording
timing-dependent: TestAIStudioExecutorClaudeMalformedFunctionCallCancelAfterErrorRecordsConductorFailure
failed in about 20% of runs (0 of 200 on the base commit). Upstream changed that
test's expectation in 7e82d0d, which the fork has not taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reverts 0b791f6 (upstream 4aca8df). Returning as soon as the request
context is canceled lets the stream wrapper exit before the executor's
trailing error chunk is read, so a failure that follows an in-band error
event can go unrecorded (same AIStudio cancel-after-error test, ~8% of runs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rune-gh
rune-gh merged commit 90c319a into main Dec 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant