Skip to content

fix: use last_usage_ prefix for usage metrics in get_template_vars#34

Open
nuthalapativarun wants to merge 1 commit into
microsoft:mainfrom
nuthalapativarun:fix/metric-key-collision
Open

fix: use last_usage_ prefix for usage metrics in get_template_vars#34
nuthalapativarun wants to merge 1 commit into
microsoft:mainfrom
nuthalapativarun:fix/metric-key-collision

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Problem

In get_template_vars, both the _last_request_metrics and _last_usage_metrics loops write keys with the prefix "last_request_". This causes the usage keys (e.g. last_request_input_tokens) to silently overwrite the request keys (e.g. last_request_message_count) when they share the same suffix. Similarly, _cumulative_usage_metrics uses "cumulative_" while _cumulative_request_metrics uses "cumulative_request_" — an inconsistent naming scheme.

Fix

Change the _last_usage_metrics loop prefix to "last_usage_" and the _cumulative_usage_metrics loop prefix to "cumulative_usage_".

Changes

  • src/webwright/models/base.py — fixed the two misnamed prefixes in get_template_vars
  • tests/unit/test_get_template_vars.py — added tests asserting both last_request_message_count and last_usage_input_tokens appear as distinct keys, and that cumulative usage uses cumulative_usage_ prefix

Not affected

  • _usage_snapshot() — separate method, not touched
  • All other methods in base.py — not touched

Both _last_request_metrics and _last_usage_metrics loops used the same
"last_request_" prefix, causing usage metrics to silently overwrite
request metrics in the returned vars dict. Use "last_usage_" for the
usage loop and "cumulative_usage_" for the cumulative usage loop.
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