Blackbox card fixes: chat fields, cache %, alerts toggle, 3d price cache#9
Merged
Merged
Conversation
…3d price cache
Four fixes to the Blackbox turn-telemetry card and pricing cache:
1. Chat fields on the card. The on_session_end emitter (conversation_loop)
never passed chat_id/chat_name, so every gateway turn recorded empty
chat fields and the card rendered 'Session: Discord <#>'. Pass
agent._chat_id/_chat_name through the hook (mirrors platform/provider).
2. Cache % denominator. _cache_line divided cache_read by bare input_tokens,
so a cache-heavy turn (12 fresh input, 669.2k cached) reported
669.2k/12 = 5,576,942%. Divide by the TOTAL prompt
(input + cache_read + cache_write) → a real 0-100% hit rate.
3. Session line readability. _session_line now shows the channel NAME
alongside the Discord mention ('Discord #ops (<#id>)') and degrades
gracefully when id or name is missing (never an empty 'Discord <#>').
4. alerts_enabled config flag (default True). When False, turns are still
recorded (visible to /cost and /context) but no alert card is pushed —
lets an operator keep telemetry without the channel noise.
Plus: _MODEL_CACHE_TTL 6h → 3 days (OpenRouter notional-pricing cache;
pricing/context rarely change, cheaper + more blip-resilient).
Tests: updated 2 expectations that codified the cache/session bugs; added
cache-denominator, discord session-line, alerts-disabled (×2), and
chat-field-passthrough tests. 67 blackbox+pricing green, ruff clean.
…uncached remainder The card's 'Tokens: N in' line rendered record.input_tokens raw, but that field is only the FRESH (uncached) input remainder. Under prompt caching nearly all input arrives as cache_read/cache_write, so the bare field reads as a tiny leftover (e.g. 12 / 16) while the real input is hundreds of thousands. Same root cause already fixed the Cached% denominator; this extends the _prompt_total helper to the Tokens-in display so both agree. Update test_hooks_alert expected bullet 500k->999k to match the corrected total (fresh 500k + cache_read 499k).
🔎 Lint report:
|
Kyzcreig
added a commit
that referenced
this pull request
Jun 5, 2026
…che (#9) * blackbox: fix card chat fields + cache %, add alerts_enabled toggle, 3d price cache Four fixes to the Blackbox turn-telemetry card and pricing cache: 1. Chat fields on the card. The on_session_end emitter (conversation_loop) never passed chat_id/chat_name, so every gateway turn recorded empty chat fields and the card rendered 'Session: Discord <#>'. Pass agent._chat_id/_chat_name through the hook (mirrors platform/provider). 2. Cache % denominator. _cache_line divided cache_read by bare input_tokens, so a cache-heavy turn (12 fresh input, 669.2k cached) reported 669.2k/12 = 5,576,942%. Divide by the TOTAL prompt (input + cache_read + cache_write) → a real 0-100% hit rate. 3. Session line readability. _session_line now shows the channel NAME alongside the Discord mention ('Discord #ops (<#id>)') and degrades gracefully when id or name is missing (never an empty 'Discord <#>'). 4. alerts_enabled config flag (default True). When False, turns are still recorded (visible to /cost and /context) but no alert card is pushed — lets an operator keep telemetry without the channel noise. Plus: _MODEL_CACHE_TTL 6h → 3 days (OpenRouter notional-pricing cache; pricing/context rarely change, cheaper + more blip-resilient). Tests: updated 2 expectations that codified the cache/session bugs; added cache-denominator, discord session-line, alerts-disabled (×2), and chat-field-passthrough tests. 67 blackbox+pricing green, ruff clean. * fix(blackbox): show total prompt tokens in card 'Tokens in', not the uncached remainder The card's 'Tokens: N in' line rendered record.input_tokens raw, but that field is only the FRESH (uncached) input remainder. Under prompt caching nearly all input arrives as cache_read/cache_write, so the bare field reads as a tiny leftover (e.g. 12 / 16) while the real input is hundreds of thousands. Same root cause already fixed the Cached% denominator; this extends the _prompt_total helper to the Tokens-in display so both agree. Update test_hooks_alert expected bullet 500k->999k to match the corrected total (fresh 500k + cache_read 499k). --------- Co-authored-by: Kyzcreig <9063726+Kyzcreig@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four fixes to Blackbox turn telemetry
1. Empty chat fields on the card (
Session: Discord <#>)The
on_session_endemitter inconversation_loop.pypassedplatform/providerbut neverchat_id/chat_name, so every gateway turn recorded empty chat fields. Now passesagent._chat_id/_chat_namethrough the hook (samegetattrpattern as platform/provider).2. Cache % nonsense (
669.2k/12 🟢 5576942%)_cache_linedividedcache_readby bareinput_tokens. A cache-heavy turn (12 fresh input, 669.2k cached) → 669200/12 = 5,576,942%. Fixed denominator to the total prompt (input + cache_read + cache_write) → a real 0–100% hit rate.3. Session line readability
_session_linenow shows the channel name with the Discord mention —Discord #ops (<#id>)— and degrades gracefully when id or name is missing (never an emptyDiscord <#>).4.
alerts_enabledconfig flag (defaultTrue)When
false, turns are still recorded (visible to/costand/context) but no alert card is pushed. Lets an operator keep telemetry without channel noise.Plus:
_MODEL_CACHE_TTL6h → 3 days (OpenRouter notional-pricing cache; pricing/context rarely change → cheaper + more resilient to OpenRouter blips).Verification