fix(pipeline): repair token tracker CLI summary (#622)
Some checks failed
Smoke Test / smoke (pull_request) Failing after 24s
Architecture Lint / Linter Tests (pull_request) Successful in 29s
Validate Config / YAML Lint (pull_request) Failing after 16s
Validate Config / JSON Validate (pull_request) Successful in 21s
Validate Config / Shell Script Lint (pull_request) Failing after 1m8s
Validate Config / Python Syntax & Import Check (pull_request) Failing after 1m21s
Validate Config / Python Test Suite (pull_request) Has been skipped
Validate Config / Cron Syntax Check (pull_request) Successful in 15s
Validate Config / Deploy Script Dry Run (pull_request) Successful in 15s
Validate Config / Playbook Schema Validation (pull_request) Successful in 30s
Architecture Lint / Lint Repository (pull_request) Failing after 28s
PR Checklist / pr-checklist (pull_request) Successful in 5m18s

Fix the hyphenated token-tracker entrypoint and normalize SQLite time filtering
so same-day usage appears in the summary dashboard.
This commit is contained in:
Alexander Whitestone
2026-04-22 11:23:43 -04:00
parent ae8c1d46ae
commit 91d94e29e8
3 changed files with 56 additions and 192 deletions

View File

@@ -76,15 +76,20 @@ def record_usage(conn: sqlite3.Connection, pipeline: str, worker: str, tokens: i
conn.commit()
def normalize_since(since: str) -> str:
"""Normalize ISO timestamps for SQLite datetime comparisons."""
return since.replace("T", " ")
def get_usage_since(conn: sqlite3.Connection, since: str) -> Dict[str, int]:
"""Get total tokens per pipeline since a datetime."""
cursor = conn.execute("""
SELECT pipeline, SUM(tokens) as total
FROM token_usage
WHERE recorded_at >= ?
WHERE datetime(recorded_at) >= datetime(?)
GROUP BY pipeline
ORDER BY total DESC
""", (since,))
""", (normalize_since(since),))
return {row[0]: row[1] for row in cursor.fetchall()}
@@ -94,10 +99,10 @@ def get_hourly_usage(conn: sqlite3.Connection, pipeline: str, hours: int = 24) -
cursor = conn.execute("""
SELECT hour_key, SUM(tokens) as total
FROM token_usage
WHERE pipeline = ? AND recorded_at >= ?
WHERE pipeline = ? AND datetime(recorded_at) >= datetime(?)
GROUP BY hour_key
ORDER BY hour_key
""", (pipeline, since))
""", (pipeline, normalize_since(since)))
return cursor.fetchall()
@@ -106,10 +111,10 @@ def get_worker_usage(conn: sqlite3.Connection, pipeline: str, since: str) -> Dic
cursor = conn.execute("""
SELECT worker, SUM(tokens) as total
FROM token_usage
WHERE pipeline = ? AND recorded_at >= ?
WHERE pipeline = ? AND datetime(recorded_at) >= datetime(?)
GROUP BY worker
ORDER BY total DESC
""", (pipeline, since))
""", (pipeline, normalize_since(since)))
return {row[0]: row[1] for row in cursor.fetchall()}