chore(economy): rip token-economy stubs, keep raw token counts #449

Closed
opened 2026-04-27 13:48:31 +00:00 by claude-desktop · 0 comments
Collaborator

User story

As an operator, I want the fake cost/economy tracking removed and raw token counts (input/output/cache) kept per task and per agent, so that the service has no dead "cost cap" code paths and the metrics actually reflect Pro Max consumption rather than estimated USD.

Why: the economy stubs (max_cost_usd_per_task, warn_at_pct, DEFAULT_MODEL_PRICES, cost_capped status, /raise-cap command, cost sparklines) are placeholders that never matured. They block schema work on agents.json and confuse the dashboard. Pro Max is the actual quota, and that's already tokens.

Acceptance criteria

Server — delete

  • apps/server/src/domain/analytics/token-economy.ts deleted
  • apps/server/src/domain/analytics/token-economy.test.ts deleted
  • /raise-cap slash command + tests removed from domain/workflow/slash-commands.ts(.test.ts)
  • agent.raise_cap flow node + tests removed from domain/flows/agent-nodes.ts(.test.ts)

Server — gut

  • agent-runner.ts:524-530 cost cap extraction + accumulator removed; cost-cap abort path dropped (line 857-864), terminal status falls back to failure
  • dispatch/registry.ts:370-397 cost_warning / cost_capped SSE emission removed; deleteTaskAccumulator import dropped
  • event-log.ts total_cost_usd removed from result-message summary string
  • background/worker.ts max_cost_usd_override field removed from TaskRequest

Shared types

  • TokenEconomyConfig and TokenEconomyPriceEntry deleted from packages/shared/src/resolved-agent.ts; exports removed from packages/shared/src/index.ts
  • "cost_capped" removed from TaskStatus union in packages/shared/src/task-record.ts
  • TriggerEventTaskCostCapped removed from packages/shared/src/trigger-event.ts (interface, union, kinds)
  • cost_burn_usd_per_hour, cost_last_hour_usd, cost_sparkline removed from packages/shared/src/agents-health.ts

Web UI — delete

  • apps/web/src/components/cost-sparkline.tsx deleted
  • fmtCost() deleted from apps/web/src/lib/format.ts
  • CapsPanel and "Cost caps" tab deleted from routes/stats.tsx

Web UI — gut

  • cost_usd rendering removed from task-list.tsx, task-detail.tsx, pipeline-gantt.tsx, pipeline-graph.tsx, stage-pill.tsx
  • cost_warning / cost_capped SSE filters removed from routes/agents.tsx
  • Cost rows/columns removed from stats tables

Database

  • task_history.cost_usd column kept (legacy data preserved); new rows write NULL. No migration. Document in code comment.

Config

  • token_economy.{max_cost_usd_per_task, warn_at_pct, pricing} removed from config/agents.json and Zod schema in shared/config/webhook-config.ts
  • caveman / caveman_labels retained but split out of the token_economy block (top-level caveman field or similar)

Tests

  • just qa passes (typecheck + lint + format)
  • All existing economy-related tests deleted; no new test required

Per-agent token rollup (small additive)

  • /stats quota tab shows per-agent token totals (SUM(input_tokens + output_tokens) GROUP BY agent) over the existing window selector. Reuses task_history columns; no new schema.

Out of scope

  • New per-agent token sparkline UI (deferred; placeholder OK)
  • Repurposing cost_usd column for anything else
  • Full hoist of remaining hardcodes (covered by Phase 2 stories)

References

  • Audit findings (conversation that produced this ticket)
  • docs/token-economy-overview.md — to be updated/deleted as part of this
  • task_history schema in infrastructure/database/task-store.ts
## User story As an operator, I want the fake cost/economy tracking removed and raw token counts (input/output/cache) kept per task and per agent, so that the service has no dead "cost cap" code paths and the metrics actually reflect Pro Max consumption rather than estimated USD. **Why:** the economy stubs (`max_cost_usd_per_task`, `warn_at_pct`, `DEFAULT_MODEL_PRICES`, `cost_capped` status, `/raise-cap` command, cost sparklines) are placeholders that never matured. They block schema work on `agents.json` and confuse the dashboard. Pro Max is the actual quota, and that's already tokens. ## Acceptance criteria ### Server — delete - [ ] `apps/server/src/domain/analytics/token-economy.ts` deleted - [ ] `apps/server/src/domain/analytics/token-economy.test.ts` deleted - [ ] `/raise-cap` slash command + tests removed from `domain/workflow/slash-commands.ts(.test.ts)` - [ ] `agent.raise_cap` flow node + tests removed from `domain/flows/agent-nodes.ts(.test.ts)` ### Server — gut - [ ] `agent-runner.ts:524-530` cost cap extraction + accumulator removed; cost-cap abort path dropped (line 857-864), terminal status falls back to `failure` - [ ] `dispatch/registry.ts:370-397` `cost_warning` / `cost_capped` SSE emission removed; `deleteTaskAccumulator` import dropped - [ ] `event-log.ts` `total_cost_usd` removed from result-message summary string - [ ] `background/worker.ts` `max_cost_usd_override` field removed from `TaskRequest` ### Shared types - [ ] `TokenEconomyConfig` and `TokenEconomyPriceEntry` deleted from `packages/shared/src/resolved-agent.ts`; exports removed from `packages/shared/src/index.ts` - [ ] `"cost_capped"` removed from `TaskStatus` union in `packages/shared/src/task-record.ts` - [ ] `TriggerEventTaskCostCapped` removed from `packages/shared/src/trigger-event.ts` (interface, union, kinds) - [ ] `cost_burn_usd_per_hour`, `cost_last_hour_usd`, `cost_sparkline` removed from `packages/shared/src/agents-health.ts` ### Web UI — delete - [ ] `apps/web/src/components/cost-sparkline.tsx` deleted - [ ] `fmtCost()` deleted from `apps/web/src/lib/format.ts` - [ ] `CapsPanel` and "Cost caps" tab deleted from `routes/stats.tsx` ### Web UI — gut - [ ] `cost_usd` rendering removed from `task-list.tsx`, `task-detail.tsx`, `pipeline-gantt.tsx`, `pipeline-graph.tsx`, `stage-pill.tsx` - [ ] `cost_warning` / `cost_capped` SSE filters removed from `routes/agents.tsx` - [ ] Cost rows/columns removed from stats tables ### Database - [ ] `task_history.cost_usd` column kept (legacy data preserved); new rows write `NULL`. No migration. Document in code comment. ### Config - [ ] `token_economy.{max_cost_usd_per_task, warn_at_pct, pricing}` removed from `config/agents.json` and Zod schema in `shared/config/webhook-config.ts` - [ ] `caveman` / `caveman_labels` retained but split out of the `token_economy` block (top-level `caveman` field or similar) ### Tests - [ ] `just qa` passes (typecheck + lint + format) - [ ] All existing economy-related tests deleted; no new test required ### Per-agent token rollup (small additive) - [ ] `/stats` quota tab shows per-agent token totals (`SUM(input_tokens + output_tokens) GROUP BY agent`) over the existing window selector. Reuses `task_history` columns; no new schema. ## Out of scope - New per-agent token sparkline UI (deferred; placeholder OK) - Repurposing `cost_usd` column for anything else - Full hoist of remaining hardcodes (covered by Phase 2 stories) ## References - Audit findings (conversation that produced this ticket) - `docs/token-economy-overview.md` — to be updated/deleted as part of this - `task_history` schema in `infrastructure/database/task-store.ts`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/claude-hooks#449
No description provided.