fix(cli): clamp post-compression token sentinel in status bar (#35858)

The status bar read context_compressor.last_prompt_tokens directly with
an 'or 0' guard that only catches 0/None. Right after a compression the
compressor parks last_prompt_tokens at the -1 sentinel
(awaiting_real_usage_after_compression) until the next API call reports
real usage. -1 is truthy, so it sailed through and rendered as '-1/200K'
and '-1%' for that one transitional turn.

Clamp negative token/context-length values to 0 in the status-bar
snapshot so the gap reads as empty context until real usage arrives.
This commit is contained in:
Teknium 2026-05-31 06:03:01 -07:00 committed by GitHub
parent 1fc7bdc5e6
commit f2d4cf4f76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View file

@ -81,6 +81,29 @@ class TestCLIStatusBar:
assert "$0.06" not in text # cost hidden by default
assert "15m" in text
def test_post_compression_sentinel_does_not_render_negative(self):
"""Right after a compression, last_prompt_tokens is parked at the -1
sentinel until the next API call reports real usage. The status bar
must clamp it to 0 instead of rendering "-1/200K" / "-1%".
"""
cli_obj = _attach_agent(
_make_cli(),
prompt_tokens=10_230,
completion_tokens=2_220,
total_tokens=12_450,
api_calls=7,
context_tokens=-1,
context_length=200_000,
)
snapshot = cli_obj._get_status_bar_snapshot()
assert snapshot["context_tokens"] == 0
assert snapshot["context_percent"] == 0
text = cli_obj._build_status_bar_text(width=120)
assert "-1" not in text
assert "0/200K" in text
def test_input_height_counts_wide_characters_using_cell_width(self):
cli_obj = _make_cli()