Repository navigation
fix(auth): follow nextToken when listing IdC Kiro profiles - #29398
Conversation
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: both first-page-only Notes
[DESIGN-REVIEWED] a35e309 Description read[DESCRIPTION-READ] e247dde97f2a959fa6aab30d457a7e3aa4c68bcf4e2785a93fc186ba38009bc2 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix is aimed at the mechanism (first-page-only reads), but the cause in the field is still a guess: the description says the empty-first-page response was never observed. Notes
What this change shipsInventory (7 items) — 4 justifiedIntent: let an IdC user whose Kiro profile is not on the first page of results sign in to Kiro Agent through Crew. FIX.
[FIRST-PRINCIPLES-REVIEWED] a35e309 Description read[DESCRIPTION-READ] 476199b4ce41d1df30ac859dcb2e7d1a58bb2719ac3bc888f5e63bb755734da1 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
iamwhatever
left a comment
There was a problem hiding this comment.
Requesting changes for one untracked follow-up at f5677cd.
The pagination fix itself looks sound: list_available_profiles follows nextToken, stops at 20 pages, refuses a repeated token, and the new zero-profile warning carries no credential. CI is green and the GPT and Opus lanes report no findings.
Blocker: unfixed sibling with no linked issue. The First Principles note is correct: _list_profile_arn in dashboard/handlers/kiro_usage_api.py still posts one ListAvailableProfiles request and reads only page 1 (L706-L717). The same account this PR fixes would sign in, then get no profileArn for GetUsageLimits. The Pattern harvest line says this was the only first-page-only reader, which is not true. Please either follow nextToken there too, or open an issue for it, link it in the description, and correct the Pattern harvest line.
AI findings judged non-blocking
- Design Review: a later-page error now fails a sign-in that page 1 could have satisfied. Failing loud on a malformed listing is a deliberate, tested choice and a retry is available (control_plane.py L130-L163).
Note: this PR changes IdC sign-in code under src/kiro_crew/auth/, so it also needs a human maintainer's review once the follow-up is tracked.
— crew-pr-reviewer (r145)
f5677cd to
cf4ac42
Compare
cf4ac42 to
83778a6
Compare
|
Thanks @iamwhatever. Done in
|
bolichen97
left a comment
There was a problem hiding this comment.
Approving 83778a6. The sign-in profile listing now follows nextToken, and so does the usage reader, so an account whose profile is not on the first page is no longer reported as having none. The usage reader's loop is bounded (20 pages) and stops on a repeated token, and a failed or malformed page counts as a miss that is not cached. The change adds no regex and no new restriction, and all 97 checks pass on this head.
@iamwhatever, could you re-review? The blocker in your change request on f5677cd is fixed: _list_profile_arn in kiro_usage_api.py no longer reads only page 1. It loops over ListAvailableProfiles with the returned nextToken, up to _LIST_PROFILES_MAX_PAGES = 20, and gives up on a repeated token. test_kiro_usage_api.py adds a test that finds the profile on page 3 after an empty page and a non-matching one. The author's reply on the PR also covers it. Auto-merge is set on my approval and will land once your change request is cleared.
|
|
Backend Tests (3.12, 5/6), Backend Tests (Windows) (2/4) and Coverage Gate fail on test/test_wait_discipline_ratchet.py and test/test_updates_handlers_facade.py, which also fail on a clean origin/main (c6b537e); neither file is touched here. #35625 fixes both. This PR waits for it to merge, then rebases. |
Code change approver recommendation: A person should decideWhy: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, but it changes 545 lines, more than the 400 it may approve on its own. Both ListAvailableProfiles readers (IdC sign-in and the usage lookup) now follow nextToken. Each has a 20-page cap and refuses a repeated token. The usage lookup also checks its existing 30s deadline before each page. Sign-in keeps the existing rule that a host that refused leads to profile_lookup_failed, not no_kiro_profile. The changed return type's only production caller and its test fake are both updated. New tests cover a profile on page 2, the cap, a loop, bad later pages, the warning text and the deadline on all three usage entry points. The finished CI checks passed; four Windows shards were still running. The only gaps are a docs spec that wasn't updated and a duplicated page-cap constant, neither blocking. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
84e464f to
ea74b09
Compare
ea74b09 to
ecfd048
Compare
ecfd048 to
ef7d34c
Compare
ef7d34c to
a35e309
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Re-approving at a35e309. My approval on 83778a6 was dismissed by the new push. I read the whole product diff again: auth/login/control_plane.py, auth/service.py and the dashboard handler kiro_usage_api.py.
- The sign-in listing now follows
nextTokenpast empty pages, up to_MAX_PAGES = 20, and stops on a repeated token. Page parsing moved unchanged into_profiles_page, which also rejects a non-stringnextToken. On main, a first page with no profiles answeredno_kiro_profile. Now the next page is read. A loop or the page cap counts as a host failure, so the outcome is still a sign-in error, and no account that main signs in is refused. - An empty listing now logs the IdC region, the control plane(s) asked, the page count and the start URL. None of these is a credential.
- The usage reader pages the same way under the same cap. It now also respects the caller's 30 s deadline, and every failure is still an uncached miss.
No regex added, no new restriction, and nothing is live red (the cancelled GPT and SCR runs are superseded by newer passes).
Problem / Motivation
Goal: An IAM Identity Center sign-in to Kiro Agent finds the account's Kiro profile even when the control plane returns it after the first page of results.
A user's IdC device-code login was approved six times in a row, and every attempt ended with
IdC login has no available Kiro profiles. With the same start URL and region, kiro-cli finds the profile and signs in. Crew read only the first page ofListAvailableProfilesand ignorednextToken, while kiro-cli follows its paginator to the end. A paginated AWS API may answer page 1 with no items and a token, which Crew read as "no profiles". That this is what the service sent is a hypothesis: Crew never logged the response, so the failing case has not been observed directly.Why it matters
An enterprise user whose profile is not on the first page cannot sign in to Kiro Agent through Crew at all, even though kiro-cli works with the same account. The failure message also gave nothing to tell a wrong host or region apart from a real provisioning gap.
Not a goal
_CPS_ENDPOINTS/control_plane_url). fix(auth): resolve Kiro profiles by control-plane discovery, not region map #29049 reworks host discovery in the same file; this PR complements it (pagination vs host discovery) and keeps its diff inside the listing and the log line so either rebases onto the other.What changed (motivation → approach → change)
Profile lookup now reads every page, the way kiro-cli does, and an empty result says where it looked.
nextToken, profile on page 2profile_lookup_failed, saving nothing, unless another lists a profilelist_available_profilesinauth/login/control_plane.pyreturns aProfileListing(profiles, host, page count) soauth/service.pycan log the diagnostics. Since #32445, main asks every Kiro control plane in turn, the sign-in region's own first; this PR makes each host's read (_list_profiles_at) follownextToken, and keeps main's rules: a host that fails is skipped, and when any host failed and none listed a profile the sign-in ends asprofile_lookup_failed(#33590), never asno_kiro_profile, since the failing host may hold it. A host's read stops at the first page that lists a profile, because sign-in uses only the first profile, so a later page can never throw away a profile already found. Tokens and theAuthorizationheader are never logged; the start URL is validated bynormalize_start_urland carries no credential.The usage lookup had the same first-page-only read:
_list_profile_arnindashboard/handlers/kiro_usage_api.pyfinds theprofileArnthatGetUsageLimitsneeds, so the account this PR fixes would sign in and then show no credit numbers. It now followsnextTokenunder the same 20-page cap, stops on a repeated token, and checks the lookup's 30-second overall deadline before each page, so a slow paged listing ends in time for the text fallback. A failed or malformed page, a loop, the cap or an expired deadline reads as "no profile", is not cached, and is re-probed on the next refresh. The usage spec (docs/system-specs/modules/learn-cron-dashboard.md) records the per-page deadline.Backwards compatibility
Compatible: the sign-in flow, stored token shape and error codes are unchanged;
list_available_profileshas one production caller (auth/service.py), updated here, and its test double intest/test_kas_auth_whoami.pyis updated to the new return type.Removes nothing: the change adds pages to the lookup and fields to a log line; nothing that was accepted is now refused except malformed later pages, which did not exist before.
Tests
test/test_kas_login_service.py:nextToken, then a page with the profile: sign-in stores that profile ARN, and page 2 is requested with the token and the same bearer.profileslist, a non-object body, or a non-string token on page 2 discards that host's listing; with the other control plane listing nothing, the sign-in fails asprofile_lookup_failedand saves nothing.no_kiro_profile) names the region, both hosts that answered, the total page count and the start URL, and contains neither the access token norBearer.test/test_kiro_usage_api.py:fetch_usage_limitsand throughfetch_usage_limits_with_credential(which still reads usage).The ten new sign-in tests passed five times in file order and five times in reversed order (serial).
Proof: PROVEN test/test_kas_login_service.py::test_poll_idc_follows_next_token_past_an_empty_first_page, test/test_kas_login_service.py::test_list_available_profiles_refuses_a_repeated_token, test/test_kas_login_service.py::test_poll_idc_bad_later_page_is_error_and_saves_nothing[non-string-token], test/test_kas_login_service.py::test_poll_idc_zero_profiles_warning_names_region_host_pages_and_start_url, test/test_kiro_usage_api.py::TestListProfileArnCache::test_profile_on_a_later_page_is_found (head a35e309)
Manual verification
N/A — the control plane is faked at the HTTP session seam in unit tests; no live IdC account whose profile lands on page 2 is available. The new zero-profile warning is the field diagnostic if the problem persists.
Related Issues
None filed; the field report is in the Goal above.
Sibling sweep
Swept: git grep -nE "maxResults|nextToken|ListAvailable" -- src/
Sibling: src/kiro_crew/apps/builtins/aws_control/backend/backup_parts/catalog.py -- not affected -- it already follows nextToken across pages
Sibling: src/kiro_crew/apps/builtins/aws_control/backend/storage.py -- not affected -- it hands NextToken back to its caller, which pages
Sibling: src/kiro_crew/dashboard/handlers/kiro_usage_api.py -- changed here --
_list_profile_arnread only page 1 of ListAvailableProfilesPattern harvest
Not generalizable: the two first-page-only
ListAvailableProfilesreaders (sign-in and the usage lookup) are both fixed here; the other paginated AWS listings in src/ already follow or return their token.Checklist