Skip to content

cotel v0.3.0

Choose a tag to compare

@github-actions github-actions released this 09 Aug 20:57
· 87 commits to main since this release

Fixed

  • Pricing table now covers the Claude 5 family (Fable 5, Mythos 5, Opus 5, Sonnet 5) and the missing 4.x models (Opus 4.8, Opus 4.6). Spans from claude-opus-5 were previously recorded with cost_usd = 0 because the model was absent from the table
  • Corrected two stale rates: Opus 4.7 ($15.00/$75.00 → $5.00/$25.00) and Haiku 4.5 ($0.80/$4.00 → $1.00/$5.00) per MTok
  • Retention roll-up no longer aborts with NOT NULL constraint failed: daily_usage.model when a span has an empty or NULL model, session_id, or tool_name. Such spans are now rolled up under an unknown sentinel instead of silently stopping all aggregation and purging (ADR-0009)
  • No more silent telemetry loss on restart/deploy: the ingest (:4318) and dashboard (:8080) ports now bind and accept connections before the DuckDB open (WAL replay + schema migration), which can take minutes on a large production database. During that window both ports answer a retryable 503 with Retry-After instead of resetting the connection, so OTLP exporters retry and spans are delivered once cotel is ready. Previously the ports bound only after the open finished, so every deploy had a multi-minute window where ingest refused connections and dropped spans
  • Retention roll-up no longer loses part of a day's usage. The cutoff was a wall-clock instant, so with the worker ticking every 6h (COTEL_RETENTION_INTERVAL) a day was rolled up in slices; because daily_usage is keyed by day and written with INSERT OR REPLACE, each slice overwrote the previous one while its raw spans were already purged. Every day's span_count, token totals and total_cost_usd were therefore systematically understated — only the last slice survived. The cutoff is now snapped back to UTC midnight — the same boundary the day key is bucketed on — so only whole days are ever rolled up and purged. Trade-off: raw spans now live up to one day longer than COTEL_RETENTION_RAW_DAYS (default 30). Aggregates already flattened by the old behaviour cannot be recovered — the raw spans are gone
  • Retention is now correct on servers that do not run in UTC. A span's day is its UTC calendar day, but both retention cutoffs were computed in the server's local zone, so on any host at a non-zero UTC offset — including UTC+1/+2 — the boundary fell inside a day bucket and re-introduced the overwrite above for spans near midnight UTC. Both cutoffs are now computed in UTC, and the retention tests run under a matrix of server timezones so the alignment cannot silently regress
  • Retention roll-up no longer overwrites an already-rolled-up day's aggregate when a span dated to that day arrives late — a backfill, or an import of telemetry older than COTEL_RETENTION_RAW_DAYS. The day had already been aggregated and its raw spans purged, so the next cycle recomputed the day from the single late span alone and INSERT OR REPLACEd the correct total away, silently corrupting historical cost. Late spans now accumulate into the existing daily_usage row (ON CONFLICT DO UPDATE) instead of replacing it; the accumulate and the raw-span purge run in one transaction so a crash between them cannot double-count
  • Fast restarts: cotel now runs a DuckDB CHECKPOINT on SIGTERM/SIGINT before exiting, folding the write-ahead log into the main file, and the container entrypoint forwards the stop signal to cotel and waits for it. That multi-minute cold start on a large DB is WAL replay, not the schema migration — previously every deploy killed cotel with a non-empty WAL (the old entrypoint never forwarded the signal and cotel had no handler), so the next start replayed the whole log. Measured on a copy of production (108 MB DB, 6.2 MB WAL): a cold start took 5m38s; after a graceful stop the next start is 0.14s. A hard kill (docker kill, OOM, SIGKILL after the stop grace period) skips the checkpoint and pays the replay again, but never corrupts the database and loses no committed span — DuckDB replays the WAL on the next open
  • GET /api/v1/bash-commands returned an empty list on every request from the day it shipped, so the Tools page's per-command Bash breakdown always looked like "no Bash calls yet". Under the bundled DuckDB engine a bare tool_name = 'Bash' predicate is pushed into the table scan and then matches nothing; the query now uses a form the optimizer leaves alone. Only tool_name and service_name are affected — filters on session, model, user and the id columns were always correct

