Skip to content

test+docs(cost): contract suite and cost model docs (#1140) - #1173

Merged
Sinity merged 1 commit into
masterfrom
feature/test/cost-contract-suite-docs
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/cost-contract-suite-docs

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

Capstone for the cost cluster (#995 → #1140). Adds a cross-cluster contract
suite that pins invariants no per-module test owns, a planner-driven legacy-
row migration helper, and a docs/cost-model.md page documenting the basis
split, subscription plans, cycle outlook semantics, surfaces, migration, and
the non-authoritative caveat.

Problem

#1140 (the cost-cluster capstone for #995) required:

  1. A cross-cluster cost contract suite — per-module tests for feat(cost): typed subscription plan config (cycle, quota, overage rules) #1132/feat(cost): split cost rollup by basis (API/subscription/catalog) with per-model breakdown #1136/
    feat(cost): cycle outlook engine — burn, projection, quota pressure, overage #1137/feat(cost): expose cycle outlook through CLI and MCP #1138/refactor(cost): remove provider_meta cost fallback reads outside extractors #1139 pin focused behavior, but nothing pinned the cross
    contracts that any one layer could silently break (basis independence,
    per-model reconciliation, partial coverage, quota absence, projection
    monotonicity, cycle-anchor determinism, shared CLI/MCP envelope).
  2. A migration helper for legacy session_profiles.total_cost_usd rows
    materialized before the feat(cost): split cost rollup by basis (API/subscription/catalog) with per-model breakdown #1136 basis split, marked with
    source = legacy-single-basis.
  3. Documentation of the cost model — explicitly covering the basis taxonomy,
    plan configuration, projection method, and the non-vendor-authoritative
    caveat. test+docs(cost): contract suite, migration of legacy rows, cost model docs #1140 ACs explicitly required docs/cost-model.md cover this.

Solution

  • tests/unit/cost/test_contract_suite.py (new): 18 contract tests grouped
    by basis split, plan/quota, outlook projection, cycle math, aggregation,
    CLI/MCP/API exposure, and migration. Each assertion-bearing test records
    bounded contract evidence via the record_contract_evidence fixture so
    PR-impact reports can attribute the exercised surface. MCP test exercises
    the live cost_outlook tool by building the MCP server, mocking the
    facade, and asserting the typed envelope matches polylogue.cost.outlook.CycleOutlook.

  • polylogue/maintenance/cost_migration.py (new): planner-driven migration
    helper. find_legacy_cost_rows(reader) filters session_profiles rows
    whose cost_provenance is in LEGACY_COST_PROVENANCE_MARKERS
    ({"unknown", ""}) AND total_cost_usd > 0. plan_cost_migration returns
    a typed BackfillOperation with kind = DERIVED_REBUILD, targets = ('session_profiles',), reason = STALE_MATERIALIZER_VERSION, and a scope
    filter tagged cost_basis = legacy-single-basis plus the conversation-id
    list. Pure-function-shaped — the actual rebuild executes through the
    existing polylogue.maintenance.planner.execute_backfill path; this
    module is the bridge that classifies the work and reasons about scope.

  • docs/cost-model.md (new): basis taxonomy (5 independent axes that do not
    sum to total_usd), status & confidence, unavailable reasons, per-model
    breakdown, subscription plans (polylogue-curated-seed vs user-config),
    cycle outlook semantics (window, burn, projected total, quota pressure,
    coverage, confidence), surfaces (CLI/MCP/API share the typed envelope),
    legacy migration path, and the non-authoritative caveat (with explicit
    call-out that subscription quota math is not vendor-authoritative).

Topology projection (docs/plans/topology-target.yaml) and topology status
regenerated via devtools build-topology-projection and
devtools render-topology-status.

Verification

pytest tests/unit/cost/test_contract_suite.py -q
  -> 18 passed in 18.91s

pytest tests/unit/cost/ tests/unit/insights/ tests/unit/mcp/test_cost_outlook_tool.py -q
  -> 140 passed in 20.71s

pytest tests/unit/maintenance/ -q
  -> 78 passed in 15.19s

mypy --strict polylogue/maintenance/cost_migration.py tests/unit/cost/test_contract_suite.py
  -> Success: no issues found in 2 source files

devtools verify --quick
  -> exit_code: 0 (all gates green: format, lint, mypy, render-all,
     verify-topology, verify-cluster-cohesion, verify-file-budgets,
     verify-test-ownership, verify-schema-roundtrip, verify-cross-cuts,
     verify-suppressions, verify-manifests, verify-ci-workflows,
     verify-witness-lifecycle, verify-lane-assertions, verification-impact)

Closes #1140
Ref #995

@coderabbitai

coderabbitai Bot commented May 17, 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 14 minutes and 57 seconds before requesting another review.

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 @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: f6079fd1-35bb-487b-b76e-dd29a4472c6c

📥 Commits

Reviewing files that changed from the base of the PR and between 89b06f2 and 0289e71.

📒 Files selected for processing (5)
  • docs/cost-model.md
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/maintenance/cost_migration.py
  • tests/unit/cost/test_contract_suite.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test/cost-contract-suite-docs

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.

@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: 116b1848ae

ℹ️ 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/maintenance/cost_migration.py Resolved
Problem: #1140 (cost-cluster capstone for #995) required a cross-cluster
contract suite, a legacy-row migration helper, and documentation of the
cost basis split, subscription plans, cycle outlook, and caveats. Per-
module tests for #1132/#1136/#1137/#1138/#1139 pinned focused behavior
but nothing pinned the cross-contracts that any one layer could silently
break (basis independence, per-model reconciliation, partial coverage,
quota absence, projection monotonicity, cycle-anchor determinism, shared
CLI/MCP envelope).

Solution:
- tests/unit/cost/test_contract_suite.py: 18 contract tests covering
  basis independence, exact-provider preservation, estimated-flag,
  per-model breakdown sum reconciles to aggregate (both total_usd and
  per-axis), partial status when rows unpriced, curated-seed
  non-authoritative notice, QuotaPressureMissing when no quota,
  QuotaPressure when quota declared, projection monotonicity (both
  primitive and full build_cycle_outlook), cycle-anchor determinism
  across month-end/DST, aggregation excludes unpriced/untimestamped,
  shared CycleOutlook envelope across API and MCP. Each assertion-
  bearing test records bounded contract evidence via
  record_contract_evidence so PR-impact reports can attribute the
  exercised surface.
- polylogue/maintenance/cost_migration.py: planner-driven migration
  helper. find_legacy_cost_rows filters session_profiles rows whose
  cost_provenance is in the legacy marker set ({"unknown", ""}) and
  total_cost_usd > 0; plan_cost_migration returns a typed
  BackfillOperation (DERIVED_REBUILD, STALE_MATERIALIZER_VERSION,
  scope tagged with cost_basis=legacy-single-basis). Pure-function-
  shaped so the executor stays in planner.execute_backfill.
- docs/cost-model.md: new page covering basis taxonomy (provider_
  reported, api_equivalent, subscription_equivalent, catalog_priced,
  tool_surcharge — independent axes, do not sum to total_usd), status
  and confidence, unavailable reasons, per-model breakdown, subscription
  plans, cycle outlook semantics, surfaces (CLI/MCP/API share typed
  envelope), legacy migration path, and the non-authoritative caveat.

Verification:
- pytest tests/unit/cost/test_contract_suite.py -q  (18 passed)
- pytest tests/unit/cost/ tests/unit/insights/ tests/unit/mcp/test_cost_outlook_tool.py -q  (140 passed)
- pytest tests/unit/maintenance/ -q  (78 passed)
- mypy --strict polylogue/maintenance/cost_migration.py tests/unit/cost/test_contract_suite.py  (Success)
- devtools verify --quick  (exit_code: 0, all gates pass)

Closes #1140
Ref #995

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity force-pushed the feature/test/cost-contract-suite-docs branch from 116b184 to 0289e71 Compare May 17, 2026 10:16
@Sinity
Sinity merged commit eb133fd into master May 17, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/test/cost-contract-suite-docs branch May 17, 2026 10:16
@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.

test+docs(cost): contract suite, migration of legacy rows, cost model docs

1 participant