Skip to content

Persist per-job model and cache telemetry to database #1701

Description

@dcrjodle

Summary

On job completion, Tendril parses the agent's result event to store Jobs.Cost and Jobs.Tokens. The same event also carries per-model breakdown (modelUsage) and cache token counts (cache_read/cache_creation), which are currently discarded. This feature request is to persist this telemetry data to the database.

Proposed Solution

Minimal approach:
Add three columns to the Jobs table:

  • Model — which model was used
  • CacheReadTokens — cache read token count
  • CacheCreationTokens — cache creation token count

Fuller approach:
Create a JobModelUsage child table to store exact per-model splits for more detailed tracking.

Rationale

This enables:

  • Cost & efficiency analytics queryable directly from SQL without re-parsing raw session logs
  • Model routing analysis — identify which model ran at what cost to optimize routing toward cheaper options
  • Cache economics analysis — understand cache hit/miss patterns and their cost impact
  • Single source of truth — the database becomes the authoritative record for agent spend, rather than relying on rotating session logs

Notes

  • Apply to new jobs only; no backfill of historical data required

Original Slack thread

Reported by Renco Smeding

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions