fix(registry): support gemini handler and strict weak ordering in GetFirstAvailableModel
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start in internal/registry/model_registry.go at GetFirstAvailableModel, where convertModelToMap output is read with model["id"] and the sort.Slice comparator handles the created timestamp. Check the gemini branch in convertModelToMap to confirm the ID lands in "name". Then run go test -race -count=1 -run TestGetFirstAvailableModel ./internal/registry against the tests in model_registry_first_available_test.go. Done means the gemini lookup succeeds and the mixed-created ordering is deterministic.
Written by the indexing model from the issue text.
Description
Reference PR: #8070 (verified against origin/dev, go test -race + Solaris cross-build passing, all Codex review findings resolved at commit 2aa9b96a).
fix(registry): support gemini handler and strict weak ordering in GetFirstAvailableModel
Summary
Fixes two bugs in ModelRegistry.GetFirstAvailableModel (internal/registry/model_registry.go):
- Gemini handler always failed:
convertModelToMap(..., "gemini")populates"name"(eithermodel.Namesuch as"models/gemini-2.5-pro"ormodel.ID) instead of"id".GetFirstAvailableModelonly readmodel["id"].(string), causingGetFirstAvailableModel("gemini")to always return"no available clients for any model in handler type: gemini". - Broken strict weak ordering in
sort.Slice: The comparator returnedfalsewhenever!okI || !okJonmodel["created"].(int64). When a slice mixes models with and without"created"timestamps,sort.Slice's comparator violates strict weak ordering (incomparability is not transitive), which can prevent the newest model from sorting to the front or cause nondeterministic ordering.
Changes
internal/registry/model_registry.go:- Added an
extractModelIDhelper insideGetFirstAvailableModelthat reads"id"first and falls back to"name"with any"models/"prefix stripped. - Updated the
sort.Slicecomparator to enforce a total/strict weak order: models with a"created"timestamp sort before those without, then by"created"descending (newest first), with lexicographical tie-breaking on the extracted model ID.
- Added an
internal/registry/model_registry_first_available_test.go:- Added
TestGetFirstAvailableModel_GeminiHandlercovering Gemini models with and withoutName("models/..."prefix stripping). - Added
TestGetFirstAvailableModel_MixedCreatedStrictWeakOrderingcovering mixed present/absentcreatedtimestamps and deterministic tie-breaking.
- Added
Verification
gofmt -w internal/registry/model_registry.go internal/registry/model_registry_first_available_test.gogo vet ./internal/registry/...— PASSgo test -v -race -count=1 -run TestGetFirstAvailableModel ./internal/registry— PASS (TestGetFirstAvailableModel_GeminiHandler,TestGetFirstAvailableModel_MixedCreatedStrictWeakOrdering)go build -o test-output ./cmd/server— PASSGOOS=solaris GOARCH=amd64 CGO_ENABLED=0 go build -o test-output-solaris ./cmd/server— PASS
Changed Files in Reference PR #8070
internal/registry/model_registry.go(+19/-14)internal/registry/model_registry_first_available_test.go(+148/-0)
- Dominant language
- Go
- Stars
- 59.4k
- Forks
- 9.1k
- Avg merge
- 11h 50m
- Merged PRs (30d)
- 67
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from router-for-me/CLIProxyAPI
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
router-for-me/CLIProxyAPI#8131 ·
Maintainers usually reply within 1 day
-
feat(auth/antigravity): add https://www.googleapis.com/auth/aicode OAuth scope for aicode.googleapis.com and Gemini 3.5 audio transcriptionPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
router-for-me/CLIProxyAPI#5289 · 1 reaction ·
Maintainers usually reply within 1 day
-
mac下正确的快速开始May be free again A pull request for this issue was closed without being merged. Openlampoon
Difficulty 2/5 Half a day Newbie friendliness 68/100
router-for-me/CLIProxyAPI#2064 · 14 comments · 17 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 32/100
router-for-me/CLIProxyAPI#8163 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 Half a day Newbie friendliness 42/100
router-for-me/CLIProxyAPI#8162 ·
Maintainers usually reply within 1 day
All issues in router-for-me/CLIProxyAPI
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
siyuan-note/siyuan#21692 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 74/100
rossoctl/context-guru#1413 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
slavakurilyak/awesome-ai-agents#1041 ·