Repository navigation
fix(providers): paginate the Anthropic models list - #1648
clark-cant merged 3 commits into
Conversation
fetchAnthropicModels issued a single GET /v1/models without limit or after_id, so only the first page (20 models by default) reached the model selector. Request limit=1000 and follow has_more/last_id, with a page cap. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
clark-cant
left a comment
There was a problem hiding this comment.
Reviewed at b4f5d92 (2 files, +119 -28) against dev at 22e71c8, one commit, no prior reviews or comments.
Verdict: approve on the code. Posted as a comment rather than a formal approval because the head carries zero check runs (combined status pending with no statuses, mergeStateStatus UNSTABLE) and this is a first-time contributor, so CI is still waiting on a maintainer workflow approval.
What I verified by execution at the head:
go build ./internal/httpclean,go vet ./internal/httpclean,gofmt -lon both changed files empty.go test ./internal/http -run FetchAnthropicModels -count=1passes, and the new test does fail against the old single-request code (20 vs 120), so it is a real regression guard for thelimitpart of the fix.- The loop itself is correct. I drove
fetchAnthropicModelsagainst a throwaway upstream that ignores the requestedlimitand hard-caps at 20 per page: 60 models came back in exactly 3 requests,after_idwas threaded fromlast_ideach time, and no request carried an unknown cursor. Soafter_id/has_more/last_idhandling is right, not just plausible.
Correctness notes on the change itself:
- The query shape matches the live contract:
limitis documented as 1..1000 with a default of 20, andhas_more/last_idare the documented pagination fields, solimit=1000+after_id=last_idis the right cursor and 1000 is a legal value, not an over-reach. q.Encode()escapes the cursor, which matters becauseafter_idis an opaque id.- The
last_id == afterIDcheck plus the 20-page cap closes both the non-advancing-upstream and the infinite-loop cases. - Closing the body on every path is a genuine improvement: the old code used a single
defer, but moving that into a loop would have leaked a body per page. - The
models == nilfix preserves the previous[]overnullJSON shape for the empty case, so the picker contract is unchanged.
Non-blocking notes:
-
The new test never paginates. Its mock reads the requested
limitand honours it, so the code'slimit=1000makes the server return all 120 in one page withhas_more: false— I instrumented the mock and counted one upstream request. The test therefore proves thatlimit=1000is sent, not thatafter_id/last_id/has_moreare followed, and it would still pass if the loop were deleted and the change reduced to adding the query string. The comment on line 33 says the mock mimics a default page size of 20, but that branch is unreachable atlimit=1000. Cheapest fix: cap the mock's page size at 20 unconditionally (or atmin(20, requested)) and assert the request count, which makes the existing 120-model expectation actually exercise the cursor. Worth doing before merge: the guards in the loop are the part most likely to rot silently. -
A later-page failure discards everything. If page 2 returns non-200 or the transport errors, the function returns
nil, err, andhandleListProviderModelsmaps any error torespond([]ModelInfo{}), so a tenant that already received 1000 models on page 1 gets an empty picker. Returning the collected models with a warning would degrade better. Unreachable in practice while the real catalog is ~20 entries andlimit=1000covers it in one page, but it is the one new failure mode this loop introduces. -
net/urlis now shadowed by the localurl := config.DockerLocalhost(base + "/api/tags")infetchOllamaModels, in this same file. It compiles and is legal Go, but the next person reaching forurl.Valuesin that function gets a confusing "url is not a package" error. Aliasing the import (neturl) or renaming that local keeps the file honest. -
limit=1000is a bare literal whileanthropicModelsMaxPagessits above as a named constant. AanthropicModelsPageSizenext to it would keep the pair readable and give the test something to assert against. -
No CHANGELOG entry. Unreleased → Fixed carries a per-fix line for user-visible bugs (see the #1627 entry), and "the Anthropic model picker only showed the first 20 models" is exactly that shape.
-
The loop guard covers a stalled cursor but not a duplicated page (upstream ignoring
after_idwhile advancinglast_id). Not required by the documented API — aseenset would be the belt-and-braces version if you want it.
Duplicate check: no open PR or issue proposes the same fix, no repo issue reports the 20-model symptom, and this is the first change to provider_models_fetch.go since the Requesty provider landed. The only overlap risk in the open set is 1639/1640, which add new provider types and do not touch this function.
No merge: zero check runs, no approving review, and the workflow gate on this head is still action_required.
— clark-cant (agent), 2026-11-03
Cap the test mock at 20 per page and assert the request count so the cursor is really exercised, keep earlier pages when a later page fails, alias net/url, name the page-size constant and add a CHANGELOG entry. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the careful review. Pushed a commit on top:
This comment was drafted with Claude Code. |
…-pagination # Conflicts: # CHANGELOG.md
clark-cant
left a comment
There was a problem hiding this comment.
Reviewed at 5a207e9 (merge of origin/dev into c0578-anthropic-models-pagination, dev at ed4ce88). This is the dev-sync commit the author pushed at 21:26Z; the last substantive review was at 0e901ba.
Verdict: approve. The merge adds nothing to the change and drops nothing from it.
What I checked on the merge itself:
- Effective diff unchanged.
git diff origin/dev...5a207e9cis still exactly three files, +175/−28 —CHANGELOG.md,internal/http/provider_models_fetch.go,internal/http/provider_models_fetch_test.go— byte-identical to the diff at 0e901ba. The dev sync brought in no unrelated churn and reverted none of the branch's own work. - The one conflict was resolved correctly.
CHANGELOG.mdconflicted because dev now carries the #1662 entry in the same Unreleased → Fixed block. The author kept both: the Anthropic pagination entry sits directly above the queued-run entry, each credited to its own fix, no entry lost and no duplicate section introduced. - Prior notes are all in. Named
anthropicModelsPageSize/anthropicModelsMaxPagesconstants,neturlimport alias sofetchOllamaModelscan keep its localurl, mock hard-capped at 20 per page with arequests != total/20assertion so the cursor is genuinely exercised, partial list retained when a later page fails, and the CHANGELOG line — all present at this head. - Executed at the merged head:
go test ./internal/http -run FetchAnthropicModels -count=1passes,gofmt -lon both changed files is empty.
I also approved the gated CI run for this head, so the checks are now real rather than action_required: web and release-versioning are green and go is running. That gate, not the diff, was the only thing standing between this PR and a merge since 2026-11-03.
Only open note carried forward, unchanged and non-blocking: the loop guards a stalled cursor but not a duplicated page (upstream ignoring after_id while still advancing last_id). A seen set would close it; the documented API does not need it.
— clark-cant (agent)
Summary
fetchAnthropicModelsmade a singleGET /v1/modelswith nolimitorafter_id. The Anthropic models API is paginated (20 per page by default, withhas_more/last_id), so the provider model selector only ever showed the first page. This requestslimit=1000and followsafter_idwhilehas_moreis true, with a page cap (20) so a misbehaving upstream cannot loop forever. Error handling and the empty-list result are unchanged.Type
main)Target Branch
devChecklist
go build ./...passesgo build -tags sqliteonly ./...passes (if Go changes)go vet ./...passes (go vet ./internal/http/passes)go test -race ./...(go test ./internal/http/ -run FetchAnthropicModelspasses)cd ui/web && pnpm build(if UI changes) — no UI changes$1, $2(no string concat) — no SQL changesinternal/upgrade/version.go(if new migration) — no migrationTest Plan
New
TestFetchAnthropicModelsFollowsPaginationserves 120 models in pages from anhttptestserver that mimics the API (default page size 20,limit,after_id,has_more,last_id) and expects all 120. Without the change it fails withgot 20 models, want 120; with it, it passes.This change was prepared with the help of an AI assistant (Claude Code), and the author is responsible for the change.
🤖 Generated with Claude Code