Python: fix(lab-tau2): check the over-max warning before the half-of-max warning by ManoharPaturi · Pull Request #9341 · microsoft/agent-framework · GitHub
Skip to content

Python: fix(lab-tau2): check the over-max warning before the half-of-max warning - #9341

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 5 commits into
microsoft:mainfrom
ManoharPaturi:fix/tau2-over-max-warning
Oct 16, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 5 commits into
microsoft:mainfrom
ManoharPaturi:fix/tau2-over-max-warning

Conversation

@ManoharPaturi

@ManoharPaturi Manohar Paturi (ManoharPaturi) commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

In SlidingWindowHistoryProvider._get_token_count the red "over max tokens, will truncate" warning could never fire. The yellow half-of-max check ran first and also matched every over-max case, so the branch was dead code and the truncation warning was silently lost. Issue #9338 has the repro.

Description & Review Guide

  • What are the major changes? The two conditions are swapped so the over-max case is checked first and the half-of-max warning becomes the elif.
  • What is the impact of these changes? Only which log line appears. Truncation itself already worked.
  • What do you want reviewers to focus on? The swapped conditions and the new test that captures the log and asserts the truncation warning is present.

Related Issue

Fixes #9338

AI Assistance

  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

…max warning

The half-of-max branch ran first and also matched every over-max case,
so the red truncation warning was dead code. Swap the branch order.

Fixes microsoft#9338

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added python Usage: [Issues, PRs], Target: Python lab Usage: [Issues, PRs], Target: lab packages labels Oct 13, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAF Automated Review — Iteration 1

Result: No findings
Scope: full PR (2 commit(s)): 624972ec549c, 0d71d4a447a7
Model: gpt-5.6-sol

Overview

The PR correctly makes the over-budget warning reachable by checking it before the overlapping half-budget condition. The strict truncation threshold and stored-history behavior remain unchanged, while the regression test demonstrates that an over-budget count emits the intended warning. No publishable correctness, compatibility, architectural, or security defect was established.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

@eavanvalkenburg

Copy link
Copy Markdown
Member

/review

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
@ManoharPaturi

Copy link
Copy Markdown
Contributor Author

The lab failures were a lint nit on my new test, one long literal. Wrapped and pushed 2faf47a.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manohar Paturi (@ManoharPaturi) python/packages/lab/tau2/tests/test_sliding_window.py:241 calls logger.remove() without a handler id before the assertion and again in finally. Because this is the real process-global Loguru logger, the test removes every sink for the entire pytest process and leaves later tests with mutated logging state, making the suite order-dependent.

Please avoid removing global handlers. Patch agent_framework_lab_tau2._sliding_window.logger, or retain the id returned by logger.add(...) and remove only that sink in finally.

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
@ManoharPaturi

Copy link
Copy Markdown
Contributor Author

Merged via the queue into microsoft:main with commit 8fe7123 Oct 16, 2026
59 checks passed

This branch was successfully deployed

1 active deployment
github-app-auth — 1bacfe21 Deployed Oct 15, 2026 by ManoharPaturi via add_label #25434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lab Usage: [Issues, PRs], Target: lab packages python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants