Skip to content

feat(cloud-agent): add compute billing UX - #5433

Open
pandemicsyn wants to merge 10 commits into
mainfrom
feat/cloud-agent-billing-ux
Open

feat(cloud-agent): add compute billing UX#5433
pandemicsyn wants to merge 10 commits into
mainfrom
feat/cloud-agent-billing-ux

Conversation

@pandemicsyn

@pandemicsyn pandemicsyn commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rename Cloud Agent inference spend to Token Usage and show separate server-authoritative compute estimates for idle, active, shared, shadow, stopping, and unavailable states.
  • Preserve structured compute billing failures end to end so initial and follow-up prompts show payer-aware 402, 409, and 503 product states without losing prompt text.
  • Add role-aware personal and organization credit actions, no-wake compute status reads, and retry handling for transient stopping/meter-unavailable queue states.

Verification

  • Browser-tested responsive Cloud Agent layout at 375px; live seeded-session status was limited by local session ownership, so no unauthorized session data was exposed.
  • Rendered billing component tests cover exact 402/409/503 copy, balances, actions, accessibility, and payment return URLs.
  • Web transport tests prove structured 402/409/503 billing details survive Worker → Next → browser and legacy token 402 remains distinct.
  • SDK tests cover prompt/command preservation and billing state clearing on retry, normal failure, reset, and destroy.
  • Cloud Agent tests cover no-wake status and transient billing queue retry/exhaustion behavior.

Visual Changes

  • Existing sessions now show Token Usage separately from Compute.
  • Compute displays an estimated hourly rate while idle, payer-level shared interval estimate while active, Not currently charged in shadow mode, and stopping/unavailable states.
  • Structured billing failures render next to the relevant composer with payer-aware recovery actions.
Screenshot 2026-08-21 at 3 06 01 PM

Reviewer Notes

  • No pre-start pricing warning or confirmation was added.
  • Shared sandbox compute is explicitly payer-level and is not presented as a per-session receipt.
  • Compute status reads the exact resolved sandbox ID and Durable Object storage/container state without waking or admitting the sandbox.
  • Active paid intervals use their immutable accepted rate; shadow/idle estimates use the current SKU catalog rate. Monetary values cross APIs as integer microdollars.
  • Insufficient compute credits are non-retryable until a new explicit funded attempt; stopping and meter-unavailable queue failures retry on the existing bounded delivery budget and fail closed at exhaustion.
  • Full verification passed: 19 focused web tests; 251 focused SDK tests; Cloud Agent unit (2,644 passed, 3 skipped), Workers-runtime (217), and wrapper (284) suites; affected typechecks/lints; repository lint; formatting; and git diff --check. Independent static review found no launch blockers.

Comment thread apps/web/src/components/cloud-agent-next/billing-payer-presentation.ts Outdated
Comment thread packages/cloud-agent-sdk/src/session-manager.ts
@kilo-code-bot

kilo-code-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (8 files)
  • apps/web/src/components/cloud-agent-next/CloudAgentBillingError.test.ts
  • apps/web/src/components/cloud-agent-next/CloudAgentBillingError.tsx
  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsx
  • services/cloud-agent-next/src/container-usage.test.ts
  • services/cloud-agent-next/src/container-usage.ts
  • services/cloud-agent-next/src/types.ts
  • services/cloud-agent-next/worker-configuration.d.ts
  • services/cloud-agent-next/wrangler.jsonc
Previous Review Summaries (5 snapshots, latest commit 2c72dcb)

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

Previous review (commit 2c72dcb)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • apps/web/src/components/cloud-agent-next/ChatHeader.test.ts
  • apps/web/src/components/cloud-agent-next/ChatHeader.tsx
  • apps/web/src/components/cloud-agent-next/SessionInfoDialog.tsx

Previous review (commit fd34257)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • services/cloud-agent-next/src/container-usage-context.test.ts
  • services/cloud-agent-next/src/container-usage-context.ts

Previous review (commit c5e33bc)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • apps/web/src/components/cloud-agent-next/billing-payer-presentation.test.ts
  • apps/web/src/components/cloud-agent-next/billing-payer-presentation.ts
  • packages/cloud-agent-sdk/src/session-manager.test.ts
  • packages/cloud-agent-sdk/src/session-manager.ts

