Skip to content

fix: the Redis problem in the CacheGetUsername function - #45

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
t0ng7u:patch-1
Jan 12, 2024
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
t0ng7u:patch-1

Conversation

@t0ng7u

@t0ng7u t0ng7u commented Jan 12, 2024

Copy link
Copy Markdown
Collaborator

fix: the Redis problem in the CacheGetUsername function

fix: the Redis problem in the CacheGetUsername function
@Calcium-Ion
Calcium-Ion merged commit 2ccd6c0 into QuantumNous:main Jan 12, 2024
sususu98 pushed a commit to sususu98/new-api that referenced this pull request Dec 1, 2025
- 将优先级说明从 "(0最高)" 改为 "(数值越小优先级越高,0为最高)"
- 消除用户对优先级排序规则的理解歧义
- 明确说明数值越小优先级越高,0为最高优先级

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
fix: the Redis problem in the CacheGetUsername function
jiutubaba pushed a commit to jiutubaba/fx-api that referenced this pull request May 17, 2026
* fix(middleware): 修复 Gemini API Key 认证中间件用户上下文类型错误

修复了 ApiKeyAuthWithSubscriptionGoogle 中间件中设置用户上下文时的类型错误。

**问题:**
- 中间件直接设置 `apiKey.User` 对象到上下文
- 导致 handler 中获取 `AuthSubject` 时类型断言失败
- 所有 Gemini v1beta 端点返回 500 "User context not found"

**修复:**
- 改为设置 `AuthSubject` 结构体,与 `api_key_auth.go` 保持一致
- 添加 `ContextKeyUserRole` 设置以完整支持角色检查

**影响范围:**
- Gemini v1beta API 端点 (generateContent, streamGenerateContent)
- 使用 Google API Key 认证的所有请求

**测试:**
- 验证 Gemini CLI 调用成功返回 200
- 确认用户上下文正确传递到 handler

* fix(web): 修复 /responses 端点被前端中间件拦截的问题

- 将 /responses 路径添加到 API 白名单,防止其被当作前端路由处理
- 修复 /responses 端点返回 HTML 而非 API 响应的 BUG
- 解决 codex CLI stream 在远程服务器上断开连接的问题

根本原因:
在 6c469b4 提交中添加了 /responses 路由,但未同步更新前端嵌入中间件
的 API 白名单,导致该路由被拦截并返回 index.html 而非 API 响应。
lingozhi referenced this pull request in lingozhi/new-api Jul 17, 2026
Measured over 262 prod requests, all six channels serving the SAME model at the
SAME reasoning effort — so the spread is the channel, not the request:

  #41 1275ms (n=90)   #51 1328ms (n=66)   #42 2337ms (n=17)
  #33 3388ms (n=24)   #45 3537ms (n=52)   #57 8133ms (n=8)

Bucketing by uncached prompt tokens holds p50 flat (1612/1934/2073/1802 for
0-2k/2-6k/6-20k/20k+), which rules out prefill volume as the cause. Meanwhile
~100% of requests are affinity-pinned, so the health-weighted selection that was
supposed to steer around slow channels almost never runs — the only exit is
IsChannelFastEnoughForAffinity, and `score > 0.1` with `score = 1/(1+latency)`
only fires past 9s. #45 and #57 kept their sticky traffic forever; 33% of
requests were pinned to a channel 2.6x+ slower than the one next to it.

Release relative to the best peer for the same model+path instead: leave only
when the sticky is BOTH slower than 2s absolute and >2x that peer. The absolute
floor stops churn over gaps nobody can feel (0.3s vs 0.15s is 2x), the ratio
stops churn for gains too small to repay a migration. #42 at 1.83x stays.

The reason this could not just be turned on: migration causes a cold prompt
cache by construction, and a cold 240k-token prefill measured 23348ms. That one
number breaks two mechanisms at once, both of which then punish the channel we
just chose *for being the fastest*:

  - the latency EWMA, which is shared by every affinity key on the channel, so
    one migration would make the destination look slow to all of them and
    stampede them off it, each paying its own cold prefill;
  - cooldownSlowChannelIfNeeded, an entirely separate path that yanks a channel
    out of rotation for 30 minutes past 30s FRT — 23.3s is 78% of that.

