Skip to content

Mobile session cost + per-message model - #4727

Merged
iscekic merged 9 commits into
mainfrom
feat/mobile-session-cost
Jul 24, 2026
Merged

Mobile session cost + per-message model#4727
iscekic merged 9 commits into
mainfrom
feat/mobile-session-cost

Conversation

@iscekic

@iscekic iscekic commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds session cost visibility and per-message model context to the mobile cloud-agent UI, in three product areas:

  1. Session cost in the list — a closed session with cost > 0 shows a subtle $X.XX folded into the row's meta line ($0.12 · 5m ago); null/zero/in-progress sessions are unchanged. Screen-reader users hear a humanized form (cost 12 cents, …).
  2. Cost breakdown in the session cost sheet — the existing Context usage sheet gains a Token usage section (input/output/reasoning/cache read/cache write/total + cache rate) and a collapsible Models (N) section (per model: friendly name + provider, step count, cost; expandable token rows), plus a Subagents residual row so the per-model costs always reconcile to the displayed session total.
  3. Per-message model label — an assistant message shows a subtle dimmed model label on the first assistant turn and whenever the resolved model changes, showing the concrete routed model for kilo-auto turns, the friendly catalog name otherwise, and a cleaned raw id when unresolvable. User messages are never labelled.

Backend / contract changes

  • Persist session total cost (packages/db, services/session-ingest): adds a nullable total_cost_microdollars column to cli_sessions_v2 and best-effort persists the already-computed session total at close (dedup-bounded, wrapped in try/catch so a Postgres failure never breaks metrics). No backfill of historical sessions.
  • Carry the routed model to the client (packages/session-ingest-contracts): adds an optional model field to the step-finish part of kiloSdkPartSchema so the concrete routed model survives the history-load path (the live-stream path already preserved it). A small type-safe accessor in the cloud-agent-sdk layer reads it; the externally generated opencode.gen.ts is not modified.

Notable design decisions

  • Session total cost is persisted at close with no backfill; sessions closed before this ships show no list cost.
  • The cost sheet stays a client-side aggregation (no new endpoint). The displayed session total remains the existing totalCost; per-model step costs plus a Subagents residual always reconcile to it, because subagent cost is folded into the parent message but never onto a step-finish part.
  • No kilocode or web-app UI changes; the only shared-boundary change is the additive step-finish model field.

Testing

  • Unit tests: microdollar cost formatting + humanized spoken cost; the cost-breakdown helper (totals, cache-rate zero-denominator, per-model grouping incl. routed vs requested, no-step-finish fallback, subagent reconciliation with/without a delta); the model-name resolver (catalog hit, date-suffix strip, never-blank); the per-message label resolver + on-change gating; the routed-model accessor.
  • pnpm format, pnpm typecheck, pnpm lint, pnpm check:unused, and the full test suite pass in apps/mobile; typecheck/lint/tests pass for the changed packages/db, packages/session-ingest-contracts, services/session-ingest, and the web router; drizzle check is clean.
  • On-device E2E (F1 list cost, F2 sheet breakdown, F3 label appears/changes) to follow.

Risks

  • Writing to Postgres from inside SessionIngestDO is a new access pattern for that DO; it is bounded to a single write per session close by the existing metricsEmitted dedup and is best-effort (failures logged, not thrown).

