Skip to content

fix: make cost_status sticky across API calls (#67764) - #67774

Closed
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/67764-cost-status-persist
Closed

fix: make cost_status sticky across API calls (#67764)#67774
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/67764-cost-status-persist

Conversation

@webtecnica

Copy link
Copy Markdown
Contributor

Summary

cost_status was being overwritten on every API call instead of accumulating the highest-confidence value. Once a call reports "actual", the session/model row should stay "actual" forever.

Priority ladder: actual > included > estimated > unknown

Changes

Layer 0 — Helper

  • agent/usage_pricing.py: Added sticky_cost_status(current, incoming) that returns the highest-confidence status.

Layer 1 — SQL persistence (3 sites)

  • hermes_state.py: Replaced COALESCE(?, cost_status) with a CASE expression in:
    • sessions absolute UPDATE
    • sessions incremental UPDATE
    • session_model_usage ON CONFLICT DO UPDATE

Layer 2 — In-memory agent attribute

  • agent/conversation_loop.py:2321: Sticky assignment via sticky_cost_status()
  • agent/codex_runtime.py:150: Sticky assignment via sticky_cost_status()

Layer 3 — Insights aggregator

  • agent/insights.py:583: Per-model sticky aggregation via sticky_cost_status()

Fixes: #67764

cost_status was being overwritten on every API call instead of
accumulating the highest-confidence value. Once a call reports
'actual', the session/model row should stay 'actual' forever.

Priority ladder: actual > included > estimated > unknown

Changes:
- usage_pricing.py: add sticky_cost_status() helper
- hermes_state.py: replace COALESCE with CASE in 3 SQL sites
  (sessions absolute, sessions incremental, session_model_usage UPSERT)
- conversation_loop.py: sticky in-memory assignment
- codex_runtime.py: sticky in-memory assignment
- insights.py: per-model sticky aggregation

Fixes: NousResearch#67764
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/billing Account usage, credit usage, billing (cross-cutting) area/usage-cost Token accounting, usage reporting, billing, cost tracking sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state needs-decision Awaiting maintainer decision before any implementation labels Jul 20, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to #67764 and competing/overlapping with #67770: this patch fixes sticky cost-status semantics, but also carries an unwired SessionDB rehydration helper that overlaps #67770's agent-construction work. Maintainer consolidation is needed.

@DavidMetcalfe

Copy link
Copy Markdown
Contributor

@webtecnica Please adjust your agent so that it does not create and submit PRs for issues that have "I'd like to fix this myself and submit a PR" checked off. You're burning tokens unnecessarily and duplicating work.

@webtecnica

Copy link
Copy Markdown
Contributor Author

Hey @DavidMetcalfe, you're absolutely right — apologies for jumping on an issue you wanted to fix yourself. PR closed. Won't happen again. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing Account usage, credit usage, billing (cross-cutting) area/usage-cost Token accounting, usage reporting, billing, cost tracking comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: cost_status overwritten on every API call across SQL, in-memory, and /insights aggregations

3 participants