Skip to content

Python: [Bug]: tau2 sliding window never logs the over max tokens warning #9338

Closed

Description

Observed Behavior

In SlidingWindowHistoryProvider._get_token_count the red "over max tokens, will truncate" warning can never fire. The yellow "half of max" check runs first and also catches every case where the count is over the max, so the red branch is dead code.

Expected Behavior

When the total goes over max_tokens I expect the red truncation warning, not the yellow percentage one.

Steps to Reproduce

  1. Create SlidingWindowHistoryProvider(max_tokens=10).
  2. Call _get_token_count with one message worth about 27 tokens.
  3. Only the yellow warning is logged ("270% of max tokens") and the red one never appears.

Minimal Reproduction

from agent_framework_lab_tau2._sliding_window import SlidingWindowHistoryProvider
from agent_framework import Message

provider = SlidingWindowHistoryProvider(max_tokens=10)
msg = Message("user", ["hello world, this message is intentionally long so it clearly exceeds the tiny ten token budget"])
total = provider._get_token_count([msg])
assert total > provider.max_tokens
# logged: "Total tokens 27 is 270% of max tokens 10" in yellow, nothing about truncation

Error Messages and Stack Traces

No error, only the yellow loguru warning is emitted.

Package Versions

agent-framework-lab packages built from main (dcbbf79)

Python Version

Python 3.14.8

Operating System

macOS

Regression

Unknown

Additional Context

The two conditions just need to be swapped so the over max case is checked first, then the half warning with elif. Truncation itself works fine, only the warning is lost. Happy to send a PR.

Acknowledgements

  • I searched existing issues and did not find a duplicate.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 13, 2026
  2. added a commit that references this issue on Oct 13, 2026
    624972e
  3. added a commit that references this issue on Oct 16, 2026
    8fe7123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

pythonUsage: [Issues, PRs], Target: Python

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions