Repository navigation
fix(adapter): skip accounts whose context window cannot fit the request - #25
Merged
Mag1cFall merged 2 commits intoNov 21, 2026
Merged
Conversation
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.
问题
账号因上下文窗口不足(413)被拒绝后,换号逻辑只把该账号加入排除集,下一个候选可能是窗口同样装不下的免费账号,或者
guest(固定 32768)。于是同一条请求会:prepare(把附件重新上传到上游);实测(v0.2.0)日志里出现 8 次
账号上下文窗口为 32768 tokens,其中 2 次 guest 甚至是第一顺位(之后 8ms 同一账号就成功了)。改动
accountContextError记录本次请求需要的输入 token 数;AccountPool.ExcludeNarrowContext(excluded, tokens),把ContextWindow() > 0 && < tokens的账号与访客会话一次性加入排除集(窗口未知=0 的不排除,避免误伤);排除上下文窗口装不下请求的账号。边界说明
这是缓解而非根治。根治需要在选号前算出 token 下界并传给
AcquireForModel,让nextFrom直接过滤——那是跨adapter/balancer/hedge的签名改造(约 100+ 行、7 个 handler 调用点),本 PR 不含,避免引入无法充分验证的大改。测试
新增
internal/balancer/context_window_test.go:TestContextTooNarrow:窗口比较表驱动(含相等仍可装下、窗口未知不判窄);TestExcludeNarrowContextKeepsUnknownWindow:token 数非正不改动、窗口未知不排除、已排除不重复;TestExcludeNarrowContextReportsAddedAccounts:返回值与实际排除集一致。go build ./...、go vet ./...、go test ./...全绿。