Skip to content

fix(usage): show Kiro credits under API-key auth - #25434

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
kirankumar15:fix/kiro-usage-api-key
Oct 29, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
kirankumar15:fix/kiro-usage-api-key

Conversation

@kirankumar15

@kirankumar15 kirankumar15 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Show real Kiro credit usage in the account widget for API-key sign-ins, the same as it does for SSO.

When you sign in to the Kiro backend with an API key, the account widget said "Account details unavailable / Credit usage isn't available for API key authentication" and never showed a number. /usage in the Kiro CLI returns the real balance for the same API-key account, so the data is reachable; the gateway just refused to fetch it.

Why it matters

Every API-key user sees a permanent "unavailable" message instead of their credits. It reads as a broken widget, and it hides the one number (balance, plan, reset date) the panel exists to show. The data was always obtainable.

Not a goal

  • Making the RTS GetUsageLimits API work with an API key. It cannot: an API-key account has no SSO/OIDC bearer token, so that call returns 403. This PR routes around it, it does not fix it.
  • Changing how SSO / Builder ID accounts fetch usage. They keep the API path.

What changed (motivation → approach → change)

The usage refresh ran kiro-cli whoami, saw accountType=ApiKey, and published an available: false, reason: api_key_auth marker before trying anything. The premise was that such accounts have no usable credential, so neither the API nor the scrape could help.

That premise was half right. The API path genuinely cannot work (no bearer token). But the /usage text scrape does work for API-key accounts: kiro-cli answers /usage locally from its own authenticated client, so the credit table prints under API-key auth exactly as it does for SSO. The gateway already pins that scrape to the v2 engine (where /usage runs as a command, not a model prompt) and already parses its output.

So the fix, in src/kiro_crew/dashboard/handlers/sessions.py, replaces the fast-fail with a skip_usage_api flag: an API-key account skips only the always-403 API call and falls through to the existing /usage scrape, which supplies the real number. The scrape's own engine selection (choosing --agent-engine v2, where /usage runs as a local command) is handled by the existing probe in usage_scrape.py and is untouched here — this PR only lets API-key accounts reach that scrape. The SSO / Builder-ID path is unchanged: the existing GetUsageLimits API call simply moves into the else branch of the new flag, so a non-API-key account runs exactly the code it ran before. With the backend no longer emitting api_key_auth, the frontend's 'api-key' usage state became unreachable, so this PR removes it rather than leave dead code: the sentinel and its render branches in website/src/shell/topbar/kiroUsageReadout.tsx and website/src/components/KiroAccountModal.tsx, the mapping in website/src/api/kiroUsage.ts and the doc comment in website/src/api/client.ts, and its two now-dead strings from every catalog under website/src/i18n/locales/. Frontend tests under website/src/test/ drop the removed assertions, and the dev screenshot script website/scripts/capture-credit-pill-states.mjs drops its now-dead api-key scenario. An API-key account now resolves to an ordinary credit reading. The two owning specs are updated to match the new behaviour: docs/system-specs/modules/learn-cron-dashboard.md describes the API-key carve-out (API call skipped, scrape runs, an unproven agreement publishes only when the whoami on both sides of the scrape is itself an API-key sign-in, and any other case discards) and drops its old "never for api-key" clause, and docs/system-specs/modules/kas-auth.md replaces the ApiKey "must fail-fast on usage/credit APIs" lesson with the skip-API-use-scrape behaviour.

Backwards compatibility

Compatible: no field is rejected, renamed or removed from any wire payload; the reason string api_key_auth simply stops being produced.

Removes nothing: the only removal is the frontend 'api-key' usage sentinel, which is internal UI state with no external consumer. No gateway payload shape, config key, or public function changes. The reason field still exists and still carries signin_required / account_unproven.

Tests

TestApiKeyAuthUsesScrape (renamed from TestApiKeyAuthFailFast) asserts an ApiKey whoami skips the API (fetch_usage_limits not called) yet runs the scrape and publishes the parsed credits, across every respelling of the enum. test_api_key_auth_with_no_identity_publishes_the_scrape covers the no-identity API-key shape (whoami returns only {account_type: ApiKey}, no email): the scrape's unproven whoami agreement must still PUBLISH, since the scrape is kiro-cli's own /usage for the signed-in key and cannot be another account's. A genuine mid-scrape account switch (different) still discards. Frontend tests drop the removed 'api-key' assertions and keep the no-handoff split on the remaining account-only state.

