Skip to content

feat(upload): push session usage metrics at launch; logs upload only via codev upload --logs - #373

Merged
quickbeard merged 3 commits into
mainfrom
feat/session-stats-push
Sep 24, 2026
Merged

quickbeard merged 3 commits into
mainfrom
feat/session-stats-push

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Summary

The analysis web app currently derives every metric by parsing uploaded markdown transcripts: tokens are chars ÷ 4, cost is absent, durations are mostly null, and re-uploads double-count. The client already records the real numbers, so this PR sends them directly. The markdown upload itself is unchanged.

Usage metrics push (new)

  • @codev/upload builds one record per top-level session, with subagent sessions added into their parent. Sources are the local store and, on desktop, each ready sandbox over the v1 API. Each record holds provider-reported tokens (input, output, reasoning, cache read/write) and cost, user prompts, tool calls (ok/error), accepted/rejected lines of code, files changed, active time, and hourly UTC buckets per model/provider. No message text is sent.
  • Records go to POST {supabase}/functions/v1/upload-session-stats as {v: 1, client, sessions}, in batches of 200. A local sent-hash cache (~/.local/share/codev/stats-sent.json) keeps unchanged sessions from being resent.
  • Errors: 401/403 refreshes the CoDev config and retries once. A 404 means the backend endpoint isn't deployed yet; it's logged quietly and retried at the next launch.
  • Triggers:
    • every codev / codev run launch, via a detached codev debug stats
    • TUI /configure sign-in
    • desktop sidecar start, each sandbox becoming ready, and desktop sign-in
  • The push has its own lock, status file and stats-*.ndjson logs under the agent's data dir. It shares nothing with the hub's ~/.codev-hub files.
  • CODEV_DISABLE_METRICS=1 turns off the automatic push.
  • The "sign in to resume" toast (TUI and desktop) now tracks this push and reads "Usage reporting is paused".

codev upload

  • codev upload runs the metrics push interactively. It signs in first if needed, ignores CODEV_DISABLE_METRICS, and shares the lock with the launch push.
  • codev upload --logs is the original log upload.
  • --force re-sends unchanged sessions in either mode.
  • --diagnostics (previously --logs) prints the last run's trail. With --logs, it shows the last log upload instead.

Log upload is now manual only. Removed:

  • the log uploads at launch and after sign-in
  • codev debug upload
  • the desktop "Upload Session Logs" menu item and its IPC plumbing
  • CODEV_DISABLE_AUTO_UPLOAD

A codebase scan confirms codev upload --logs is the only remaining path that uploads logs. codev-hub still uploads codev-code logs on its own schedule; that's out of scope here.

Behavior changes

  • Desktop Work (sandbox) session logs are no longer uploaded; only their metrics are.
  • Existing muscle memory for codev upload --logs now starts a log upload instead of printing diagnostics.
  • codev upload without flags no longer uploads logs.

Follow-ups

  • ai-hub-web: the upload-session-stats edge function, the tables and views, and moving the reports to the new data. The payload contract is SessionStats in packages/codev-upload/src/stats.ts.
  • User docs in codev-landing-page still describe automatic upload, CODEV_DISABLE_AUTO_UPLOAD and --logs as the diagnostics flag.
  • Cost is 0 for every session today because the gateway's model list has no prices.

DIVERGENCES rows are updated for the CLI wiring, desktop wiring, TUI dependency, desktop menu, gateway sign-in toast, TUI toast and the upload registration. The CHANGELOG has a new "Usage reporting" section.

Test plan

  • bun typecheck in codev-upload, opencode, tui, desktop and app
  • bun test in codev-upload (57, including new stats-builder, push and daemon tests) and desktop (194)
  • bun run test:unit in app (823)
  • CLI help snapshot regenerated (debug upload → debug stats; new upload flags)
  • Read-only dry run against a real local store: 52 sessions, 96 ms, 46 KB payload; tokens and lines of code look plausible
  • CODEV_DISABLE_METRICS=1 codev debug stats exits 0 and logs the skip; codev upload --diagnostics and codev upload --logs --diagnostics print the right trails
  • End-to-end push against the backend (blocked on the ai-hub-web endpoint)

🤖 Generated with Claude Code

quickbeard and others added 3 commits September 24, 2026 16:48
…via codev upload --logs

Every launch of codev, codev run and CoDev Desktop (plus a fresh sign-in and
each desktop sandbox as it comes up) now pushes per-session usage statistics
to the analysis backend's upload-session-stats function instead of uploading
session logs: provider-reported tokens and cost, prompts, tool calls, lines
of code, and hourly buckets per model. Only sessions whose stats changed are
sent. CODEV_DISABLE_METRICS=1 turns the automatic push off.

`codev upload` sends the same metrics on demand; `codev upload --logs` is the
original log upload and the only path that uploads logs. The diagnostic
trail moves from --logs to --diagnostics. The desktop "Upload Session Logs"
menu item, the launch/sign-in log uploads, `codev debug upload` and
CODEV_DISABLE_AUTO_UPLOAD are removed; the sign-in toast now tracks the
metrics push.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@quickbeard
quickbeard merged commit 577f668 into main Sep 24, 2026
0 of 5 checks passed
@quickbeard
quickbeard deleted the feat/session-stats-push branch September 24, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant