Repository navigation
Conversation
Fix lint/type errors in outlook.py, align session-profile cost fields with storage contracts, and reconcile test_cost_queries.py expectations with actual cost return types. Refs #870
Problem: The archive.semantic __init__.py was empty, the CLI cost command had a redundant model_validate, and test_cost_queries.py lacked contract validation between SessionCostSummary and SessionProfileRecord. Solution: Add typed re-exports to __init__.py, simplify CLI cost command to use the now-typed outlook return, and add contract-alignment tests that pin field mappings and JSON roundtrip expectations. Ref #870 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
…1166) ## Summary Splits cost rollups across the five basis axes (#803/#870 carry-over) and adds per-model breakdowns to both session-cost and cost-rollup insights. Every ``unavailable`` row now carries a discrete reason so consumers can render "why" instead of an opaque zero. ``Closes #1136``. ## Problem Cost rollups today expose a single ``total_cost_usd`` per session. - #803 explicitly required separating ``provider_reported_usd``, ``api_equivalent_usd``, ``subscription_equivalent_usd``, ``catalog_priced_usd``, and ``tool_surcharge_usd``. - #870 AC required API-equivalent value and subscription quota/burn as separate fields. - PR #987 (which closed #870) was lint/type cleanup only; the basis split never landed. - #803 also called out "Per-model breakdown in cost surfaces" as an explicit carry-over. Consumers querying ``CostRollupInsight.total_usd`` cannot distinguish "this session billed $1.25 against the API" from "this session would cost $1.25 against the catalog if billed via API" from "this session burned X subscription credits". Mixed-model sessions collapse into one row keyed by the dominant model. ## Solution **Typed basis split.** ``CostBasisPayload`` carries the five basis axes as independent fields. Same usage may be expressed on more than one axis (e.g. a provider-reported total alongside a parallel catalog-priced reconciliation), so basis values do not sum to ``total_usd``. ``total_usd`` remains the legacy single-number summary for backwards compatibility — documented as drawing from ``provider_reported_usd`` when present, otherwise from ``catalog_priced_usd``. **Per-model breakdown.** ``CostModelBreakdown`` rows hang off both: - ``CostEstimatePayload.per_model_breakdown`` (session scope) — built in ``estimate_conversation_cost`` by grouping message estimates by ``(model_name, normalized_model)``. - ``CostRollupInsight.per_model_breakdown`` (cross-session scope) — aggregated by ``aggregate_cost_rollup_insights`` in ``insights/archive_rollups.py``. Sessions with no breakdown contribute a single synthesized row from the dominant model so provider-reported-only sessions still surface per-model context. Mixed-model sessions return one row per model, ranked by ``total_usd`` desc. Nothing is collapsed. **Unavailable reasons.** ``CostEstimatePayload.unavailable_reason`` (``CostUnavailableReason`` literal) enumerates ``no_model``, ``no_price``, ``no_tokens``, ``provider_zero``, ``subscription_unconfigured``, ``no_messages``. Rollups carry ``unavailable_reason_counts`` so a consumer can see "12 sessions unavailable: 8 ``no_tokens``, 4 ``no_model``". **Surfaces.** Existing CLI/MCP envelopes update automatically: ``cost_rollups`` registry adds ``provider_usd``/``api_usd``/``sub_usd``/``catalog_usd`` columns alongside the existing total; ``CostRollupInsight.model_dump`` carries the full ``basis`` and ``per_model_breakdown`` shapes through JSON. **Refactor.** ``operations/archive.py:list_cost_rollup_insights`` shrinks to a thin orchestrator over the new ``aggregate_cost_rollup_insights`` helper, keeping ``operations/archive.py`` under its 1200-line budget. Files touched: - ``polylogue/archive/semantic/pricing.py`` — ``CostBasisPayload``, ``CostModelBreakdown``, ``CostUnavailableReason``, ``CostBasis``; ``_exact_estimate``/``_estimate_from_usage``/``estimate_conversation_cost`` populate basis and breakdown - ``polylogue/insights/archive.py`` — ``CostRollupInsight`` gains ``basis``, ``unavailable_reason_counts``, ``per_model_breakdown`` - ``polylogue/insights/archive_rollups.py`` — new ``aggregate_cost_rollup_insights`` + helpers - ``polylogue/insights/registry.py`` — basis columns in ``cost_rollups`` field list - ``polylogue/operations/archive.py`` — call the new aggregator - ``tests/unit/insights/test_cost_basis_split.py`` — 7 new contracts Non-goals: no new pricing catalog sources, no tokenizer changes, no CLI/MCP surface changes beyond the auto-generated registry columns. Surface-facing children land separately. ## Verification - ``nix develop -c pytest tests/unit/insights/test_cost_basis_split.py tests/unit/core/test_pricing.py tests/unit/insights/ tests/unit/mcp/ tests/unit/cli/test_insights.py -q`` → ``288 passed`` - ``nix develop -c devtools verify --quick`` → ``exit_code: 0`` (mypy --strict, ruff, render-all --check, file budgets all green) - ``nix develop -c mypy polylogue tests devtools`` → ``Success: no issues found in 1395 source files`` Closes #1136. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Fix lint/type errors and contract mismatches in the cost modules. Make
outlook return typed Pydantic models, remove dict hack on frozen model,
add semantic module re-exports, simplify CLI cost wiring, and pin cost
contract validation in tests.
Problem
Per #870 reconciler note: semantic cost files had formatting issues,
outlook.py returned raw dicts instead of typed models, cost_compute.py
used dict.update() on a frozen Pydantic model, session-profile cost
fields were not validated against cost records, and test_cost_queries.py
lacked contract-alignment tests.
Solution
build_subscription_cycle returns SubscriptionCycle, helpers return
typed models (AnomalyPayload, ModelBreakdownPayload)
SessionCostBreakdown instead of mutating via dict.update()
subscription_models, subscription_pricing
typed models
SessionProfileRecord vs SessionCostSummary field mapping, JSON
roundtrip test for per_model serialization, and test that
compute_usage_outlook returns a typed model
Verification
Cert block
Ref #870— does not close; outlook/anomaly surface still needs feat(insights): subscription-aware cost tracking with client-side tokenizer and per-model breakdown #803/feat(config): unified config system — polylogue.toml, four-layer precedence, shared daemon/CLI config #829🤖 Generated with Claude Code