Skip to content

feat(gateway): expand model compatibility and harden failover, quotas, and billing - #82

Open
xiaoguai1818 wants to merge 50 commits into
CherryLover:mainfrom
xiaoguai1818:backport/unified-integration-20261120
Open

xiaoguai1818 wants to merge 50 commits into
CherryLover:mainfrom
xiaoguai1818:backport/unified-integration-20261120

Conversation

@xiaoguai1818

Copy link
Copy Markdown

Summary

Selectively backport gateway reliability, new-model compatibility, security and usage fixes into Sub2API Lite, while preserving Lite-specific routing and billing defaults. This is one integrated delivery; no unrelated upstream product modules were restored.

Account safety and routing

  • Atomically consume refresh tokens, preserve successfully rotated OAuth credentials, and guard credential changes with CAS. Prevent old probes or shadow accounts from overwriting later authorization, manual disabled state, or fresh error evidence.
  • Fix concurrency-slot release on hydration failure, cooldown recovery, group RPM/rate synchronization, and bounded per-bucket DB fallback coalescing.
  • Scope Gemini/Antigravity 403, 404, 429 and capacity-503 failures correctly. Do not globally poison healthy accounts on empty streams, retry loops, or model-specific failures.
  • Harden OpenAI SSE first-output failover, session-safe WebSocket replay/search activation, response-body memory ownership and server shutdown.

Protocol compatibility and model support

  • Bring in GPT-6.2 Sol/Astra, Claude Fable/Mythos 5.2 and Gemini 4 Carbon model catalog/routing/protocol/fallback-price support, without changing unapproved pricing policy or claiming live account eligibility.
  • Preserve Anthropic cache-creation TTL usage, thinking signatures, per-turn output settings, actual upstream response model, Codex Desktop context/tool metadata, and Gemini stream/tool boundaries.
  • Restore custom_tool_call and tool history correctly for Antigravity Responses in buffered and streamed modes; reject ambiguous tool declarations and invalid JSON locally.
  • Route OpenAI-compatible Embeddings by the actual requested group platform, including Lite-supported domestic providers.

Usage, quotas and UI

  • Keep user debits distinct from internal account costs; preserve Fable, Kimi and Gemini quota/window freshness and Grok server-side search counts.
  • Keep account rows and quota cells stable across refreshes; account cost remains admin-only.

