Repository navigation
fix: compare oauth_flow without case in the identity fingerprint - #16925
Conversation
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check that #14979's timeline shows only casing drift; a different spelling like What this change shipsInventory (3 items) — 3 justifiedIntent: stop a routine kiro-cli token refresh from looking like an account switch, which retires idle chats and their sub-agents. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 573f136 Description read[DESCRIPTION-READ] 90fe166eb0f38b324f9fd1c5cc19ba419da4967a96872e839561b0503d292191 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Before merge, confirm that no kiro-cli build writes two genuinely different flows whose names differ only by case. [DESIGN-REVIEWED] 573f136 Description read[DESCRIPTION-READ] 91bf99438236a2e38f3c79a258056889d5c26f6031320b78c38512ce3627fece 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 |
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: |
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: |
kiro-cli's token refreshers serialise the same sign-in flow with different casing (PKCE and Pkce, minutes apart on one login). The fingerprint hashed the raw spelling, so a routine refresh read as an account change and the next turn's identity sweep retired idle chats together with their running spawn_run sub-agents. Case-fold oauth_flow before hashing. A genuine flow change still moves the fingerprint, and identifiers (start_url, client_id) stay exact. Refs #14979
359ed76 to
573f136
Compare
|
Self-review (crew-pr-reviewer, read-only): RECOMMEND APPROVE The fix is minimal and correct. Only the |
buluoray
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Reviewed at 573f136.
No blocking findings.
What I verified
Case-folding is limited to one claim. It applies only to oauth_flow (src/kiro_crew/kiro_prerequisite.py:451, _CASE_INSENSITIVE_CLAIM_FIELDS = frozenset({"oauth_flow"})), and runs at kiro_prerequisite.py:1811-1812 after list normalisation and before hashing. All other allowlisted claims are still hashed byte-exact: client_id, region, scopes, start_url (:436-444). So are the key names.
It can't merge two different identities. oauth_flow names the sign-in method. It does not identify an account. For two different accounts to share a fingerprint after this change, they would need identical start_url, client_id, region, scopes and key names, and differ only in flow spelling. client_id is the OIDC registration, so it already separates two logins. The flow values the code knows about are PKCE/Pkce (the casing drift reported in #14979) and DeviceCode/device_code (apps/builtins/aws_control/.../kiro_login.py:135-140). No two of them differ only by case. A real flow change (PKCE to device code) still moves the fingerprint.
Failure direction. The change makes the detector less sensitive in exactly one dimension: case differences in a non-identifying label. That doesn't open any path for a real account switch to go undetected. The fingerprint is compared in memory against the process's own baseline (kiro_prerequisite.py:3572, :3606). Grepping session-map and store modules found no persisted fingerprint, so the one-time hash change on upgrade can't trigger a sweep. I took "re-seeded at startup" from the code path above rather than reproducing it.
Mutations (test/test_external_logout_detection.py::TestIdentityFingerprint, worktree restored after each run, git status clean):
- Case-fold removed:
test_oauth_flow_casing_is_not_an_account_changefails. - Case-fold applied to every claim:
test_start_url_and_client_id_stay_case_sensitivefails. This is the guard against merging identities. test_an_oauth_flow_change_is_still_detectedpasses in both cases, as expected.
CI on head: 86 pass, 12 skipped, 0 failing. Auto-merge is off.
Non-blocking follow-ups
- Comment wording. The
hooks.py:2163comment listsoauth_flowamong the participating claims. Consider adding "(case-insensitive)" so the two lists stay in sync. - Other spelling drift. If kiro-cli ever drifts by more than case (
pkce_flow,PKCE_FLOW), this fix won't cover it. That is acceptable scope. A canonicalising map would be the next step if it is ever seen.
Bot concern dispositions
- First Principles (PASS): "#14979 shows only casing drift;
pkce_flowwould still look like a change." Agreed and intended, so it does not gate. Recorded as a follow-up above. - Design (PASS): "confirm no kiro-cli build writes two genuinely different flows differing only by case." Checked the flow values present in the repo (
PKCE/Pkce,DeviceCode/device_code): none collide under casefold. Even a collision would be caught byclient_id/start_url. Does not gate. - Opus / GPT: no findings.
In-repo continuation of #14998 by @Flolight. The original commits are preserved with their authorship, so credit stays in the commit history.
Problem / Motivation
Goal: A routine kiro-cli token refresh no longer reads as an account switch, so idle chats and their running
spawn_runsub-agents stop being retired about once an hour.kiro-cli's token refreshers write the same sign-in flow into the auth store with different casing (
PKCEandPkce, minutes apart, on one unchanged login — timeline in #14979).oauth_flowis one of the allowlisted stable claims inidentity_fingerprint, and_identity_claimshashes its raw spelling. The fingerprint therefore changes on those refreshes, and the next turn in any chat runs the identity sweep, which retires every idle chat and cancels the sub-agents it launched ("provider shutdown").Why it matters
Users whose kiro-cli refreshers alternate the
oauth_flowspelling lose long-runningspawn_runwork sessions without warning as soon as they use another chat after a refresh. On the reporter's machine this killed two running sub-agents in one afternoon, and the value flipped three times in 95 minutes. #14609 does not cover it: the chat was started under the pre-flip fingerprint, so it is still retired.Not a goal
What changed (motivation → approach → change)
oauth_flowis compared byte-exact, and its spelling alternates between refreshers._CASE_INSENSITIVE_CLAIM_FIELDS = frozenset({"oauth_flow"});_identity_claimscase-folds those values before hashing.oauth_flowstays in the allowlist, so a real flow change (PKCE to device code) still moves the fingerprint. All other claims (start_url,client_id,region,scopes) keep exact comparison. Chosen over droppingoauth_flowfrom the allowlist, which would lose a signal that currently distinguishes two logins.Backwards compatibility
Removes nothing: the fingerprint is an in-memory digest compared within one process lifetime; its value changes once on upgrade (for every
oauth_flowspelling), the same one-time effect as any restart. Nothing persists or rejects the old value, and no field, key, or reader is removed, renamed, or tightened.Tests
In
test/test_external_logout_detection.py::TestIdentityFingerprint:test_oauth_flow_casing_is_not_an_account_change:PKCE,Pkce,pkcegive one fingerprint. Fails onmain, passes with the fix.test_an_oauth_flow_change_is_still_detected:PKCEtodevice_codestill changes it.test_start_url_and_client_id_stay_case_sensitive: case changes inclient_idorstart_urlstill change it.test/test_external_logout_detection.py::TestIdentityFingerprint: 22 passed on the current base (Python 3.12).Related Issues
Fixes #14979
Continues #14998 by @Flolight; the original author keeps credit in the commit history.
Pattern harvest
Not generalizable:
oauth_flowis the only allowlisted claim that is a label rather than an identifier, and the allowlist is already the guard for new fields.