@iscekic iscekic self-assigned this Jul 23, 2026
Comment thread apps/mobile/src/components/agents/session-cost-breakdown.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The only incremental change since the last review (pluralizing the accessibility label in the cost sheet's model row) correctly fixes the previously-flagged issue, and no new issues were introduced.

Files Reviewed (1 file)
  • apps/mobile/src/components/agents/session-context-sheet.tsx - incremental fix verified correct, no issues
Previous Review Summaries (5 snapshots, latest commit 459effb)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 459effb)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The only incremental change since the last review (XDG isolation added to the mobile E2E remote-CLI script) introduces no new issues; one previously-flagged accessibility pluralization mismatch in the cost sheet's model row remains open.

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
apps/mobile/src/components/agents/session-context-sheet.tsx 241 Accessibility label always says "N steps" (no singular form), unlike the adjacent visible label
Files Reviewed (34 files)
  • apps/mobile/e2e/remote-cli.sh - incremental change (XDG isolation), no issues
  • apps/mobile/src/components/agents/session-cost-breakdown.ts - reconciliation clamp fix verified correct, resolved
  • apps/mobile/src/components/agents/session-cost-breakdown.test.ts
  • apps/mobile/src/components/agents/session-cost-formatters.test.ts
  • apps/mobile/src/components/agents/message-model-label.ts
  • apps/mobile/src/components/agents/message-model-label.test.ts
  • apps/mobile/src/components/agents/session-model-display.ts
  • apps/mobile/src/components/agents/session-model-display.test.ts
  • apps/mobile/src/components/agents/message-bubble.tsx
  • apps/mobile/src/components/agents/active-now-section.tsx
  • apps/mobile/src/components/agents/active-now-section.test.ts
  • apps/mobile/src/components/agents/remote-session-row.tsx
  • apps/mobile/src/components/agents/session-list-helpers.ts
  • apps/mobile/src/components/agents/session-row-accessibility-label.ts
  • apps/mobile/src/components/agents/session-row-actions.ts
  • apps/mobile/src/components/agents/session-row.tsx
  • apps/mobile/src/lib/session-list-cache.test.ts
  • apps/mobile/src/components/agents/context-usage-display.ts
  • apps/mobile/src/components/agents/context-usage-display.test.ts
  • apps/mobile/src/components/agents/session-context-sheet.tsx - 1 issue (unresolved)
  • apps/mobile/src/components/agents/session-detail-content.tsx
  • apps/mobile/vitest.config.ts
  • apps/web/src/components/cloud-agent-next/hooks/useSidebarSessions.ts
  • apps/web/src/components/cloud-agent-next/store/db-session-atoms.ts
  • apps/web/src/routers/cli-sessions-v2-router.ts
  • apps/web/src/lib/cloud-agent-sdk/index.ts
  • apps/web/src/lib/cloud-agent-sdk/part-utils.ts
  • apps/web/src/lib/cloud-agent-sdk/part-utils.test.ts
  • services/session-ingest/src/dos/SessionIngestDO.ts
  • packages/db/src/schema.ts
  • packages/db/src/migrations/0197_daffy_mentor.sql
  • packages/db/src/migrations/meta/_journal.json
  • packages/db/src/migrations/meta/0197_snapshot.json - generated, skipped
  • packages/session-ingest-contracts/src/rpc-contract.ts

Fix these issues in Kilo Cloud

