Repository navigation
Description
Summary
All the data needed to understand subscription pressure already exists in the database — token counts per message, cost per execution, rate-limit events per subscription — but none of it is surfaced in the UI. Operators have no way to see how close a subscription is to its 5-hour rolling limit, which agents are burning the most quota, or how frequently a given subscription has hit the wall. This issue wires the existing data to the front end.
Context
Triggered by subscriptions exhausting their limits significantly faster than expected (#435, SUB-003). Investigation confirmed:
subscription_idis already recorded on everychat_messagesandschedule_executionsrow (wired intask_execution_service.py)GET /api/subscriptions/{id}/usagealready aggregates 5h and 7d token windows from that data (SUB-004)subscription_rate_limit_eventstable is populated by SUB-003 on every 429, but is never exposed via APISettings.vuesubscription list calls none of these endpoints — all data is dark
Anthropic does not expose remaining budget or proximity-to-limit. The only signal available is the 429 itself and our own token consumption records.
Acceptance Criteria
Tier 1 — Surface existing data in Settings → Subscriptions
- Each subscription card in Settings.vue shows a usage summary for the last 5 hours: input tokens, output tokens, cost (USD), message count
- Each subscription card shows a 7-day aggregate for the same fields
- Rate-limit event count (last 24h) is shown per subscription with a visual warning indicator if > 0
- Data auto-refreshes on page load (no polling needed)
Tier 2 — Per-agent breakdown endpoint
- New endpoint
GET /api/subscriptions/{id}/usage/breakdownreturns token consumption grouped byagent_namefor the 5h and 7d windows - Settings.vue subscription cards show an expandable per-agent breakdown (collapsed by default)
- Makes it clear which agent is consuming the most quota on a shared subscription
Tier 3 — Subscription pressure indicator on Agents list
- Agents.vue shows a small warning badge on any agent card whose subscription had 1+ rate-limit events in the last 24h
- Hovering the badge shows the subscription name and event count
- Badge is sourced from a new lightweight endpoint (or piggy-backed on the existing agents list response)
Tier 4 — Auto-assign to available subscription
- Settings → Subscriptions shows an "Auto-assign agents" button (or equivalent action per subscription card)
- Clicking it reassigns all agents whose current subscription is rate-limited to the selected subscription (if that subscription has no active rate limit)
- If no available subscription exists, the button is disabled with a tooltip explaining why
- The action is scoped to subscriptions the user owns; admin can act across all
Technical Notes
Backend changes needed:
db/subscriptions.py: addget_rate_limit_event_count(subscription_id, hours=24)methodrouters/subscriptions.py: newGET /{id}/usage/breakdownendpoint, newGET /{id}/rate-limit-eventsendpoint (or add count to existing/usageresponse)routers/agents.pyor agents list response: optionally includesubscription_rate_limited: boolper agentrouters/subscriptions.py: newPOST /{id}/auto-assignendpoint — reassigns agents from rate-limited subscriptions to this one; returns count of agents reassigned
Frontend changes needed:
Settings.vue: call/api/subscriptions/{id}/usageper subscription on load; render usage bars + rate-limit badgeAgents.vue: call new lightweight endpoint or extend existing agent list response to carrysubscription_rate_limitedflagSettings.vue: "Auto-assign agents" button per subscription card; callsPOST /{id}/auto-assign, shows toast with reassignment count
Related issues:
- fix: Replace budget display with actual token usage tracking #250 — Replace budget display with actual token usage tracking (agent detail page; complementary but different scope)
- Subscription auto-switch: trigger on any subscription/auth failure and enable by default #442 / Lower subscription auto-switch threshold to 1 failure and broaden to auth errors #441 — Improve auto-switch behavior (reactive; this issue is about proactive visibility)
- bug(subscriptions): auto-switch (SUB-003) does not fire on monthly usage cap exhaustion #435 — Auto-switch doesn't fire on monthly cap exhaustion (related context)
Constraints:
- Anthropic does not expose remaining budget in the current 5-hour window; proximity-to-limit must be inferred from token consumption history + rate-limit event frequency
- All DB queries must use existing indexes (
idx_chat_messages_subscription,idx_executions_subscription,idx_rl_events_subscription)
Activity
vybe commentedon Jul 28, 2026
Promoted incubating → ready (operator, 2026-07-28) — greenlit together with its dashboard-tile consumer, trinity-enterprise#259.
Added scope — estimation-precision research (pre-build). Before the Tier 1 UI work starts, produce a short findings note (as a comment here) answering how precise a "remaining headroom" estimate can actually be, given that Anthropic exposes no remaining-budget API:
Research acceptance: achievable precision stated honestly (what can and cannot be known), the weighting scheme, the calibration approach for shifting plan limits, and the adapter boundary — recorded on this issue before build.
vybe commentedon Aug 7, 2026
Premise correction (2026-08-07): the Technical Notes constraint — "Anthropic does not expose remaining budget or proximity-to-limit; the only signal available is the 429 itself and our own token consumption records" — is no longer accurate, and was already contradicted by evidence in this repo when it was written:
scripts/poc/test-subscription-usage.py(Feb 2026) validatedGET https://api.anthropic.com/api/oauth/usage— with a subscription OAuth bearer token and headeranthropic-beta: oauth-2025-04-20it returns actual 5-hour and 7-day utilization percentages, per-model limits, and reset times. See the 2026-02-23 planning entry indocs/archive/memory/changelog.md(the poller + usage MCP tools planned there were never built). Caveats: undocumented endpoint, aggressively rate-limited without a properUser-Agent— treat as best-effort with the DB-derived aggregate as fallback.rate_limitsobject piped to the statusline command —five_hour/seven_day→used_percentage+resets_atfor subscription sessions: https://code.claude.com/docs/en/statusline.mdImplication for this issue: the 5h/7d usage bars (Tier 1) and the pressure indicator (Tier 3) can show actual utilization sourced from Anthropic (with the existing DB-derived aggregate as honest fallback, source flagged), instead of only inferred consumption. Tier structure stays as specced; the data source upgrades.
vybe commentedon Aug 14, 2026
Priority raised P2 → P1 (operator reconciliation, 2026-08-14).
Rationale: this is the data layer under five separate consumers, and it is the only one of them nobody has scheduled — nothing in the v0.9 cut touches it.
Consumers waiting on it:
trinity-enterprise#259— Subscription-pressure grid tile (ready)trinity-enterprise#351— agent subscription self-awareness, self + fleet (ready)trinity-enterprise#98/#101— fleet cost + token-consumption tiles (incubating)trinity-enterprise#166— enforceable per-agent spend cap (incubating, and blocked on this: the spend figure shown today is an API-price estimate, not real subscription cost, so a cap built on it would enforce a fiction)Operator, on the record 2026-08-14: "these are definitely going in… that's one of the problems I'm running into all the time."
Sequencing note: the grid chassis (
trinity-enterprise#325) and bucketed timeline rollups (#326) ship in this release, which makes #259 a small build immediately after the cut — this data layer is the thing standing in front of it.Premise correction from 2026-08-07 stands unchanged and is a prerequisite read before build.
vybe commentedon Aug 17, 2026
Adding the concrete approach, prompted by #2170, which attempted this and took a wrong turn worth recording so nobody repeats it.
Don't build on a provider allowance signal. #2170 shipped a discriminated
subscription/api/unconfiguredcontract whoseavailablearm requires an allowance percent, window, and reset from Anthropic. That signal doesn't exist under setup-token auth, so the arm is unreachable and every subscription agent rendersusage unavailablepermanently. This issue already established that in April. Treat the 429 and our own consumption records as the only inputs.Step 0 — verify the cost figure under subscription auth. For Claude Code,
costis the runtime's nativetotal_cost_usd(token counts at API prices), not our estimate. Confirm it's actually populated when auth is an OAuth subscription token rather than an API key:on an instance with real subscription traffic. Everything below assumes non-zero; if it's zeros, drop to token counts only.
Tier 0 (new) — relabel, don't delete. The live defect is semantic, not numeric: a bare
$on a subscription agent reads as a bill. Keep the sparkline, today's cost, and the trend; present them as API-equivalent (≈$3.12 API-equivalent) with a billing-mode badge naming the funding subscription. Agents on a platform/per-agent API key keep plain metered-cost semantics. This is a labeling change on existing surfaces — no contract change, no aggregation change, and it leaves enterprise #166's spend-cap foundation intact.Tiers 1–3 as already specified. Wire the dark data:
/usage5h/7d windows into Settings → Subscriptions, a rate-limit event count with a warning indicator, then the per-agent breakdown and the pressure badge. Proximity-to-limit is inferred from our own consumption plus 429 frequency — stated as inference, never as a provider reading.Out of scope here: the fleet roster (
get_all_agent_metadata) also serves shared non-owner users, so putting subscription names on it is an access decision to make deliberately, not a side effect of a display change. If a provider-side signal ever appears, #855 is the spike that establishes it and the contract gets designed then, against a real payload.9 remaining items
feat(dashboard): Subscription pressure grid tile — per-subscription 5…
fix(subscriptions): a rejected token is not a rate limit (#2354)
feat(subscriptions): headroom history — durable probe snapshots for u…
feat(subscriptions): a recovered subscription stops claiming it is ra…
docs(requirements): file the weekly-limit alert as §20.5c (Abilityai/…
fix(#2358): Dashboard List columns share ONE sizing context, and a la…
fix(subscriptions): a pull-dispatched terminal triggers SUB-003 (#2643)…
Merge origin/dev into fix/2638-subscription-switch-on-turn
fix(workspace): thread titles authenticate as the agent, not as the i…
feat(model): one model door for the backend — the credential follows …
fix(model): the token is read before the rate limit, the limit is the…
feat(model): one model door for the backend — the credential follows …