Skip to content

feat(reader): cost panel with confidence chips (#1122) - #1171

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/reader-cost-panel
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/reader-cost-panel

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the per-conversation cost panel to the daemon web reader plus the
backing /api/conversations/{id}/cost endpoint. The panel surfaces the
typed cost-estimate substrate (basis split, per-model breakdown,
unavailable reasons) and renders one MK3 confidence chip per number.

Problem

Issue #1122 specifies a reader cost panel with explicit confidence
chips so the operator can tell at a glance whether a cost is canonical
(provider-reported exact), estimated (catalog-priced), heuristic
(partial coverage), or unavailable. Until this PR the daemon's web
shell had no cost surface at all — selecting a conversation rendered
Info / Raw / Notes tabs only, with no view onto the typed
SessionCostInsight substrate landed under #1132 / #1136 / #1137.

Solution

  • New route GET /api/conversations/{id}/cost in polylogue/daemon/http.py.
    Routes through Polylogue.list_session_cost_insights(SessionCostInsightQuery(conversation_id=id))
    — the same public read adapter the CLI and MCP cost-outlook surfaces use, so
    the reader does not import cost-rollup internals directly (AC#1122).
  • Module-level helpers _confidence_tag, _cost_panel_payload, and
    _empty_cost_payload project the typed estimate into a stable JSON
    shape. The mapping exact -> q-canonical / priced -> q-estimated / partial -> q-heuristic / unavailable -> q-unavailable is the single
    source of truth and is exercised by unit tests.
  • Reader inspector gains a Cost tab. The renderer lazy-loads the
    endpoint into state.costPanels, shows the total + chip, the
    cycle-style basis split (provider_reported / api_equivalent /
    subscription_equivalent / catalog_priced / tool_surcharge), the
    per-model breakdown, token usage, and any missing_reasons —
    explicit unavailable state for unconfigured / unpriced sessions
    instead of a blank panel (AC#1122).
  • Unknown conversations return a 404 (not_found). Existing
    conversations without a materialised session-cost insight return 200
    with status: "unavailable", confidence_tag: "q-unavailable", and
    a zero-valued basis/usage so the panel is never blank.
  • File-size budgets bumped: polylogue/daemon/http.py 1200 -> 1280,
    new entry for polylogue/daemon/web_shell.py at 1220, both with a
    split candidate note pointing at the future per-domain handler /
    per-tab decomposition.

Verification

$ devtools verify --quick
... exit_code: 0  (~40s, all gates pass)

$ pytest tests/unit/daemon/test_cost_panel_endpoint.py -q
16 passed in 9.53s

$ pytest tests/visual/test_reader_dom_smoke.py::test_reader_cost_panel_evidence -q
1 passed in 11.93s

$ pytest tests/unit/daemon/ tests/visual/test_reader_dom_smoke.py \
         tests/unit/mcp/test_cost_outlook_tool.py \
         tests/unit/core/test_facade_api.py -q
498 passed in 16.08s

Unit contracts pin the four confidence-tag mappings, the payload
shape, the empty/unavailable fallback, JSON round-trip safety, and
the dispatch path (404 for unknown, 200 + typed envelope for known).
Visual DOM smoke evidence (#865) pins the Cost inspector tab and the
chip vocabulary (q-canonical / q-estimated / q-heuristic /
q-unavailable, plus Basis split and Per-model section labels)
in the shell HTML, and exercises the live endpoint against the seeded
reader workspace.

Closes #1122

Add a per-conversation cost panel to the daemon web reader plus the
backing /api/conversations/{id}/cost endpoint. The panel surfaces the
typed cost-estimate substrate (basis split, per-model breakdown,
unavailable reasons) and renders one MK3 confidence chip per number
keyed on the cost-estimate status:

  exact       -> q-canonical
  priced      -> q-estimated
  partial     -> q-heuristic
  unavailable -> q-unavailable

The reader does not import cost-rollup internals directly; the new
handler routes through ``Polylogue.list_session_cost_insights`` so the
panel consumes the same typed SessionCostInsight contract the CLI and
MCP outlook tools already use.

Unknown conversations return 404. A conversation that exists but has no
materialised session-cost insight returns a 200 with an explicit
"unavailable" shape so the panel is never blank.

Tests: unit contracts for the four chip mappings, the payload shape,
the empty/unavailable fallback, and the dispatch path (404/200). Visual
DOM smoke evidence (#865) pins the Cost inspector tab + chip vocabulary
in the shell HTML and exercises the live endpoint against the seeded
reader workspace.

Closes #1122

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@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 24 minutes and 5 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: e6b5cf51-22f8-4eca-9b59-19992747d56f

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd65a7 and 23c3c1b.

📒 Files selected for processing (5)
  • docs/plans/file-size-budgets.yaml
  • polylogue/daemon/http.py
  • polylogue/daemon/web_shell.py
  • tests/unit/daemon/test_cost_panel_endpoint.py
  • tests/visual/test_reader_dom_smoke.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/reader-cost-panel

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 f3275ad into master May 17, 2026
4 checks passed
@Sinity
Sinity deleted the feature/feat/reader-cost-panel branch May 17, 2026 10:09

@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: 23c3c1bb24

ℹ️ 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
Comment thread polylogue/daemon/web_shell.py Resolved
@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.

  • 62.F078 / P1: fixed-already at the checked revision: Session cost collection now forwards request.session_id into archive.iter_session_cost_insights at polylogue/api/insights.py:131-132 before enrichment and paging. The per-session cost panel no longer lists and hydrates every conversation before filtering in memory.

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(reader): cost panel with confidence chips

1 participant