Skip to content

Price Claude 5.5/5.2, revive cost backfill, rename users to actors (schema v11) - #162

Merged
Fl0p merged 4 commits into
mainfrom
flo-actors-pricing-backfill
Nov 15, 2026
Merged

Fl0p merged 4 commits into
mainfrom
flo-actors-pricing-backfill

Conversation

@Fl0p

@Fl0p Fl0p commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Why

Production showed $0 cost since 2026-11-07, and the Users list mixes one person, one host and fifteen Paperclip agents under the name "user". This PR fixes the first and renames the second.

(Agents going silent on 2026-11-07 is a separate cause, outside this repo: Paperclip v2026.1106 strips each agent's OTEL_* env, including its cotel token, unless company observability is configured. That will be handled on the Paperclip side.)

What

1. Pricing (e3ffa95)

  • Adds Opus 5.5 ($4/$20), Sonnet 5.5 ($2/$10), Haiku 5.5 ($0.10/$0.50), Fable/Mythos 5.2 ($8/$40) and 5.1 ($10/$50), with the published cache-read rates where they differ from 0.1 × input.
  • Sonnet 5 moves from $3/$15 to the $2/$10 still published.
  • Haiku 5.5's >100K-prompt rate is not modelled: a span does not say which tier billed it.
  • pricing.Known() separates an unpriced model from a priced span that costs zero.

2. Cost backfill (e3ffa95)

  • Revives the reviewed code from the closed feat(storage): backfill cost_usd for pre-FLO-550 spans #67 (FLO-551/552): --backfill-cost is a dry run, --backfill-cost-apply writes. Both touch spans only.
  • The README procedure is rewritten for today's deploy. The dry run restores the newest snapshot into a throwaway file. Both one-offs set --entrypoint so they don't start a second tunnel connector.

3. Users → actors, down to the schema (1bf04ff, e1fb0e1, b2d3412, ADR-0027)

  • Schema v11: users → actors, spans.user_id / daily_usage.user_id → actor_id, idx_spans_user_id → idx_spans_actor_id.
  • How the rename runs: migrateUsersToActors runs in Go before schema.sql. A rename can't be idempotent in SQL, and CREATE TABLE IF NOT EXISTS actors would otherwise create an empty twin. The function:
    • checks the catalog step by step;
    • drops the spans indexes, which schema.sql then recreates;
    • commits as one transaction;
    • refuses to start if both tables exist.
  • API: /api/v1/actors, ?actor_id=, actors_count, mode=actor_only|actor_and_history. The old route, param and modes still work as aliases. Response field names change (breaking for consumers that read users_count / user_id).
  • Export: format_version 2 (actor_id). The importer still reads v1.
  • UI: the Actors page lives at /actors, and /users[/:id] redirects there. The Setup step now explains what an actor is.

Verification

  • go vet ./..., go test ./... (under TZ=UTC, as CI runs), npm run build, vitepress build (no dead links).

  • New tests:

    • migration from a database built with the frozen v10 schema.sql (data, tokens, soft-deletes, indexes, idempotence, refusal when both tables exist);
    • v1 export import;
    • legacy API aliases;
    • prices for every new model.
  • Real data, read-only: today's 11:39Z prod snapshot restored locally and opened with this build. Results:

    • schema reached v11;
    • 17 actors;
    • all 64 894 spans and 3 679 roll-ups kept their attribution;
    • no users table left;
    • indexes rebuilt.

    The copy was deleted afterwards.

  • Backfill dry run on that copy: +$921.18 across 12 802 spans:

    model spans delta
    claude-opus-5-5 10 868 +$858.60
    claude-fable-5-2 558 +$53.37
    claude-opus-5-5[1m] 212 +$8.63
    claude-haiku-5-5 1 164 +$0.67
    claude-sonnet-5[1m] 2 −$0.09
  • Ran the dashboard locally against seeded data: the Actors list, the actor page, the Overview KPI and the /users redirects all render correctly.

Rollout notes

  • Deploying this migrates the prod DB to v11. An older binary can't use a migrated file (its tokens would stop authenticating). Rolling back means restoring a pre-v11 snapshot.
  • After deploy, run the backfill (README → Maintenance commands; brief downtime for the apply) before ~2026-12-07, when the first unpriced day leaves the 30-day raw window.
  • docs/assets/dashboard-actors.png is renamed but still shows the old "Users" heading until the screenshots are re-shot.
  • Locally (non-UTC timezone) TestRollupAndPurge_BoundaryDayNotSplit and TestHistory_TenMinuteGranularity fail on main as well. They pass under TZ=UTC, which is what CI uses.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added cost recalculation previews and an apply option, with per-model summaries. Unknown or empty models are skipped.
    • Updated model pricing, including rates for newer Claude models and revised Sonnet rates.
    • Dashboard actor filters now work across overview, sessions, costs, history, models, and tools.
  • Changes
    • Renamed “Users” to “Actors” across the dashboard, API, authentication guidance, and documentation. Existing user links redirect to actor pages, and legacy exports remain importable.
    • Updated exports to use format version 2 with actor attribution; version 1 archives are still supported.
  • Documentation
    • Added guidance for cost recalculation and the users-to-actors transition.

FlopBut and others added 4 commits November 15, 2026 12:27
…ll-cost

Since 2026-11-07 production has stored cost_usd unset for every span from
claude-opus-5-5, claude-fable-5-2 and claude-haiku-5-5: the table did not
know them, so the dashboard showed $0 for a week of traffic. Adds Opus 5.5,
Sonnet 5.5, Haiku 5.5, Fable/Mythos 5.2 and 5.1, and moves Sonnet 5 to the
$2/$10 rate Anthropic still publishes.

Revives the cost backfill from the closed PR #67 (FLO-551/552) as reviewed:
--backfill-cost is a dry run, --backfill-cost-apply writes spans only. The
README procedure is rewritten for the current deploy: the dry run restores
the newest snapshot instead of copying a live file, and both one-offs bypass
the entrypoint so they do not start a second tunnel connector.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The entity a token belongs to was never only a person: production holds
people (flop), Paperclip agents (Daedalus, Clio, ...) and hosts (rpi5). It
is now an actor everywhere below the UI.

Storage (schema v11): table users -> actors, spans.user_id and
daily_usage.user_id -> actor_id, idx_spans_user_id -> idx_spans_actor_id.
The rename runs in Go before schema.sql (migrateUsersToActors): a rename
cannot be written idempotently in SQL, and schema.sql's CREATE TABLE IF NOT
EXISTS actors / ADD COLUMN IF NOT EXISTS actor_id would otherwise create
empty twins beside the populated originals. It checks the catalog per step,
drops the spans secondary indexes first (DuckDB refuses to ALTER an indexed
table; schema.sql recreates them), commits as one transaction, and refuses
to start if both users and actors exist. Tested against a database built
from the frozen v10 schema.sql (testdata/schema_v10.sql).

Export format v2 names the column actor_id at the same offset; the importer
still reads v1 files' user_id. Pre-v11 snapshots restore unchanged and are
migrated by the next open.

API: /api/v1/actors, ?actor_id=, mode=actor_only|actor_and_history,
actors_count in /overview. The old /users route, ?user_id= and user_* delete
modes are accepted as aliases. Response field names change.

BREAKING CHANGE: JSON fields users_count and user_id are now actors_count
and actor_id; export manifests are format_version 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pages, routes, components and the actor filter follow the API rename:
/actors and /actors/:id, ?actor_id=, actors_count on the Overview KPI.
The old /users and /users/:id URLs redirect so bookmarks keep working.
The Setup step now says what an actor is - a person, an AI agent or a
host - instead of asking the reader to add themselves as a user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he docs

ADR-0027 records the rename and how the schema moves: why it runs in Go
before schema.sql, what stays compatible, and that rolling back across
v11 needs a pre-v11 snapshot. The auth guide becomes actors-and-auth.md;
the API reference, export format (v2), snapshot, recovery (index names for
v11 and older files), agent-identity and page docs follow. The README
screenshot is renamed to dashboard-actors.png but still shows the old
"Users" heading until the screenshots are re-shot. CHANGELOG covers the
pricing fix, the backfill and the rename.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request migrates user attribution to actors across the database, API, exports, and dashboard, with compatibility for selected legacy inputs. It also updates model pricing and adds preview and apply commands to recalculate stored span costs.

Changes: Users-to-actors migration

Layer / File(s) Summary
Schema migration and actor storage
internal/storage/duckdb.go, internal/storage/schema.sql, internal/storage/actors.go, internal/storage/*_test.go
Schema v11 renames user tables and attribution columns to actors. Actor storage handles listing, statistics, tokens, deletion, anonymous usage, and roll-ups. Tests cover migration and actor storage behavior.
Actor API and telemetry identity
internal/api/*, internal/ingest/*, cmd/cotel/main.go
The API adds actor management routes and uses actor identity for filtering and ingestion. Legacy user routes, filters, and deletion modes remain accepted as described in the change.
Dashboard routes and actor filters
frontend/src/api/index.ts, frontend/src/components/*, frontend/src/context/*, frontend/src/main.tsx, frontend/src/pages/*
The dashboard uses actor types, routes, labels, and filters. Former user-page URLs redirect to actor pages.
Export/import compatibility
internal/export/*, internal/importpkg/*, internal/storage/export.go
Exports use format version 2 and the actor_id column. Imports accept actor_id and fall back to user_id for earlier archive data.
Actor documentation and tooling
README.md, docs/*, scripts/*
Guides, API references, demo seeding, and screenshot configuration use actor terminology and document the schema and compatibility changes.

Cost backfill and pricing

Layer / File(s) Summary
Model pricing and recognition
internal/pricing/*
The pricing table adds Claude model rates, revises Sonnet 5 rates, and adds Known to distinguish priced models from unknown models.
Backfill calculation and updates
internal/storage/backfill.go, internal/storage/backfill_test.go
Storage reports recalculated costs, leaves empty or unknown models unchanged, and transactionally updates changed span costs. The tests cover dry runs, repeat runs, and the fact that daily_usage is not updated.
CLI and operating instructions
cmd/cotel/main.go, README.md, CHANGELOG.md
The CLI supports dry-run and apply modes before listeners bind. Documentation describes the report, database requirements, and effect on stored spans.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CLI as cotel main
  participant Storage as DB backfill
  participant DuckDB
  participant Pricing as pricing.Compute
  CLI->>Storage: Run dry-run or apply
  Storage->>DuckDB: Read span data
  Storage->>Pricing: Recompute known-model costs
  Pricing-->>Storage: Return calculated costs
  Storage->>DuckDB: Write changed costs in apply mode
  Storage-->>CLI: Return backfill report
Loading
Merge Risk: Moderate · up to b2d34

Fix the two 5.1 cache-read prices and the backfill's handling of spans without token counts before running the cost backfill. Otherwise persisted span costs can be wrong. The cost preview can also migrate a v10 database before the operator opts in. Old dashboard links with user_id may show unfiltered data.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Fl0p
Fl0p merged commit daead07 into main Nov 15, 2026
11 of 12 checks passed
@Fl0p
Fl0p deleted the flo-actors-pricing-backfill branch November 15, 2026 11:48
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