Added

  • COTEL_WAL_AUTOCHECKPOINT (default 4MB, DuckDB's own default is 16MB) caps how large the write-ahead log grows before DuckDB folds it into the main file. A graceful stop avoids WAL replay entirely; this cap only bounds the replay an ungraceful kill (OOM, SIGKILL after the grace period) leaves behind, by folding the log — including a retention roll-up's ~6MB of deletes — into the main file promptly. The cost is slightly more frequent checkpoints during ingest, negligible at cotel's write rate
  • Startup logging of each phase — opening db, db ready: schema/migrations applied in <duration>, and ready: serving live traffic … — so a slow open is visible instead of a silent container. Plus a Docker HEALTHCHECK (cotel -healthcheck, which probes the dashboard /healthz) so the container reports health: starting until the database is open rather than a misleading Up; no curl/wget is added to the runtime image
  • daily_usage now preserves cache-token totals through roll-up: new total_cache_read_tokens and total_cache_write_tokens columns (schema v8) are filled by RollupAndPurge and carried through /api/v1/export and import. Previously only input/output tokens survived the roll-up, so aggregates older than the raw-span retention window (default 30 days) undercounted total tokens by ~2 orders of magnitude — in real traffic cache tokens are ~99% of volume. Additive, idempotent migration (ADD COLUMN IF NOT EXISTS); rows rolled up before the migration keep NULL (honestly unknown, not 0). Export format_version stays 1 — additive columns don't bump it (ADR-0005). Cost was already correct (SUM(spans.cost_usd))
  • Retention worker health on GET /api/v1/health: a retention object (status / last_run_at / last_error); a failed roll-up flips top-level health to degraded and logs at ERROR level instead of failing silently
  • Schema migrations are version-guarded on startup: storage.Open skips the whole of schema.sql when the database already records the current schema version, so migrations run once (on the deploy that introduces them) rather than on every boot. Measured against a copy of production the apply is ~165 ms, so this is correctness hygiene — the multi-minute open is DuckDB WAL replay, which the guard cannot affect (ADR-0010)
  • Users page is now one sortable, searchable, paged list carrying per-user cost and session count, scoped by a range switcher (All / Year / Month / Week / Day, default month) that persists in a cookie. Sorting and paging happen in SQL, so "top spender" means top of the whole table for the chosen window rather than top of whatever the browser had loaded. Ranged figures union raw spans with the daily_usage roll-up, so a window older than the raw-span retention still answers; created_at and last_seen stay all-time (ADR-0011)
  • Per-user page at /users/:id (new GET /api/v1/users/{id}), reached by clicking any row. The token, rotate and delete actions that used to crowd every list row live there
  • Tools page gains the same contract: ranged call counts, average duration and error rate per tool, server-side sort, search and paging, with the range switcher in the page toolbar. Tool metrics union raw spans with the roll-up; rows aggregated before schema v9 count toward calls but stay out of the duration and failure denominators, and the response names the instant those two figures actually start from. /api/v1/bash-commands is raw-only by design and reports the window it covers (ADR-0012)
  • GET /api/v1/users and GET /api/v1/tools accept range, q, sort, order, page and limit and echo the resolved values back. Sort keys are whitelisted, total counts matches before paging, and limit=0 returns the unpaginated list the typeahead needs
  • daily_usage preserves average duration and failure counts through roll-up (schema v9): new nullable total_duration_ms and fail_count columns, accumulated the same additive, idempotent way as the v8 cache-token migration, so pre-v9 rows stay honestly unknown rather than counting as zero
  • Sessions and the Overview sessions block show a User column; the Sessions search box filters by user instead of by opaque session ID, and clicking a user filters the table to their sessions

Changed

  • The Users page is flat — title, search, range switcher and Add user on one toolbar row above the table, with no card wrapper around a page that holds a single thing

Removed

  • The "Cost by user (top 10)" chart on Users and the top-10 chart on Tools. Both ranked a fixed slice on one hardcoded metric; the ranged, sortable lists that replace them answer the same question for any column and any window
  • Token display, copy-token and delete from the Users list rows — those actions moved to the per-user page