Skip to content

feat(telemetry): forward cache_write_tokens to conductor - #20

Closed
Wyn2004 wants to merge 1 commit into
mainfrom
feat/telemetry-cache-write-tokens
Closed

Wyn2004 wants to merge 1 commit into
mainfrom
feat/telemetry-cache-write-tokens

Conversation

@Wyn2004

@Wyn2004 Wyn2004 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Forwards cache_write_tokens from the agent's usage counters to Conductor's telemetry hook. usage_to_dict already computed cache_write internally, but the Conductor telemetry hook only ever read cache_read off the usage dict — cache-write activity was silently dropped instead of reaching Conductor's cache-accounting pipeline.

This is the evoflux-side half of a paired change. The Conductor-side half (schema, storage, aggregate rollups, and the UI that displays cache writes and net cache savings) is in evoelsewhere/evo-conductor#6 — merge both together, since Conductor's new column stays 0 for every event until this side ships.

What changed

  • app/conductor/constants/telemetry.py: added TelemetryField.CACHE_WRITE_TOKENS, included in TELEMETRY_NUMERIC_TOKEN_FIELDS.
  • app/agent/hooks/conductor_telemetry.py: wrap_model_call's success path now passes cache_write_tokens=_counter(usage.get("cache_write")) into _record(...); _record gained the parameter and enqueues it.

Checklist

  • Change is scoped to telemetry forwarding only — no behavior change to cost calculation, model calls, or anything user-facing.
  • Backward compatible: cache_write_tokens defaults to 0 via _counter(None) when a provider's usage dict has no cache_write key, so nothing breaks for providers that don't report it.
  • Existing test suite passes.
  • Extended tests/conductor/test_telemetry.py::test_hook_queues_only_safe_model_and_tool_metadata to assert the new field is actually forwarded (cache_write: 15 in the mock usage → TelemetryField.CACHE_WRITE_TOKENS == 15 in the enqueued event), not just that nothing crashed.
  • No new dependencies, no config/migration changes on this side.
  • Playwright / browser evidence: not applicable — evoflux has no frontend or e2e suite for this path. The visual/behavioral proof that cache-write tokens now flow end-to-end (schema → storage → aggregate → UI) is in the paired Conductor PR's evidence section.

Test evidence

$ uv run pytest tests/conductor/test_telemetry.py -v
...
tests/conductor/test_telemetry.py::test_hook_queues_only_safe_model_and_tool_metadata PASSED
tests/conductor/test_telemetry.py::test_hook_attributes_managed_agent_and_skill_and_closes_request PASSED
tests/conductor/test_telemetry.py::test_hook_attributes_plugin_tools_by_runtime_installation_identity PASSED
tests/conductor/test_telemetry.py::test_hook_closes_failed_request_once_with_resource_attribution PASSED
tests/conductor/test_telemetry.py::test_outbox_preserves_oldest_events_and_reports_queue_health PASSED
tests/conductor/test_telemetry.py::test_client_posts_sanitized_batch PASSED
tests/conductor/test_telemetry.py::test_client_posts_empty_batch_to_refresh_delivery_summary PASSED
tests/conductor/test_telemetry.py::test_managed_skill_usage_is_durable_and_content_free PASSED

8 passed in 7.37s

Usage already computed cache_write internally (app/agent/usage.py), but
the conductor telemetry hook only ever read cache_read off the usage
dict — cache-write activity was silently dropped instead of reaching
conductor's cache-accounting pipeline. Forwards it the same way
cache_read already is, and extends the queueing test to assert it lands
in the enqueued event.

Companion change on the conductor side (evo-conductor repo) adds the
cache_write_tokens field this now populates, plus the storage/aggregate
work that uses it.
@khuonghung

Copy link
Copy Markdown
Member

Already Fixed

@khuonghung khuonghung closed this Sep 11, 2026
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.

2 participants