Skip to content

bug: subscription_included cost_events store cost_cents=0 — budget gates can't fire #27

Description

@AnilChinchawale

Tracks upstream paperclipai/paperclip#6728.

Problem

100% of cost_events rows with billing_type=subscription_included store cost_cents=0 even when usage_json.costUsd is non-zero. As a result agents.spent_monthly_cents is never incremented and any budget gate built on it is silently a no-op.

Why this is priority #1 for Levi

Levi runs primarily on subscription plans (Claude Pro/Max). Every budget-governance feature we port from upstream (per-agent caps, fallback recovery guards, etc.) depends on spent_monthly_cents being a truthful number. Today it is not. Fix this first or all downstream governance work is silently dead.

Files

  • Cost-event write site in packages/server/src/services/heartbeat.* (or current Levi equivalent)
  • One-time backfill SQL to populate historical rows from usage_json.costUsd

Effort

S — fix at one write site + a backfill SQL. Half a day.

Risk

L — correctness fix to a write path. Only failure mode is double-counting; covered by a regression test that asserts cost_cents matches usage_json.costUsd * 100 for new rows.

Levi-specific implementation note

Pair with upstream PR #6740 (recurring_fixed cost events) ONLY if Levi tracks hosting/Claude subscription as a fixed monthly line. Otherwise scope narrowly to the per-event fix to keep the change small.

Acceptance criteria

  • Any heartbeat run that produces usage_json.costUsd > 0 writes a cost_events row with cost_cents = round(costUsd * 100), regardless of billing_type
  • Backfill SQL applied to all historical rows where cost_cents=0 but usage_json.costUsd>0
  • Regression test: claude-local subscription run → cost_event.cost_cents matches expected
  • agents.spent_monthly_cents is observed to advance month-over-month in production after fix

Surveyed by the Levi planning agent on 2026-05-26.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions