Skip to content

Blackbox card fixes: chat fields, cache %, alerts toggle, 3d price cache#9

Merged
Kyzcreig merged 2 commits into
mainfrom
feat/blackbox-chat-fields-and-context
Jun 4, 2026
Merged

Blackbox card fixes: chat fields, cache %, alerts toggle, 3d price cache#9
Kyzcreig merged 2 commits into
mainfrom
feat/blackbox-chat-fields-and-context

Conversation

@Kyzcreig

@Kyzcreig Kyzcreig commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Four fixes to Blackbox turn telemetry

1. Empty chat fields on the card (Session: Discord <#>)

The on_session_end emitter in conversation_loop.py passed platform/provider but never chat_id/chat_name, so every gateway turn recorded empty chat fields. Now passes agent._chat_id/_chat_name through the hook (same getattr pattern as platform/provider).

2. Cache % nonsense (669.2k/12 🟢 5576942%)

_cache_line divided cache_read by bare input_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_line now shows the channel name with 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 channel noise.

Plus: _MODEL_CACHE_TTL 6h → 3 days (OpenRouter notional-pricing cache; pricing/context rarely change → cheaper + more resilient to OpenRouter blips).

Verification

  • 67 blackbox + pricing tests green; 100 conversation/hook tests green; ruff clean.
  • Updated 2 test expectations that had codified the cache/session bugs.
  • Added tests: cache-denominator (incl. the 669k regression), discord session-line variants, alerts-disabled (records-but-no-push, and ignores always_card), chat-field passthrough.

Kyzcreig added 2 commits June 4, 2026 04:56
…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).
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

🔎 Lint report: feat/blackbox-chat-fields-and-context vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9830 on HEAD, 9830 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5116 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@Kyzcreig Kyzcreig merged commit 8816eea into main Jun 4, 2026
23 checks passed
@Kyzcreig Kyzcreig deleted the feat/blackbox-chat-fields-and-context branch June 4, 2026 12:05
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>
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