Proof: PROVEN test/test_session_usage.py::TestApiKeyAuthUsesScrape::test_api_key_auth_skips_api_but_scrapes, test/test_session_usage.py::TestApiKeyAuthUsesScrape::test_api_key_auth_with_no_identity_publishes_the_scrape, test/test_session_usage.py::TestApiKeyAuthUsesScrape::test_account_type_comparison_tolerates_respelling[apikey], test/test_session_usage.py::TestApiKeyAuthUsesScrape::test_account_type_comparison_tolerates_respelling[APIKEY], test/test_session_usage.py::TestApiKeyAuthUsesScrape::test_account_type_comparison_tolerates_respelling[ ApiKey ] (head 6f9db4d)

Manual verification

Confirmed in the real UI: built the frontend, ran the gateway, and the Kiro Account widget shows a live balance for an API-key sign-in (KIRO CREDIT POOLING, ~903 / 4777, ~19%, resets 2026-11-01) where it previously said "Credit usage isn't available for API key authentication". Also ran the real _fetch_usage_bg from this branch against the live account: before the fix it published {available: false}; after, a full reading matching the CLI's own /usage and the GetUsageLimits-backed IDE meter. The value refreshes on the existing 10-minute cache timer, not just once. The raw API key is not a valid RTS bearer (confirmed 403), which is why the API path is skipped rather than fixed. SSO / Builder-ID accounts were regression-checked: the existing usage suites (API-first path, refresh timer, scrape fallback, account-unproven, signin-required) pass unchanged.

Screenshots / video

Why no screenshot: the frontend diff only removes the unreachable 'api-key' state; a reachable API-key account now renders through the ordinary credit-reading path, which existing KiroAccountModal tests already cover.

Sibling sweep

Siblings: none -- the fast-fail that hid usage existed at exactly one site (the account_type == "apikey" branch in _fetch_usage_bg), and the frontend 'api-key' sentinel it fed had one producer (kiroUsage.ts) and the render branches removed here; no other auth type short-circuits the usage fetch.

Pattern harvest

Not generalizable: a single correct-looking guard built on one unchecked premise ("API-key auth has no usable credential source") that was half true -- the API path cannot work, but the /usage scrape can. The defect is the specific premise, not a repeatable code shape a linter could catch; the guard against it is testing a fast-fail's assumption against each fallback path it skips, which is a review habit rather than an automatable rule.

Closes #17443

@kirankumar15
kirankumar15 requested review from a team and KiroCrewCaptain as code owners October 28, 2026 21:15
@github-actions github-actions Bot added readiness: checking Automated validation is still running fork Pull request from a fork (external contributor) labels Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of 6f9db4d222da18a81b53b93aade0a77204487f42 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The frontend change only deletes the API-key "unavailable" state and its strings. It adds no control, and API-key accounts now use the existing credit display.

[UX-REVIEWED] 6f9db4d

Description read

[DESCRIPTION-READ] 99dbfd2c505eedd95a0f4f16a7f54cfe958ed2bb69fe714b7779bf1701e1572a

That sha256 names everything this verdict read: the PR description, plus the 3 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 28, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 6f9db4d222da18a81b53b93aade0a77204487f42 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the fix is aimed at the real cause, and every reader of the removed api_key_auth / 'api-key' state is updated in this patch.

Notes

  • The ApiKey unproven carve-out cannot see a switch between two different API keys made during the scrape (both sides read {"accountType":"ApiKey"}). The spec text should name this as a known gap instead of saying the reading "describes that account by construction".
  • The deleted test_api_key_auth_never_spawns_the_scrape was there to stop a scrape that cost credits. On an unpinned or V3 host the argv drops --agent-engine, so API-key accounts now pay up to 3 model turns before the back-off parks the scrape. Accept that cost or state it in the spec.

[DESIGN-REVIEWED] 6f9db4d

Description read

[DESCRIPTION-READ] 4a6e54e1d71ad9b7182f6ba26f6c0790e657a7f7d697999331abb6500e0e2169

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 28, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 6f9db4d222da18a81b53b93aade0a77204487f42 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. This is a fix for #17443, and the test that was deleted is reversed openly, backed by a live API-key reading and a 403 on the API call.

What this change ships

Inventory (7 items) — 7 justified

Intent: let a user who signs in with an API key see their real Kiro credit balance in the account widget. FIX.

  1. API-key sign-ins now show a live credit reading from the /usage scrape instead of "unavailable" — justified
  2. API-key sign-ins still skip the GetUsageLimits call, and a missing reading no longer tells the user to sign in again — justified
  3. The identity check now accepts an unproven scrape when the whoami on both sides of it reports an API-key sign-in — justified
  4. The pill and modal no longer show "Credit usage isn't available for API key authentication", which nothing produces any more — justified
  5. Its two strings are removed from all 13 locale catalogs — justified
  6. The dev screenshot script drops its api-key scenario — justified
  7. kas-auth.md and learn-cron-dashboard.md now describe the scrape route for API-key sign-ins — justified

[FIRST-PRINCIPLES-REVIEWED] 6f9db4d

Description read

[DESCRIPTION-READ] abc6bc67cd7cc3ff54b582fb41596ea0c9d8db55ff43db5cbc82ee8be2bc93b3

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 28, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] 6f9db4d

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 6f9db4d

@kirankumar15
kirankumar15 force-pushed the fix/kiro-usage-api-key branch from 6cea6a2 to f1bb565 Compare October 28, 2026 21:44
@bolichen97

Copy link
Copy Markdown
Contributor

Thanks for this. The backend change reads well: an ApiKey account now skips only the GetUsageLimits call that can only return 403, synthesizes a neutral AUTH_OTHER result so a later empty reading does not advise signing in again, and falls through to the existing bracketed /usage scrape. The frontend removal of the now-unreachable 'api-key' state and its strings is clean.

The branch currently conflicts with main. #25309 merged today and replaced USAGE_SCRAPE_ENGINE_PIN_MIN_VERSION with a probe of kiro-cli chat --help: the scrape pins --agent-engine v2 whenever the binary lists it, and _run_scrape now returns None (nothing spawned) when no engine answers /usage locally. Please rebase onto main (gh pr update-branch 25434 --rebase or a local rebase; PR Hygiene refuses merge commits). When resolving:

  1. Drop the usage_scrape.py hunk that lowers the floor to 2.27.1 and the matching (2, 27, 9) -> (2, 27, 0) test change. The constant no longer exists on main; the probe decides instead. Please confirm the bundled 2.27.1 lists v2 in chat --help, since that is now what makes the scrape run for API-key accounts on the bundled CLI.
  2. Keep skip_usage_api working with the new raw is None branch: for an API-key account on a kiro-cli with no V2, the API is skipped and the scrape is not spawned, so the refresh ends with no reading. A test for that path (ApiKey whoami plus _wrap_argv_usage_scrape returning (None, ...), asserting fetch_usage_limits is not called and the published marker carries no signin_required) would pin it.

One non-blocking design note for the rebase: once kiro-cli retires V2, an API-key account has no source at all, and with the 'api-key' state removed the widget shows the generic "no reading" dash with a Refresh that can never fill it. Previously it said why. If that future matters to you, keeping a reason for "API-key auth and no local /usage engine" would preserve the explanation; fine to leave as a follow-up.

I will take another look once the branch is rebased and readiness has run on the new head.

@kirankumar15
kirankumar15 force-pushed the fix/kiro-usage-api-key branch 3 times, most recently from c231dc8 to 384a105 Compare October 28, 2026 22:18
@kirankumar15

Copy link
Copy Markdown
Contributor Author

Thanks Bolin, all addressed. Rebased onto main (head 384a105349c2); the branch is mergeable again.

1. Dropped the floor hunk. The usage_scrape.py change that lowered USAGE_SCRAPE_ENGINE_PIN_MIN_VERSION to 2.27.1 and the matching (2, 27, 9) -> (2, 27, 0) test edit are gone — I took main's probe version of both files in the rebase. #25309's chat_agent_engines_at probe now decides the engine.

