Skip to content

fix(tests): pass timezone_name to record_token_usage in settings tests - #5349

Open
albatrossflyon-coder wants to merge 3 commits into
HKUDS:mainfrom
albatrossflyon-coder:fix/token-usage-timezone-test-mismatch
Open

fix(tests): pass timezone_name to record_token_usage in settings tests#5349
albatrossflyon-coder wants to merge 3 commits into
HKUDS:mainfrom
albatrossflyon-coder:fix/token-usage-timezone-test-mismatch

Conversation

@albatrossflyon-coder

Copy link
Copy Markdown

Summary

Fixes #5348 — two tests in tests/webui/test_settings_api.py fail deterministically during a ~5-hour daily window because record_token_usage() was called without timezone_name, defaulting to UTC, while the payload read-back (settings_payload()/settings_usage_payload()) always reads with config.agents.defaults.timezone (America/Chicago by default). Whenever UTC has already rolled to the next calendar day but the configured timezone hasn't, the written row falls outside every windowed field's today cutoff.

Full root-cause writeup, including confirmation this is test-only (all three real production call sites already thread the configured timezone correctly), is in #5348.

Fix

Pass timezone_name=config.agents.defaults.timezone to both record_token_usage() calls, matching the convention tests/webui/test_token_usage.py already uses everywhere else in this file's neighborhood.

Test plan

  • Both previously-failing tests pass: test_settings_payload_includes_token_usage_summary, test_settings_usage_payload_returns_lightweight_token_usage
  • Full tests/webui/test_settings_api.py file: 85 passed
  • Reproduced the failure standalone first (isolated script dumping the state at each stage) to confirm root cause before writing the fix

test_settings_payload_includes_token_usage_summary and
test_settings_usage_payload_returns_lightweight_token_usage called
record_token_usage() with no timezone_name, defaulting to UTC, while
settings_payload()/settings_usage_payload() always read back with
config.agents.defaults.timezone (America/Chicago by default). Whenever
UTC has already rolled to the next calendar day but the configured
timezone hasn't (roughly a 5-hour daily window for US Central), the
row lands under a date the windowed fields (requests_30d,
active_days_30d, total_tokens_30d, current_streak_days) never look at,
since they filter against "today" computed in the configured timezone.

Every real production call site (gateway_runtime.py x2,
command/builtin.py) already threads the configured timezone through
consistently, so this is a test-only gap. Matches the convention
tests/webui/test_token_usage.py already uses.

Fixes HKUDS#5348.
albatrossflyon-coder added a commit to albatrossflyon-coder/nanobot that referenced this pull request Aug 12, 2026
@chengyongru chengyongru added priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. bug Something isn't working fix test labels Aug 12, 2026
@chengyongru

Copy link
Copy Markdown
Collaborator

BUILDLOG.md

BUILDLOG.md is an internal fork-tracking file (our own convention, not
part of upstream's docs) that only shows up in this diff because it
lives on our fork's main but not on HKUDS:main. It doesn't belong in a
PR meant to land upstream. Removed here; still present on the fork's
own main branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two token-usage settings tests fail in a ~5hr/day window: record_token_usage() defaults to UTC while settings payload reads the configured timezone

2 participants