Skip to content

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

Closed
Flolight wants to merge 2 commits into
kirodotdev:mainfrom
Flolight:fix/identity-oauth-flow-case
Closed

Flolight wants to merge 2 commits into
kirodotdev:mainfrom
Flolight:fix/identity-oauth-flow-case

Conversation

@Flolight

Copy link
Copy Markdown
Contributor

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 kirocli:odic:token blob 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

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 = {"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; the tests cover start_url and client_id. Chosen over dropping oauth_flow from the allowlist, which would lose a signal that currently distinguishes two logins.

Backwards compatibility

Compatible: the fingerprint is an in-memory digest compared within one process lifetime; its value changes once on upgrade (for every oauth_flow spelling), which is the same one-time effect as any restart, and nothing persists or rejects the old value.

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: 173 passed. scripts/local-gate.py: 2232 passed, 2 failed in test/test_kiro_prerequisite.py (test_timeout_without_a_runnable_candidate_is_still_not_installed, test_no_candidate_has_nothing_to_report); both fail identically on unmodified main on the same macOS machine, so they are environment-related and not caused by this diff. black, isort, flake8 clean; mypy --platform linux clean on the changed module.

Manual verification

N/A: unit coverage exercises the exact store shape. The casing flip itself was observed on a live store and is documented in #14979.

Related Issues

Fixes #14979. Related: #14605, #14609.

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.

Checklist

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

Contribution License Agreement

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 kirodotdev#14979
@Flolight
Flolight requested a review from a team as a code owner September 29, 2026 09:53
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of db9da7f8bff2a82d581aa4644a83e4beb0746599 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify CI runs test/test_kiro_prerequisite.py green — the two locally-failing tests live in the module this diff edits, and "fails on main too" is a local claim.

[DESIGN-REVIEWED] db9da7f

Description read

[DESCRIPTION-READ] c4b4457847f0611688daa26c1331bb274813f06e684d8e764f75e50b09921aee

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

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of db9da7f8bff2a82d581aa4644a83e4beb0746599 via the fork AI-review pipeline — 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

Verify the one premise: kiro-cli never distinguishes two real sign-in flows by casing alone — case-folding would silently merge them into one fingerprint.

What this change ships

Inventory (3 items) — 3 justified

Intent: FIX — stop a routine kiro-cli token refresh (which re-spells oauth_flow as PKCE/Pkce) from reading as an account switch and retiring idle chats and their running sub-agents (#14979, with a test that fails on base).

  1. A refresh that only re-spells oauth_flow no longer retires healthy sessions and their sub-agents — justified
  2. A genuine flow change (PKCE → device_code) still moves the fingerprint, pinned by a new test — justified
  3. identity_fingerprint's docstring now notes oauth_flow is compared without case — justified

The mechanism is one private constant plus one casefold() in _identity_claims; no existing normalization mechanism in the module does this job (grepped casefold|\.lower\(\) in kiro_prerequisite.py: 1 unrelated hit), no pin is deleted, all other claims keep exact comparison, and the upstream kiro-cli cause is declared out of scope in ## Not a goal.

[FIRST-PRINCIPLES-REVIEWED] db9da7f

Description read

[DESCRIPTION-READ] 7840ed7efb7cb77d0eb58403acbf73603cc7665e069e956b9eaaeccb5bf0b0b7

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

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed db9da7f8bff2a82d581aa4644a83e4beb0746599 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] db9da7f

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

Reviewed db9da7f8bff2a82d581aa4644a83e4beb0746599 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] db9da7f

@Flolight

Copy link
Copy Markdown
Contributor Author

Follow-up on the open question from the description: I ran the patched identity_fingerprint against a live sign-in store through an hourly token refresh. The unpatched fingerprint changed at the refresh, the patched one stayed the same, and no other claim moved.

The remaining red check, Backend Tests (Windows) shard 1, fails in test_apps_registry_coverage.py on two symlink-loop tests, which this change doesn't touch. Happy to look into it if it doesn't reproduce as flaky on main.

@Flolight

Copy link
Copy Markdown
Contributor Author

The Windows shard 1 failure reproduces on unrelated PRs today (same two tests in test_apps_registry_coverage.py, e.g. on papyrus-paper-titles and fix/markdown-link-parenthesised-url), so it looks inherited from main rather than caused by this change.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you for this fix, @Flolight — the case-insensitive oauth_flow comparison is a clean, well-targeted solution, and your tests cover it nicely.

To get it onto an in-repo branch where the full CI and review lanes run, the change now continues in #16925. Your original commits are carried over unchanged, so you keep full credit in the commit history (you remain the author of both commits). #16925 is rebased on current main and all automated checks are green; it's awaiting a maintainer review to merge.

Closing this PR in favour of #16925. Thanks again for the contribution and the thorough write-up!

@iamwhatever iamwhatever closed this Oct 5, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

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

2 participants