Skip to content

chore: sync with upstream router-for-me/CLIProxyAPI main - #8

Merged
bntvllnt merged 735 commits into
mainfrom
chore/sync-upstream-2026-11-14
Nov 14, 2026
Merged

bntvllnt merged 735 commits into
mainfrom
chore/sync-upstream-2026-11-14

Conversation

@bntvllnt

Copy link
Copy Markdown

Summary

Merge upstream router-for-me/CLIProxyAPI main (905e70c4, 732 commits) into the fork. Brings Claude Fable 5.2 support (claude-fable-5-2 in the catalog, Claude Code fingerprint 2.1.321 — Anthropic rejects Fable 5.2 from older client versions — and preserved-thinking/timing gates for 5.2).

Conflicts

17 files, resolved keeping both sides. Fork features preserved and re-verified: per-key credential allowlist, headroom / reset-aware routing, overload cooldown, max-retry-duration.

Fixes on top of the merge

  • fix(access): upstream's new /muse-code relay picked Meta credentials without the client key's allowlist (regression test fails without the fix).
  • fix(access): websocket per-turn re-auth now rebinds a narrowed allowlist after a config reload (never widens mid-socket).

Verification

  • go build, go vet (only a pre-existing upstream test warning), go test ./...: only pre-existing upstream failures, identical on a clean upstream checkout (internal/discovery mDNS integration, internal/pluginhost timing test).
  • Full suite also passes with -tags purego.
  • go mod verify against sum.golang.org: all modules verified.
  • New dependency github.com/MoeForge/moego (replaced by router-for-me/moego v0.1.2): pure compute (no net/os/exec), but uses unsafe, SIMD asm and go:linkname runtime.mallocgc; its own tests pass with and without purego.
  • Independent reviews (supply chain / egress, access control, merge integrity): no high-severity findings.
  • govulncheck: 3 findings, all pre-existing on main (brotli v1.0.6, klauspost/compress v1.17.4, Go 1.26.10 net/http) — follow-up PR.

Known upstream risks (not changed here)

  • /v1/tunnel: no per-key peer cap (authenticated memory DoS).
  • Remote model catalogs are unsigned; production runs --local-model.
  • Config file replaced by atomic rename is not hot-reloaded (watcher only watches the inode); edit in place or use the management API.

luispater and others added 30 commits October 30, 2026 22:33
…ng to OpenAI

- Expand recognized CPA compaction capsules into developer context messages across Codex HTTP, compact, WebSocket, duplex steering, and token-counting paths while preserving native OpenAI compaction items.
- Reject corrupted CPA compaction capsules with HTTP 400 instead of forwarding unverifiable ciphertext to upstream.

Closes: router-for-me#7118
- Add `client.claude.show-codex-commentary` config and propagate the request-scoped display policy through HTTP and WebSocket Codex executors.
- Mirror public Codex `commentary` messages into visible Claude text blocks alongside the `cpa:commentary:v1` thinking marker in streaming and non-streaming responses without altering genuine reasoning or token accounting.
- Deduplicate only the exact adjacent mirrored commentary text block during Claude-to-Codex request replay when enabled.

Closes: router-for-me#7129
- Add Capabilities.AuthProviders and MultiAuthProvider (Identifiers() []string) in sdk/pluginapi, bump sdk/pluginabi.SchemaVersion to 10, and forward AuthProviders in sdk/pluginhost
- Extend internal/pluginhost to register, expose, and route multiple OAuth login identifiers per plugin across StartLogin, PollLogin, RefreshAuth, ParseAuths, and ExchangeCallback, while preserving per-credential oauth_provider/portal attribution for shared credential providers
- Expose oauth_providers alongside primary oauth_provider in RegisteredPluginInfo and GET /v0/management/plugins, and support target-credential re-login (StartOAuthV8) across sibling portals

Closes: router-for-me#7126
…ion.parts

- Remove empty JSON part objects from request.systemInstruction.parts in ConvertGeminiRequestToAntigravity after system_instruction key normalization so upstream Cloud Code Assist does not fail Part.data oneof deserialization with HTTP 400.
- Delete request.systemInstruction when all of its parts are empty objects while preserving zero-copy pass-through when all parts are non-empty.

