Skip to content

fix: compare oauth_flow without case in the identity fingerprint - #16925

Merged
iamwhatever merged 2 commits into
mainfrom
replace/oauth-flow-case-14998
Oct 5, 2026
Merged

iamwhatever merged 2 commits into
mainfrom
replace/oauth-flow-case-14998

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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_run sub-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 (PKCE and Pkce, minutes apart, on one unchanged login — timeline in #14979). oauth_flow is one of the allowlisted stable claims in identity_fingerprint, and _identity_claims hashes 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_flow spelling lose long-running spawn_run work 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

  • Treating a chat with running sub-agents as busy rather than idle during a genuine account change. Separate behaviour change.
  • Logging which claim moved when the fingerprint changes.
  • Normalising casing in kiro-cli itself.

What changed (motivation → approach → change)

  • Symptom: sub-agents die roughly hourly with "provider shutdown" although the account never changed.
  • Root cause: oauth_flow is compared byte-exact, and its spelling alternates between refreshers.
  • Change: a new _CASE_INSENSITIVE_CLAIM_FIELDS = frozenset({"oauth_flow"}); _identity_claims case-folds those values before hashing. oauth_flow stays 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 dropping oauth_flow from 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_flow spelling), 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, pkce give one fingerprint. Fails on main, passes with the fix.
  • test_an_oauth_flow_change_is_still_detected: PKCE to device_code still changes it.
  • test_start_url_and_client_id_stay_case_sensitive: case changes in client_id or start_url still 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_flow is the only allowlisted claim that is a label rather than an identifier, and the allowlist is already the guard for new fields.

@iamwhatever
iamwhatever requested a review from a team as a code owner October 5, 2026 06:46
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 573f136b793ce8423499475c1546186c599ce999 — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check that #14979's timeline shows only casing drift; a different spelling like pkce_flow would still look like an account change.

What this change ships

Inventory (3 items) — 3 justified

Intent: 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.

  1. A refresh that only changes the case of oauth_flow (PKCE/Pkce) no longer changes the identity fingerprint, so idle chats stay alive — justified
  2. A real change of sign-in flow (PKCE to device code) still changes the fingerprint — justified
  3. Every other identity claim (start_url, client_id, region, scopes) is still compared case-sensitively — justified

[FIRST-PRINCIPLES-REVIEWED] 573f136

Description read

[DESCRIPTION-READ] 90fe166eb0f38b324f9fd1c5cc19ba419da4967a96872e839561b0503d292191

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 Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 573f136b793ce8423499475c1546186c599ce999 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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 .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 Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 573f136

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 573f136b793ce8423499475c1546186c599ce999: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 573f136

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 573f136b793ce8423499475c1546186c599ce999: <one-sentence reason>

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
@iamwhatever
iamwhatever force-pushed the replace/oauth-flow-case-14998 branch from 359ed76 to 573f136 Compare October 5, 2026 07:41
@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 Oct 5, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Self-review (crew-pr-reviewer, read-only): RECOMMEND APPROVE

The fix is minimal and correct. Only the oauth_flow label is case-folded, and every identifying claim (start_url, client_id, region, scopes, key names) still compares exactly, so case-folding can't merge two real accounts. The baseline is in memory and re-seeded at startup, so the hash change won't cause a one-time sweep on upgrade. The casing test fails on the old code, and the two guard tests confirm a real flow change and identifier case still count. Approve.

@buluoray buluoray 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.

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_change fails.
  • Case-fold applied to every claim: test_start_url_and_client_id_stay_case_sensitive fails. This is the guard against merging identities.
  • test_an_oauth_flow_change_is_still_detected passes 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:2163 comment lists oauth_flow among 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_flow would 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 by client_id/start_url. Does not gate.
  • Opus / GPT: no findings.

@iamwhatever
iamwhatever merged commit 396c2a2 into main Oct 5, 2026
98 checks passed
@iamwhatever
iamwhatever deleted the replace/oauth-flow-case-14998 branch October 5, 2026 18:16
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hourly kiro-cli token refresh reads as an account switch (oauth_flow changes case), identity sweep kills running spawn_run sub-agents

3 participants