Skip to content

feat(usage): token collection pipeline + rate-limit bucket tracking#3

Merged
fdatoo merged 8 commits intomainfrom
claude/usage-pipeline
Apr 30, 2026
Merged

feat(usage): token collection pipeline + rate-limit bucket tracking#3
fdatoo merged 8 commits intomainfrom
claude/usage-pipeline

Conversation

@fdatoo
Copy link
Copy Markdown
Owner

@fdatoo fdatoo commented Apr 30, 2026

Summary

  • Token collection per run: A usage_tailer actor starts alongside each container, polls runs/<id>/mount/**/*.jsonl every 2s, parses Claude's JSONL output, and atomically writes token counts to run_usage_events + runs.tokens_*. Live {"type":"usage"} frames flow over the run WebSocket so RunUsage updates in real-time during a run.
  • Rate-limit buckets + Usage page: Rate-limit headers embedded in JSONL lines are parsed into rate_limit_buckets. GET /api/usage now returns real data (utilization bars, countdown timers) instead of the missing_credentials stub. The usage WebSocket publishes {"type":"snapshot"} frames on every bucket update.
  • Threshold notifications + pacing: Crossing 75% or 90% emits {"type":"threshold_crossed"} on the usage pubsub (picked up by UsageNotifier for browser notifications). Pacing verdicts (chill/on_track/hot) are computed from window_started_at/reset_at and included in every snapshot.

Test plan

  • Start a run and watch RunUsage in the drawer populate with live token counts
  • Check /usage page shows bucket utilization bars and countdown timers after the first JSONL line with rateLimits is parsed
  • Verify GET /api/usage/daily returns non-zero token totals after a completed run
  • Confirm browser notification fires when a bucket crosses 75% (requires notifications enabled in Settings)
  • make test-server passes (48 tests)

🤖 Generated with Claude Code

fdatoo and others added 8 commits April 30, 2026 10:21
Fixes the "Format check" step on this PR's CI.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fdatoo fdatoo merged commit 7d7032c into main Apr 30, 2026
1 of 2 checks passed
@fdatoo fdatoo deleted the claude/usage-pipeline branch April 30, 2026 13:03
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.

1 participant