Closes: router-for-me#7136
The flusher rebuilt its pending map from every release group on each
release-flush tick. Groups are retained after acknowledgement, so a
long-lived credential pool paid O(groups) allocations and lock time every
250ms even with no in-flight requests.

Track unacknowledged groups in a dedicated pending map, return before
allocating when it is empty, and arm the flush timer only while work is
pending. The timer is re-armed by MarkDirty's wake signal, so release
latency is unchanged.

Tested with a regression test asserting an idle flush over 1,000
acknowledged groups performs zero allocations, plus a test that an
acknowledged group leaves the pending set.
- Exempt HTTP 400 responses whose JSON error message starts with "Your credit balance is too low" from request-fault classification in clienterror.
- Apply 30-minute payment_required cooldown, cooldown view reason mapping, and session-affinity rebinding so depleted Anthropic API keys fail over to fallback credentials.

Closes: router-for-me#7120
…5.5 models

- Add supported thinking levels (`low`, `medium`, `high`) to the Antigravity `claude-opus-5-5-high` and `claude-sonnet-5-5-high` model definitions so hybrid capability validation preserves explicit `thinkingLevel` settings instead of converting them to `thinkingBudget`.
- Add regression tests covering `ApplyRequestThinking` and streaming/non-streaming Antigravity executor requests for both Claude 5.5 models.

Closes: router-for-me#7133
Add an optional `connection-pool` block to the api-key config surface: group
level on codex/claude/gemini/vertex/openai-compatibility entries and per key
inside `keys`. There is deliberately no global switch, so enabling reuse for one
key cannot change the transport lifecycle of another provider or OAuth identity.

- `connection-pool` joins the v8 shared key fields, so a group block is flattened
  into every key and each key may override it.
- A per-key block merges onto the group block: fields the key does not mention
  (or sets to null) keep inheriting the group value. Replacing the whole block
  would silently drop the group's `enabled: true` when a key only overrides a
  timeout.
- The resolved block reaches executors on `Auth.ProxyConnectionPool` (deep-copied
  on clone so auth snapshots never share mutable state). Writing the block is the
  opt-in; only an explicit `enabled: false` turns pooling off for that key.
- OpenAI-compatible keys use the same field-level inheritance against their
  provider group default, and watcher config diffs report connection-pool
  changes on hot reload.
Give the generic proxy-aware clients a reusable transport per api-key
credential, driven by the `connection-pool` block added in the previous commit.

- Pools are keyed by credential scope (auth ID, then path/source, then a digest
  of refresh/access/API-key material, then anonymous), normalized proxy target
  (authenticated proxies fold a SHA-256 digest of user:pass into the key so each
  proxy identity or sticky-session username keeps its own pool without storing
  plaintext secrets in the cache key or logs), and the resolved settings. Two
  keys therefore never share a TCP/TLS connection regardless of whether the
  proxy is unauthenticated, authenticated, direct, or inherited.
- Capacity is a 512-entry LRU: one key keeps a warm pool, 100 keys keep one each,
  and 100000 keys fall back to the historical one-transport-per-request behavior
  when the cache is full. Each transport is bounded to MaxIdleConnsPerHost
  instead of the cloned default of 100 idle sockets, so idle sockets stay at
  capacity*max no matter how many keys exist.
- Dead peers are detected without request timeouts: 30s TCP keepalive on every
  dialed connection (including SOCKS5, which used proxy.Direct before) plus the
  idle timeout, 300s by default. Measured against ollama.com, an idle pooled
  connection was still reusable after 600s; the 90s that used to bound this path
  was net/http's own IdleConnTimeout, not an upstream limit.
- Explicit 0 or negative values disable keep-alives (including when proxy-url is
  empty), invalid durations are parsed once per pool instead of warning per
  request, and pooling works with or without an explicit proxy-url while keeping
  priority for context-injected RoundTrippers when proxy-url is empty.
- Config snapshots carry a generation so a request holding an obsolete snapshot
  cannot repopulate the cache after a reload. Generation 0 means the config never
  passed the fence and stays poolable, so callers that build their own config are
  not silently downgraded.
