Skip to content

feat(cost): subscription usage outlook and quota forecasting (#870) - #943

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/870-final
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/870-final

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026 •

Copy link
Copy Markdown
Owner

SubscriptionCycle, UsageOutlookPayload, polylogue cost CLI command.

Summary by CodeRabbit

  • New Features
    • Added subscription cost forecasting command to analyze usage trends and estimate credit burn rate.
    • Forecasts project remaining credits, daily consumption averages, and estimated exhaustion dates.
    • Supports multiple output formats: JSON and human-readable text reports.
    • Includes cost anomaly detection to identify unusual spending patterns.
    • Provides per-model usage breakdown and confidence metrics for forecast accuracy.

Copilot AI review requested due to automatic review settings May 7, 2026 20:13
@Sinity
Sinity merged commit 78e5623 into master May 7, 2026
1 check passed
@Sinity
Sinity deleted the feature/fix/870-final branch May 7, 2026 20:13
@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

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: d4d27d50-dd6f-435a-b463-d4cb1170d6b2

📥 Commits

Reviewing files that changed from the base of the PR and between 5e00990 and 40c2c76.

📒 Files selected for processing (4)
  • polylogue/archive/semantic/outlook.py
  • polylogue/archive/semantic/subscription_models.py
  • polylogue/cli/click_command_registration.py
  • polylogue/cli/commands/cost.py

📝 Walkthrough

Walkthrough

This PR introduces a complete cost forecasting feature for subscription usage tracking. It defines typed Pydantic data models, implements a projection pipeline that aggregates daily costs, detects anomalies, and computes burn rates, then wires a new CLI command to fetch archived conversation summaries and render forecasts as JSON or formatted text.

Changes

Cost Forecast Feature

Layer / File(s) Summary
Data Models & Contracts
polylogue/archive/semantic/subscription_models.py
Adds PlanConfidence enum and Pydantic models: AnomalyPayload, ModelBreakdownPayload, SubscriptionPlanConfig, UsageOutlookPayload, SubscriptionCycle, and CostOutlookRequest for type-safe quota/outlook semantics.
Outlook Computation
polylogue/archive/semantic/outlook.py
Implements compute_usage_outlook with private helpers for cycle resolution, daily aggregation, projection math, anomaly detection (flagging outlier daily API costs), confidence scoring, and per-model cost breakdown. build_subscription_cycle wraps the outlook with plan metadata and generation timestamp.
CLI Registration & Command
polylogue/cli/click_command_registration.py, polylogue/cli/commands/cost.py
Registers cost_command in ROOT_COMMANDS. Command fetches up to 1000 conversation summaries from archive, normalizes cost fields, invokes compute_usage_outlook, and outputs results as JSON or formatted text report showing burn rate, exhaustion date, confidence, per-model breakdown, and anomalies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit hops through cost dimensions deep,
Aggregating daily totals, anomalies to keep.
Projections dance where burn rates flow,
From archive summaries, forecasts grow.
🐰 CLI commands now speak of coins—
Six Pydantic models lock the joins! ✨

✨ 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/fix/870-final

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: 40c2c76e2d

ℹ️ 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/cli/commands/cost.py Resolved
Comment thread polylogue/archive/semantic/outlook.py Resolved
@Sinity
Sinity removed the request for review from Copilot May 7, 2026 20:35
Sinity added a commit that referenced this pull request May 7, 2026
Polylogue's cost work was geared toward API billing logs, but the
common local-chat/export use case has no provider-reported cost. The
primary product value is subscription-oriented: plan cycle, estimated
burn, quota/rate-limit pressure, model usage, anomaly detection, and
what consumed the user's practical allowance.

- Adds `polylogue/archive/semantic/outlook.py` and
  `subscription_models.py` defining `SubscriptionCycle` and the
  `UsageOutlookPayload` so cost data has a typed shape that can
  describe a plan cycle, not just per-API-call totals.
- Wires a `polylogue cost` CLI command via
  `cli/click_command_registration.py` and `cli/commands/cost.py` so
  the outlook surface is reachable from the user CLI without going
  through ad-hoc reporting scripts.

Builds on the cost-tracking substrate from #803 (PR #938) which
supplies model assignment, token classes, and cost basis.

Refs #870
Sinity added a commit that referenced this pull request May 7, 2026
Polylogue's cost work was geared toward API billing logs, but the
common local-chat/export use case has no provider-reported cost. The
primary product value is subscription-oriented: plan cycle, estimated
burn, quota/rate-limit pressure, model usage, anomaly detection, and
what consumed the user's practical allowance.

- Adds `polylogue/archive/semantic/outlook.py` and
  `subscription_models.py` defining `SubscriptionCycle` and the
  `UsageOutlookPayload` so cost data has a typed shape that can
  describe a plan cycle, not just per-API-call totals.
- Wires a `polylogue cost` CLI command via
  `cli/click_command_registration.py` and `cli/commands/cost.py` so
  the outlook surface is reachable from the user CLI without going
  through ad-hoc reporting scripts.

Builds on the cost-tracking substrate from #803 (PR #938) which
supplies model assignment, token classes, and cost basis.

Refs #870
Sinity added a commit that referenced this pull request May 8, 2026
…rift (#944) (#959)

## Summary

Restore the local verification baseline to green (format/lint/mypy/render/topology/budgets/manifests) and reconcile partially-implemented closed-scope work. Pytest goes from 346 failures to 0 (5859 passed, 1 pre-existing xfail).

## Problem

`devtools verify --quick` was red across every gate. 95 mypy errors. 10 topology orphans. 346 test failures. Several closed issues landed scaffolding without reaching product closure. The underlying causes: schema/upsert drift from the #943 cost-attribution work, FTS external-content table incompatibility with SQLite >=3.50, and config-layer rot from multiple refactors.

## Solution

**Schema v12** — messages table gains `input_tokens`, `output_tokens`, `cache_read_tokens`, `cache_write_tokens`, `model_name` to match the UPSERT SQL already referencing them.

**FTS fix** — Five code paths handled `DELETE FROM messages_fts` on external-content FTS5 tables. Replaced with FTS5-safe commands (`INSERT...VALUES('delete',...)` in triggers, `AND rowid IN (SELECT id FROM messages_fts_docsize)` guard in repair SQL, `'delete-all'` in rebuild paths).

**source_name propagation** — `conversation_to_record` and `save_conversation_record` now extract from `provider_meta.source`.

**Config surface** — API-default-on, pruned dead keys, TOML section-key round-trip, embedding cost cap, fixed `polylogue config` CLI.

**Bug fixes** — daemon facets handler async-correctness, pidfile atexit ordering, `ConversationFormatter` db_path resolution, `PlainConsole` markup handling, `compute_session_cost` import path, attachment upsert column parity.

## Verification

```
$ devtools verify --quick
verify: all checks passed

$ pytest --ignore=tests/integration --ignore=tests/benchmarks
5859 passed, 1 xfailed
```

116 files changed, +1345/-1396.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@Sinity

Sinity commented Oct 1, 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.

@Sinity

Sinity commented Oct 1, 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.

1 participant