Skip to content

feat: add cost estimation products - #394

Merged
Sinity merged 2 commits into
masterfrom
feature/feat/cost-estimation
Apr 24, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/feat/cost-estimation

Conversation

@Sinity

@Sinity Sinity commented Apr 24, 2026

Copy link
Copy Markdown
Owner

Summary

Add a typed cost-estimation substrate and expose it through registry-backed archive products. Polylogue can now report session-level cost estimates and provider/model rollups through CLI, facade, sync facade, and MCP surfaces.

Problem

#388 asked for cost estimation across providers, models, and sessions. The repository had only a legacy (cost_usd, is_estimated) helper and no product contract for provenance, missing data, model normalization, or provider/model rollups. That made cost analysis ad hoc and encouraged false precision when token or price data was incomplete.

Solution

  • replace the pricing helper internals with typed usage, price, component, and estimate payloads while preserving harmonize_session_cost() as a compatibility adapter
  • add a curated LiteLLM-shaped seed pricing catalog with explicit provenance and effective date; provider/archive-reported exact costs still win
  • add session_costs and cost_rollups product contracts, operations, facade methods, sync facade methods, CLI commands, and MCP tools through the shared product registry
  • represent estimate status as exact, priced, partial, or unavailable, with confidence and missing reasons
  • refresh generated CLI/quality/verification docs for the new product commands
  • cover exact archive cost, catalog-priced estimate, partial estimate, missing price, model normalization, CLI JSON, facade, and MCP contracts

Verification

  • pytest -q tests/unit/core/test_pricing.py tests/unit/cli/test_products.py::test_products_costs_json tests/unit/cli/test_products.py::test_products_cost_rollups_json tests/unit/core/test_facade_api.py::TestPolylogueArchiveProducts::test_durable_session_products_are_publicly_queryable tests/unit/mcp/test_tool_contracts.py::TestProductTools::test_product_list_tools_use_archive_queries passed: 9 passed in 10.91s
  • mypy --strict polylogue/lib/pricing.py polylogue/archive_products.py polylogue/operations/archive.py polylogue/products/registry.py polylogue/facade_products.py polylogue/sync_product_queries.py tests/unit/core/test_pricing.py tests/unit/cli/test_products.py tests/unit/core/test_facade_api.py tests/unit/mcp/test_tool_contracts.py passed: Success, no issues found
  • devtools render-all --check passed: all generated surfaces sync OK
  • devtools verify passed: verify: all checks passed
  • git push -u origin feature/feat/cost-estimation passed pre-push quick verification: verify: all checks passed

Closes #388

Sinity and others added 2 commits April 24, 2026 02:24
Problem

Polylogue had only a legacy session-cost float, which made provider/model
cost analysis impossible to expose consistently across CLI, facade, and
MCP surfaces.

What changed

Replace the pricing helper with typed usage, price, component, and
estimate payloads backed by a curated LiteLLM-shaped seed catalog. Add
session-cost and provider/model cost-rollup products to the shared product
registry, facade, sync facade, operations layer, CLI reference, and MCP
registry surface.

Compatibility

The existing harmonize_session_cost() helper remains as a compatibility
adapter over the richer estimate contract.

Verification

 passes locally.

Ref #388
Co-Authored-By: Claude <[email protected]>
Problem

The new cost-estimation contract needs coverage at the substrate and
public product boundaries so uncertainty semantics do not regress.

What changed

Add pricing tests for exact provider costs, catalog-priced estimates,
partial estimates, missing prices, and model normalization. Extend CLI,
facade, and MCP product tests to assert session-cost and cost-rollup
payloads are exposed through the shared registry surfaces.

Verification

bringing up nodes...
bringing up nodes...

.........                                                                [100%]
9 passed in 10.67s passes locally.
Success: no issues found in 10 source files passes locally.
 passes locally.

Ref #388
Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 32 minutes and 49 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 32 minutes and 49 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f3573d5f-c024-48a7-980c-5f9f6416f85c

📥 Commits

Reviewing files that changed from the base of the PR and between d095414 and ee8bbd3.

📒 Files selected for processing (14)
  • docs/cli-reference.md
  • docs/test-quality-workflows.md
  • docs/verification-catalog.md
  • polylogue/archive_products.py
  • polylogue/facade_products.py
  • polylogue/lib/pricing.py
  • polylogue/operations/archive.py
  • polylogue/products/registry.py
  • polylogue/sync_product_queries.py
  • tests/infra/storage_records.py
  • tests/unit/cli/test_products.py
  • tests/unit/core/test_facade_api.py
  • tests/unit/core/test_pricing.py
  • tests/unit/mcp/test_tool_contracts.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/cost-estimation

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity merged commit f6aad25 into master Apr 24, 2026
11 of 12 checks passed
@Sinity
Sinity deleted the feature/feat/cost-estimation branch April 24, 2026 00:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee8bbd3684

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/lib/pricing.py Resolved
Comment thread polylogue/lib/pricing.py Resolved
@Sinity
Sinity requested review from Copilot and removed request for Copilot May 1, 2026 00:44
@Sinity
Sinity removed the request for review from Copilot May 1, 2026 02:15
Sinity added a commit that referenced this pull request May 7, 2026
Summary

Add a typed cost-estimation substrate and expose it through registry-backed archive products. Polylogue can now report session-level cost estimates and provider/model rollups through CLI, facade, sync facade, and MCP surfaces.

Problem

#388 asked for cost estimation across providers, models, and sessions. The repository had only a legacy `(cost_usd, is_estimated)` helper and no product contract for provenance, missing data, model normalization, or provider/model rollups. That made cost analysis ad hoc and encouraged false precision when token or price data was incomplete.

Solution

- replace the pricing helper internals with typed usage, price, component, and estimate payloads while preserving `harmonize_session_cost()` as a compatibility adapter
- add a curated LiteLLM-shaped seed pricing catalog with explicit provenance and effective date; provider/archive-reported exact costs still win
- add `session_costs` and `cost_rollups` product contracts, operations, facade methods, sync facade methods, CLI commands, and MCP tools through the shared product registry
- represent estimate status as `exact`, `priced`, `partial`, or `unavailable`, with confidence and missing reasons
- refresh generated CLI/quality/verification docs for the new product commands
- cover exact archive cost, catalog-priced estimate, partial estimate, missing price, model normalization, CLI JSON, facade, and MCP contracts

Verification

- `pytest -q tests/unit/core/test_pricing.py tests/unit/cli/test_products.py::test_products_costs_json tests/unit/cli/test_products.py::test_products_cost_rollups_json tests/unit/core/test_facade_api.py::TestPolylogueArchiveProducts::test_durable_session_products_are_publicly_queryable tests/unit/mcp/test_tool_contracts.py::TestProductTools::test_product_list_tools_use_archive_queries` passed: 9 passed in 10.91s
- `mypy --strict polylogue/lib/pricing.py polylogue/archive_products.py polylogue/operations/archive.py polylogue/products/registry.py polylogue/facade_products.py polylogue/sync_product_queries.py tests/unit/core/test_pricing.py tests/unit/cli/test_products.py tests/unit/core/test_facade_api.py tests/unit/mcp/test_tool_contracts.py` passed: Success, no issues found
- `devtools render-all --check` passed: all generated surfaces sync OK
- `devtools verify` passed: verify: all checks passed
- `git push -u origin feature/feat/cost-estimation` passed pre-push quick verification: verify: all checks passed

Closes #388
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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.

[feat] Cost estimation across providers, models, and sessions

1 participant