Describe the api-keys `connection-pool` block in the shipped template: writing it
is the opt-in, pools stay per key, authenticated proxy URLs are isolated by a
digest of their proxy credentials, the defaults are a 300s idle window and two
idle connections per host, and zero or negative values disable keep-alives. Note
that no global pooling switch exists and that Antigravity keeps its own
antigravity.connection-pool settings.
- Keep an empty connection-pool block as an opt-in. Synthesising it to nil
  silently disabled pooling for `connection-pool: {}` and for keys inheriting
  an empty group block.
- Fold the transport kind into the pool key and pool the Claude Code uTLS
  transport per credential. Anthropic upstreams previously shared one
  transport across keys and ignored the key's pool settings.
- Fence generations per publisher instead of process-wide. Building or
  reloading one service no longer retires the pools another service is
  still serving, which degraded it to one transport per request.
…utors, and close retired pools outside fence lock
…tion-pool

feat(proxy): add opt-in per-api-key upstream connection pooling
Subscription keys return HTTP 403 client_attestation_denied when the
request still looks like muse-build/1.3.0. Stamp the headers captured
from Muse Code 1.4.14-R7309.1: muse-build/1.4.14, X-Client-Id tbh:exec,
and a fresh session id set.
…ants

- Resolve strict "<level>-fast" requests (parenthesis suffix or body thinking_level) to "<base>-<clamped-level>-fast" in ResolveDevinChatModelUID instead of silently falling back to the default effort.
- Treat a bare "fast" request as the default-effort fast variant so "(fast)" no longer resolves to the plain default UID; private aliases, special families, and the lightning tier keep their existing handling.
- Add regression coverage for the fast suffix and body-level forms plus pinning cases for private aliases and lightning models.

Closes: router-for-me#7144
… manual refresh

- Fail forced refreshes when rejected refresh tokens remain unchanged without disk rotation and preserve rejected access token markers across no-op refreshes.
- Require a valid active access token when sign-in is required before restoring active routing status during refresh and lifecycle updates.
- Return the redacted credential entry view from the v8 management credential refresh endpoint.

Closes: router-for-me#7135
…lusher-idle

fix(home): keep the release flusher idle when nothing is pending
…h the stream translator

Plugin executor streams whose output format equaled the requested format bypassed stream translation, so SSE-framed chunks ("data: {...}" plus "data: [DONE]") reached the OpenAI/Gemini handlers unchanged. Those handlers add their own "data:" prefix and terminal marker, producing a doubled "data: data:" prefix and a duplicated [DONE] on the wire.

Built-in executors always run TranslateStream, and the registered same-format translators strip that framing. Route same-format plugin executor streams through the same translation instead of returning the channel or payload unchanged. Formats without a same-format translator keep the existing behavior via the TranslateStream fallback, which returns the payload unchanged, and the OpenAI Responses usage-details fixup still runs after translation.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…nses websocket items

- Sanitize only upstream-originated replay copies (transcript merge and tool-call repair cache entries) so another credential cannot reject them as unknown input.
- Match passthrough members by decoded key name across duplicates and escaped spellings, drop objects emptied by removal, and leave client input, downstream payloads, and invalid JSON unchanged.

Closes: router-for-me#7146
luispater and others added 26 commits November 13, 2026 00:33
- Restore Claude signature carriers onto their original Gemini parts with message and semantic boundaries.
- Return Gemini tool signatures in streaming and non-streaming Chat Completions responses without weakening provider compatibility.
- Cover delayed signatures, metadata, unsupported payloads, and payload-rule precedence with regression tests.

Closes: router-for-me#7484
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
- Add Gemini 4 Hydrogen and Antigravity Gemini variants.
- Update Devin model versions while retaining previous entries.
- Prefer /v8/management endpoints for config, credentials, api-keys, logs, and OAuth flows, normalizing the v8 config tree to the TUI's flat view and falling back to /v0/management only when a route is genuinely unimplemented.
- Read access.api-keys from the same versioned root-config snapshot and write back with If-Match, refusing unconditional replaces and stale-index edits/deletes so concurrent changes are not lost.
- Return a non-zero exit via CheckManagementSupport when a server definitively exposes neither contract, while keeping transient probe failures and wrong-password retries non-fatal.

Closes: router-for-me#7462
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
…aining

