Skip to content

feat(admin-costs): content-free per-user conversation list and session profile - #1093

Merged
philmerrell merged 1 commit into
developfrom
feature/admin-cost-drilldown-api
Sep 14, 2026
Merged

philmerrell merged 1 commit into
developfrom
feature/admin-cost-drilldown-api

Conversation

@philmerrell

Copy link
Copy Markdown
Contributor

Summary

The admin console could show what a conversation cost but had no path that starts from a user and nothing that records what they were doing. Both prior quota investigations (the 5801a350 write:read audit, the compaction spiral) were hand-run DynamoDB sessions that ended in a named, computable classification. This PR adds the missing drill-down and turns those classifications into rules — without reading any conversation content.

Spec: docs/specs/admin-cost-drilldown.md. PR 1 of 3 (API); the SPA and the behavioral census follow as separate PRs.

  • GET /admin/costs/users/{id}/sessions — a user's conversations, content-free (costKnown=false means unrecorded, never $0; 20% of session rows have no cost aggregate).
  • GET /admin/costs/sessions/{id}/profile — attachments (count/bytes, never names), per-call context trajectory, model mix, prefix-fingerprint churn, tool census (populated by PR 3), coverage flags, and 15 diagnosis rules with numeric evidence and the fix each investigation landed on.
  • Content-free is enforced in code: apis/shared/observability/content_policy.py (denylist + aliased projections) and a test that walks every admin cost response model — exactly one named exemption, TopSessionCost.title, kept by decision. A moto test seeds every kind of content and proves none returns.
  • Hardens an existing path: the anatomy read fetched whole C# items including citations[].text; it now projects the twelve attributes it consumes.
  • Top-users enrichment (email / tier / quota %) replaces a hard-coded None — the user about to hit their quota is now visible from the table.

Deploy notes

🏗️ backend.yml only. No new table, no GSI operation on any existing table, no feature flag (read-only, admin-only, degrades to "not tracked").

🧰 Adds an app-api-branch entry to .claude/launch.json (uvicorn on :8010) for verifying a branch against dev data without touching a running :8000.

Verification

  • uv run python -m pytest tests/ — 8,474 passed (92 new).
  • Live against dev data via the branch server: 93 sessions for September's top user, zero content-bearing keys, shares computed; a 13-call profile with trajectory, coverage flags and two diagnoses; top-users rows carrying email, tier and quota share.

🤖 Generated with Claude Code

…n profile

Adds the missing drill-down between "top users by cost" and the per-session
cost anatomy: an admin starts from a user, lists their conversations without
reading any of them, and opens one for the diagnostic profile a developer (or
a model handed the JSON) needs to find cost-effectiveness work.

- apis/shared/observability/content_policy.py: the denylist of every
  content-bearing attribute on the session/cost/upload row families, three
  aliased allowlist projections, and walkers. Enforced by a test that walks
  every admin cost response model (one named exemption: TopSessionCost.title,
  kept by decision) and a moto test that seeds content and proves none of it
  returns.
- GET /admin/costs/users/{id}/sessions and GET /admin/costs/sessions/{id}/profile
  (scope admin.costs). Unrecorded cost renders costKnown=false, never $0.
- admin/costs/diagnoses.py: 15 pure rules encoding the classifications prior
  quota investigations reached by hand (prefix spiral, partial-miss heavy,
  over-threshold, summary over budget, prompt/toolConfig mutation, agent-cache
  bypass, attachment-heavy, ...), each with numeric evidence and the fix.
- get_session_cost_records now projects the twelve attributes the anatomy
  consumes, closing the citations[].text read on the existing path.
- Top-users enrichment (email, tier, quota %) replaces a hard-coded None.

No new table, no GSI operation, no feature flag (read-only, admin-only,
degrades to "not tracked"). Adds an app-api-branch launch config (:8010) so a
branch can be verified against dev data without touching the :8000 process.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@philmerrell
philmerrell merged commit 6bf8269 into develop Sep 14, 2026
6 checks passed
@philmerrell
philmerrell deleted the feature/admin-cost-drilldown-api branch September 14, 2026 14:21
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