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

Merged
charles merged 2 commits from chore/449-rip-economy into main 2026-04-27 15:43:22 +00:00
Collaborator

Closes #449.

Summary

  • Rips the placeholder cost-cap subsystem: max_cost_usd_per_task, warn_at_pct, DEFAULT_MODEL_PRICES, /raise-cap, agent.raise_cap flow node, cost_capped status, cost_warning/cost_capped SSE, fleet cost burn, per-agent cost sparkline.
  • Keeps raw token counts (input_tokens, output_tokens, cache_creation_tokens, cache_read_tokens) per task — already in task_history. Pro Max quota is the real ceiling; tokens are what matters.
  • Caveman-appendix logic split out of the token_economy block into a top-level caveman: { enabled, labels } field per agent type. Same behaviour, cleaner schema.
  • /stats per-agent table swaps cost columns for Tokens (in) / Tokens (out) via SUM(input_tokens + output_tokens) GROUP BY agent over the existing window.

Surface

Layer Change
Server Deleted domain/analytics/token-economy.ts(.test.ts); gutted agent-runner.ts, dispatch/registry.ts, event-log.ts, worker.ts, slash-commands.ts(.test.ts), flows/agent-nodes.ts(.test.ts)
Shared TokenEconomyConfigCavemanConfig { enabled, labels }; TaskStatus lost cost_capped; TriggerEventTaskCostCapped deleted (TRIGGER_KINDS now 19 members); FleetHealthResponse lost burn/sparkline/last-hour fields
Web Deleted cost-sparkline.tsx; fmtCost removed; cost rendering stripped from task-list, task-detail, pipeline-gantt, pipeline-graph, stage-pill, agents.tsx; routes/stats.tsx lost the "Cost caps" tab + CapsPanel
Config config/agents.json per-type token_economy block replaced — boss/dev/reviewer get caveman: { labels: ["type:chore"] }; designer/design-reviewer/foreman drop the block
Docs Deleted docs/token-economy.md + docs/token-economy-overview.md; CLAUDE.md ToC pruned

Database

  • task_history.cost_usd column kept for legacy data. New rows write NULL. No migration. Code comment marks it deprecated.

Notable corrections (post-review)

  • listZeroOutputSuccesses predicate drops cost_usd IS NULL — every new row writes NULL post-rip, so the original predicate would have flagged 100% of successful tasks as silent bail-outs. Turns alone remains the signal.
  • slash-commands-other-graph.json drops "raise-cap" from its router predicate + description so flow dispatch doesn't silently no-op on stale commands.