- Add server.shutdown-timeout config (default 0 = immediate close, preserving router-for-me#6094 behavior); positive values drain in-flight HTTP requests via http.Server.Shutdown bounded by the configured seconds, then force-close the rest.
- Bound the drain by the configured timeout even when the caller's context is more generous, while a tighter parent deadline still wins; hijacked WebSocket connections remain managed by their own handlers.
- Cover drain completion, budget-expiry fallback, tighter parent ctx, zero default, and v8/legacy config parsing in tests.

Closes: router-for-me#7475
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
- Add a lightweight per-request in-flight tracker on the auth manager that covers selection, upstream calls, retry waits, and the full stream lifetime; it stays disabled in Home mode where the execution registry is authoritative.
- Register GET /v8/management/observability/requests/in-flight returning counts only (in_flight, oldest_started_at, by_provider) with no request bodies or credential identifiers.

Closes: router-for-me#7476
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
…s across config apply

- Add Builder.WithPluginInterceptorHost so embedders can install a custom PluginInterceptorHost that survives startup and reload; the server wraps it to keep plugin model routing, executor dispatch, lifecycle, and websocket observers delegated to the internal plugin host.
- Add Hooks.OnConfigApplied invoked after each successful config apply so embedders can reinstall executor wrappers and other caller-owned runtime state.
- Cover the delegated interceptor host with nil-safety, skip-forwarding, capability-detection, and real execute-chain regression tests.

Closes: router-for-me#7499
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
…ressure tests

- Sequence the WebSocket close frame ahead of socket teardown by waiting on the writer in finishClose with a bounded grace window, closing the 1006-vs-1002 race.
- Add waitServersVisible to drain the topology stream until expected servers are observable, fixing empty server_list and stale server_online reads in client tests.
- Make the backpressure test deterministic via a gated transport plus tighter byte budgets, and route background-read errors through bounded barrier channels to prevent hangs.

Closes: router-for-me#7504
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
- Implement core Muse Code relay handler, origin resolution, header/query sanitization, credential selection/preparation, 401 refresh, and bounded failover in internal/client/musecode.
- Register thin /muse-code routes, safe-mode proxy guarding, and request-ID logging prefixes in internal/api and internal/logging.
- Isolate model-less credential-scoped cooldowns, preserve execution sequence ordering, and honor request-scoped error rules across sdk/cliproxy/auth.

Closes: router-for-me#7508
…g-safe

- Default credential-bound plugin executors to OAuth model scope and skip static ModelRegistry clients unless ExecutorModelScopeStatic is explicitly set.
- Keep StaticModels catalog collection enabled for OAuth-scoped plugins without leaking static models into ModelRegistry or credential fallback appends.
- Decouple OAuth executor provider binding from catalog provider names and add regression coverage for exclusions, aliases, disabled state, and management catalog definitions.

Closes: router-for-me#7512
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
…e HTTP 200 commit

- Detect MALFORMED_FUNCTION_CALL, UNEXPECTED_TOOL_CALL, and MALFORMED_RESPONSE with zero visible output before bootstrap commit, reasoning replay caching, or usage finalization across Antigravity, Gemini, Vertex, and AI Studio executors.
- Withhold only contentless leading shell frames while keeping thought chunks unbuffered for TTFT, and align Claude response error handling and stream completion flags while preserving valid partial outputs.
- Add unit, executor, bootstrap failover, and cross-module HTTP regression tests covering credential rotation and HTTP 502 exhaustion.

Closes: router-for-me#7513
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
- Cache verified management secret HMAC-SHA256 digests bound to the active bcrypt hash for a one-hour TTL while coalescing concurrent cold-cache verifications.
- Invalidate cached verification entries on management secret changes in SetConfig and ConfigV8 while preserving failure counting, IP ban checks, and non-caching of invalid keys.
- Add deterministic unit tests, a ConfigV8 HTTP integration test, and a benchmark covering TTL expiration, rotation, concurrency coalescing, and ban preservation.

Closes: router-for-me#7519
Co-authored-by: Dylan <1990016@gmail.com>
Co-authored-by: lzt404 <2596933790@qq.com>
…gin listing

- Add Priority *int to pluginListEntry, populated from the host RegisteredPlugins snapshot so clients can verify effective ordering, including zero and negative values.
- Gate exposure to the maintained v8 route while leaving the deprecated v0 response shape unchanged, and add RegisterPluginWithPriorityForTest to cover non-default priorities in tests.

Closes: router-for-me#7522
…sponse interceptors

- Build interceptor metadata in WriteModelListResponse from the authenticated gin context (caller_scope, access_provider, frontend_auth_metadata) instead of always passing nil.
- Reuse requestCallerScope so model-list requests share the same irreversible caller handle as execution paths, enabling per-key catalog filtering including ?key= credentials.
- Forward the same metadata to the request lifecycle tracker and add regression tests for identity forwarding, metadata isolation, and unauthenticated nil metadata.

Closes: router-for-me#7524
- Wrap the final 429 in a poolCooldownTerminalError at the Execute/ExecuteCount/ExecuteStream boundaries when every candidate credential for the model is blocked and at least one is in a timed cooldown, preserving the upstream error body and status while marking IsModelCooldown so the Claude handler appends the reset time.
- Compute the Retry-After from the earliest auto-recovery across all blocked candidates (including non-cooldown timed blocks) so the client sees the pool's real recovery instead of the last attempt's hint.
- Add regression coverage for both cooldown variants across the three execution paths, the available-candidate guard, mixed-block earliest deadlines, the sub-floor hint clamp, and the Claude handler end-to-end.

Closes: router-for-me#7521
…tional pool-wide protective pause

- Detect the 403 PERMISSION_DENIED ErrorInfo reason=TOS_VIOLATION signature and mark the credential StatusDisabled + Disabled so it is excluded from rotation and persisted across restarts, while OAuth refresh stays intact; carry appeal_url/appeal_url_link_text through Error.Metadata to auth.Metadata and the management API.
- Add an optional pool-wide protective pause (antigravity.tos-pause-window, default 6h) armed only by TOS results, never by transient 429s, covering all Antigravity request paths including SSE mid-stream error frames and CountTokens.
- Distinguish terminal TOS results from stale/superseded results using a new Result.RefreshToken account hint so a same-account OAuth refresh applies the suspension while a genuine credential replacement discards it safely.

Closes: router-for-me#7515
- Resolve and validate the target Codex credential proxy_url in StartSIWCBind and construct the OAuth client via codex.NewCodexAuthWithProxyURL so account proxy takes precedence over global proxy without falling back on failure.
- Update siwcOAuthFactory to pass the resolved account proxy URL and add regression tests covering account proxy precedence, global proxy inheritance, direct bypass, unreachable proxy failure, and credential field preservation.

Closes: router-for-me#7531
…ishReason before HTTP 200 commit

- Stop counting signature-only empty-text parts as thought output in InspectGeminiZeroOutputPayload so leading signature-only frames stay buffered until real content arrives.
- Fail buffered candidate-bearing zero-output streams with a retryable 502 on EOF in GeminiZeroOutputStreamGuard.Finalize and harden Antigravity OpenAI streaming translation against all-null delta emission.
- Add unit, executor, and HTTP failover regression tests covering signature-only zero-output streams across downstream formats and credential rotation.

Closes: router-for-me#7536
…igravity, Devin, and Claude

- Add sensitive-patterns-replace configuration rules with load-time RE2 validation, comment-preserving YAML persistence, config diffing, and bounded matcher caching across Antigravity, Devin, and Claude cloak paths.
- Apply ordered non-cascading regex replacements against original text boundaries while preserving Devin original-line drop ownership and existing sensitive-words-replace semantics.

Closes: router-for-me#7540
Merge upstream main (905e70c, 732 commits) into the fork. Conflicts resolved
keeping both sides: credential allowlist, headroom/reset-aware routing,
overload cooldown and max-retry-duration stay intact on top of upstream.

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@bntvllnt

Copy link
Copy Markdown
Author

CodeQL gate triage before merge: the 2 critical rules (go/unsafe-quoting selector.go, go/request-forgery api_tools.go) are already open on main. The new rule+file pairs are path-injection in auth-file/management paths, sha256 IDs flagged as weak password hashing, and pass-through ResponseWriter.Write wrappers flagged as reflected XSS; spot-checked as false positives. Pre-existing upstream test failures confirmed on pure upstream 905e70c: internal/discovery TestAdvertiserAndBrowser_Integration, internal/pluginhost TestPluginErrorCarriesRetryAfterIntoCooldownAndHTTPHeader.

@bntvllnt
bntvllnt merged commit 166815d into main Nov 14, 2026
1 of 2 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.