Workflow cleanup

  • Remove the inherited CLA Assistant workflow: all its jobs are conditioned on Wei-Shaw/sub2api and cannot run in the Lite or fork repositories.
  • Remove the obsolete claude/** [rc-build] branch-push trigger from Branch Docker Image, retaining explicit manual dispatch and internal-rc-* tag builds.
  • Preserve target repository CI, Security Scan, Auto Release, Release and main/branch image workflows with real history. Fork RC/release workflows remain disabled.

Validation for final fork SHA

Final SHA: 51cbaa4.

  • CI: passed, including frontend, Go unit/integration, lint, embedded build and deployment fixtures (4 jobs successful).
  • Security Scan: passed (both backend and frontend).
  • Local Go unit: all 52 test-bearing packages pass; golangci-lint 0 issues; focused race checks pass for service/handler/repository/securityaudit; embedded server build passes.
  • Real isolated PostgreSQL 18.1 + Redis 8.4.0: repository 1,384 passing and one pre-existing conditional skip; audit 210 passing with no skips.
  • Frontend: 228 Vitest files / 1,858 tests pass; typecheck, ESLint and production build pass.
  • No deployment, production database change or automatic merge.

Upstream sources

Upstream PRs may still be open or superseded; fixes were selectively adapted to Lite, not automatically cherry-picked.

Reviewer notes and boundaries

  • Overlap: Lite PRs #73 through #81 are still open; their fixes are incorporated here. Avoid merging duplicated changes twice. This PR does not automatically close older PRs.
  • No new schema migrations, cache pricing buckets, Ultra Fast/Carbon dated billing multipliers, or default Vertex routing. Decisions/Rerank/DeepSeek Files remain outside scope pending product decisions.
  • Local simulations do not establish real-provider subscription eligibility. Price/catalog fallbacks must be confirmed against live provider/plan details before operational reliance.

Detailed source mapping and validation evidence are in docs/maintenance/upstream-reviews/.

leobot added 30 commits November 17, 2026 19:27
leobot added 20 commits November 18, 2026 15:15
…ases

Preserve Antigravity 429/503 failover, final retry cooldowns and shared accounts after empty streams. Detect incomplete Gemini streams across six entry paths, truncate leaked turns, and preserve thinking configuration and accumulated usage.

Persist irreversible OpenAI OAuth rotations with compare-and-swap, protect concurrent reauthorization and credential shadows, and keep peer-instance Redis leases intact during startup. Add PostgreSQL atomicity and Redis lifecycle regressions.

Keep Codex external context and additional_tools IDs intact, prevent native WebSocket later turns from replaying the initial request, preserve metadata and tool-loop affinity, and return protocol errors rather than successful completions after Anthropic upstream read failures.

Retain lite-specific routing, pricing and product boundaries. Refresh outdated model/version/reasoning test fixtures and close test-owned WebSocket pools.

Upstream: Wei-Shaw#8973, Wei-Shaw#8974, Wei-Shaw#8975, Wei-Shaw#8987, Wei-Shaw#8997, Wei-Shaw#8980, Wei-Shaw#8685, Wei-Shaw#8671, Wei-Shaw#8703, Wei-Shaw#8589, Wei-Shaw#8741, Wei-Shaw#8786, Wei-Shaw#8622, Wei-Shaw#8769, Wei-Shaw#8564, Wei-Shaw#8754, Wei-Shaw#8673, Wei-Shaw#8994.

Local verification: full unit suite (19,640 passes, 14 explicit environment/platform skips), focused race suites (182 and 60 overlapping cases), frontend typecheck/lint/1,841 tests/build, embed build and deployment fixtures. PostgreSQL integration code compiles; actual database execution and final-SHA CI/Security remain required. No migration, pricing-policy change, merge, release or deployment.
Record the unified gateway code commit, pinned upstream PR heads, existing 40-commit inventory, failure reproductions, local unit/race/frontend/build evidence, database validation requirements and unresolved scope boundaries.

Keep the original conflicting checkout and local Cairn knowledge untouched by Git publication. The current branch is for consolidated verification only; a final PR remains gated on the remaining applicable work and final-SHA CI/Security results.
… masking

Explicitly acknowledge strings.Builder's non-failing writes and format the existing GPT-6.2 model tests.

Strengthen the PostgreSQL rotation/outbox atomicity regression using an autocommit connection so test SAVEPOINT rollback cannot hide a partial production update. Clean only fixture-owned account/outbox records.

Affected Antigravity/OpenAI packages passed 315 race-enabled tests. The revised integration suite compiles; actual PostgreSQL/Redis execution remains blocked by the stopped local Docker engine and repository Actions dispatch denial. No migration, pricing-policy change or deployment.
…xplicit

Acknowledge non-failing strings.Builder writes in reasoning conversion and turn-boundary fixtures. Add explicit returns after fatal nil guards in existing tests so staticcheck can follow their control flow without changing runtime assertions.

Keep all lint checks enabled and remove diagnostic output limits for verification: golangci-lint v2.9.0 reports zero issues. Darwin and Linux/amd64 source-target govulncheck report no code-reachable vulnerabilities; seven uncalled required-module advisories remain recorded. No production control-flow, routing, schema or billing-policy changes.
Pin final gateway code 6601085 and its backend tree. Record the content-fenced full unit pass (19,657 tests/subtests, 14 explicit skips), zero lint issues, race/frontend/build results, strengthened PostgreSQL integration compile, and local vulnerability-scan scope.

Correct the earlier Actions-permission inference: CI and Security Scan dispatch were actually denied with HTTP 422 despite enabled metadata. Preserve explicit real-database and remaining-feature gates; do not claim a final unified PR, merge, deployment, or zero dependency vulnerabilities.
Restore Antigravity Responses custom-tool roundtrips and correct Embeddings platform scheduling. Harden OAuth probe fencing, request-scoped Gemini 403 behavior, OpenAI stream failover and WebSocket current-turn safety.

Preserve Claude/GPT-6.2/Grok protocol details and model observations; correct Fable/Kimi quota refreshes and user-vs-account cost reporting. Bound scheduler fallback, request memory retention and shutdown/stream lifecycles without unapproved pricing or schema changes.

Local checks: complete Go unit packages, PostgreSQL 18.1/Redis 8.4 repository and audit integration, focused -race, frontend typecheck/lint/1858 Vitest/build, backend lint 0 issues and embedded server build. Remote CI/Security Scan remain pending.

Upstream references: Wei-Shaw/sub2api Wei-Shaw#8833 Wei-Shaw#8875 Wei-Shaw#8856 Wei-Shaw#8730 Wei-Shaw#8990 Wei-Shaw#8806 Wei-Shaw#8832 Wei-Shaw#8809 Wei-Shaw#8164 Wei-Shaw#8804 Wei-Shaw#8773 Wei-Shaw#8309.
…isks

Link the local gateway development commit to upstream sources and verified Go, PostgreSQL/Redis, frontend, race, lint and embedded-build results. Preserve approval requirements and GitHub CI/Security limitations without claiming remote checks.
Record fork Actions HTTP 422 despite enabled API status, pending required CI/Security Scan, and overlapping existing lite PRs CherryLover#73-CherryLover#81. Do not claim the single consolidated PR is review-ready until the final SHA checks can actually run.
The CLA Assistant workflow is gated to Wei-Shaw/sub2api and performs no useful checks on CherryLover/sub2api or the development fork. Remove this obsolete inherited workflow; retain CI, Security Scan, and target release/image workflows with actual usage.

Document why the development fork keeps its three inactive image/release workflows disabled and why the target repository release paths must remain intact.
Keep Branch Docker Image available through explicit workflow_dispatch and internal-rc-* tag pushes. Remove the legacy claude/** branch push path and redundant [rc-build] guard, which generated historical skipped workflow runs and is no longer needed for validation.

Preserve the target repo release pipeline and the fork disabled states; document the retained workflow ownership and deprecation evidence.
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