Skip to content

fix(auth): follow nextToken when listing IdC Kiro profiles - #29398

Merged
bolichen97 merged 2 commits into
mainfrom
fix/kas-idc-profiles-pagination
Nov 12, 2026
Merged

bolichen97 merged 2 commits into
mainfrom
fix/kas-idc-profiles-pagination

Conversation

@kyleseaman

@kyleseaman kyleseaman commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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 of ListAvailableProfiles and ignored nextToken, 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

  • Changing which control-plane host is asked (_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.
  • Choosing between several profiles. The first one still wins, as before.

What changed (motivation → approach → change)

Profile lookup now reads every page, the way kiro-cli does, and an empty result says where it looked.

Before After
Page 1 empty with a nextToken, profile on page 2 sign-in fails, "no available Kiro profiles" page 2 is fetched and its profile ARN is stored
Several pages, profile on a later one only page 1 seen pages are read until one lists a profile; that page is used and later pages are not requested
A service that keeps returning new tokens n/a (one request) stops after 20 pages with a coded error
A token the service already sent n/a refused at once as a loop
A bad page (non-200, malformed body, non-string token) before any profile n/a that control plane's listing is discarded; the next one is asked, and the sign-in fails with profile_lookup_failed, saving nothing, unless another lists a profile
Zero profiles after the last page bare warning warning names the IdC region, every control-plane host that answered, total pages read and start URL

list_available_profiles in auth/login/control_plane.py returns a ProfileListing (profiles, host, page count) so auth/service.py can 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) follow nextToken, 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 as profile_lookup_failed (#33590), never as no_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 the Authorization header are never logged; the start URL is validated by normalize_start_url and carries no credential.

The usage lookup had the same first-page-only read: _list_profile_arn in dashboard/handlers/kiro_usage_api.py finds the profileArn that GetUsageLimits needs, so the account this PR fixes would sign in and then show no credit numbers. It now follows nextToken under 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_profiles has one production caller (auth/service.py), updated here, and its test double in test/test_kas_auth_whoami.py is 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:

  • an empty first page with 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.
  • an empty page, then a page with profile A and a token, then a page with B: only A is returned after 2 requests; a single page makes exactly one request.
  • page 1 lists a profile and carries a token while page 2 would answer 500: the sign-in stores that profile and page 2 is never requested.
  • the 20-page cap stops a token loop after exactly 20 requests on that host; a repeated token is refused after 3 (the other control plane refuses in both tests, so the error is raised).
  • after an empty first page with a token, a non-200, a body with no profiles list, 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 as profile_lookup_failed and saves nothing.
  • the zero-profile warning (code no_kiro_profile) names the region, both hosts that answered, the total page count and the start URL, and contains neither the access token nor Bearer.

test/test_kiro_usage_api.py:

  • a profile on page 3, after an empty page and a non-matching page, is found, each later request carries the previous page's token, and its display name is cached.
  • a repeated token stops after 2 requests and caches nothing; the 20-page cap stops after exactly 20 requests.
  • an expired deadline stops the listing after one request and caches nothing, on the direct call, through fetch_usage_limits and through fetch_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_arn read only page 1 of ListAvailableProfiles

Pattern harvest

Not generalizable: the two first-page-only ListAvailableProfiles readers (sign-in and the usage lookup) are both fixed here; the other paginated AWS listings in src/ already follow or return their token.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@kyleseaman
kyleseaman requested review from a team and KiroCrewCaptain as code owners November 4, 2026 00:09
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of a35e309cc7f9659ac6a0fa5ad4f82d4b26cfd1db and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a35e309

False positive or not applicable? A repository writer can comment:
/ai-review override gpt a35e309cc7f9659ac6a0fa5ad4f82d4b26cfd1db false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision a35e309cc7f9659ac6a0fa5ad4f82d4b26cfd1db touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of a35e309cc7f9659ac6a0fa5ad4f82d4b26cfd1db — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: both first-page-only ListAvailableProfiles readers now follow nextToken with a page cap and loop guard, and the one changed return type has no other readers.

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a35e309cc7f9659ac6a0fa5ad4f82d4b26cfd1db — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • Item 1 — inherited: the field defect rests on "That this is what the service sent is a hypothesis: Crew never logged the response". The tests show that pagination works. They don't show that it was the user's failure. Item 3's log line is the only check, and it only runs after this merges.
  • Item 5 — duplicate of src/kiro_crew/auth/login/control_plane.py:_MAX_PAGES: _LIST_PROFILES_MAX_PAGES = 20 is commented "the same bound as the sign-in listing's" but is a second copy that can drift. Subtraction: delete it and use control_plane._MAX_PAGES.

What this change ships

Inventory (7 items) — 4 justified

Intent: let an IdC user whose Kiro profile is not on the first page of results sign in to Kiro Agent through Crew. FIX.

  1. IdC sign-in reads later ListAvailableProfiles pages until one lists a profile — justified
  2. The listing stops after 20 pages, or at a repeated token, with an error — justified
  3. The zero-profile warning names the IdC region, the hosts asked, the pages read and the start URL — rides along (the Goal's "Why it matters" covers it)
  4. A bad later page now fails that host's listing, which ends as profile_lookup_failed — justified
  5. The dashboard usage lookup follows nextToken with the same 20-page cap, as a separate constant — rides along, duplicate of control_plane._MAX_PAGES
  6. The usage lookup checks its 30-second deadline before each page, including for vault credentials — justified
  7. A new ProfileListing return type (profiles, host, page count) with one production caller — rides along

[FIRST-PRINCIPLES-REVIEWED] a35e309

Description read

[DESCRIPTION-READ] 476199b4ce41d1df30ac859dcb2e7d1a58bb2719ac3bc888f5e63bb755734da1

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed a35e309cc7f9659ac6a0fa5ad4f82d4b26cfd1db — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] a35e309

Verdict parsed from the review's SHA-scoped output markers for commit a35e309cc7f9659ac6a0fa5ad4f82d4b26cfd1db.

False positive or not applicable? A repository writer can comment:
/ai-review override fable a35e309cc7f9659ac6a0fa5ad4f82d4b26cfd1db false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 4, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 4, 2026
@kyleseaman
kyleseaman force-pushed the fix/kas-idc-profiles-pagination branch from f5677cd to cf4ac42 Compare November 6, 2026 19:05
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@kyleseaman
kyleseaman force-pushed the fix/kas-idc-profiles-pagination branch from cf4ac42 to 83778a6 Compare November 6, 2026 22:52
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@kyleseaman

Copy link
Copy Markdown
Contributor Author

Thanks @iamwhatever. Done in 83778a6908b60c5410b7c8b2f48ac38820fb972a: _list_profile_arn in dashboard/handlers/kiro_usage_api.py now follows nextToken too, under the same 20-page cap as the sign-in listing, and stops on a repeated token. A failed or malformed page, a loop or the cap is still a miss that is not cached and is re-probed on the next refresh, as before.

  • Tests in TestListProfileArnCache: the profile on page 3 (after an empty page and a non-matching one) is found and each later request carries the previous token; a repeated token stops after 2 requests and caches nothing; the cap stops after exactly 20 requests. All three fail on the old one-page reader.
  • The description's Sibling sweep now lists kiro_usage_api.py as fixed here, and the Pattern harvest line is corrected.

bolichen97
bolichen97 previously approved these changes Nov 7, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bolichen97
bolichen97 enabled auto-merge (squash) November 7, 2026 06:43
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 11, 2026
@kyleseaman

Copy link
Copy Markdown
Contributor Author
  • span=a8f78d298c62 Pagination bypasses the usage lookup's aggregate deadline

fixed in 84e464f: _list_profile_arn takes a monotonic deadline and checks it before every page request; an expired deadline is an uncached miss.
fetch_usage_limits passes its existing 30s aggregate deadline; fetch_usage_limits_with_credential sets its own 30s deadline for both of its listing calls. Those are the only callers.
Tests in test/test_kiro_usage_api.py (deadline stops pagination; fetch and vault paths pass it) fail with the production change reverted.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 12, 2026
@kyleseaman

Copy link
Copy Markdown
Contributor Author

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.

@KiroCrewCaptain

KiroCrewCaptain commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: 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 a35e309cc7 · 545 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@kyleseaman
kyleseaman force-pushed the fix/kas-idc-profiles-pagination branch from 84e464f to ea74b09 Compare November 12, 2026 02:34
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 12, 2026
@kyleseaman
kyleseaman force-pushed the fix/kas-idc-profiles-pagination branch from ea74b09 to ecfd048 Compare November 12, 2026 04:56
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 12, 2026
@kyleseaman
kyleseaman force-pushed the fix/kas-idc-profiles-pagination branch from ecfd048 to ef7d34c Compare November 12, 2026 05:45
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 12, 2026
@kyleseaman
kyleseaman force-pushed the fix/kas-idc-profiles-pagination branch from ef7d34c to a35e309 Compare November 12, 2026 06:10
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 12, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nextToken past 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-string nextToken. On main, a first page with no profiles answered no_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).

@bolichen97
bolichen97 merged commit d9ae339 into main Nov 12, 2026
102 of 114 checks passed
@bolichen97
bolichen97 deleted the fix/kas-idc-profiles-pagination branch November 12, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants