Skip to content

feat(dashboard): read the credit balance through /usage by default - #12918

Merged
bolichen97 merged 1 commit into
mainfrom
fix/usage-refresh-button
Sep 24, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/usage-refresh-button

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Some accounts (org-managed, IAM Identity Center) get no credits_plan from the free usage API. For them the top-bar credit pill shows nothing unless the dashboard reads the balance another way: run kiro-cli chat --no-interactive --agent kirocrew-lite /usage and parse the table it prints.

That read has been treated as a billed chat turn since #2039, so it sits behind dashboard.usage_text_scrape_enabled (default off), a Settings > Display toggle for that key (#12037), an owner-only gate on enabling it, and copy that tells the user each check spends credits.

It costs nothing. /usage is a kiro-cli slash command handled locally. Three checkable facts: the kiro.dev CLI reference lists /usage in the slash-command table next to /help and /context as "Usage limits with progress bar and credit balance", a client-side panel; the kiro-cli 2.23.0 binaries carry AmazonCodeWhispererService.GetUsageLimits and crates/amzn-codewhisperer-client/src/operation/get_usage_limits.rs, the same free API the pill's primary path calls; and three back-to-back runs on this account 7 s apart left the usage counter unchanged at 0.01 granularity, with the output being the usage table alone and no model text.

Why it matters

The people who need the fallback are exactly the people whose pill is empty. Today they see "not available", are told to edit config.json, and if they find the toggle they are warned about a cost that does not exist. A meter that reads for free should just read.

What changed (motivation → approach → change)

Before After
Fallback off unless a config key is set Fallback runs whenever the API has no plan
Toggle in Settings > Display No toggle, no key
"Spends a few credits" Plain "Refresh"
Where What
src/kiro_crew/dashboard/handlers/sessions.py The timed refresh runs the /usage read whenever the API returns no plan; api_sessions_usage_refresh for POST /api/sessions/usage/refresh
src/kiro_crew/dashboard/handlers/core.py, handlers/__init__.py, routes/system.py Key removed from the PATCH allowlist with its owner-only branch; route registered
src/kiro_crew/config/sections.py, config/loader.py, config-baseline.json dashboard.usage_text_scrape_enabled field and reader removed; baseline regenerated
website/src/components/KiroAccountModal.tsx, website/src/api/kiroUsage.ts, website/src/api/client.ts, website/src/App.tsx Refresh button and its states; shared payload parser; pill copy for the no-reading state
website/src/pages/settings/DisplayPanel.tsx Toggle removed
website/src/i18n/locales/*.json (13 catalogs incl. en.manual.json, en-XA.json) Toggle and cost strings removed; Refresh strings added
website/src/components/commandPalette/settingsRegistry.gen.ts, src/kiro_crew/docs/settings-registry.generated.json Regenerated without the toggle
src/kiro_crew/docs/configuration.md, docs/system-specs/modules/learn-cron-dashboard.md, docs/feature-map/README.md Key row removed; the fallback and the route's guards specified

The fallback is on. _fetch_usage_bg tries the API; with no plan it runs the /usage read. Parking after three failed or unparseable scrapes stays. An auth-class verdict plus a failed read carries reason: signin_required.

One Refresh button. Compact beside a reading, primary under "Could not read your balance." when there is none. Success renders the meter and writes the ['kiro-usage'] query so the pill updates. Every outcome that is not a new reading renders through ErrorNotice with the agent hand-off: a running refresh, a parked scrape ("Balance checks are paused because recent ones failed. Try again in about N min."), an earlier reading, anything else ("Could not read your balance.").

The route. POST /api/sessions/usage/refresh runs one refresh (API first, read second, like the timer) and answers with the GET's payload. Guards: the GET's reject_if_kiro_unverified, and single-flight (409 refresh_in_flight), shown through the same notice ("A refresh is already running.") with a usage re-read 3 s later and Refresh held meanwhile. A parked scrape is reported after the API attempt, not pre-checked, including one that parks during this refresh: skipped: "scrape_parked" with retry_after, returning what the parked path wrote.

Identity. A reading is published only when a whoami taken immediately before the credential read and one taken immediately after it prove the same account (_whoami_agreement: a shared non-empty email, start_url or ARN, nothing disagreeing). This brackets the API call and the /usage read alike; a disagreement or an identity-less pair publishes nothing. Every cache writer re-resolves whoami before writing and keeps a prior reading only under _same_identity. Timeout and exception paths reap the scrape process first.

In the modal, every refresh result is written into the shared usage query before any notice is chosen; an outcome notice replaces the standing one; Refresh is held while parked. An earlier reading returned by a refresh is not stamped as checked now: the modal says "The refresh did not return a new reading. Showing the earlier one." A failed refresh says "Could not read your balance."

Removed. The config key, the Display toggle with its test and harness, the scrape-disabled state, all cost copy.

No reading is a visible state, on the Kiro backend. With nothing to read, the pill shows a dimmed dash ("no balance reading yet; open to refresh") and the modal stays open with Refresh. The dash is gated on isKiroBackend (a positive check on agent.acp_backend); other harnesses keep hiding the pill and closing the modal once the config has loaded. When the ['kirocrewConfig'] read itself fails, the backend is unknown, so the pill is not hidden: it shows the dash labelled "could not read the backend setting; open to retry" (config-unreadable) and the modal opens on an ErrorNotice ("Could not load settings, so your balance can’t be shown.") with hand-off and Refresh, re-reading the config on open and on each press. The state is errorUpdatedAt > 0 && data === undefined, the last settled outcome, so an in-flight retry does not flip the pill to the hidden shape.

Backwards compatibility

Breaking: dashboard.usage_text_scrape_enabled is removed. Writer sweep on origin/main @ 4e7f968: config/sections.py (schema field, deleted), config/loader.py (reader, deleted), handlers/core.py (_EDITABLE_CONFIG entry + owner-only PATCH branch, deleted; PATCH /api/config/kirocrew with that key now answers 400 "field not editable"), handlers/sessions.py (gate + log copy, deleted; the read is unconditional), config-baseline.json (regenerated), both settings registries (regenerated), configuration.md (row deleted), learn-cron-dashboard.md and docs/feature-map/README.md (rewritten), test/test_usage_scrape_editable.py (rewritten to pin that the key is not a setting), test/test_session_usage.py (gate tests replaced by fallback tests). A config.json still carrying the key loads, keeps it in _extra_keys, round-trips it on save, and logs nothing about it (pinned by test). kirocrew config set dashboard.usage_text_scrape_enabled ... writes an unknown key with no effect. Anyone who had the key on gets the same behaviour they had; anyone who had it off gets a working pill.

website/package.json swaps one script (verify:credit-meter-toggle → verify:usage-refresh); no dependency changes.

Tests

Backend, test/test_session_usage.py (111 pass): the timed refresh runs the read when the API has no plan and does not when it has one; TestUsageRefreshRoute: any authenticated caller 200; unverified-kiro guard ordering; 409 during a concurrent click and during a timer refresh with one spawn total; a parked scrape reported only after the API attempt (API returns a plan while parked → 200 with the plan and no skipped; API has no plan while parked → skipped: scrape_parked, no scrape spawned); cache replaced; auth-class verdict + failed read → reason: signin_required; a lapsed switch from account A to account B never shows A's email or balance under B; a timed-out refresh keeps only the same account's reading; a switch inside the refresh window is caught by the whoami resolved before preserving, on the failure and the parked paths alike. test/test_usage_scrape_editable.py (3 pass): key not editable, not in the schema, not in the registry; a config.json carrying it loads and round-trips with zero log lines. TestFetchUsageBg: a recording fake pins the order whoami, kill, wait, whoami on both the timeout and the exception path, one kill, elapsed under 5 s. TestCredentialSelectionIsAnchored: the API path runs whoami, api, whoami; an A→B switch between the two publishes nothing and leaves {"available": False} with no trace of A; the same account publishes the adjacent snapshot's fields; a Builder ID pair agreeing on email alone publishes; the same email in a different org is a switch. Two identity-less whoamis with an API plan never publish the API numbers, spawn one scrape and cache its reading; with the scrape parked the cache is exactly {"available": False}; an identity that appears or vanishes between the two is a switch with no scrape. The scrape is bracketed too: order whoami, api, whoami, spawn, whoami; A→B across the scrape publishes nothing; {}×3 publishes nothing; a top whoami that fails but a bracket that proves A publishes from the after-snapshot; parked API partials ride the marker only when the pair agrees. Frontend (App.test.tsx 110, App.creditPillError.test.tsx 7, KiroAccountModal.test.tsx 32): config 500 with no reading renders the dash with the config label and no no-reading label; opening shows the alert with hand-off and an enabled Refresh and re-reads the config; with that retry left hanging for 600 ms the dash, alert and dialog persist; the Refresh press invalidates the config query again before the POST.

Frontend, KiroAccountModal.test.tsx (23 pass): Refresh in the reading, failed and none states; pending disabled with aria-busy and no second POST; success re-renders the meter and writes the query; stale line present on stale; a refresh that returns stale is not stamped as checked now and shows the stale-refresh notice; 409 renders as a status line with no alert and re-reads after 3 s; parked and generic copy; a cold failure renders through ErrorNotice with the hand-off and Refresh under it; a refresh that resolves to no reading writes that state into the query and the previous account's email is gone; askAgent and onHandoff on every failure notice; a parked refresh writes its result into the query before the notice; the pill keeps a dash and the modal stays open on a no-reading payload; the dash is absent for a non-Kiro backend and present for Kiro; a 409 renders through the notice with the hand-off, re-reads after 3 s and holds Refresh; one notice at a time in the failed state; Refresh held while parked or in flight. src/i18n/productName.test.ts passes (the round-one string it flagged is gone).

Mutation-verified, source restored byte-identical after each: drop the 409 → 2 fail; pre-check the back-off before the API → 1 fail; drop the scrape_parked marker → 2 fail; drop signin_required on read failure → 2 fail; drop the frontend 409 classification → 1; not disabling while pending → 1; drop the query write → 2; drop onHandoff → 1; drop askAgent → 3; drop the stale line → 1; drop the identity check in _cache_transient_failure → 5; pass the cache instead of the whoami on the timeout path → 1; re-add setCheckedAt on a stale refresh → 1; drop the stale-refresh notice → 1; render 409 as an alert → 1; drop the 3 s re-read → 1; route the cold failure back to the passive div → 1; drop its hand-off → 1; skip the query write on a no-reading refresh → 1; preserve against the top-of-refresh identity → 1; pass the stale identity on the parked path → 1; skip the query write on a parked refresh → 1; restore the modal auto-close → 1; hide the dash on a no-reading payload → 1; drop the backend check → 1; treat an unloaded config as Kiro → 1; drop the 409 hand-off → 1; drop the 409 re-read → 1; not hold Refresh on 409 → 1; stack both notices → 1; keep the stale line under the stale notice → 1; not hold Refresh → 4; hold only in flight → 2. Round 12: drop the config-unreadable branch → 1; isError-only → 1; no config re-read on open → 2; none on Refresh → 1; notice without hand-off → 2; old reap order on timeout → 1; on exception → 1; reap without kill → 4. Round 13: drop the adjacent check → 4; compare against the top identity → 7; publish before the check → 1; merge top-identity fields → 1; ignore start_url → 1; one-sided agreement → 1. Round 14: empty pair agrees → red; skip the scrape fallthrough → red; publish before the check → red; keep api_usage on the parked marker → red; one-sided evidence agrees → red; ignore a disagreeing field → red. Round 15: drop the before-snapshot → 7; judge the scrape against the top identity → 3; publish on unproven → 3; label from before → 1; publish before the check → 7; no-plan path against the top identity → 2; partials on an unproven pair → 1.

Manual verification

/usage cost: kiro-cli chat --no-interactive --agent kirocrew-lite /usage run three times at 22:22:10, :19, :26 UTC; the printed "Credits (N of M covered in plan)" showed the same N each time. Output is the usage table only, no model text.

npm run verify:usage-refresh mounts the built SPA against the stub API, opens the pill's modal and asserts each state (button present where expected, pending disabled, one POST per click, meter reads the refreshed payload, pill updates, no credit control on Display) before shooting the frames below. Gates run locally: black (diff-scoped), isort, flake8, mypy, comment-history, feature-map, docs-lint, tsc, eslint at CI's warning cap, i18n:check with the per-locale suites.

Screenshots / video

A reading with the compact Refresh:

reading light

No reading yet, with the primary Refresh:

failed light

An earlier reading, said plainly:

stale light

A refresh already running:

in-flight light

Pending, dark variants, and Settings > Display without the toggle

pending light
reading dark
failed dark
stale dark
in-flight dark
checked at light
paused light
paused dark
failed refresh light
stale refresh light
no reading light
pill no reading light
pill no reading dark
config unreadable light
signin required light
display light
display dark

Related Issues

no linked issue: #7627 asked for the fallback to be reachable without the CLI, which an always-on fallback satisfies; #12037's placement of the toggle is moot once the toggle is gone.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

@CrysisDeu
CrysisDeu requested review from a team and krishdhasmana September 22, 2026 21:48
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Intent: Make the billed credit-balance fallback pay-per-click: a Refresh button beside the meter runs one owner-only, single-flight, cooled-down /usage turn, and the Settings > Display background toggle goes away.
Not a goal: Removing or renaming the dashboard.usage_text_scrape_enabled config key (that is an RFC-level change); touching the free usage API path; changing the top-bar pill beyond reading the refreshed payload.

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

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

The no-cost premise is verified on an unspecified account class, yet the opt-out for exactly the untested class (org/IAM Identity Center) is deleted.

Watch

The design overturns #2039's pin ("a REAL billed kiro-cli chat turn") on three evidence legs, but the empirical leg — "three back-to-back runs on this account… unchanged" — doesn't state the account class, and the fallback fires only for accounts the free API returns no credits_plan for, which the author's account apparently isn't. If /usage bills differently for that class, or a future kiro-cli routes it through a model turn, the timer spends credits every 10 minutes per open tab with no in-product off-switch ("No toggle, no key"); the remedy is a revert. The mechanism argument (client-side slash command over the same free GetUsageLimits call) is account-independent and probably sound, which is why this is not a Blocker.
Clears when: the three-run cost check is repeated on an account of the affected class (one whose API response carries no credits_plan), or a maintainer confirms /usage is unbilled for org-managed/IAM Identity Center accounts.

[DESIGN-REVIEWED] d15c192

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of d15c1926a4acbd56eccadc815353ca7c673d2439 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d15c192

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

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ human override accepted

@CrysisDeu overrode this lane for d15c1926a4acbd56eccadc815353ca7c673d2439 via /ai-review override (this commit only).

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

A transient kiro-cli whoami failure is indistinguishable from an account switch on every new bracket, so a good reading is discarded and the cache blanked — advisory only; nothing blocks.

FINDING — src/kiro_crew/dashboard/handlers/sessions.py:926 — _adjacent_identity returns await _fetch_whoami(kiro_bin), which maps any whoami failure (30 s timeout, nonzero exit, spawn error) to {}, so _whoami_agreement({"email": …}, {}) hits the a is None and b is None miss and returns _WHOAMI_DIFFERENT: a refresh whose second whoami merely failed logs "the signed-in account changed during the refresh" as fact, drops a just-fetched API reading, skips the scrape fallback entirely, and _cache_transient_failure({}) fails _same_identity so a previously-good reading for the same account is overwritten with {"available": False} → Fix: have _adjacent_identity call _fetch_whoami_or_none and treat its None as _WHOAMI_UNPROVEN (dropping the or {} at the four call sites), keeping different for two snapshots that both actually answered.

FINDING — src/kiro_crew/dashboard/handlers/sessions.py:193 — the touched comment still sizes the ceiling as "whoami ≤30s + the /usage scrape ≤60s" while the refresh now runs three whoami calls on the scrape path (top, before at :1115, after at :1124) and four when the API branch falls through unproven, so the bounded sum is 180–210 s against _USAGE_FETCH_DEADLINE_SECS = 180; a healthy-but-slow host is cancelled mid-after, feeds _record_scrape_outcome(False), and three such cycles park the scrape for 6 h — and the handlers' own await _adjacent_identity() runs outside the wait_for, so the guard the comment says is "guaranteed to release" is held up to ~215 s → Fix: raise _USAGE_FETCH_DEADLINE_SECS to cover the new sum (or give the bracketing whoamis a shorter bound) and restate the comment's arithmetic with the real call count.

FINDING — src/kiro_crew/dashboard/handlers/sessions.py:546 — the new docstring asserts _WHOAMI_SAME is "at least the proof _same_identity demands (email AND start_url)", but the loop sets proven = True on a single matching field, so the docstring's own example (a Builder ID account reporting "its email alone") yields _WHOAMI_SAME while _same_identity on that same pair returns False — the weaker predicate gates publishing and the stronger one gates preserving → Fix: correct the docstring to state that the agreement test is deliberately weaker than _same_identity, or make _WHOAMI_SAME require the same both-field proof.

[OPUS-REVIEWED] d15c192

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

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

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — 🟡 CONCERNS

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

UX-Verdict: CONCERNS

One stale fact ships in two tones and wordings, and "Try again in about N min." sits above a Refresh the modal keeps disabled.

Watch

  • Same situation, two severities: the quiet grey balance_may_be_stale ("Showing an earlier reading; the latest refresh did not return one.") and the red refresh_returned_stale ("The refresh did not return a new reading. Showing the earlier one.") state one fact in different words and alarm levels — the blind reader: "I can't tell why the same situation is calm in one and alarming in the other." Hit by anyone whose refresh returns stale, every time. Use one sentence, and reserve red for the user-initiated outcome only if the tones must differ.
  • refresh_paused says "Try again in about {{minutes}} min." while held disables Refresh and the parked notice never clears until the modal is reopened — copy invites the exact press the control refuses; reader on shot-11: "I'm unsure if pressing it now would work at all → no idea." Fix: leave Refresh enabled (a press just re-reports parked) or say checks resume automatically at that time.

Suggestions

  • Render the benign 409 ("A refresh is already running.") in the grey status style, not the red ErrorNotice with an agent hand-off — it self-clears in 3 s and needs no alarm (shot-04).
  • credit_usage_signin_required still instructs "running kiro-cli login"; the reader had "no idea how I would 'run kiro-cli login' as an ordinary user" — name where to run it (a terminal) or lean on the Ask-the-agent hand-off in the copy.

[UX-REVIEWED] d15c192

@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 Sep 22, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/usage-refresh-button branch from 4b8892f to e236ee2 Compare September 22, 2026 23:41
@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 Sep 22, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/usage-refresh-button branch from e236ee2 to 604e40b Compare September 23, 2026 00:40
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Design, watch: the "free /usage" premise is verified on one account and one kiro-cli version; keep the key as a kill switch. Declined on the key; the premise now has provenance beyond the measurement, in the description. /usage is listed in the kiro.dev CLI reference's slash-command table beside /help and /context ("Usage limits with progress bar and credit balance"), a client-side panel, and the kiro-cli 2.23.0 binaries carry AmazonCodeWhispererService.GetUsageLimits plus operation/get_usage_limits.rs, the same free call the pill's primary path makes. A slash command that opens a local panel has no model turn to bill; a version that changed that would be changing what /usage is, not a billing flag. The maintainer's decision is that a config key guarding a cost that does not exist is dead surface, and the back-off that parks a broken scrape after three misses stays as the safety for a changed output format. The stale route comment the First Principles lane flagged is deleted on this head.

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

Copy link
Copy Markdown
Contributor Author

UX, watch: 409 rendered as an error; three outcomes unshot; bonus-row label. Fixed on this head for the first two. A colliding click now renders as progress: a muted role="status" line with a spinner, no alarm styling, no agent hand-off, and the usage query is re-read 3 s later (the pill's own 30 s poll covers a slower gateway refresh); a mutant that renders it as an alert fails a test. The Checked-at row, the parked notice, the generic failure and the new stale-refresh notice are each in an asserted frame in the description (light and dark). The bonus rows' reuse of remaining_credit_balance is on origin/main at lines this PR does not touch, so it is left for its own change rather than widening this one.

@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 Sep 23, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/usage-refresh-button branch from 604e40b to 9b2e188 Compare September 23, 2026 01:47
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Design, watch: the free-read premise was verified on an account whose CLI printed a plan, while the fallback fires for accounts the API returns no plan for; also on kiro-cli 2.23.0 only. Declined, with one correction to the premise of the finding. The account the measurement ran on IS the fallback case: the dashboard's fetch_usage_limits returns no credits_plan for it (an org-managed plan, which is exactly why its pill was empty and why this work started), while /usage prints "Credits (N of 10000 covered in plan) … Your plan is managed by your organization's administrator." So the measurement covers the only account class the fallback ever runs for. On versions: /usage is documented as a client-side panel in the kiro.dev CLI reference, and the binary carries the GetUsageLimits client it reads from; a CLI release that turned a documented local panel into a metered chat turn would be a change to what /usage is, and a minimum-version guard in this repo cannot see that either. The safety that does track the CLI, the output parser plus the three-miss park, is unchanged. The maintainer's decision is that a kill switch for a cost that does not exist is dead surface.

@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 Sep 23, 2026
@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 Sep 23, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/usage-refresh-button branch from e26d2e0 to 02eb060 Compare September 24, 2026 00:26
@CrysisDeu

CrysisDeu commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Opus, BLOCK: a failed ['kirocrewConfig'] read hid the pill and its recovery path. Fixed on 02eb060f22115c126cdd563a06ab59632b2d0d8b. App.tsx derives config-unreadable from errorUpdatedAt > 0 && data === undefined when the usage query says none; the pill keeps its segment as a dimmed dash labelled "could not read the backend setting; open to retry", and the modal opens on ErrorNotice ("Could not read the gateway configuration.") with the agent hand-off and the Refresh button, invalidating the config query on open and before each refresh POST. isError alone was not used because a data-less errored query reports pending/error: null for the whole refetch and would flip the segment to the hidden shape on every retry; the App test pins that with a retry left hanging. Frame 14-config-unreadable-light is in the body.

Opus, FINDING (span=21910eb8fc84): the adjacent whoami ran before the wedged scrape child was reaped. Fixed on the same head. sessions.py gains _reap_scrape_proc() (kill + bounded wait, idempotent); the TimeoutError and Exception handlers call it before _adjacent_identity(), and finally reuses it. TestFetchUsageBg pins the order whoami, kill, wait, whoami on both paths with one kill and elapsed under 5 s.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

/ai-review override first-principles 02eb060: /usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@CrysisDeu marked the first-principles AI finding as false positive, not applicable, or explicitly accepted for 02eb060f22115c126cdd563a06ab59632b2d0d8b.

/usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

This decision applies only to this commit. A new push requires a new judgment.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

UX, BLOCK (evidence): the paused frame showed a superseded layout. Fixed in the body: 08-paused-light and 08-paused-dark re-shot by npm run verify:usage-refresh at this head (scenario 08 asserts the paused notice replaces the standing box and sits above Refresh) replace the earlier frames. No code change; UX Review rerun on this head to read the current body.

UX, watch: "Could not read the gateway configuration." Held for the next push if one is needed; the sentence is changed to "Could not load settings, so your balance can't be shown." then. The notice already carries the agent hand-off and the Refresh button beneath it, so the action is present on this head.

UX, watch: stale and in-flight outcomes render in the alert. Declined on the same grounds as the previous heads: the GPT lane's blocking rule errors-use-error-notice requires every non-success outcome to go through ErrorNotice; the earlier-reading footnote yields while the outcome notice shows, so the fact is stated once.

UX, watch: the dimmed "—" pill's explanation is hover-only. Declined as on the previous heads: the segment carries the same text as aria-label, and opening it lands on the notice plus Refresh; a label in the pill itself would widen the header for a transient state.

@CrysisDeu
CrysisDeu force-pushed the fix/usage-refresh-button branch from 02eb060 to ce595e7 Compare September 24, 2026 01:27
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

GPT, BLOCK (fenced): the API publish path judged identity against the top-of-refresh whoami. Fixed on ce595e751cbe. The API success branch now resolves a second whoami adjacent to the publish (_adjacent_identity()), publishes only when _same_whoami_account(identity, fresh_identity) holds (field-wise agreement over email, start_url and profile ARN wherever either snapshot carries them; evidence on one side only refuses), couples and merges the identity fields from that adjacent snapshot, and on a switch writes _cache_transient_failure(fresh_identity) so nothing of the previous account is kept. The text-branch comment that claimed the API branch did not need this is rewritten to the actual contract. TestCredentialSelectionIsAnchored pins the order whoami, api, whoami, the A→B discard with the cache still holding the pre-refresh value at the second whoami, the Builder ID (email-only) and same-email-different-org cases; seven mutants killed (drop the check, compare against the top identity, publish before the check, merge top-identity fields, ignore start_url, one-sided agreement).

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

/ai-review override first-principles ce595e7: /usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@CrysisDeu marked the first-principles AI finding as false positive, not applicable, or explicitly accepted for ce595e751cbeec4db7a10911803cd8b17cc03e5b.

/usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

This decision applies only to this commit. A new push requires a new judgment.

@CrysisDeu
CrysisDeu force-pushed the fix/usage-refresh-button branch from ce595e7 to c5121ca Compare September 24, 2026 01:58
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

GPT, BLOCK (fenced): two empty whoami snapshots agreed vacuously. Fixed on c5121ca2c6. _same_whoami_account is replaced by _whoami_agreement(before, after) with three verdicts: same requires at least one of email, start_url, profile ARN present as a non-empty string in both snapshots and equal, with no carried field disagreeing; different (any carried field disagrees, or evidence on one side only) discards the reading and writes _cache_transient_failure(fresh_identity), so nothing of the previous account is kept and no scrape runs for it; unproven (no identity evidence on either side) never publishes the API numbers — api_usage is dropped and the refresh falls through to the /usage text scrape, kiro-cli's own panel, which describes the signed-in account by construction and is gated on its own adjacent whoami. Dropping api_usage before the fallthrough also keeps the API's credits_plan off the parked marker. Tests: two identity-less whoamis + an API plan → _publish_usage never sees the API numbers, one scrape spawned, the cache holds the scrape's reading; same pair with the scrape parked → cache exactly {"available": False}; {}→{email} and {email}→{} are switches with no scrape; the Builder ID email-only case still publishes. Six mutants killed (empty pair agrees, skip the fallthrough, publish before the check, keep api_usage on the parked marker, one-sided evidence agrees, ignore a disagreeing field). Spec and feature-map sentences rewritten.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

/ai-review override first-principles c5121ca: /usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@CrysisDeu marked the first-principles AI finding as false positive, not applicable, or explicitly accepted for c5121ca2c681d1d70d30af0373e87749b4eeda3f.

/usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

This decision applies only to this commit. A new push requires a new judgment.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

GPT, BLOCK (fenced): the scrape branch labelled and published against a whoami taken only after the read. Fixed on ccb8352ba7, and this round closed the whole class rather than the one line: an identity-window matrix of every await in _fetch_usage_bg (top whoami, API call, pre-scrape, scrape, post-scrape, no-plan, parked, timeout, exception, finally) found two undetected windows — the scrape had no before-snapshot and trusted its after-snapshot unconditionally, and the parked marker carried API partials judged only against the top identity. The invariant now, on both sources: a reading is published only when a whoami taken immediately before the credential read and one immediately after it prove same under _whoami_agreement; different and unproven publish nothing. Scrape branch: before right before the spawn, after right after communicate(), the label and the regression guard use after; a switch or an identity-less pair writes _cache_transient_failure(after) and the refresh ends with no reading. Parked path: the API partials ride the unavailable marker only when the top and parked snapshots agree. The consequence is stated in the docstring and the spec: a kiro-cli whose whoami prints no identity yields no credit reading from either source. Tests pin whoami, api, whoami, spawn, whoami, A→B across the scrape → nothing published, {}×3 → nothing, a top-whoami failure with a proving bracket → published from after; seven mutants killed (drop the before-snapshot, judge against the top identity, publish on unproven, label from before, publish before the check, no-plan path against the top identity, partials on an unproven pair).

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

/ai-review override first-principles ccb8352: /usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@CrysisDeu marked the first-principles AI finding as false positive, not applicable, or explicitly accepted for ccb8352ba710054595f50f8e4358fa0c7cf6fdb5.

/usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

This decision applies only to this commit. A new push requires a new judgment.

When the free usage API returns no plan, the credit pill can still be
filled by running `kiro-cli chat /usage` and reading the table it
prints. That read costs nothing: /usage is a local slash command over
the same free GetUsageLimits call, and three back-to-back runs left the
account's usage counter unchanged. The code treated it as a billed chat
turn, so it sat behind an opt-in config key that defaulted to off, a
Settings > Display toggle for that key, an owner-only gate, and copy
that warned about spending credits.

The read is now the pill's automatic fallback: API first, /usage when
the API has no plan, parked after repeated failures exactly as before.
The account modal gets one plain Refresh button backed by
POST /api/sessions/usage/refresh, refused with 409 while a refresh is
already running and reporting a parked scrape only after the free API
attempt. The dashboard.usage_text_scrape_enabled key, its schema field,
its PATCH allowlist entry, the Settings toggle, its harness, its tests
and its strings are removed; a config.json still carrying the key loads
and keeps it as an unknown extra.
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

/ai-review override first-principles d15c192: /usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@CrysisDeu marked the first-principles AI finding as false positive, not applicable, or explicitly accepted for d15c1926a4acbd56eccadc815353ca7c673d2439.

/usage is a free local kiro-cli panel over GetUsageLimits (measured, documented); a config key guarding zero cost is dead surface, so the fallback is always on and the key/toggle go.

This decision applies only to this commit. A new push requires a new judgment.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Design, watch (span=51e54068b0da): the cost check should be repeated on the affected account class. Declined as on the previous heads. The three-run measurement was taken on the plan-less account class the fallback serves (the API returned no credits_plan for it, which is exactly the branch that runs the read), kiro.dev documents /usage as a client-side panel, and the binary carries GetUsageLimits, the same call the API branch makes for free. The maintainer's decision is recorded in the accepted First Principles override on this head.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

UX, watch (span=37facf2380c3): the earlier-reading fact appears in two severities. Declined on the same grounds as the previous heads: the GPT lane's blocking rule errors-use-error-notice requires every non-success refresh outcome to render through ErrorNotice, so the refresh outcome is an alert; the standing grey footnote yields while that alert shows, so only one statement is on screen at a time.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

UX, watch (span=40d33582634e): the paused copy names a wait while Refresh is held. Declined: the sentence names WHEN the next press will work ("Try again in about N min.") and the button is held for exactly that window, which is the only honest pairing — an enabled button would answer 409/parked again. The notice clears on the next successful refresh or when the modal is reopened after the back-off; a countdown that re-enables the button live is a follow-up if the modal grows a ticking clock.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

UX, suggestion (span=c8e23d9514d0): render the 409 in the grey status style. Declined on the same grounds as the previous heads: the GPT lane's blocking rule errors-use-error-notice covers the 409 outcome; it self-clears with the 3 s re-read and carries the hand-off in the meantime.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

UX, suggestion (span=245ff677d23d): credit_usage_signin_required says "running kiro-cli login". Not changed on this PR: the English sentence is pre-existing and this PR only re-registered four translations of it; the notice carries the Ask-the-agent hand-off, which is the route an ordinary user takes. A wording pass on that sentence belongs with the other sign-in copy, outside this change.

@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 over the First Principles BLOCK, on evidence rather than on the author's own override.

The BLOCK rests on #2039's premise that a usage reader must not itself spend a billed turn. That premise was tested directly against this path, not reasoned about: two kiro-cli chat --no-interactive /usage calls three seconds apart on an org-managed account (the only account class the fallback serves) left the credit count byte-identical and returned the usage table with no model text. The fallback is not a billed turn, so the pin it is said to reverse does not reach it.

Every failure path still has a retreat in code and in tests: no kiro-cli writes available:false without spawning, an unparseable table parks the scraper for 6 hours after 3 strikes, and both timeouts reap the child before writing. The residual risk is upstream changing what /usage costs, whose remedy is a revert, not a config key.

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.

2 participants