fix: stop /tokens from permanently ratcheting the REPL token cap down - #145
Open
shrdgn wants to merge 1 commit into
Open
fix: stop /tokens from permanently ratcheting the REPL token cap down#145shrdgn wants to merge 1 commit into
shrdgn wants to merge 1 commit into
Conversation
The chat REPL's /tokens N command applied apply_overrides() (a narrow-only transform) against its own already-narrowed running config instead of the original loaded config, so raising the cap back up (e.g. /tokens 100 then /tokens 5000) silently stayed at the lower value for the rest of the session. /tokens and /preset now both recompute from the base config and compose with each other. Also fixes the startup banner's tools: line, which ignored web_fetch whenever web_search was on. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfTJhjkqkDfTMzufuBcLtQ
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
openfusion chat's REPL/tokens Ncommand (cli.py:364-369) appliedapply_overrides()against its own current (possibly already-narrowed) config instead of the original loaded
config.
apply_overrides'smax_tokenshandling goes through_narrow(), which isintentionally narrow-only (
min(configured, requested)) — that's correct for the HTTPper-request-override path, where a client must never widen a server-set ceiling. But reusing
it against the REPL's own running config meant that once a user typed
/tokens 100, a later/tokens 5000stayed silently capped at 100 for the rest of the session — the cap could onlyever go down, never back up:
This is a real, user-visible UX bug: answers get truncated indefinitely with no error message
explaining why, until the REPL is restarted. It went uncaught because
run_chat— the entireREPL loop including all
/-commands — had no direct test; the existing CLI tests only exercise_chat_turnand dispatch torun_chat, never the command loop itself.Separately, switching
/preset(cli.py:357-363) already rebuilt correctly frombase_config, but doing so silently discarded any active/tokensoverride — so the twocommands didn't compose correctly with each other either.
Fix:
/tokensand/presetnow both recompute the active config from the originalbase_configvia a small_rebuild(preset, tokens)closure, tracking the currently-activepreset and token override as REPL-local state. Each command re-applies both overrides on
top of the base config, so either command can be issued in either order, any number of times,
without the other's effect being lost or becoming a ratchet.
Also fixed a related, smaller correctness bug found in the same area: the startup summary's
tools:line (_summarize_config,cli.py:43) reportedweb search+fetchwheneverweb_searchwas enabled, regardless ofweb_fetch's actual (independently configurable)value — and never reported a
web_fetch-only configuration (web_search: false, web_fetch: true)at all, always showing
offfor it instead.Found via an automated repo-review scheduled task; verified by hand by reading
cli.py'sREPL command handlers and
overrides.py::_narrow, and reproducing the ratchet with a scriptedREPL session before fixing it.
How it was tested
ruff check .passespytest -qpasses (494 passed, no live network)tests/test_cli.py::test_tokens_command_can_raise_the_limit_back_upand
test_preset_switch_preserves_an_active_tokens_overridedrive the actualrun_chatREPLloop (monkeypatching
rich.console.Console.inputandcli._chat_turn) and assert theeffective
panel_max_tokensseen by each simulated turn. Also addedtest_summarize_config_reports_fetch_only_when_search_is_offandtest_summarize_config_reports_search_only_when_fetch_is_offfor the banner fix.session-local behavior
Notes for reviewers
Only
run_chat's REPL command handlers and_summarize_config's tools label are touched.apply_overrides/_narrowthemselves are unchanged — they're correct as-is for the HTTPper-request-override path this bug isn't part of; the fix is entirely in how the CLI's REPL
loop composes its own local state before calling into them.
Generated by Claude Code