Skip to content

fix(cost): report unavailable prices as null with typed reasons - #4239

Closed
Sinity wants to merge 1 commit into
masterfrom
feature/packet/polylogue-jfeaz
Closed

Sinity wants to merge 1 commit into
masterfrom
feature/packet/polylogue-jfeaz

Conversation

@Sinity

@Sinity Sinity commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes polylogue-jfeaz (P0): cost surfaces reported $0.00 spent when the price was absent and silently windowed rollups to 50 sessions.

Problem (evidence)

An unpriceable session (missing price table entry, or tokens without materialized pricing) surfaced as $0.00 — indistinguishable from genuinely free — and the cycle outlook read only a 50-session window, understating spend.

Solution

  • Unavailable costs are total_usd: null with the typed reason price_not_materialized (distinct from no_tokens).
  • Canonical cost reads and rollups no longer fall back to profile costs.
  • Cycle outlook reads all sessions and reports counts/truncation metadata.
  • HTTP and enrichment layers preserve unavailable semantics end-to-end.

Verification

  • Focused cost/API/CLI/MCP/HTTP suites: 56 passed in-lane; HTTP broader selection 17 passed.
  • Quick gate at harvest (lane env lacked ruff).

🤖 Generated with Claude Code

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e79fab6f-31e3-4415-ac9a-f468fef4d6fc


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.

@Sinity
Sinity enabled auto-merge (squash) August 26, 2026 11:55

@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: 6c89b576c3

ℹ️ 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".

u.model_name AS model_name,
COUNT(DISTINCT u.session_id) AS session_count,
COALESCE(SUM(COALESCE(u.cost_usd, sp.cost_usd, 0.0)), 0.0) AS stored_cost_usd,
COALESCE(SUM(u.cost_usd), 0.0) AS stored_cost_usd,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve reported totals when model-usage rows exist

When a session has sessions.reported_cost_usd and any session_model_usage row, it is excluded from no_usage_rows, while this query sums only u.cost_usd. Providers such as Claude Code produce both a reported total and model rows, so their exact provider total is now discarded or replaced by a catalog estimate in cost rollups even though the session-cost insight still reports it as exact. Aggregate the canonical per-session verdict or otherwise include each reported total exactly once.

Useful? React with 👍 / 👎.

Comment thread polylogue/archive/semantic/pricing.py Resolved
u.model_name AS model_name,
COUNT(DISTINCT u.session_id) AS session_count,
COALESCE(SUM(COALESCE(u.cost_usd, sp.cost_usd, 0.0)), 0.0) AS stored_cost_usd,
COALESCE(SUM(u.cost_usd), 0.0) AS stored_cost_usd,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Distinguish unpriced model rows from missing tokens

For a session_model_usage row with positive token counts but no catalog price, SUM(u.cost_usd) is null and this COALESCE converts it to zero. The downstream rollup then classifies the row as unavailable but unconditionally records {"no_tokens": ...} at lines 2742-2744, so rollups contradict session-cost insights by claiming token evidence is absent rather than reporting price_not_materialized. Preserve the missing-price state through aggregation and emit the corresponding typed reason.

Useful? React with 👍 / 👎.

Comment thread polylogue/archive/semantic/pricing.py Resolved
Comment thread polylogue/insights/cost_enrichment.py Resolved
Comment thread polylogue/api/insights.py Resolved
@Sinity
Sinity force-pushed the feature/packet/polylogue-jfeaz branch from 6c89b57 to caf551a Compare August 26, 2026 11:58
@Sinity
Sinity disabled auto-merge August 26, 2026 11:58
@Sinity

Sinity commented Aug 26, 2026

Copy link
Copy Markdown
Owner Author

Closing without merge: this branch was cut pre-#4225 and its core change (removing the profile-cost fallback) collided with #4225's v75 rework of the same surface. After rebase the branch mixes eras (unavailable-cost tests still assert 0.0 vs the branch's null semantics, coverage rollup drops duration, v75 schema mismatches in facade tests). The bead is being redispatched against current master; the null-with-typed-reason design from this attempt carries forward.

@Sinity Sinity closed this Aug 26, 2026
@Sinity
Sinity deleted the feature/packet/polylogue-jfeaz branch August 26, 2026 12:01

@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: caf551a480

ℹ️ 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/daemon/http.py Resolved
Sinity added a commit that referenced this pull request Aug 26, 2026
## Summary
Fixes polylogue-jfeaz (P0): cost surfaces no longer coerce an absent
price to $0.00, and the cycle outlook reads the whole archive instead of
a 50-session window.

## Problem (evidence)
An unpriceable session surfaced as `$0.00` — indistinguishable from free
— and outlook rollups silently truncated. A prior attempt (PR #4239)
collided with #4225's v75 rework and was rejected; this redispatch was
built against current master with the collision guidance on the bead.

## Solution
- `total_usd: float | None` with the typed `price_not_materialized`
reason; JSON surfaces preserve `null`.
- Canonical availability semantics kept intact:
`priced`/`provider_money`/`known_zero` (origin-reported provider money,
`reported_cost_usd`) remain authoritative, now with explicit test
coverage.
- Cycle outlook uses an explicit unbounded selection; unavailable-status
insights preserve the archive's typed absence evidence.

## Verification
- Lane-verified quick gate green post-rebase (machine trailer); focused
pricing/profile suites extended (+61/−35 across 11 files).

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

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA
@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.

@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.

  • 58.F007 / P1: fixed-already at the checked revision: polylogue/api/insights.py:584-588 computes the active billing cycle first and supplies both cycle bounds to SessionCostInsightQuery. Historical sessions outside that window are no longer requested for a current-cycle outlook.
  • 58.F036 / P1: fixed-already at the checked revision: polylogue/analysis/registry.py:765 no longer supplies a zero default for session-cost USD. The shared nested accessor at lines 263-270 renders missing values with a dash, so plaintext unavailable prices no longer become usd=0.
  • 58.F037 / P1: fixed-already at the checked revision: tests/unit/core/test_pricing.py:183 asserts that an unavailable price has total_usd is None; the other unavailable cases at lines 44 and 109 do the same. The obsolete zero-valued assertions identified by the review have been replaced.

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.

  • 62.F083 / P1: fixed-already at the checked revision: The evidence-summary regression test now asserts that the unpriced session's total_usd is None at tests/unit/daemon/test_web_reader.py:3374. Its expectation matches the endpoint's null-cost contract rather than requiring 0.0.

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