Previous review (commit c54a2ca)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The previously-flagged cost-reconciliation clamp is now correctly fixed with the documented epsilon-bounded residual; the only new finding is a minor accessibility-label pluralization mismatch in the cost sheet's model row.

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
apps/mobile/src/components/agents/session-context-sheet.tsx 241 Accessibility label always says "N steps" (no singular form), unlike the adjacent visible label
Files Reviewed (33 files, note: this run used the full PR diff since the recorded previous-review base commit does not correspond to this PR's history)
  • apps/mobile/src/components/agents/session-cost-breakdown.ts — epsilon-bounded reconciliation fix verified correct
  • apps/mobile/src/components/agents/session-cost-breakdown.test.ts
  • apps/mobile/src/components/agents/session-cost-formatters.test.ts
  • apps/mobile/src/components/agents/message-model-label.ts
  • apps/mobile/src/components/agents/message-model-label.test.ts
  • apps/mobile/src/components/agents/session-model-display.ts
  • apps/mobile/src/components/agents/session-model-display.test.ts
  • apps/mobile/src/components/agents/message-bubble.tsx
  • apps/mobile/src/components/agents/active-now-section.tsx
  • apps/mobile/src/components/agents/active-now-section.test.ts
  • apps/mobile/src/components/agents/remote-session-row.tsx
  • apps/mobile/src/components/agents/session-list-helpers.ts
  • apps/mobile/src/components/agents/session-row-accessibility-label.ts
  • apps/mobile/src/components/agents/session-row-actions.ts
  • apps/mobile/src/components/agents/session-row.tsx
  • apps/mobile/src/lib/session-list-cache.test.ts
  • apps/mobile/src/components/agents/context-usage-display.ts
  • apps/mobile/src/components/agents/context-usage-display.test.ts
  • apps/mobile/src/components/agents/session-context-sheet.tsx - 1 issue
  • apps/mobile/src/components/agents/session-detail-content.tsx
  • apps/mobile/vitest.config.ts
  • apps/web/src/components/cloud-agent-next/hooks/useSidebarSessions.ts
  • apps/web/src/components/cloud-agent-next/store/db-session-atoms.ts
  • apps/web/src/routers/cli-sessions-v2-router.ts
  • apps/web/src/lib/cloud-agent-sdk/index.ts
  • apps/web/src/lib/cloud-agent-sdk/part-utils.ts
  • apps/web/src/lib/cloud-agent-sdk/part-utils.test.ts
  • services/session-ingest/src/dos/SessionIngestDO.ts
  • packages/db/src/schema.ts
  • packages/db/src/migrations/0197_daffy_mentor.sql
  • packages/db/src/migrations/meta/_journal.json
  • packages/db/src/migrations/meta/0197_snapshot.json - generated, skipped
  • packages/session-ingest-contracts/src/rpc-contract.ts

Fix these issues in Kilo Cloud

Previous review (commit 1c3e4df)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The only changes since the last review fix the previously flagged reconciliation-clamp issue with an explicit, epsilon-bounded residual calculation and matching test coverage; no new issues were introduced.

Files Reviewed (2 files)
  • apps/mobile/src/components/agents/session-cost-breakdown.ts
  • apps/mobile/src/components/agents/session-cost-breakdown.test.ts

Previous review (commit db0792c)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The two files changed since the last review are purely formatter-applied line-wrap changes with no behavioral difference; no new issues were introduced.

Files Reviewed (2 files)
  • apps/web/src/lib/cloud-agent-sdk/part-utils.test.ts
  • services/session-ingest/src/dos/SessionIngestDO.ts

Previous review (commit 1fb55b2)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The session cost breakdown's subagent-residual reconciliation can silently drift from the displayed session total in session-cost-breakdown.ts.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/mobile/src/components/agents/session-cost-breakdown.ts 157 Residual reconciliation is clamped to 0 instead of surfaced, which can silently break the "rows reconcile to total" guarantee under floating-point drift
Files Reviewed (34 files)
  • apps/mobile/src/components/agents/active-now-section.test.ts
  • apps/mobile/src/components/agents/active-now-section.tsx
  • apps/mobile/src/components/agents/context-usage-display.test.ts
  • apps/mobile/src/components/agents/context-usage-display.ts
  • apps/mobile/src/components/agents/message-bubble.tsx
  • apps/mobile/src/components/agents/message-model-label.test.ts
  • apps/mobile/src/components/agents/message-model-label.ts
  • apps/mobile/src/components/agents/remote-session-row.tsx
  • apps/mobile/src/components/agents/session-context-sheet.tsx
  • apps/mobile/src/components/agents/session-cost-breakdown.test.ts
  • apps/mobile/src/components/agents/session-cost-breakdown.ts - 1 issue
  • apps/mobile/src/components/agents/session-cost-formatters.test.ts
  • apps/mobile/src/components/agents/session-detail-content.tsx
  • apps/mobile/src/components/agents/session-list-helpers.ts
  • apps/mobile/src/components/agents/session-model-display.test.ts
  • apps/mobile/src/components/agents/session-model-display.ts
  • apps/mobile/src/components/agents/session-row-accessibility-label.ts
  • apps/mobile/src/components/agents/session-row-actions.ts
  • apps/mobile/src/components/agents/session-row.tsx
  • apps/mobile/src/lib/session-list-cache.test.ts
  • apps/mobile/vitest.config.ts
  • apps/web/src/components/cloud-agent-next/hooks/useSidebarSessions.ts
  • apps/web/src/components/cloud-agent-next/store/db-session-atoms.ts
  • apps/web/src/lib/cloud-agent-sdk/index.ts
  • apps/web/src/lib/cloud-agent-sdk/part-utils.test.ts
  • apps/web/src/lib/cloud-agent-sdk/part-utils.ts
  • apps/web/src/routers/cli-sessions-v2-router.ts
  • packages/db/src/migrations/0197_daffy_mentor.sql
  • packages/db/src/migrations/meta/0197_snapshot.json (generated)
  • packages/db/src/migrations/meta/_journal.json (generated)
  • packages/db/src/schema.ts
  • packages/session-ingest-contracts/src/rpc-contract.ts
  • services/session-ingest/src/dos/SessionIngestDO.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 18 · Output: 2.6K · Cached: 318.7K

Review guidance: REVIEW.md from base branch main

@iscekic
iscekic force-pushed the feat/mobile-session-cost branch from 1c3e4df to c54a2ca Compare July 23, 2026 20:20
Comment thread apps/mobile/src/components/agents/session-context-sheet.tsx Outdated
iscekic added 2 commits July 23, 2026 22:57
The disposable per-worktree remote CLI read the machine-global kilo OAuth
login at $XDG_DATA_HOME/kilo/auth.json and used that production credential
for AI-gateway calls, ignoring the minted local KILO_API_KEY. The local
gateway then rejected it ("You need to sign in to use this model"). Point
XDG_DATA_HOME and XDG_CONFIG_HOME into the disposable CLI home so the CLI
falls back to the minted local token against this worktree's stack.
The Models row accessibilityLabel always said "N steps", so VoiceOver read
"1 steps" while the visible label singularized to "1 step". Mirror the
existing visible-label pluralization in the accessibility label.
@iscekic
iscekic merged commit 236dc91 into main Jul 24, 2026
65 checks passed
@iscekic
iscekic deleted the feat/mobile-session-cost branch July 24, 2026 07:04
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