Skip to content

fix(usage): read credit usage from Crew sign-in without kiro-cli - #21956

Merged
iamwhatever merged 1 commit into
mainfrom
fix/usage-without-kiro-cli
Oct 24, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/usage-without-kiro-cli

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Changing the kiro-cli path: any harness other than KAS, or KAS without a Crew sign-in, reads usage exactly as today.
  • Adding a per-user subject to the Crew sign-in vault or its identity fingerprint.
  • The five other reject_if_kiro_unverified call sites (chat_regenerate.py x2, 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.
  • Any frontend change: the pill already renders the available / reason shape 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.

When Usage comes from
default harness is KAS and Crew's vault holds a usable identity GetUsageLimits with the vault token, no kiro-cli
anything else the existing kiro-cli path, unchanged

On the vault path, src/kiro_crew/dashboard/handlers/sessions.py skips 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_required when 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.md describes the vault path beside the kiro-cli one.

In src/kiro_crew/dashboard/handlers/kiro_usage_api.py the GetUsageLimits request and response mapping moves into one helper, _get_usage, shared by the existing candidate loop and the new single-credential fetch_usage_limits_with_credential. Ownership is decided by the KAS spawn's own predicate, src/kiro_crew/auth/bridge.py vault_holds_identity, called with warn=False so the per-poll check logs its diagnostics at DEBUG. Only an issuer that refuses the refresh grant (RefreshRejected) reports signin_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 report signin_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.
  • Determinism: the new file passed --count 20 under xdist (540 runs) and a shuffled pytest-randomly run (seed 1208269002).
  • Locally green: the new file plus 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 GetUsageLimits read 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 seed config.json of agent.acp_backend: "kas", agent.kas_bundle: true; the pod home's kas/ 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/usage answered 200 {"usage": {}}. After, POST /api/sessions/usage/refresh answered:

{"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 ps sampler at 100 ms over the gateway PID for the whole refresh saw no kiro-cli child 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 two whoami subprocesses per refresh. The response also carries no email/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:

top bar pill 95K/10K from the Crew vault read

Kiro Account modal, KIRO POWER 95,027 / 10,000 credits, from the Crew vault read

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 one social entry (GET /api/kas-login → authenticated: true, provider: "Google", identity: "social", usable: true). POST /api/sessions/usage/refresh answered:

{"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 ps sampler saw no kiro-cli child during the 3.1 s refresh. Pod torn down afterwards; the social sign-in lived only in that pod's vault.

Kiro Account modal, KIRO FREE 0 / 50 credits, from the social (Google) vault read

Observed, not in this PR's scope: for the social identity the modal header shows "Account details unavailable" (the reading carries no account name; 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_fingerprint hashes 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

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

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 5744bcbfafc56227ea2032e1b57456039dd10f44 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 5744bcbfafc56227ea2032e1b57456039dd10f44 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 RefreshBlocked type it adds is a subclass of RefreshError, so it takes nothing away.

Notes

  • _refresh_from_vault and its helpers add about 190 lines to sessions.py, bringing it to 1,493 of the 1,600-line split threshold. They are a separate responsibility, so a sibling module such as usage_vault.py would hold them better than another section in the handler.
  • Each 30 s poll from every open tab now runs a config load and a vault resolve() before the gate. That is cheap now, but the poll's cost grows with whatever resolve() does later.

[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 .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 18, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 5744bcbfafc56227ea2032e1b57456039dd10f44 — 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: 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 ships

Inventory (8 items) — 7 justified

Intent: let a user chatting on KAS with Kiro Crew's own sign-in and no kiro-cli installed see their credit balance. FIX.

  1. Credit pill shows a reading on KAS plus a Crew sign-in with no kiro-cli installed — justified
  2. Usage GET and Refresh skip the kiro-cli readiness gate when the vault owns usage — justified
  3. Vault-path failures show unavailable or signin_required and never fall back to kiro-cli — justified
  4. A cached reading from another identity or the other path is dropped and refreshed at once — justified
  5. A refresh that cannot be attempted (RefreshBlocked, missing client credentials or token endpoint) now prompts "sign in again" — undeclared
  6. The vault probe logs at DEBUG when the poll asks (warn=False) and still warns at spawn — justified
  7. The GetUsageLimits request and response mapping is folded into one shared _get_usage — justified
  8. New single-credential client fetch_usage_limits_with_credential — justified

[FIRST-PRINCIPLES-REVIEWED] 5744bcb

Description read

[DESCRIPTION-READ] abf1bc429f321085fd89afc3544f2b1ca916c96fbcd5b17904e3b385f5be4c6b

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 5744bcbfafc56227ea2032e1b57456039dd10f44 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 5744bcb

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

@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 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 5744bcbfafc56227ea2032e1b57456039dd10f44 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 5744bcb

Verdict parsed from the review's SHA-scoped output markers for commit 5744bcbfafc56227ea2032e1b57456039dd10f44.

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

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: do one live GetUsageLimits read with the vault token on a build carrying the fix

needs-a-decision (maintainer): the read needs this branch loaded into a running gateway with a Crew sign-in; it is not yet done and the description says so under Manual verification.
I will run it on my host before merge and record the result here.

@CrysisDeu
CrysisDeu force-pushed the fix/usage-without-kiro-cli branch from 83596df to 946e22b Compare October 18, 2026 20:26
@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • span=523788411d80 Item 2 -- symptom-level: 5 sibling reject_if_kiro_unverified call sites

accepted-and-deferred: the five other gated sites (chat_regenerate.py x2, chat_rewind.py, handlers/agents.py /api/models, openai_compat.py) are real on a KAS + Crew sign-in host with no kiro-cli.
They are out of this PR's goal (the credit readout); each guards a different risk (history rewrite, model listing, a turn with no transcript) and needs its own ruling, most likely one rule inside kiro_verified_ready.
Tracked in #21957 (deferred-finding, assigned, Due: 2026-11-01). The PR description names them as deferred.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • span=de05dc4b505d _vault_owns_usage_sync copies the check inside bridge.vault_holds_identity

rebutted: the copy is only the composition resolve() + KasToken.is_usable(); is_usable is the one predicate the KAS spawn, kirocrew doctor and the sign-in card already share, so a change to what counts as usable lands in both places.
It does not call vault_holds_identity on purpose: that function logs a spawn-time WARNING for an unusable entry, and this probe runs on every 30s poll of every open tab.
A test pins that the probe owns usage exactly when the vault entry is usable.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: foreign-reading check on the usage GET

  • span=21910eb8fc84 The foreign-reading check only runs when vault_owned is true

fixed in 946e22b: when the vault no longer owns usage and the cache holds a reading the vault path published, the GET drops it (available: false) and refreshes now, behind the kiro-cli readiness gate.
Dropped rather than hidden, so the kiro-cli path's same-identity preserve can never keep it; a kiro-cli reading is still served unchanged.
Locked by test_vault_reading_is_never_served_once_vault_stops_owning and test_kiro_cli_reading_is_served_when_vault_does_not_own.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • span=21910eb8fc84 The owning spec is out of date

fixed in 946e22b: docs/system-specs/modules/learn-cron-dashboard.md now states that both usage routes skip the readiness gate on KAS with a usable Crew sign-in, read GetUsageLimits with the vault credential, and are bracketed by the vault identity fingerprint instead of whoami; the kiro-cli path text is unchanged.

@CrysisDeu
CrysisDeu force-pushed the fix/usage-without-kiro-cli branch from 946e22b to 41e007c Compare October 18, 2026 20:29
@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 18, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • span=0efb8548dd9a Item 1 -- inherited premise: the vault OIDC token has never been shown to work for GetUsageLimits

needs-a-decision (maintainer): this is a provider fact no unit test can establish; the read needs this branch running against a real Crew sign-in vault, which an isolated pod does not hold.
Evidence so far: KAS chat on the same host authenticates with this exact credential (KAS auth callback served from Crew vault), and GetUsageLimits is the endpoint kiro-cli's own /usage calls with the same OIDC bearer shape.
@CrysisDeu: run one live read (Builder ID/social and, if available, enterprise) on a build carrying 41e007c and record the result here before merge.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: check that the vault's OIDC token is accepted by GetUsageLimits before merge

needs-a-decision (maintainer): same ask as the First Principles item on this head; a live read on a build carrying 41e007c is pending with the maintainer, and its result will be recorded on this PR before merge.

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

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. _refresh returns before _resolve_kiro_bin_for_spawn, and the timeout and error handlers call _adjacent_identity, which returns None when kiro_bin was never set. So skipping reject_if_kiro_unverified on a vault verdict does not reopen the signed-out spawn that gate exists for.
  • The identity bracket is sound. vault_identity_fingerprint hashes identity claims only (kind, provider, profile ARN, region, client id, token endpoint), not token material, so a normal token refresh inside KasAuthProvider.current() does not make before != after.
  • Cross-path leaks are closed. A vault reading carries no email or start_url, so the kiro-cli path's _same_identity preserve 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_ENDPOINTS host for the ARN's region, and refreshes stay under the existing per-identity lock in auth/refresh.py.
  • The _get_usage extraction keeps the candidate loop's behaviour: the same payload, the 401-only AUTH_REJECTED rule, the stop on a 200 with no CREDIT breakdown, and the same name anchor.
  • Blocking work stays off the loop (asyncio.to_thread and subprocess_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.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks for the review of 41e007c.

@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 18, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/learn-cron-dashboard.md since this head went green (8fd2af9 -> 1709685); CI re-running.

@CrysisDeu
CrysisDeu force-pushed the fix/usage-without-kiro-cli branch from 41e007c to fbe6c9d Compare October 18, 2026 21:20
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 22, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Head is now 7c8d537 (rebased onto main; the doc conflict in learn-cron-dashboard.md is resolved).

Both items from the r111 HOLD and the lane dispositions are addressed on this head:

  1. Live GetUsageLimits read with the vault token -- done on this head and recorded under Manual verification in the description (JSON response, the no-kiro-cli-spawn evidence, pill + modal screenshots). Enterprise / Identity Center identity; Builder ID and social were not available on the host.
  2. The 🟡 thread -- fixed: RefreshBlocked(RefreshError) for a refresh refresh_blocker() refuses, mapped to signin_required beside RefreshRejected. Replied in the thread.

The Design and First Principles "needs-a-decision (maintainer)" items on 86ef5ab were this live read; it is recorded now.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

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.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

CI on 7c8d537: the only reds are Backend Tests shard 3 (Linux + Windows), all 8 cases in test/test_chat_runner_redact_across_tool_boundary.py. That file and the code it covers are untouched here; main is red on the same 8 cases since #22914 (tracked in #23200 / #23198). Will rebase once main is green.

@CrysisDeu
CrysisDeu force-pushed the fix/usage-without-kiro-cli branch from 7c8d537 to 87b5f00 Compare October 22, 2026 22:03
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased onto main at fdd621b (#23201 fixed the 8 inherited test_chat_runner_redact_across_tool_boundary reds). New head 87b5f00, same patch; CI re-running.

@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 22, 2026
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.
@CrysisDeu
CrysisDeu force-pushed the fix/usage-without-kiro-cli branch from 87b5f00 to 5744bcb Compare October 22, 2026 23:00

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

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:

  1. GET snapshot. api_sessions_usage now takes the payload and its fingerprint together (served, served_fp = _usage_cache, _usage_cache_vault_fp) and _cached_reading_is_foreign judges that pair instead of the live globals. _publish_usage rebinds 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 new test_get_judges_the_snapshot_it_serves_not_the_live_cache drives exactly that interleaving.
  2. Failed credential refresh. The RefreshRejected/RefreshBlocked and 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 by test_failed_refresh_judges_against_the_identity_signed_in_now.
  3. The spec paragraph in learn-cron-dashboard.md matches 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:

  1. #16886 (yours) reads the credit balance with Crew's own credential and touches the same files; this PR supersedes it. Please close #16886 as a duplicate.
  2. #17784 edits the same usage paths in sessions.py and kiro_usage_api.py. Please land this PR first and let #17784 rebase onto it.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up read. Housekeeping done:

  1. feat(dashboard): read the credit balance with Crew's own Kiro credential #16886 closed as superseded by this PR.
  2. fix(usage): show an account-type-only sign-in without another user's balance #17784 stays behind this one and rebases onto it once merged.
  3. F1 (shared social profile fingerprint) is recorded in the description under Manual verification as a known residual, accepted -- bounded by the 10-minute timed refresh, no follow-up planned unless a user reports it.

CI: the eight reds on 5744bcb are still the installation token's GitHub API rate limit (attempt 2 at 00:02Z hit it again: API rate limit exceeded for installation; the license gate's "dependency graph not enabled" is the same token failing the dependency-review API, it passed on 7c8d537). Re-running the lanes once more after the next hourly reset.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

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 🟡 RefreshBlocked one, fixed in 7c8d537 and carried on this head) -- @bolichen97, please resolve it if the fix reads right to you.

@bolichen97

Copy link
Copy Markdown
Contributor

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.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • F2 sessions.py:1323 GET validates a different cache snapshot from the one it returns

fixed in 5744bcb: the GET captures (payload, fingerprint) in one step before its first await and _cached_reading_is_foreign(payload, payload_fp) judges that snapshot, not the live globals. Locked by test_get_judges_the_snapshot_it_serves_not_the_live_cache, where B's reading is published during the fingerprint read and A's payload is still refused.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • F3 sessions.py:645 Failed renewal preserves the account that preceded a sign-in switch

fixed in 5744bcb: every credential-failure branch re-reads the vault fingerprint adjacent to the failure; a changed identity drops the previous reading and publishes a plain unavailable marker (the failure was the previous account's), an unchanged one keeps the existing same-identity stale/signin_required behaviour. Locked by test_failed_refresh_judges_against_the_identity_signed_in_now.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • F1 sessions.py:608 Profile-only fingerprints conflate different social accounts

downgraded by adjudication (disproportionate remedy); not changed here. The fingerprint is shared with the per-turn KAS retire sweep, so adding token material would retire engines on every renewal; the 10-minute timed refresh bounds the exposure.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Oct 23, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

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

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.

Credit usage readout needs kiro-cli even when KAS runs on Crew's own sign-in

3 participants