fix(cli): keep TOML digit separators in --codex-config values - #34
Open
bluzername wants to merge 1 commit into
Open
bluzername wants to merge 1 commit into
bluzername wants to merge 1 commit into
Conversation
TOML let a number use `_` between digits, like
`model_max_output_tokens=100_000`, so it is nicer to read than
`100000`. But coerce() in backends.ts just call Number() on the raw
text, and Number("100_000") is NaN in JS - it not understand that
syntax at all. So the value fall through to the string branch and
Codex get the literal text "100_000" where its config want a number.
This is exactly the same class of bug the function already exist for
(a string reaching Codex where a scalar was expect), just a different
syntax that trip it up.
Fix strip an underscore only when it sit between two digits before
calling Number() on it, using a regex lookaround. A wrongly placed
underscore (leading, trailing, or doubled, like "_100", "100_",
"1__000") is left alone and still fail the numeric check same as
before, so it keep falling back to a string like real TOML would treat
it as invalid too.
Test: added cases in backends.test.ts for an integer, a float, a
negative number, all with separators, plus the three invalid-placement
cases that must stay strings. Ran the new tests against the old
coerce() first to confirm they fail (they did, 3 failing), then again
with the fix to confirm all pass. Full suite: pnpm typecheck and pnpm
turbo run test --filter=@airshiplabs/cli both green, 182 tests passed
(176 before, +6 new).
This branch has not been deployed
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.
The bug
TOML let a number use
_between digits as a separator, somodel_max_output_tokens=100_000is valid TOML and much nicer to readthan
100000.coerce()inapps/cli/src/lib/backends.tsdecide if a--codex-config k=vvalue is a bool, a number or a string by tryingNumber(raw)on the text, butNumber("100_000")isNaNinJavaScript, it does not know this TOML syntax at all. So the value
fall through to the string branch, and Codex would get the literal
text
"100_000"in its config where it expect the integer100000.It is the exact same class of bug the docstring on
coerce()alreadycall out (a JS string reaching Codex where a scalar was wanted), just
a different input shape that was not covered.
The fix
Strip an underscore only when it sit between two digits, with a small
regex lookaround, before calling
Number(). A wrongly placed one(leading
_100, trailing100_, doubled1__000) is left alone, soit still fail the numeric check and fall back to a string, same as
real TOML would also treat it as invalid.
Test plan
apps/cli/src/lib/backends.test.ts: an integer withseparators, a float with separators, a negative number, and the
three invalid-placement cases that must stay strings.
coerce(), 3 of them failed exactly as expected.pnpm --filter @airshiplabs/cli exec vitest run src/lib/backends.test.ts-> all 22 tests in that filepass.
pnpm typecheckandpnpm turbo run test --filter=@airshiplabs/cliboth green, 182 tests passed (176 beforethis change, +6 new).
Not a collaborator, opening this for review whenever you get to it.