Confirmed the bundled CLI lists v2, as you asked. backend-dist/kiro-cli/kiro-cli-chat reports 2.27.1, and its chat --help shows:

--agent-engine <ENGINE>
    Agent engine to use: "v1", "v2" (default), or "v3"
    [possible values: v2, v1, v3]

So the probe pins v2 and the scrape runs for API-key accounts on the bundled CLI. Verified end-to-end on a live API-key account: _fetch_usage_bg publishes KIRO CREDIT POOLING, ~903 / 4777 where it used to publish {available: false}, and the real widget renders it.

2. Added the no-V2 test. TestApiKeyAuthUsesScrape::test_api_key_auth_with_no_v2_engine_spawns_nothing_and_does_not_misadvise: an ApiKey whoami with chat_agent_engines_at returning ("v3", "v1") (so _usage_scrape_argv returns None). It asserts fetch_usage_limits is not called, create_subprocess_exec is never awaited, and the published marker's reason != "signin_required". The path reaches _cache_without_scrape(..., reason=_unavailable_reason(api_result)) with api_result = UsageResult(None, AUTH_OTHER), and _unavailable_reason(AUTH_OTHER) is None, so no "sign in again" for a signed-in API-key account.

On the non-blocking note: agreed. Once V2 is retired, an API-key account has no local /usage source and the widget falls to the generic no-reading dash with no explanation. Preserving a reason for "API-key auth and no local /usage engine" would keep the "why". I've left it as a follow-up rather than widen this PR; happy to file an issue for it if you'd prefer it tracked.

@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 Oct 28, 2026
@kirankumar15 kirankumar15 changed the title [kiro_crew + 1 more] Show Kiro credits under API-key auth fix(usage): show Kiro credits under API-key auth Oct 28, 2026
@kirankumar15
kirankumar15 force-pushed the fix/kiro-usage-api-key branch from 384a105 to af72408 Compare October 28, 2026 22:33
@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 Oct 28, 2026
@kirankumar15
kirankumar15 force-pushed the fix/kiro-usage-api-key branch from af72408 to 76f16de Compare October 28, 2026 22:42
@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 Oct 28, 2026
@kirankumar15
kirankumar15 force-pushed the fix/kiro-usage-api-key branch from 76f16de to 5354bc0 Compare October 28, 2026 22:51
@kirankumar15

Copy link
Copy Markdown
Contributor Author

Rebased: main moved +8 commits (38ac0f0 -> 0ff4f73) since this head went green, touching server.py and the dashboard composition-contract tests adjacent to this PR (no file overlap, no conflict). Re-synced, related usage suites green locally (116 passed), CI re-running.

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 28, 2026
@kirankumar15

Copy link
Copy Markdown
Contributor Author

fixed in 841f5d2: on the API-key path (skip_usage_api), an unproven whoami agreement now PUBLISHES the scraped reading instead of discarding it. The scrape is kiro-cli's own /usage for the one signed-in key, so it describes that account by construction; a genuine mid-scrape _WHOAMI_DIFFERENT still discards. Added test_api_key_auth_with_no_identity_publishes_the_scrape (whoami returns only {account_type: ApiKey}, no email), which prove.py confirms fails if the fix is reverted.

  • API-key no-identity scrape discarded: the no-identity whoami pair was unproven, which routed to _cache_transient_failure; it is now published on the API-key path.

@kirankumar15

Copy link
Copy Markdown
Contributor Author

Both addressed, and the fix landed at 841f5d295f33 (pushed right after your review of 5354bc0, so it is on the current head now).

1. The whoami shape. On my account kiro-cli whoami --format json under API-key auth returns two keys: accountType and email ({"accountType":"ApiKey","email":"<redacted>"}) -- no startUrl, no profile ARN. So my manual run took the proven path because an email was present. You and the Opus lane are right that this is account-specific: a host whose key-only whoami prints just {"accountType":"ApiKey"} has no identity on either side, so the old code discarded the scrape as unproven. That is a real regression for the key-only shape, not a theoretical one.