So the release is gated three ways. ColdCacheStart marks the attempt and keeps
its latency out of both mechanisms (failures still count — a cold start is no
excuse for erroring). A per-key cooldown stops one key bouncing. A global
minimum interval drains a slow channel one key at a time, because the slow
verdict is per-channel: without it every key pinned to #45 leaves on the same
tick and their cold prefills land on #41 together, making it genuinely slow —
a cascade no latency-exclusion can prevent, since that load is real.

Circuit-open releases stay unconditional and never reach AcquireChannelHealth,
or a rate-limited key would be parked on a tripped channel and a paying request
would become its half-open probe.

Accepted: weighted re-selection can hand a released key back to the same slow
channel (~12.5% by weight). Not excluded — that risks a 503, and the cache
there is still warm, so the only cost is the 10-minute slot.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Firesuiry pushed a commit to Firesuiry/tako-newapi that referenced this pull request Aug 27, 2026
…ls-embed

feat(playground): search, speech, and copyable skill cards
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
fix: the Redis problem in the CacheGetUsername function
jahnli pushed a commit to jahnli/new-api that referenced this pull request Oct 17, 2026
Upstream scope: 22 commits / 123 files since the last sync (ef60ef2). 19 conflicted files were resolved one by one with explicit confirmation: 9 manual merges, 3 files taken from upstream (console search refactor plus its new test), and key-set unions in all 7 locale files. Every auto-merged file was reviewed one by one and both sides' changes are preserved (line-level check: no local line and no upstream line lost). No upstream deletions.

Local behavior kept: QuantumNous#2 AIGatewayError naming across relaykit and host error paths, QuantumNous#23/QuantumNous#24 LDAP login and LDAP default login, QuantumNous#27 avatar_url, QuantumNous#29/QuantumNous#31 removed OAuth providers, QuantumNous#37 subscription and violation fee flow, QuantumNous#39 user management table, QuantumNous#45/QuantumNous#69/QuantumNous#71 data overview access and BP roles, QuantumNous#49 pricing currency, QuantumNous#51/QuantumNous#56/QuantumNous#65 profile, audit and demo mode, QuantumNous#54/QuantumNous#55/QuantumNous#57 pricing square and dashboard/four-token stats, QuantumNous#58 online image generation, QuantumNous#60 API key interactions, QuantumNous#61 auto subscribe, QuantumNous#62 admin entry permissions, QuantumNous#77 removed frontend update check, seven-locale custom copy, header-removal convention.

Upstream adopted: QuantumNous#7822 upstream address masking (upstreamURLs plumbing through relaykit error paths, task errors, WebSocket error events, playground/relay/gemini/chat_via_responses/violation fee), QuantumNous#7317 container cgroup overload sentinel with consecutive and freshness sampling, QuantumNous#7816 Claude explicit zero usage and cache-only billing, QuantumNous#7813 pricing sorts by input/output/per-request price, QuantumNous#7840 provider rules for Cloudflare and NVIDIA, QuantumNous#7814 sensitive word filtering off by default, AWS Mantle Messages API, Vertex multi-region hostnames and API key project_id, Hailuo/Vidu/Veo plugin channel bindings and Vidu billing, per-group rate limits, API key owner quota query, moejs v0.1.0-alpha.7, theme class applied before first paint, console search limited to sidebar pages.

Collateral decisions (user approved): removed local test web/src/components/__tests__/command-menu-permissions.test.tsx (superseded by upstream command-menu.test.tsx) and added the newly required allow_user_quota_query field to the web/src/features/keys/components/__tests__/api-key-timestamp-cell.test.tsx fixture.

Verification: go build ./... exit 0; GOWORK=off go build ./... in relaykit exit 0; gofmt clean on modified Go files; web bun run typecheck exit 0; oxlint clean on the 49 merged web files; bun run i18n:sync reports missingCount 0 and extrasCount 0 for all seven locales; no conflict markers left; every upstream commit's added lines are present.

Not verified: SQLite/MySQL/PostgreSQL migration matrix for the new tokens.allow_user_quota_query column, unit tests (not run per project rule), web production build, runtime manual checks.
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.

2 participants