Skip to content

refactor(archive): own semantic pricing - #672

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/archive-semantic-pricing
May 1, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/archive-semantic-pricing

Conversation

@Sinity

@Sinity Sinity commented May 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Move provider/model cost-estimation semantics from polylogue.lib into archive semantic ownership.

Problem

pricing.py estimates costs from archive message model and token facts. It is not a generic library primitive, and keeping it under polylogue.lib left another archive semantic in the shrinking library root.

Solution

  • Rename polylogue/lib/pricing.py to polylogue/archive/semantic/pricing.py.
  • Update operations, session runtime, product payload, MCP, and tests to import the semantic owner directly.
  • Remove pricing.py from the remaining lib-root topology primitive list and regenerate topology docs.

Ref #635

Verification

  • devtools build-topology-projection && devtools verify-topology — realized=695 declared=695 blocking=False
  • ruff check polylogue/ tests/ devtools/ — all checks passed
  • mypy polylogue/ — no issues found in 695 source files
  • pytest -q tests/unit/core/test_pricing.py tests/unit/core/test_semantic_facts.py tests/unit/core/test_conversation_semantics.py tests/unit/mcp/test_tool_contracts.py tests/unit/operations/test_archive_helpers.py — 120 passed
  • devtools render-all --check — sync OK
  • pre-push devtools verify --quick — all checks passed

Summary by CodeRabbit

  • Refactor

    • Reorganized internal pricing module structure to improve code organization and maintainability.
    • Updated test imports to reflect the new module structure.
  • Chores

    • Updated build topology configuration to reflect module reorganization.

Copilot AI review requested due to automatic review settings May 1, 2026 21:35
@Sinity
Sinity enabled auto-merge (squash) May 1, 2026 21:35
@Sinity
Sinity merged commit 011c761 into master May 1, 2026
@Sinity
Sinity deleted the feature/refactor/archive-semantic-pricing branch May 1, 2026 21:35
@coderabbitai

coderabbitai Bot commented May 1, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7eb31d37-197c-4283-8cf2-ccf39d6f0461

📥 Commits

Reviewing files that changed from the base of the PR and between 6a5929e and abc1563.

📒 Files selected for processing (12)
  • devtools/build_topology_projection.py
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/archive/semantic/pricing.py
  • polylogue/archive/session/runtime.py
  • polylogue/operations/archive.py
  • polylogue/products/archive.py
  • tests/unit/core/test_conversation_semantics.py
  • tests/unit/core/test_pricing.py
  • tests/unit/core/test_semantic_facts.py
  • tests/unit/mcp/test_tool_contracts.py
  • tests/unit/operations/test_archive_helpers.py

📝 Walkthrough

Walkthrough

This PR relocates pricing-related functionality from polylogue/lib/ to polylogue/archive/semantic/ by updating import statements across the codebase and adjusting topology classification rules to reflect the new module structure.

Changes

Cohort / File(s) Summary
Build & Configuration
devtools/build_topology_projection.py, docs/plans/topology-target.yaml, docs/topology-status.md
Removes pricing.py from lib-root primitives classification. Topology updates reflect the relocation: archive-semantic domain increases to 6 target cells; Primitives summary decreases from 15 to 14.
Core Implementation
polylogue/archive/session/runtime.py, polylogue/operations/archive.py, polylogue/products/archive.py
Updates imports for pricing utilities (harmonize_session_cost, CostUsagePayload, CostEstimatePayload, estimate_conversation_cost, _normalize_model, generated_at) to source from polylogue.archive.semantic.pricing instead of polylogue.lib.pricing. Logic and usage remain unchanged.
Tests
tests/unit/core/test_conversation_semantics.py, tests/unit/core/test_pricing.py, tests/unit/core/test_semantic_facts.py, tests/unit/mcp/test_tool_contracts.py, tests/unit/operations/test_archive_helpers.py
Updates test imports to use polylogue.archive.semantic.pricing for pricing utilities and payload types. Test logic and assertions remain unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #438: Both PRs modify devtools/build_topology_projection.py to adjust topology classification rules; this PR removes pricing from lib-root primitives as part of the relocation effort.

