Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

KR-SNAPSHOT-EXPAND-COST-FIELDS — schema v3 cost-ladder spend/pool#169

Merged
rafe-walker merged 1 commit into
feature/phase2-upgradesfrom
feat/kora-KR-SNAPSHOT-EXPAND-COST-FIELDS
May 24, 2026
Merged

KR-SNAPSHOT-EXPAND-COST-FIELDS — schema v3 cost-ladder spend/pool#169
rafe-walker merged 1 commit into
feature/phase2-upgradesfrom
feat/kora-KR-SNAPSHOT-EXPAND-COST-FIELDS

Conversation

@rafe-walker

Copy link
Copy Markdown
Owner

Summary

Bumps the daemon snapshot to schema_version 3 with two new cost_ladder fields and a resolved model_default:

Bucket spec: 17_cc_bucket_prompts/KR-SNAPSHOT-EXPAND-COST-FIELDS_spent_credit_pool.md.

Env vars

Env Default Purpose
KORA_CREDIT_POOL_USD 200.00 Operator override for the credit-pool fallback when the cost-state holder isn't wired. Malformed / non-positive values warn + fall back to DEFAULT_CREDIT_POOL_USD.

Populated vs degraded fields

cost_ladder field Holder wired Holder import fails / raises / None Holder wired but .current raises
current_tier holder.active_rung().name (e.g. WARN_75) "unknown" "unknown"
monthly_budget_pct_used holder.current_pct_used() * 100 rounded 2dp None None
model_default DEFAULT_HAIKU_MODEL (or "unknown" if router import fails) DEFAULT_HAIKU_MODEL DEFAULT_HAIKU_MODEL
spent_to_date_usd holder.current.spent_to_date_usd rounded 6dp "unknown" "unknown"
credit_pool_usd holder.current.credit_pool_usd rounded 2dp (wins over env) KORA_CREDIT_POOL_USD or $200 default KORA_CREDIT_POOL_USD or $200 default

Holder wins over env for credit_pool_usd — rungs compute against the holder figure, so the snapshot must agree.

CC#2 follow-on recommendation

PR #164 (CostCardBody) currently pulls cost figures from /api/cost-telemetry directly. With snapshot v3 surfacing spent_to_date_usd + credit_pool_usd from a single 5-min-cron'd file, CC#2 can shift to reading daemon_snapshot.json instead:

  • Latency: snapshot is local file read (no live cost-holder lookup) — sub-ms.
  • Decoupling: panel survives cost-holder boot windows / restarts without spinning a "loading…" state.
  • Consistency: same figure shown in cockpit as routed against (snapshot reflects whatever the holder reported at last cron tick).

The cron cadence is 5-min so the displayed value will lag by up to 5 min — acceptable for a cockpit panel, but CC#2 should keep /api/cost-telemetry as the live source for any pre-decision read.

Test plan

  • tests/kora_cli/snapshot/test_state_snapshot.py — 47 tests pass (schema bump, shape, env override truthy / malformed / zero, holder-wins-over-env, model-default router-resolved, router-import degrade, holder-current-raises full degrade)
  • Regression: snapshot + telemetry + router + cost_state_holder tests — 159 passed
  • ruff check clean on changed files

🤖 Generated with Claude Code

…end/pool fields

* Bump snapshot schema_version 2 → 3.
* Add `spent_to_date_usd` + `credit_pool_usd` to `cost_ladder` section.
  - When the cost-state holder is wired, fields flow from
    `holder.current.spent_to_date_usd` and `holder.current.credit_pool_usd`.
  - When the holder is unavailable: `spent_to_date_usd` degrades to
    `"unknown"` (no observed-state env); `credit_pool_usd` falls back to
    `KORA_CREDIT_POOL_USD` env (fail-soft, $200 default per
    `reference-anthropic-sdk-billing-split`).
  - Holder wins over env when both are present — the holder figure is
    what the cost rungs compute against, so the snapshot must agree.
* Wire `cost_ladder.model_default` to KR-HAIKU-ROUTER's
  `DEFAULT_HAIKU_MODEL` constant (resolves PR #157's `"unknown"`
  placeholder). Router import fail degrades back to `"unknown"`.
* Tests cover: schema bump, env override (truthy / malformed / zero /
  negative), holder-wins-over-env, model-default resolution,
  router-import degrade, and holder-current-raises full degrade.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rafe-walker rafe-walker merged commit 26a7e99 into feature/phase2-upgrades May 24, 2026
@rafe-walker rafe-walker deleted the feat/kora-KR-SNAPSHOT-EXPAND-COST-FIELDS branch May 24, 2026 03:00
rafe-walker added a commit that referenced this pull request May 24, 2026
…n holdouts (#174)

4-of-4 dashboard hero fields snapshot-driven on warm cache. Verified at DashboardPage.tsx:1270-1345 — loadInitial does NOT call api.getOperationalState / getCurrentAlerts / getCostState / getHealthRollup with fresh snapshot.

PR #162 anti-projection tests FLIPPED (not deleted): test_dashboard_does_not_project_*_from_snapshot → test_dashboard_projects_*_from_snapshot with null-return + per-field fallback pins. New pins: badge surfaces N-of-M hero count + DASHBOARD_HERO_FIELD_COUNT===4 literal regression guard.

K-DG drift caught + fixed: SnapshotResponse TS type was stale — missing cost_ladder.spent_to_date_usd + credit_pool_usd (#169) + the entire daemon_health section (#170). Added; required before projection helpers could compile.

Per-card retry buttons + forceFullLiveRefresh still fan out by design (operator-triggered force paths). 19/19 tests pass, tsc + vite build clean.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant