fix(commandcode): char-safe model canonicalize, MiniMax pricing, per-turn input - #750
Merged
Conversation
…turn input Three confirmed bugs in the Command Code session parser (PR #717): (a) PANIC: canonicalize_model byte-sliced `base[base.len()-N..]` guarded only by a length check. A non-ASCII model id from the untrusted ~/.commandcode/config.json could place that byte index mid-codepoint and panic. Switch to a boundary-safe `str::get(..)` slice that returns None (instead of panicking) when the tail is not on a char boundary, preserving the case-insensitive `-free` strip. (b) PRICING: dropping the org prefix turned `MiniMaxAI/MiniMax-M3-Free` into bare `MiniMax-M3`, but the client's own `command-code` provider is not a pricing provider, so the resolver never reached a `minimax/...` key and pricing was lost. Recover the real provider from the gateway id via `provider_identity::inferred_provider_from_model` and use it as the message provider_id (matching the claudecode convention), falling back to `command-code` when nothing is inferred. (c) O(N^2) INPUT: per-assistant-turn input was estimated from `context_chars`, a running cumulative sum of ALL prior messages, inflating input across the session versus other clients. Estimate per-turn input from only the new context introduced since the previous response (user prompt + tool results). Summed over the session this charges each message's content once. Regression tests added: non-ASCII / emoji model ids do not panic; a MiniMax model resolves non-zero pricing; per-turn input does not accumulate. Updated the module doc-comment and renamed the pinning test to match the new model. Confidence: high Scope-risk: moderate Directive: provider_id for MiniMax sessions is now `minimax`, not `command-code`; this is intentional so pricing resolves. Do not revert without restoring a pricing path for the gateway provider. Not-tested: real-world non-MiniMax gateway ids that infer no provider (fall back to `command-code`, unchanged behavior)
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
makoMakoGo
added a commit
to makoMakoGo/tokscale
that referenced
this pull request
Jun 23, 2026
ported from upstream junhoyeo#735 ported from upstream junhoyeo#737 ported from upstream junhoyeo#747 ported from upstream junhoyeo#750 ported from upstream junhoyeo#752 ported from upstream junhoyeo#760 ported from upstream junhoyeo#766
t1000040
pushed a commit
to tmobi-internal/tokscale
that referenced
this pull request
Jun 30, 2026
…turn input (junhoyeo#750) Three confirmed bugs in the Command Code session parser (PR junhoyeo#717): (a) PANIC: canonicalize_model byte-sliced `base[base.len()-N..]` guarded only by a length check. A non-ASCII model id from the untrusted ~/.commandcode/config.json could place that byte index mid-codepoint and panic. Switch to a boundary-safe `str::get(..)` slice that returns None (instead of panicking) when the tail is not on a char boundary, preserving the case-insensitive `-free` strip. (b) PRICING: dropping the org prefix turned `MiniMaxAI/MiniMax-M3-Free` into bare `MiniMax-M3`, but the client's own `command-code` provider is not a pricing provider, so the resolver never reached a `minimax/...` key and pricing was lost. Recover the real provider from the gateway id via `provider_identity::inferred_provider_from_model` and use it as the message provider_id (matching the claudecode convention), falling back to `command-code` when nothing is inferred. (c) O(N^2) INPUT: per-assistant-turn input was estimated from `context_chars`, a running cumulative sum of ALL prior messages, inflating input across the session versus other clients. Estimate per-turn input from only the new context introduced since the previous response (user prompt + tool results). Summed over the session this charges each message's content once. Regression tests added: non-ASCII / emoji model ids do not panic; a MiniMax model resolves non-zero pricing; per-turn input does not accumulate. Updated the module doc-comment and renamed the pinning test to match the new model. Confidence: high Scope-risk: moderate Directive: provider_id for MiniMax sessions is now `minimax`, not `command-code`; this is intentional so pricing resolves. Do not revert without restoring a pricing path for the gateway provider. Not-tested: real-world non-MiniMax gateway ids that infer no provider (fall back to `command-code`, unchanged behavior)
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.
Problem
Three confirmed bugs in
crates/tokscale-core/src/sessions/commandcode.rs(PR #717):canonicalize_modelbyte-slicedbase[base.len() - PROMO_SUFFIX.len()..]guarded only by a length check, not a char boundary. A non-ASCII model id from the untrusted~/.commandcode/config.jsoncould place that byte index mid-codepoint and panic the parse.MiniMaxAI/MiniMax-M3-Freeinto bareMiniMax-M3, but the client's owncommand-codeprovider is not a pricing provider, so the resolver never reached theminimax/...pricing key and cost resolved to 0.context_chars, a cumulative running sum of all prior messages that grows across the session, inflating reported input versus other clients.Fix
-freestrip viastr::get(..), which returnsNone(instead of panicking) when the tail is not on a char boundary.provider_identity::inferred_provider_from_model(e.g.minimax) and use it as the messageprovider_id, matching the claudecode convention. Falls back tocommand-codewhen no provider is inferred.Tests
test_canonicalize_model_does_not_panic_on_non_ascii— non-ASCII/emoji model ids do not panic (fails before fix a).test_minimax_model_resolves_nonzero_pricing— a MiniMax session resolves non-zero pricing against aminimax/...key (fails before fix b).test_input_is_per_turn_delta_not_cumulative+ rewritten pinning testtest_commandcode_input_is_per_turn_delta— per-turn input does not accumulate (fails before fix c).cargo test -p tokscale-core(985 lib + integration tests) andcargo clippy -p tokscale-core --testsboth pass clean.Residual concern
provider_idfor MiniMax sessions is nowminimaxrather thancommand-code(intentional, so pricing resolves and matches how claudecode attributes multi-provider models). Gateway ids that infer no known provider keep the priorcommand-codeprovider unchanged.🤖 Generated with Claude Code
Summary by cubic
Fixes three issues in the Command Code session parser: safe model canonicalization to prevent panics, correct MiniMax pricing via provider inference, and per-turn input accounting to stop inflated usage. Improves stability, pricing accuracy, and consistent usage metrics.
-freewith char-boundary checks; non-ASCII ids no longer panic.MiniMaxAI/MiniMax-M3-Free-> providerminimax, modelMiniMax-M3), falling back tocommand-code, so pricing hitsminimax/....Written for commit 2bdbd61. Summary will update on new commits.