Skip to content

[P0.1] Create the token_usage table (with indexes) in the per-workspace schema #712

Description

@frankbria

Severity: critical | Category: data-integrity | Phase: P0.1

Problem

No production code creates token_usage; the only CREATE TABLE is in test fixtures. Verified: grep finds zero CREATE TABLE ... token_usage in codeframe/. Every write raises OperationalError: no such table (double-swallowed in react_agent), so all token/cost data is silently dropped and the /costs page/cf stats render zeros or crash. Contradicts shipped Phase 5.2 cost tracking.

Evidence

codeframe/platform_store/repositories/token_repository.py:54 (INSERT), codeframe/core/workspace.py (schema build omits it), codeframe/cli/stats_commands.py:116 (crash)

Acceptance criteria

  • token_usage is created by create_or_load_workspace() with the columns the INSERT expects and indexes on timestamp, task_id, agent_id.
  • A fresh workspace can save_token_usage() and read it back with no error.
  • react_agent._persist_token_usage logs at WARNING (not debug/swallow) on failure.
  • Test fixtures invoke the real schema builder instead of hand-rolling the table.

Dependencies

None


Filed from the SaaS launch-readiness audit. Atomic: one developer, one session. Work order: strictly P0.1 → P3.12 (no forward dependencies).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0-blocker-betaCritical blocker - must fix before beta testingpriority:hightype:bugSomething is broken and needs fixing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions