TO

Provides debugging steps and implementation details for fixing missing token data or adding new usage visualizations in the Analysis page.

Install

mkdir -p .claude/skills/token-data-sources && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/10571" && unzip -o skill.zip -d .claude/skills/token-data-sources && rm skill.zip

Installs to .claude/skills/token-data-sources

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

When debugging why the analysis page shows missing or zero token data, or when adding new cost/usage visualizations.
116 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Debug missing token data on analysis page
  • Trace data flow from WebSocket events
  • Implement new cost and usage visualizations
  • Fix token record gating issues

How it works

The skill identifies whether token data failure stems from the in-memory Live Agent path or the DB-Persisted Cost path, then provides a plan to fix gating logic in AgentManager.

Inputs & outputs

You give it
Analysis page token data errors
You get back
Resolved token data attribution or new visualization implementation

When to use token-data-sources

  • Debugging 'Waiting for token data' errors
  • Adding new cost-per-agent charts
  • Fixing issues with token record gating
  • Tracing data flow from WebSocket events

About this skill

Analysis Page Token Data Sources

When to use: When debugging why the analysis page shows missing or zero token data, or when adding new cost/usage visualizations.

Two Token Data Paths

The analysis page has two independent data sources for token information. Understanding which is active and when is critical.

Path 1: Live Agent Objects (In-Memory)

  • Source: AnalysisPage.tsx reads agent.inputTokens / agent.outputTokens from the app store
  • Populated by: WebSocket agent:usage events → appStore updates agent objects in memory
  • Works when: Session is active and agents are running
  • Fails when: Session is inactive (agents gone from memory → all zeros → "Waiting for token data...")
  • Used for: Time-series token usage chart, total token counts

Path 2: DB-Persisted Cost Records

  • Source: CostBreakdown.tsx fetches /costs/by-agent and /costs/by-task API endpoints
  • Populated by: CostTracker.recordUsage() → writes to task_cost_records DB table
  • Works when: Data has been recorded to the DB (persists across sessions)
  • Fails when: The dagTaskId gate blocks recording (see below)
  • Used for: Per-agent and per-task cost attribution breakdown

The dagTaskId Gate Bug

In AgentManager.ts, token usage recording has a gate condition:

// packages/server/src/agents/AgentManager.ts ~line 725
if (dagTaskId && agent.parentId) {
  tracker.recordUsage(agent.id, dagTaskId, ...);
}

This requires BOTH:

  1. dagTaskId — agent must have an active DAG task
  2. agent.parentId — agent must have a parent (not be the lead)

Problem: The lead agent (which has no parentId) never records usage. And child agents only record when they have an active DAG task. This means task_cost_records is often empty → "No token attribution data yet."

Meanwhile, emit('agent:usage') at line ~730 fires unconditionally, so the time-series chart works fine.

Fix Plan

  1. Remove the parentId requirement: The lead's token usage should be tracked too
  2. Fall back to a synthetic task ID: When no dagTaskId exists, use agent.id or a session-level bucket
  3. Add DB fallback for inactive sessions: When live agents aren't available, fetch historical data from /costs/by-agent instead of reading from in-memory agent objects

Key Files

FileLinesRole
packages/server/src/agents/AgentManager.ts~721-731Token usage wiring — emit (unconditional) vs record (gated)
packages/server/src/agents/CostTracker.ts102-154recordUsage() — writes to task_cost_records
packages/server/src/agents/CostTracker.ts157-182getAgentCosts() — reads aggregated costs
packages/server/src/routes/lead.ts263-296/costs/by-agent and /costs/by-task API endpoints
packages/web/src/components/AnalysisPage/AnalysisPage.tsx84-86Token data from live agent objects
packages/web/src/components/TokenEconomics/CostBreakdown.tsx34-37Fetches DB-backed cost data

When not to use it

  • General frontend debugging
  • Database schema migrations

Limitations

  • Requires understanding of two independent data paths
  • Fixes are limited to AgentManager and CostTracker logic

How it compares

It specifically targets the discrepancy between real-time WebSocket usage reporting and DB-persisted cost records, which is a common source of 'Waiting for token data' errors.

Compared to similar skills

token-data-sources side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
token-data-sources (this skill)05moNo flagsIntermediate
optimizing-performance12moReviewIntermediate
audit04moNo flagsIntermediate
analytics-pipeline16moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry