Skip to content

feat(core): add soft max-cost nudge state - #11831

Merged
johnnyeric merged 4 commits into
mainfrom
johnnyeric/maxcost-nudge-core
Jul 1, 2026
Merged

feat(core): add soft max-cost nudge state#11831
johnnyeric merged 4 commits into
mainfrom
johnnyeric/maxcost-nudge-core

Conversation

@johnnyeric

@johnnyeric johnnyeric commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Context

Add a reusable core state machine for soft per-session max-cost nudges. The nudge tracks cumulative assistant message costs, alerts once a configured whole-dollar limit is crossed, and lets callers continue or stop without hard-blocking the running session.

Implementation

  • Add MaxCostNudge under packages/core/src/kilocode/cost/.
  • Normalize max-cost limits to positive whole-dollar thresholds.
  • Aggregate assistant message costs by session, including updates, removals, resets, direct session cost floors, and session deletion cleanup.
  • Track alerted and acknowledged limit values so continue suppresses repeat alerts while stop can re-arm on the next run.
  • Add focused Bun coverage for normalization, formatting, aggregation, alert lifecycle, and cleanup.

Screenshots / Video

N/A, core logic only.

How to Test

Manual/local verification

  • Agent: bun test ./test/kilocode/cost/max-cost-nudge.test.ts from packages/core/ passed with 19 tests.

Reviewer test steps

  1. From packages/core/, run bun test ./test/kilocode/cost/max-cost-nudge.test.ts.
  2. Review MaxCostNudge behavior for limit normalization, cost aggregation, continue suppression, stop re-arm, and session cleanup.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

@johnnyeric
johnnyeric force-pushed the johnnyeric/maxcost-nudge-core branch from 98517b8 to 7195102 Compare June 30, 2026 12:12
Surface-agnostic, dependency-free MaxCostNudge: aggregates per-assistant
message cost into a session total (session.cost is written via direct SQL
and never emits session.updated), and decides when to fire a non-blocking
"keep going?" alert once a global limit is crossed.

check() alerts once per run; resolve("continue") suppresses re-alerts for
that limit; rearm() re-arms on a new run; onSessionDeleted() clears state.
Consumers own the limit (set via setLimit) and the UI/abort.
@johnnyeric
johnnyeric force-pushed the johnnyeric/maxcost-nudge-core branch from 7195102 to 68f1feb Compare June 30, 2026 12:34
@johnnyeric
johnnyeric marked this pull request as ready for review June 30, 2026 12:38
Comment thread packages/core/src/kilocode/cost/max-cost-nudge.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • packages/core/test/kilocode/cost/max-cost-nudge.test.ts
Previous Review Summaries (2 snapshots, latest commit 506f6e0)

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

Previous review (commit 506f6e0)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/core/src/kilocode/cost/max-cost-nudge.ts 74 updateMessageCost() still leaves the previous assistant cost behind when that message later updates with a non-assistant role.

Fix these issues in Kilo Cloud

Files Reviewed (2 files)
  • packages/core/src/kilocode/cost/max-cost-nudge.ts - 1 issue
  • packages/core/test/kilocode/cost/max-cost-nudge.test.ts - 0 issues

Previous review (commit 68f1feb)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/core/src/kilocode/cost/max-cost-nudge.ts 74 updateMessageCost() keeps a stale assistant cost when a later snapshot no longer has a finite assistant cost.

Fix these issues in Kilo Cloud

Files Reviewed (2 files)
  • packages/core/src/kilocode/cost/max-cost-nudge.ts - 1 issue
  • packages/core/test/kilocode/cost/max-cost-nudge.test.ts - 0 issues

Reviewed by gpt-5.4-20260305 · Input: 44.1K · Output: 4.2K · Cached: 225.3K

Review guidance: REVIEW.md from base branch main

@johnnyeric
johnnyeric merged commit f0cbf8c into main Jul 1, 2026
24 checks passed
@johnnyeric
johnnyeric deleted the johnnyeric/maxcost-nudge-core branch July 1, 2026 10:07
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
* feat(core): soft max-cost nudge state machine

Surface-agnostic, dependency-free MaxCostNudge: aggregates per-assistant
message cost into a session total (session.cost is written via direct SQL
and never emits session.updated), and decides when to fire a non-blocking
"keep going?" alert once a global limit is crossed.

check() alerts once per run; resolve("continue") suppresses re-alerts for
that limit; rearm() re-arms on a new run; onSessionDeleted() clears state.
Consumers own the limit (set via setLimit) and the UI/abort.

* feat(core): extend max cost nudge state

* fix(core): clear stale message cost when value becomes non-finite

* test(core): add missing cost aggregation and session isolation tests
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