Poem

🐰 From lib/ to archive/semantic/ we hop,
Pricing logic moves to a better spot!
Imports reroute with careful care,
Tests still dance without a glare,
Topology shifts—our topology's a-prime! 🌟

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/archive-semantic-pricing

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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Polylogue Proof Pack

Refs: origin/master..HEAD
Changed paths: 0

Affected Domains

  • none

Required Gates

  • devtools verify --quick — full PR gate remains explicit
  • devtools verify — full PR gate remains explicit
  • devtools build-package — deployment readiness gate; run when packaging or release confidence matters
  • nix flake check — deployment readiness gate; run when packaging or release confidence matters

Known Gaps

  • none for affected domains

Oracle / Cost

  • oracle mix: {}
  • cost tier: {}
  • stale evidence: 0
  • manual review cells: 0

Copilot AI 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.

Pull request overview

Moves archive cost-estimation (“pricing”) semantics out of the shrinking polylogue.lib facade and into the archive semantic layer (polylogue.archive.semantic), aligning ownership with the archive domain model and topology plan.

Changes:

  • Introduces polylogue/archive/semantic/pricing.py and removes pricing.py from the lib-root primitives list/topology projection.
  • Updates operational/runtime/product code and unit tests to import pricing payloads/helpers from polylogue.archive.semantic.pricing.
  • Regenerates topology docs/status to reflect the new ownership and file counts.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
polylogue/archive/semantic/pricing.py New archive-owned pricing/cost-estimation module and payload models.
polylogue/archive/session/runtime.py Updates session profile builder to import harmonize_session_cost from archive semantic pricing.
polylogue/operations/archive.py Updates archive operations to use the new pricing module import path.
polylogue/products/archive.py Updates product contracts to reference pricing payload types from archive semantic pricing.
tests/unit/core/test_pricing.py Updates pricing tests to import from the new module.
tests/unit/core/test_semantic_facts.py Updates semantic facts tests to import harmonize_session_cost from the new module.
tests/unit/core/test_conversation_semantics.py Updates conversation semantics tests to import harmonize_session_cost from the new module.
tests/unit/mcp/test_tool_contracts.py Updates MCP tool contract tests to import pricing payloads from the new module.
tests/unit/operations/test_archive_helpers.py Updates operations helper tests to import CostEstimatePayload from the new module.
devtools/build_topology_projection.py Removes pricing.py from the lib-root primitive set used for topology projection.
docs/plans/topology-target.yaml Moves pricing ownership from lib-root to archive-semantic and updates LOC counts.
docs/topology-status.md Updates generated topology status counts reflecting the new archive-semantic file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sinity added a commit that referenced this pull request May 7, 2026
## Summary
Move provider/model cost-estimation semantics from `polylogue.lib` into
archive semantic ownership.

## Problem
`pricing.py` estimates costs from archive message model and token facts.
It is not a generic library primitive, and keeping it under
`polylogue.lib` left another archive semantic in the shrinking library
root.

## Solution
- Rename `polylogue/lib/pricing.py` to
`polylogue/archive/semantic/pricing.py`.
- Update operations, session runtime, product payload, MCP, and tests to
import the semantic owner directly.
- Remove `pricing.py` from the remaining `lib-root` topology primitive
list and regenerate topology docs.

Ref #635

## Verification
- `devtools build-topology-projection && devtools verify-topology` —
realized=695 declared=695 blocking=False
- `ruff check polylogue/ tests/ devtools/` — all checks passed
- `mypy polylogue/` — no issues found in 695 source files
- `pytest -q tests/unit/core/test_pricing.py
tests/unit/core/test_semantic_facts.py
tests/unit/core/test_conversation_semantics.py
tests/unit/mcp/test_tool_contracts.py
tests/unit/operations/test_archive_helpers.py` — 120 passed
- `devtools render-all --check` — sync OK
- pre-push `devtools verify --quick` — all checks passed
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.

2 participants