fix(jumpstart): send NextToken when Hub.list_models pages through hub contents - #6262
Open
evakravi wants to merge 1 commit into
Open
fix(jumpstart): send NextToken when Hub.list_models pages through hub contents#6262evakravi wants to merge 1 commit into
evakravi wants to merge 1 commit into
Conversation
… contents `Hub._list_and_paginate_models` reads `NextToken` from each `list_hub_contents` response but never sends it, so every call requests the first page. On a hub with more than one page the loop never ends. `Hub.list_models()` on `SageMakerPublicHub` (743 models) ran for 5 minutes without a result. Pass the token as `next_token` on each call after the first. `Session.list_hub_contents` maps it to `NextToken`. --- X-AI-Prompt: Why does Hub.list_models never return on SageMakerPublicHub, and how do we fix the pagination? X-AI-Tool: claude-code
5 tasks
Narrohag
approved these changes
Sep 11, 2026
e-davidson
approved these changes
Sep 11, 2026
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.
Problem
Hub.list_models()never returns on a hub with more than one page of contents.Hub._list_and_paginate_modelsreadsNextTokenfrom eachlist_hub_contentsresponse but never sends it, so every call requests the first page and the loop never ends. OnSageMakerPublicHub(743 models, 8 pages of 100) the call ran for 5 minutes without a result. Every 2.x release with the hub module (2.224.1 through 2.257.6) has the same loop.Solution
Pass the token as
next_tokenon each call after the first.Session.list_hub_contentsmaps it toNextToken. #6263 is the same fix for v3.Tests
A unit test serves each page once and raises
KeyErroron a second request for the same page. The old loop fails on its second call. Onorigin/master-v2it fails withKeyError: ('ModelReference', None). On this branchtests/unit/sagemaker/jumpstart/hub/test_hub.pypasses:10 passed.Live check with this branch against
SageMakerPublicHubinus-west-2:Hub.list_models(max_results=100)returned in 2.8 s after 9ListHubContentscalls (1ModelReference, 8Model, 7 withNextToken). It returned 743 uniqueModelrows, each withOriginalCreationTime.black==24.3.0,flake8==7.1.2, andpydocstyle==6.1.1pass on the two changed files.Merge Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.