Skip to content

fix: accept 0 as a valid token_count in ContextManager.add_message - #356

Open
andrewwhitecdw wants to merge 1 commit into
huggingface:mainfrom
andrewwhitecdw:andrewwhitecdw/fix/context-manager-token-count-optional
Open

fix: accept 0 as a valid token_count in ContextManager.add_message#356
andrewwhitecdw wants to merge 1 commit into
huggingface:mainfrom
andrewwhitecdw:andrewwhitecdw/fix/context-manager-token-count-optional

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

Bug

ContextManager.add_message annotated token_count as int but defaulted to None, and the guard if token_count: treated 0 as unset. This prevented callers from explicitly setting the running context usage to zero.

Fix

Annotate token_count as int | None and check if token_count is not None: so 0 is honored.

Test

Added tests/unit/test_context_manager.py with a regression test that sets token_count=0 and asserts running_context_usage becomes 0.

Verification

uv run --extra dev pytest tests/unit/test_context_manager.py -v passes.

add_message annotated token_count as int but defaulted to None, and the
 guard  treated 0 as unset. This meant callers could not
 explicitly set the running context usage to 0.

Annotate token_count as int | None and check  so 0 is
honored.

Signed-off-by: Andrew White <andrewh@cdw.com>
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