Repository navigation
fix(usage): read credit usage from Crew sign-in without kiro-cli - #21956
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The vault path reuses the KAS spawn's own ownership predicate, keeps the kiro-cli path as it was, and ties cached readings to the vault identity. The Notes
[DESIGN-REVIEWED] 5744bcb Description read[DESCRIPTION-READ] aa609315ba05dc05bd0f9000f7d300f8d6b5a070d04469c3e8dfa8f0783b0559 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: the fix removes the kiro-cli readiness refusal at its cause, the usage read now runs on the credential KAS already uses, and the five sibling gate sites are declared and deferred to #21957. What this change shipsInventory (8 items) — 7 justifiedIntent: let a user chatting on KAS with Kiro Crew's own sign-in and no kiro-cli installed see their credit balance. FIX.
[FIRST-PRINCIPLES-REVIEWED] 5744bcb Description read[DESCRIPTION-READ] abf1bc429f321085fd89afc3544f2b1ca916c96fbcd5b17904e3b385f5be4c6b That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
|
83596df to
946e22b
Compare
|
|
|
self-added: yes
|
|
946e22b to
41e007c
Compare
|
|
bolichen97
left a comment
There was a problem hiding this comment.
Code review of 41e007c: no code changes requested. One maintainer check remains before merge, and one overlap needs a decision.
What I checked on this head:
- The vault path never resolves or spawns kiro-cli.
_refreshreturns before_resolve_kiro_bin_for_spawn, and the timeout and error handlers call_adjacent_identity, which returnsNonewhenkiro_binwas never set. So skippingreject_if_kiro_unverifiedon a vault verdict does not reopen the signed-out spawn that gate exists for. - The identity bracket is sound.
vault_identity_fingerprinthashes identity claims only (kind, provider, profile ARN, region, client id, token endpoint), not token material, so a normal token refresh insideKasAuthProvider.current()does not makebefore != after. - Cross-path leaks are closed. A vault reading carries no
emailorstart_url, so the kiro-cli path's_same_identitypreserve can never keep it. The GET drops a vault reading once the vault stops owning usage, and hides a reading for another fingerprint. - The bearer goes only to the hardcoded
_RTS_ENDPOINTShost for the ARN's region, and refreshes stay under the existing per-identity lock inauth/refresh.py. - The
_get_usageextraction keeps the candidate loop's behaviour: the same payload, the 401-onlyAUTH_REJECTEDrule, the stop on a 200 with no CREDIT breakdown, and the same name anchor. - Blocking work stays off the loop (
asyncio.to_threadandsubprocess_executor()). - The description matches the diff: 26 new tests, the spec paragraph, and the helper reset.
Maintainer check before merge: the live read. The Design and First Principles lanes both ask for it, and the author's disposition is still open. This matters for more than the no-kiro-cli host. On a host with KAS, a Crew sign-in AND a working kiro-cli, usage now comes from the vault with no fallback. If GetUsageLimits refuses the vault token, that user goes from a working readout to "sign in required". Please record one real reading on a build with this head (Builder ID or social, and enterprise if available) before this merges.
Overlap: #16886 (same author) targets the same problem with an older design: a vault candidate inside fetch_usage_limits plus kiro_spawn_allowed. It is open with a merge conflict. If this PR is the one you want, please close #16886 so that the two mechanisms do not both land. #17784 touches the same two handler files and also has a conflict. Merge this one first, then rebase #17784.
Not raised: the deferred readiness-gate sites (#21957) and a per-user subject in the vault fingerprint. The PR lists both as not a goal.
|
@bolichen97 thanks for the review of 41e007c.
|
41e007c to
fbe6c9d
Compare
|
Head is now 7c8d537 (rebased onto main; the doc conflict in Both items from the r111 HOLD and the lane dispositions are addressed on this head:
The Design and First Principles "needs-a-decision (maintainer)" items on 86ef5ab were this live read; it is recorded now. |
|
Second live read recorded under Manual verification: a social (Google) vault identity on the same head, KIRO FREE 0 / 50. Differential as well: the host's kiro-cli is signed in to the enterprise account (KIRO POWER 95,027 / 10,000), so that reading can only have come from the vault token. No kiro-cli child during the refresh. Enterprise (Identity Center) and social are now both covered live; Builder ID is not. |
|
CI on 7c8d537: the only reds are Backend Tests shard 3 (Linux + Windows), all 8 cases in |
7c8d537 to
87b5f00
Compare
When the default harness is KAS and Crew's sign-in vault holds a usable identity -- exactly when chat itself draws its credential from the vault -- /api/sessions/usage reads GetUsageLimits directly with the vault's OIDC token (resolved and refreshed through KasAuthProvider) and needs no kiro-cli. The kiro-cli readiness gate is skipped on that path because no kiro-cli is spawned, and the handler's verdict is carried into the refresh so it can never fall back to a kiro-cli spawn, even if the sign-in disappears in between. The vault path is authoritative: failures report unavailable (signin_required when auth-class). A reading is published only when the vault identity fingerprint read before the credential matches the one read after the API answers, and a stale reading is kept only for the same vault identity. Any other harness keeps the existing kiro-cli path unchanged. A refresh that can never succeed names the remedy: the issuer refusing the grant (RefreshRejected) and a refresh that cannot be attempted because the entry lacks a local input -- stored client credentials, a token endpoint -- (the new RefreshBlocked, raised where refresh_blocker is non-empty) both report signin_required; any other refresh failure reports no reason, since the grant may still be valid. The GetUsageLimits request and response mapping move into one helper, _get_usage, shared by the candidate loop and the single-credential client.
87b5f00 to
5744bcb
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Follow up review of head 5744bcb, read as the delta since 7c8d537 (rebased onto current main, plus two race fixes in sessions.py).
What changed and what I checked:
- GET snapshot.
api_sessions_usagenow takes the payload and its fingerprint together (served, served_fp = _usage_cache, _usage_cache_vault_fp) and_cached_reading_is_foreignjudges that pair instead of the live globals._publish_usagerebinds both names without yielding, so the pair is consistent, and a reading published by another refresh during the awaited fingerprint read can no longer slip A's payload out under B. This resolves the second blocking finding from the GPT lane on 87b5f00. The newtest_get_judges_the_snapshot_it_serves_not_the_live_cachedrives exactly that interleaving. - Failed credential refresh. The
RefreshRejected/RefreshBlockedand transient branches now go through_failed, which rereads the fingerprint adjacent to the failure. If the sign-in changed while the refresh waited on the identity lock, it publishes a plain unavailable marker with no reason, so A's balance is not kept as stale under B and B is not told to sign in for A's failure. This resolves the third blocking finding. Covered bytest_failed_refresh_judges_against_the_identity_signed_in_now. - The spec paragraph in
learn-cron-dashboard.mdmatches the new behavior.
Local run on this head: test_usage_crew_vault.py, test_kas_host_auth.py and test_kas_auth_flows.py all pass (83 tests). Backend shards are green on this head.
Still open, not blocking from my side: the first GPT finding (two social accounts on one shared profile hash to the same fingerprint) was downgraded by adjudication and is not addressed here. The ten minute timed refresh bounds it. Please say in the description whether you accept that as a known residual or plan a follow up.
CI note: every red check on this head is infrastructure, not this change. The AI review lanes failed in their merge base fetch step before reviewing, and the license gate reports that dependency review is not enabled for the repository. A rerun of the review lanes is needed for a readiness verdict on this head.
Approval stays with a human maintainer: this change sends the sign in vault credential to a network call, which is a secret handling path, so I am leaving a comment rather than an approval.
Two housekeeping asks:
|
Thanks for the follow-up read. Housekeeping done:
CI: the eight reds on 5744bcb are still the installation token's GitHub API rate limit (attempt 2 at 00:02Z hit it again: |
|
All checks green on 5744bcb after the rate-limit re-run (Design PASS, First Principles PASS, GPT 6.1 and Opus 5.5 no blocking findings, backend shards green). Mergeable; merge is blocked only on a human approval, as this change sends the sign-in vault credential to a network call. One review thread is still open (the 🟡 |
|
The code on 5744bcb looks good to ship and every check except PR Readiness is green. Readiness is holding on the disposition rule: comment 6353196458 answers three lane findings in one comment, and the readiness check expects one disposition comment per finding. Could you split it into three comments, one per finding? Once readiness passes I can approve this head. |
|
|
|
|
@bolichen97 the combined disposition is split into three comments (one per finding) and PR Readiness now passes on 5744bcb; every check is green. Could you approve this head when you have a moment? Thanks. |
Problem / Motivation
Goal: The credit readout works when chat runs on Kiro Crew's own sign-in, with no kiro-cli installed.
With KAS on Crew's own sign-in and no kiro-cli on the host, chat works but the credit pill is blank. The gateway logs
'/api/sessions/usage' refused with 503 kiro_prerequisite_required: Kiro CLI is not verified ready.Why it matters
KAS on Crew's own sign-in is the setup that needs no kiro-cli at all. On that setup the account's credit usage, the one number that tells a user how much they have left, is unreachable from the dashboard.
Not a goal
reject_if_kiro_unverifiedcall sites (chat_regenerate.pyx2,chat_rewind.py,handlers/agents.py/api/models,openai_compat.py), which also refuse on this setup: deferred to Kiro readiness gate returns 503 on KAS + Crew sign-in hosts with no kiro-cli #21957.available/reasonshape this returns.What changed (motivation → approach → change)
The usage endpoint is gated on kiro-cli readiness and reads only credentials kiro-cli keeps. Crew already holds a working OIDC token, the same one KAS uses for chat, but usage never looked at it.
GetUsageLimitswith the vault token, no kiro-cliOn the vault path,
src/kiro_crew/dashboard/handlers/sessions.pyskips the kiro-cli readiness gate (it exists only to stop a signed-out kiro-cli spawn) and passes that verdict into the refresh, so the refresh never falls back to kiro-cli, even if the sign-in disappears in between. Failures show unavailable (signin_requiredwhen auth-class). A reading is published only when the vault identity matches before and after the API call, a stale reading is kept only for the same identity, and a cached reading is never served to the other path or to a different identity.docs/system-specs/modules/learn-cron-dashboard.mddescribes the vault path beside the kiro-cli one.In
src/kiro_crew/dashboard/handlers/kiro_usage_api.pytheGetUsageLimitsrequest and response mapping moves into one helper,_get_usage, shared by the existing candidate loop and the new single-credentialfetch_usage_limits_with_credential. Ownership is decided by the KAS spawn's own predicate,src/kiro_crew/auth/bridge.pyvault_holds_identity, called withwarn=Falseso the per-poll check logs its diagnostics at DEBUG. Only an issuer that refuses the refresh grant (RefreshRejected) reportssignin_required; a transient refresh failure reports unavailable with no sign-in prompt.Backwards compatibility
Compatible: hosts whose default harness is not KAS, or that have no Crew sign-in, take the same code path as before.
Removes nothing: the readiness gate still applies to every caller that may spawn kiro-cli, and no function, key or record is removed.
Tests
test/test_usage_crew_vault.py(new, 27 tests): a vault-published reading is dropped once the vault stops owning usage, while a kiro-cli reading is still served; vault reading with no kiro-cli; a sign-in vanishing or signing out after the verdict never reaches kiro-cli; identity change mid-refresh drops the reading; an auth-rejected read and an issuer-refused refresh reportsignin_required, while a transient refresh failure does not; stale preservation only for the same identity; a fresh reading for another identity is not served; ownership only on KAS (never on the kiro-cli harness) and with no per-poll WARNING; gate bypass on GET and on the refresh route; the single-credential client (stored ARN, discovered ARN and its region, 401, transport error, empty token).test/session_usage_helpers.py: the shared reset clears the new cache fingerprint.test/test_kas_host_auth.py:vault_holds_identity(warn=False)returns the same verdict with no WARNING, and the default still warns.--count 20under xdist (540 runs) and a shuffledpytest-randomlyrun (seed 1208269002).test_session_usage*.py,test_kiro_usage_api.py,test_kiro_spawn_readiness_gate.py,test_kas_login_api.py,test_kas_host_auth.py,test_approval_chain_no_cryptography.py(355 passed); isort, flake8, mypy, the black, agent-SDK boundary, sync-io, comment-history and harness-parity gates, semgrep and the flake-pattern ratchet.Manual verification
Observed on a macOS host with kiro-cli removed and KAS on Crew's sign-in: the gateway logged the 503 refusal above at startup. The fix was not loaded into that running app.
Live
GetUsageLimitsread with the vault credential, on 7c8d537 (2026-10-22, Linux dev host, isolated pod from this worktree).Setup:
kirocrew pod up usage-vault --provision --seed <dir>with a seedconfig.jsonofagent.acp_backend: "kas",agent.kas_bundle: true; the pod home'skas/leaf was populated with a copy of the host's Crew sign-in vault (an Identity Center / enterprise identity; access token live, so no refresh ran). The pod was torn down right after (pod down, home nuked), so the copy is gone.Before the vault existed in the pod home,
GET /api/sessions/usageanswered200 {"usage": {}}. After,POST /api/sessions/usage/refreshanswered:{"status":200,"body":{"usage":{"credits_used":95027.08,"credits_plan":10000.0,"credits_overage":85027.0,"credits_covered":10000.0,"percentage":950.3,"source":"api","overage_rate":0.04,"cost_usd":3401.08,"plan":"KIRO POWER","resets":"2026-11-01","account":"KiroProfile-us-east-1"}}}That it went over the vault path, not kiro-cli (kiro-cli IS installed and signed in on this host, so the two paths would otherwise be indistinguishable from the number alone): a
pssampler at 100 ms over the gateway PID for the whole refresh saw nokiro-clichild at all (only the gateway's own multiprocessing helpers), and the refresh completed in 2.7 s wall; the kiro-cli path spawns at least twowhoamisubprocesses per refresh. The response also carries noemail/start_url, which the kiro-cli path attaches on an ARN match and the vault path never does.Pill and account modal on that pod, both rendering the reading:
Second live read, social (Google) identity, same head, same pod recipe (2026-10-22). The pod came up with an empty vault; a Google device sign-in was started through the pod's own
POST /api/kas-login/device {"provider":"google"}and approved by the maintainer in a browser, so the pod vault held exactly onesocialentry (GET /api/kas-login→authenticated: true, provider: "Google", identity: "social", usable: true).POST /api/sessions/usage/refreshanswered:{"status":200,"body":{"usage":{"credits_used":0.0,"credits_plan":50.0,"credits_overage":0.0,"credits_covered":0.0,"percentage":0.0,"source":"api","overage_rate":0.04,"cost_usd":0.0,"plan":"KIRO FREE","resets":"2026-11-01"}}}This one is a differential proof as well as a provider proof: the host's kiro-cli is signed in to the Identity Center account above (KIRO POWER, 95,027 / 10,000), so a KIRO FREE 0 / 50 reading can only have come from the vault's Google token. The same 100 ms
pssampler saw nokiro-clichild during the 3.1 s refresh. Pod torn down afterwards; the social sign-in lived only in that pod's vault.Observed, not in this PR's scope: for the social identity the modal header shows "Account details unavailable" (the reading carries no
accountname; the enterprise reading did), and the footer copy still says "from kiro-cli /usage" on both.Not exercised here: a Builder ID vault identity, and a host with kiro-cli genuinely absent (the pod inherits the host's install directories).
Known residual, accepted. Two social accounts signed in on the same shared social profile hash to the same vault identity fingerprint (
vault_identity_fingerprinthashes identity claims only, by design, since the same fingerprint drives the per-turn KAS retire sweep), so a switch between them inside one refresh interval can show the previous account's balance until the 10-minute timed refresh. GPT 6.1 F1 on 87b5f00, downgraded by adjudication as a disproportionate remedy; not changed here, no follow-up planned unless a user reports it.Related Issues
Closes #21955
Supersedes #21732 (same change from a fork; reopened as a same-repo branch).
Pattern harvest
Not generalizable: a readiness gate written for one credential source was applied to an endpoint that now has a second source; the fix is specific to where usage reads its credential.
Checklist