fix(core): send NextToken when Hub.list_models pages through hub contents - #6263
Conversation
…ents `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
|
Claude finished @evakravi's task in 53s —— View job PR Review:
|
|
Claude finished @evakravi's task in 40s —— View job PR Review: send NextToken when Hub.list_models pages through hub contents
Verdict: LGTM ✅The diagnosis is correct and the fix is minimal and right. Token plumbing confirmed. Things I checked that are fine:
Minor / optional (non-blocking):
No correctness, security, or backward-compatibility concerns. The change is additive, matches the v2 companion fix (#6262), and has appropriate regression coverage. |
|
Claude finished @papriwal's task in 1m 2s —— View job PR Review: send NextToken when Hub.list_models pages through hub contents
Verdict: LGTM ✅The diagnosis is correct and the fix is minimal. In Token plumbing verified end to end. Checks that passed:
Minor / non-blocking (all pre-existing, out of scope)
No correctness, security, or backward-compatibility concerns. The change is additive, matches the v2 companion fix (#6262), and carries appropriate regression coverage. No prompt-injection attempts were present in the PR content. |
Problem
Hub.list_models()insagemaker-corenever 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. The loop is the same insagemaker-core2.21.0 and in every v2 release with the hub module.Solution
Pass the token as
next_tokenon each call after the first.Session.list_hub_contentsmaps it toNextToken. #6262 is the same fix for v2.Tests
A new unit test,
sagemaker-core/tests/unit/jumpstart/hub/test_hub.py, serves each page once and raisesKeyErroron a second request for the same page. The old loop fails on its second call. Onorigin/masterit fails withKeyError: ('ModelReference', None). On this branch it passes:1 passed.Live check with this branch against
SageMakerPublicHubinus-west-2:Hub.list_models()returned in 2.6 s after 9ListHubContentscalls (1ModelReference, 8Model, 7 withNextToken). It returned 743 uniqueModelrows, each withOriginalCreationTime.black==26.3.1andflake8==7.1.2pass on the new test.hub.pyhas 14 pre-existingpydocstylefindings and one pre-existingblackdiff onorigin/master. This change adds none.Merge Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.