Previous review (commit 1ad3e86)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/components/cloud-agent-next/billing-payer-presentation.ts 22 Credit recovery actions attached for 409/503 billing failures
packages/cloud-agent-sdk/src/session-manager.ts 1917 Unguarded billing atom writes can leak across session switch
Files Reviewed (22 files)
  • apps/web/src/app/(app)/cloud/(agent)/chat/CloudChatPageWrapperNext.tsx
  • apps/web/src/app/(app)/cloud/(agent)/chat/page.tsx
  • apps/web/src/app/(app)/cloud/(agent)/page.tsx
  • apps/web/src/app/(app)/organizations/[id]/cloud/(agent)/chat/CloudChatPageWrapperNext.tsx
  • apps/web/src/app/(app)/organizations/[id]/cloud/(agent)/chat/page.tsx
  • apps/web/src/app/(app)/organizations/[id]/cloud/(agent)/page.tsx
  • apps/web/src/components/cloud-agent-next/ChatHeader.test.ts
  • apps/web/src/components/cloud-agent-next/ChatHeader.tsx
  • apps/web/src/components/cloud-agent-next/CloudAgentBillingError.test.ts
  • apps/web/src/components/cloud-agent-next/CloudAgentBillingError.tsx
  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsx
  • apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx
  • apps/web/src/components/cloud-agent-next/billing-payer-presentation.test.ts
  • apps/web/src/components/cloud-agent-next/billing-payer-presentation.ts - 1 issue
  • packages/cloud-agent-sdk/src/schemas.test.ts
  • packages/cloud-agent-sdk/src/schemas.ts
  • packages/cloud-agent-sdk/src/session-manager.ts - 1 issue
  • packages/container-usage/src/contracts.ts
  • services/cloud-agent-next/src/container-usage-context.ts
  • services/cloud-agent-next/src/execution/types.ts
  • services/cloud-agent-next/src/router/handlers/session-management.ts
  • services/cloud-agent-next/src/trpc-error.ts

Previous review (commit d20c157)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/components/cloud-agent-next/billing-payer-presentation.ts 15 Credit recovery actions attached for 409/503 billing failures
packages/cloud-agent-sdk/src/session-manager.ts 1917 Unguarded billing atom writes can leak across session switch
Files Reviewed (38 files)
  • apps/web/src/app/(app)/organizations/[id]/cloud/(agent)/chat/CloudChatPageWrapperNext.tsx
  • apps/web/src/app/(app)/organizations/[id]/cloud/(agent)/chat/page.tsx
  • apps/web/src/app/(app)/organizations/[id]/cloud/(agent)/page.tsx
  • apps/web/src/components/cloud-agent-next/ChatHeader.tsx
  • apps/web/src/components/cloud-agent-next/CloudAgentBillingError.test.ts
  • apps/web/src/components/cloud-agent-next/CloudAgentBillingError.tsx
  • apps/web/src/components/cloud-agent-next/CloudChatPage.tsx
  • apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx
  • apps/web/src/components/cloud-agent-next/SessionInfoDialog.tsx
  • apps/web/src/components/cloud-agent-next/billing-payer-presentation.test.ts
  • apps/web/src/components/cloud-agent-next/billing-payer-presentation.ts - 1 issue
  • apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts
  • apps/web/src/lib/openapi/trpc-openapi.test.ts
  • apps/web/src/lib/trpc/transport.ts
  • apps/web/src/routers/cloud-agent-next-router.ts
  • apps/web/src/routers/organizations/organization-cloud-agent-next-router.ts
  • packages/cloud-agent-sdk/src/index.ts
  • packages/cloud-agent-sdk/src/schemas.test.ts
  • packages/cloud-agent-sdk/src/schemas.ts
  • packages/cloud-agent-sdk/src/session-manager.test.ts
  • packages/cloud-agent-sdk/src/session-manager.ts - 1 issue
  • services/cloud-agent-next/src/agent-sandbox/cloudflare/cloudflare-agent-sandbox.ts
  • services/cloud-agent-next/src/agent-sandbox/protocol.ts
  • services/cloud-agent-next/src/container-usage-context.ts
  • services/cloud-agent-next/src/container-usage.test.ts
  • services/cloud-agent-next/src/container-usage.ts
  • services/cloud-agent-next/src/execution/types.ts
  • services/cloud-agent-next/src/kilo-facade/user-kilo-facade.ts
  • services/cloud-agent-next/src/persistence/CloudAgentSession.ts
  • services/cloud-agent-next/src/router/handlers/session-management.ts
  • services/cloud-agent-next/src/router/schemas.ts
  • services/cloud-agent-next/src/session/pending-messages.ts
  • services/cloud-agent-next/src/session/queue-message.ts
  • services/cloud-agent-next/src/session/session-message-queue.test.ts
  • services/cloud-agent-next/src/session/session-message-queue.ts
  • services/cloud-agent-next/src/terminal/access.test.ts
  • services/cloud-agent-next/src/trpc-error.test.ts
  • services/cloud-agent-next/src/trpc-error.ts

Reviewed by grok-4.6 · Input: 61.4K · Output: 10.1K · Cached: 411.8K

Review guidance: REVIEW.md from base branch main

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