stacklok / stacklok/toolhive

CLI validation probe paginates entire catalog, causing timeout on large registries

Open
#4,452 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug cli registry
Dominant language
Go
Stars
2.2k
Forks
300
Avg merge
1d 15h
Merged PRs (30d)
184

Description

Summary

thv registry list times out with "context deadline exceeded" when the registry contains more than ~97 servers. The CLI's validation probe inadvertently paginates the entire catalog instead of fetching a single page.

Root cause

When creating an APIRegistryProvider, the CLI runs a validation probe (provider_api.go:62):

_, err = client.ListServers(ctx, &api.ListOptions{Limit: 1})

The intent is to fetch one server to verify the API works. However, ListServers always paginates through the entire catalog — Limit only controls page size, not total results. The method loops until nextCursor is empty (client.go:134-146):

for {
    servers, nextCursor, err := c.fetchServersPage(ctx, cursor, opts)
    // ...
    if nextCursor == "" {
        break
    }
    cursor = nextCursor
}

With Limit: 1 and 100+ servers, the probe makes 100+ sequential HTTP requests, exceeding the 10-second context timeout.

Reproduction

# Point at a registry with 50+ servers (e.g. the full ToolHive catalog)
thv config set-registry https://registry.example.com/registry/toolhive
thv registry list
# Error: failed to get registry provider: custom registry API at
# https://registry.example.com/registry/toolhive is not reachable:
# API endpoint not functional: failed to fetch servers: context deadline exceeded

The registry endpoint itself works fine via curl — this is purely a client-side issue.

Affected versions

Confirmed on v0.12.4 and current main (v0.13.1).

Suggested fix

The validation probe should fetch one page, not paginate the entire catalog. Options:

  1. Call fetchServersPage directly instead of ListServers (currently unexported)
  2. Add a MaxPages or NoPaginate option to ListOptions
  3. Use a simpler health check (e.g. confirm a 200 with valid JSON from a single request)

Related

  • stacklok/ai-toolkit#78 (tracking issue from PoC deployment)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at provider_api.go:62, where APIRegistryProvider performs the validation probe, then trace ListServers in client.go:134-146 and its pagination behavior. Reproduce with a registry containing 50+ servers and compare the probe's requests; done means validation fetches only one page and does not time out on a large catalog.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.