Repository navigation
fix: stop anonymous lane from locking up after quota+network change - #59
Merged
jasonxu114514 merged 2 commits intoOct 15, 2026
Merged
Conversation
Owner
|
其實推薦做法是 不保留佔位的zenkey ,可能是我描述問題 應該是在添加了匿名渠道的時候移除了必須存在key的限制 但是沒有更新文檔 |
RED: Retry-After honored without cap; anonymous pool has no RestoreProxy.
Cap Retry-After at 8x base cooldown in both MarkFailure paths, add anonymousPool.RestoreProxy, and clear anonymous cooldowns when a proxy recovers, so a new IP's fresh quota is reachable without a restart.
cheerc
force-pushed
the
fix/anonymous-cooldown-lockup
branch
from
October 13, 2026 08:05
3d4ae18 to
74d6a7c
Compare
This was referenced Oct 14, 2026
jasonxu114514
added a commit
that referenced
this pull request
Oct 15, 2026
…change (#59) A quota response with a multi-hour Retry-After cooled anonymous exits for hours, so after a network change gave them a fresh allowance traffic kept falling through to key lanes until restart. Cap Retry-After on the anonymous lane at the 8x backoff ceiling, and clear anonymous cooldowns when their proxy recovers. Key lanes keep honoring Retry-After in full. Co-authored-by: CheerC <[email protected]>
SK-DEV-AI
added a commit
to SK-DEV-AI/opencode2api
that referenced
this pull request
Oct 15, 2026
…ver-key usage) Takes upstream f8e996d/be91f86/0204ca1 (client fingerprint + inference endpoint + genuine tools), jasonxu114514#59 anon cooldown lockup, jasonxu114514#63 token floor, jasonxu114514#64 whole-attempt deadline, jasonxu114514#62 tool images, jasonxu114514#58 server-key usage split, jasonxu114514#65/jasonxu114514#66 models surface, plus our merged jasonxu114514#76/jasonxu114514#77/jasonxu114514#78. Kept local (fork-owned, still no upstream equivalent): zero-delivery replay + length rescue + SSE heartbeat + stop/tail census (stream lanes), offline no_upstream_contact probe guard, single-marshal Zen shaping with paid-model gate, tcp4 dial + TLS resumption, RandomID math/rand fallback, cancel-detached refresh fix (PR jasonxu114514#80 superseded by maintainer feedback; kept locally pending lifetime-context rework). Telemetry takes upstream's session-burn + server-key split with their LRU session cap (better than our smallest-first); CloneMap takes upstream's merged comment. Metrics ring test retargeted at upstream's concrete ring types. doUpstream keeps upstream's 3-value signature; replay uses a new doUpstreamCounted wrapper for continuous legs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題:換 IP 後持續 401,必須重啟 process 才恢復
使用場景:免費模型額度用完 → 上游回 401。同時透過更換網路環境(換 IP)來恢復額度
(anonymous 免費通道是按 IP 限流的)。但網路明明已通、新 IP 也有額度了,
opencode2api 仍然持續對外回 401,只有把 process 整個 kill 重開才會恢復 200。
根因(兩個記憶體狀態,症狀是 401 卡死)
本站典型配置:
anonymous:true+ 唯一 proxydirect+ 佔位 zen key。請求先走 anonymous 通道,失敗才 fallback 到 key 通道(
doUpstreamTiers),而佔位 key 註定永遠 401。所以 anonymous 通道一旦被跳過,對外就是穩定的 401。
Retry-After無上限(pool.go兩個MarkFailure):上游 401/403/429/5xx 都會續冷卻,基底 15s、指數退避最高 8 倍(120s)。
但
Retry-Afterheader 會無條件覆蓋且無上限——免費額度用完時上游常帶一個很大的
Retry-After,冷卻直接到數小時後。anonymousCursor.Next):冷卻中的 anonymous 節點直接回
nil、整條 lane 被跳過(key 池還有earliest-expiry fallback)。換了新 IP 本該恢復,但新 IP 的第一次嘗試根本沒
機會發生——lane 選擇在冷卻檢查這步就回頭了,只走必 401 的佔位 key。
restoreProxy):斷線期 transport error 把唯一 proxy 標 unhealthy,anonymous lane 要求 healthy
被整段跳過;恢復時只清 key 節點冷卻(
nodePool.RestoreProxy),anonymous的只能等過期。
重啟能修,只是因為它清空了這兩個記憶體狀態。
本 PR 的修改
pool.go:兩個MarkFailure的Retry-After上限為base * 8(與既有指數退避封頂一致,預設配置下即 120s)。只縮短超長 Retry-After,
不影響正常退避語意。
pool.go:新增anonymousPool.RestoreProxy,鏡像nodePool.RestoreProxy清除同 proxy 下 anonymous 節點的冷卻。
refresh.go:Gateway.restoreProxy一併呼叫,接上既有的恢復路徑(2xx / 非同步 cloudflare 探測 / 15 分鐘定時檢查)。
pool_test.go(test-first,RED 先提交):巨大Retry-After被 cap;restore 清掉 anonymous 冷卻且節點可再被選中。
沒做的(有意排除)
anonymousCursor.Next加 earliest-fallback:會削弱退避語意;cap + restore已把鎖死上界壓到分鐘級且可隨 proxy 恢復立即解除。
症狀無關。
驗證
gofmt -l internal/無輸出;go vet ./...通過;go test ./internal/gateway/ -v三個新測試全過;go build -trimpath ./cmd/opencode2api成功。GET /healthz看proxies.healthy區分是 proxy 閂鎖還是冷卻。claude-12b1b8 · muse-spark