Out of scope (future tickets)

  • StageEntry.cost_usd is now a dead synthetic aggregate — kept for API-shape stability; can be dropped in a follow-up.
  • Phase 2 hardcode hoist (#450-#454).

Test plan

  • just qa passes (typecheck + lint + format)
  • Server unit tests pass
  • Shared package tests pass
  • Web tests: 516/516 pass; 10 pre-existing theme-test failures (window.localStorage.clear is not a function) confirmed unrelated by stashing the branch
  • Manual: dispatch a real task post-merge, confirm task_history.cost_usd is NULL but token counts are populated
  • Manual: open /stats quota tab, confirm Tokens (in) / Tokens (out) columns render

Review

Implementation by general-purpose subagent; reviewed by code-review subagent before commit. Two critical issues found by reviewer (janitor predicate regression + stale flow descriptor) fixed before commit. Ship.

🤖 Generated with Claude Code

Closes #449. ## Summary - Rips the placeholder cost-cap subsystem: `max_cost_usd_per_task`, `warn_at_pct`, `DEFAULT_MODEL_PRICES`, `/raise-cap`, `agent.raise_cap` flow node, `cost_capped` status, `cost_warning`/`cost_capped` SSE, fleet cost burn, per-agent cost sparkline. - Keeps raw token counts (`input_tokens`, `output_tokens`, `cache_creation_tokens`, `cache_read_tokens`) per task — already in `task_history`. Pro Max quota is the real ceiling; tokens are what matters. - Caveman-appendix logic split out of the `token_economy` block into a top-level `caveman: { enabled, labels }` field per agent type. Same behaviour, cleaner schema. - `/stats` per-agent table swaps cost columns for **Tokens (in)** / **Tokens (out)** via `SUM(input_tokens + output_tokens) GROUP BY agent` over the existing window. ## Surface | Layer | Change | |---|---| | Server | Deleted `domain/analytics/token-economy.ts(.test.ts)`; gutted `agent-runner.ts`, `dispatch/registry.ts`, `event-log.ts`, `worker.ts`, `slash-commands.ts(.test.ts)`, `flows/agent-nodes.ts(.test.ts)` | | Shared | `TokenEconomyConfig` → `CavemanConfig { enabled, labels }`; `TaskStatus` lost `cost_capped`; `TriggerEventTaskCostCapped` deleted (`TRIGGER_KINDS` now 19 members); `FleetHealthResponse` lost burn/sparkline/last-hour fields | | Web | Deleted `cost-sparkline.tsx`; `fmtCost` removed; cost rendering stripped from `task-list`, `task-detail`, `pipeline-gantt`, `pipeline-graph`, `stage-pill`, `agents.tsx`; `routes/stats.tsx` lost the "Cost caps" tab + `CapsPanel` | | Config | `config/agents.json` per-type `token_economy` block replaced — boss/dev/reviewer get `caveman: { labels: ["type:chore"] }`; designer/design-reviewer/foreman drop the block | | Docs | Deleted `docs/token-economy.md` + `docs/token-economy-overview.md`; `CLAUDE.md` ToC pruned | ## Database - `task_history.cost_usd` column kept for legacy data. New rows write `NULL`. No migration. Code comment marks it deprecated. ## Notable corrections (post-review) - `listZeroOutputSuccesses` predicate drops `cost_usd IS NULL` — every new row writes NULL post-rip, so the original predicate would have flagged 100% of successful tasks as silent bail-outs. Turns alone remains the signal. - `slash-commands-other-graph.json` drops `"raise-cap"` from its router predicate + description so flow dispatch doesn't silently no-op on stale commands. ## Out of scope (future tickets) - `StageEntry.cost_usd` is now a dead synthetic aggregate — kept for API-shape stability; can be dropped in a follow-up. - Phase 2 hardcode hoist (#450-#454). ## Test plan - [x] `just qa` passes (typecheck + lint + format) - [x] Server unit tests pass - [x] Shared package tests pass - [x] Web tests: 516/516 pass; 10 pre-existing theme-test failures (`window.localStorage.clear is not a function`) confirmed unrelated by stashing the branch - [ ] Manual: dispatch a real task post-merge, confirm `task_history.cost_usd` is NULL but token counts are populated - [ ] Manual: open `/stats` quota tab, confirm Tokens (in) / Tokens (out) columns render ## Review Implementation by general-purpose subagent; reviewed by code-review subagent before commit. Two critical issues found by reviewer (janitor predicate regression + stale flow descriptor) fixed before commit. Ship. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chore(economy): rip token-economy stubs, keep raw token counts (#449)
Some checks failed
qa / qa (pull_request) Failing after 8m56s
qa / dockerfile (pull_request) Successful in 13s
370002a148
Removes the placeholder cost-cap subsystem (max_cost_usd_per_task,
warn_at_pct, DEFAULT_MODEL_PRICES, /raise-cap, agent.raise_cap node,
cost_capped status, cost_warning/cost_capped SSE, fleet cost burn,
per-agent cost sparkline) that never matured past stubs. Pro Max
quota is the real ceiling and that is already tracked in tokens.

What stays:
  - task_history.{input_tokens, output_tokens, cache_creation_tokens,
    cache_read_tokens} — already raw per-task counts
  - task_history.cost_usd column kept (legacy data; new rows write NULL)
  - Caveman appendix logic — split out of the token_economy block into
    a top-level `caveman: { enabled, labels }` field per agent type

What's added:
  - /stats per-agent table swaps cost columns for Tokens (in) / Tokens
    (out) using SUM(input_tokens + output_tokens) GROUP BY agent

Notable:
  - listZeroOutputSuccesses predicate drops `cost_usd IS NULL` — every
    new row writes NULL post-rip, so the predicate would flag 100% of
    successes. Turns alone remains the silent-bail signal.
  - slash-commands-other-graph.json drops "raise-cap" from its router
    predicate + description.
  - TRIGGER_KINDS now 19 members (was 20); flow node-types now 18
    (was 19).
  - StageEntry.cost_usd kept as a synthetic aggregate field for now —
    UI no longer renders it; can be dropped in a follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
fix(tests): repair stats + agents-health asserts post-rip (#449)
Some checks failed
qa / qa (pull_request) Has been cancelled
qa / dockerfile (pull_request) Has been cancelled
937c27828d
Two server tests still asserted economy-era fields after #449:

- `stats.test.ts` "by_agent entries include avg_turns_per_task and
  avg_cost_per_task" — `avg_cost_per_task` is gone. Swap for the
  new token-total fields (`total_input_tokens`, `total_output_tokens`).

- `agents-health.test.ts` "response is cached for 5s — a second hit
  returns the same body" — third-hit assertion checked
  `last_activity.newest_dispatch_ts`, but the test fixture doesn't
  register live workers (it only seeds SQLite via `loadWebhookConfig`),
  so the fleet rollup that walks the worker map never sees the
  persisted task. Previously this passed because the assertion read
  `cost_burn_usd_per_hour` (computed direct from `task_history`,
  no worker-map dependency). Replace with a body-text inequality
  check — cache reset re-runs `buildFleetHealth`, refreshing
  `generated_at`, so the third body must differ from the cached one.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
charles force-pushed chore/449-rip-economy from 937c27828d
Some checks failed
qa / qa (pull_request) Has been cancelled
qa / dockerfile (pull_request) Has been cancelled
to 265a08bc11
All checks were successful
qa / qa (pull_request) Successful in 9m27s
qa / dockerfile (pull_request) Successful in 13s
2026-04-27 15:22:01 +00:00
Compare
charles deleted branch chore/449-rip-economy 2026-04-27 15:43:22 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!467
No description provided.