2. The fix. Rather than keep a terminal marker, the scrape is now PUBLISHED for the key-only case. On the API-key path (skip_usage_api), an unproven whoami agreement no longer discards the reading: the scrape is kiro-cli's own /usage for the single signed-in key, so it describes that account by construction and there is no other account it could be confused with. A genuine mid-scrape account switch (_WHOAMI_DIFFERENT) still discards. This means a key-only API-key account sees its real balance, not a terminal "unavailable" marker.

The test you asked for is test_api_key_auth_with_no_identity_publishes_the_scrape in TestApiKeyAuthUsesScrape: whoami returns only {"account_type": "ApiKey"} (no email), and it asserts the scraped plan IS published (not discarded). prove.py confirms it fails if the fix is reverted. The earlier no-v2 test you noted is also still there.

Frontend Lint: agreed, that red is RedactionCards.tsx on main, unrelated to this PR -- it is not a file this PR touches. Waiting on the main-side fix.

@kirankumar15

Copy link
Copy Markdown
Contributor Author

The red Frontend Lint & Type Check is a main-side failure, not from this PR: the only eslint error is website/src/components/RedactionCards.tsx:1102 (no-restricted-syntax, the OverlayPortal/document.body rule), a file this PR does not touch, and it reproduces on origin/main. It is already being fixed in #25429 (fix(chat): route redaction preview tooltip through OverlayPortal). This PR's own frontend files lint clean. Once #25429 merges I rebase onto it and this red clears.

@kirankumar15
kirankumar15 force-pushed the fix/kiro-usage-api-key branch from 841f5d2 to 2102033 Compare October 28, 2026 23:26
@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 Oct 28, 2026
@kirankumar15
kirankumar15 force-pushed the fix/kiro-usage-api-key branch from 2102033 to 6d71e98 Compare October 28, 2026 23:43
@kirankumar15

Copy link
Copy Markdown
Contributor Author

Rebased: main moved since this head went green and now carries #25429, which fixes the RedactionCards.tsx:1102 lint error behind the red Frontend Lint (2102033 -> 6d71e98). Locally on the new head: full eslint src/ --max-warnings 0 and tsc clean, usage suites 117 passed, frontend tests pass; CI re-running.

@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 Oct 28, 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.

Thanks for the quick turnaround. The range diff from 5354bc0 to 6d71e98 is the rebase onto main plus the fix for the earlier point: on the API-key path an unproven whoami pair no longer drops the reading, and test_api_key_auth_with_no_identity_publishes_the_scrape pins the key-only {"account_type": "ApiKey"} shape. That part reads well.

One blocking point remains, and it matches the Opus lane. skip_usage_api is decided from the whoami at the top of the refresh, but the relaxed rule is applied to the before / after pair around the scrape. _whoami_agreement compares only email, start_url and the profile ARN, so any pair with none of those is unproven, not only an API-key pair. If the sign-in changes after the top whoami to an ExternalIdP sign-in ({"accountType":"ExternalIdP","email":""}), a lapsed type-only sign-in, or a signed-out profile, the pair is still unproven and the scrape is published as a live reading for that account. That breaks the _account_type_only rule that an ExternalIdP sign-in never shows a balance.

Suggested fix: allow unproven to publish only when both before and after are themselves the normalized apikey account type, and discard otherwise as on the non-API-key path. A test with an ApiKey top whoami and an ExternalIdP (or empty) after whoami, asserting nothing is published, would pin it.

Rebase-wise the branch is clean on main. CI is still running on this head.

# unpublishable here; on the API-key path `unproven` falls through
# and publishes.
discard = (
agreement == _WHOAMI_DIFFERENT if skip_usage_api else agreement != _WHOAMI_SAME

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.

unproven publishes for any identity-less sign-in, not only an API key

skip_usage_api comes from the top-of-refresh whoami, but this check judges the before / after pair taken around the scrape. _whoami_agreement never looks at account_type, so a switch to ExternalIdP, a type-only lapsed sign-in, or a signed-out profile also yields unproven, and the scrape is then published for that account.

discard = (
    agreement == _WHOAMI_DIFFERENT if skip_usage_api else agreement != _WHOAMI_SAME
)

Suggestion: on the API-key path, treat unproven as publishable only when both snapshots are API-key sign-ins:

def _is_api_key(ident):
    t = ident.get("account_type")
    return isinstance(t, str) and re.sub(r"[^a-z0-9]", "", t.lower()) == "apikey"

if skip_usage_api and agreement == _WHOAMI_UNPROVEN:
    discard = not (_is_api_key(before) and _is_api_key(after))
else:
    discard = agreement != _WHOAMI_SAME

Please add a test with an ApiKey top whoami and an ExternalIdP or empty after whoami that asserts nothing is published.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6f9db4d. The API-key carve-out now requires the whoami on both sides of the scrape to be an API-key sign-in, so an ExternalIdP, lapsed type-only, or signed-out after discards instead of publishing. test_api_key_switch_to_identity_less_sign_in_publishes_nothing pins it for ExternalIdP, BuilderId and an empty whoami, and test_api_key_auth_with_no_identity_publishes_the_scrape still pins the key-only shape publishing. Spec updated to match.

@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 Oct 29, 2026
@kirankumar15
kirankumar15 force-pushed the fix/kiro-usage-api-key branch from 6d71e98 to 6f9db4d Compare October 29, 2026 00:21
@kirankumar15

Copy link
Copy Markdown
Contributor Author

fixed in 6f9db4d: unproven now publishes only when the whoami on BOTH sides of the scrape is itself an API-key sign-in (_is_api_key(before) and _is_api_key(after)); any other identity-less pair (ExternalIdP, a lapsed type-only sign-in, signed out) and any different pair discards, as on the non-API-key path. Regression test test_api_key_switch_to_identity_less_sign_in_publishes_nothing covers ExternalIdP, BuilderId and empty after and asserts nothing is published. The owning spec in learn-cron-dashboard.md states the same rule.

  • API-key unproven publish ignores a mid-refresh switch: the carve-out keyed off the top-of-refresh whoami; it now requires the before/after pair itself to be API-key.

@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 Oct 29, 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.

Thanks for the quick turnaround. The earlier blocking point is fixed at 6f9db4d: an unproven whoami pair around the /usage scrape now publishes only when both the before and after reads are themselves API-key sign-ins, so a switch to ExternalIdP, a lapsed type-only sign-in, or a signed-out profile discards the reading as it does on the non-API-key path. A different pair still always discards.

What I checked at this head:

  • Range-diff against the previous head: only sessions.py, the usage test file and the one spec sentence changed; the other files are identical to the revision I read in full.
  • Ran test/test_session_usage.py at this head: 76 passed. The new switch test fails for the ExternalIdP and type-only cases against the previous sessions.py and passes with this one.
  • _WHOAMI_UNPROVEN is now a runtime import, which the new comparison needs.
  • AI review lanes on this head report no blocking findings.

This resolves my earlier change request. I will approve once the remaining backend test shards finish and the readiness check passes on this head.

@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 29, 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 at 6f9db4d.

The earlier blocking point is fixed: an unproven whoami pair around the /usage scrape now publishes only when both the before and after reads are API-key sign-ins, so a switch to ExternalIdP, a lapsed type-only sign-in, or a signed-out profile discards the reading as it does on the non-API-key path. A different pair still always discards.

What I checked at this head:

  • Range-diff against the previous head: only sessions.py, the usage test file and one spec sentence changed. The other 21 files are identical to the revision I read in full, so every hunk of the 24 files has been read.
  • Ran test/test_session_usage.py at this head: 76 passed. The new switch test fails for the ExternalIdP and type-only cases against the previous sessions.py and passes with this one.
  • Readiness is passed on this head, all checks are green, every AI review lane reports no blocking findings, and there is no merge conflict.

This replaces my earlier request for changes.

@bolichen97
bolichen97 enabled auto-merge (squash) October 29, 2026 05:05
@bolichen97
bolichen97 merged commit 3fe8d02 into kirodotdev:main Oct 29, 2026
106 of 107 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 29, 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.

Show actual credit/usage data for API Key accounts, not just an "unavailable" message

2 participants