Repository navigation
Refuse inexact Helicone quotas and cost ceilings in both clients - #11
charlespers merged 2 commits into
Conversation
The house rules say the two clients are twins and money is exact, and the TypeScript side broke both. ceilingFromPolicy read the quota with parseInt, so "1.5;w=60;u=cents" became a 1 cent ceiling and "10abc" or "1e3" were accepted where Python raised. costCeiling passed any integer number through String(), so 1e21 went out as "1e+21" and 2 ** 60 + 1 as a rounded amount. The quota must now be plain digits in both languages, a negative ceiling is refused in both, and TypeScript refuses a ceiling it cannot hold exactly.
|
This comment has been minimized.
This comment has been minimized.
|
VERIFIER: APPROVE 2ad64d8 Independent verification of the whole PR ( Covering tests at head
Executed table repro, base -> head (
|
| quota | TS base | TS head | Py base | Py head |
|---|---|---|---|---|
1e3 |
1 cent (1e7) | PortErr | PortErr | PortErr |
0.1 |
0 ceiling | PortErr | PortErr | PortErr |
10.005 |
10 cents | PortErr | PortErr | PortErr |
1_000 |
1 cent | PortErr | 1000 cents | PortErr |
5 |
5 cents | 5 cents | 5 cents | 5 cents |
-1 |
-1e7 | PortErr | -1e7 | PortErr |
| `` (empty) | PortErr | PortErr | PortErr | PortErr |
9007199254740993 |
9.007e+22 (inexact) | PortErr | exact int | exact int (documented gap) |
99999999999999999999 |
1e+27 | PortErr | exact int | exact int (documented gap) |
900719925 (last safe) |
9007199250000000 | same | same | same |
900719926 |
9007199260000000 (unsafe) | PortErr | exact | exact (documented gap) |
1000, 0, 00010 |
1e10, 0, 1e8 | same | same | same |
١٢٣ (Arabic-Indic) |
PortErr | PortErr | 123 cents | PortErr |
5 (fullwidth) |
PortErr | PortErr | 5 cents | PortErr |
0x10 |
0 ceiling | PortErr | PortErr | PortErr |
10abc |
10 cents | PortErr | PortErr | PortErr |
+10 |
10 cents | PortErr | 10 cents | PortErr |
\x1c5 |
PortErr | PortErr | 5 cents | 5 cents |
5 |
5 cents | 5 cents | PortErr | PortErr |
"1"*5000 |
n/a | n/a | PortErr on 3.11 | PortErr on 3.11 |
costCeiling / cost_ceiling, base -> head:
- TS:
-1went out as-1and now raises PortErr.1e21went out as the header"1e+21"and now raises PortErr.2**53and2**60(rounded) were sent and now raise PortErr.2**53-1is still sent exactly.0and-0both still send"0".1.5,NaNandInfinityraise PortErr at both base and head. - Python:
-1was sent and now raises PortErr.10**21and2**60are still sent exactly, because Python ints are exact.Trueand1.5raise PortErr at both.
Money result: at head, no input in either client produces a ceiling above the value the user wrote. Every refusal I observed is ConiferPortabilityError, and no refusal escapes as a bare ValueError or TypeError. Every previously accepted plain-ASCII-digit quota, and every non-negative safe ceiling, is still accepted with the same value.
TS and Python agree on every row except three kinds. The CHANGELOG documents the first (quotas past MAX_SAFE_INTEGER / 1e7) but not the other two (F2).
Mutation checks on the new lines (covering tests; killed = suite fails)
- Killed: TS unanchored regex; TS
isFinitein place of the safe-integer check;parseIntrestored; TS negative check dropped; TS< 0changed to< -1; TS safe-integer check incostCeilingdropped; Pythonfullmatchchanged tomatch; Python regex gate dropped; Python negative check dropped; Pythonexcept ValueErrorchanged toexcept IndexError(killed on 3.11, survives on 3.9 only because that test is skipped there). - Survived:
- TS
isSafeInteger(quota * 10_000_000)changed toisSafeInteger(quota). No test uses a quota between 900719926 and 2^53. End to end this is still safe, becausecostCeilingrefuses the unsafe amount at send time. F3. - Python
[0-9]+changed to\d+. No test covers Unicode digits. F3.
- TS
Findings
- F1 (P3, docs): the CHANGELOG says "A quota too long for Python's
int()digit limit is now refused as a portability error rather than a bareValueError." Base already caught it:except (ValueError, IndexError)atportability.py:312. The 5000-digit repro raises PortErr at base on 3.11, and the new test passes at base. The claim is not a regression, but it describes a fix this PR does not make. - F2 (P3, parity/docs): the claim that "both accept the same quota syntax" is not quite true.
- Python
str.strip()and JStrim()strip different characters:\x1c5is accepted by Python and refused by TS, and5is the reverse. The value is exact in both, so no money impact. - Python now also refuses Unicode-digit quotas (
١٢٣,5) that base accepted exactly. That is an intended tightening for parity, but the CHANGELOG does not mention it.
- Python
- F3 (P3, tests): the two surviving mutants above. Adding the quota
900719926to the TS table and١٢٣to the Python table would kill them. - F4 (P3, comment):
tests/portability.test.tssays"1.5" became 10 cents. The base repro gives 1 cent (1e7 nanodollars), which matches the CHANGELOG.
There are no P0, P1 or P2 findings, and nothing about money, security or data loss blocks. The P3s are follow-ups under the merge bar.
What this changes
ceilingFromPolicyrefuses a Helicone quota that is not plain digits, as Python already did. Python now also refuses a signed or underscored quota (-10,+10,1_0), so both accept the same quota syntax. One gap stays: TypeScript also refuses a quota whose ceiling passesNumber.MAX_SAFE_INTEGER(about 900,000,000 cents), which Python accepts; the changelog says so. Python also turns a quota longer than itsint()digit limit into a portability error instead of a bareValueError.costCeilingandcost_ceilingrefuse a negative ceiling instead of sending it.costCeilingrefuses a value aboveNumber.MAX_SAFE_INTEGERwith the sameConiferPortabilityErrorit already throws for fractions.Why
Two TypeScript helpers broke the twins rule and the money is exact rule.
ceilingFromPolicyread the quota withNumber.parseInt, which stops at the first non-digit:Python's
ceiling_from_policyraises on all three, but accepts-10,+10and1_0becauseint()does.costCeilingonly checkedNumber.isInteger:Expected: a quota is accepted only when it is plain digits in both languages, a negative ceiling is refused in both, and TypeScript refuses a ceiling it cannot hold exactly rather than sending a rounded or exponent form value.
One asymmetry is left on purpose: Python still sends a ceiling above 2^53 exactly, while TypeScript now refuses it. Closing that would mean accepting
bigintinmaxCostNanoUsd, a type change toChatRequestandEmbeddingsRequest, so I left it for you to decide.How it was verified
npm testandnpm run typecheckpass (223 pass, 0 fail; typecheck clean)python3 -m unittest discover -s tests -t testsfrompython/, 138 tests OK (pytest is not installed on this machine, so I used the stdlib runner CONTRIBUTING mentions)tests/portability.test.tsandtests/client.test.ts, and inpython/tests/test_sdk.py. With the source change stashed, 2 TypeScript and 2 Python tests fail.## [Unreleased]inCHANGELOG.md(node scripts/check-changelog.mjsok)Covering tests at 2ad64d8 (merge sweep 2026-09-27)
node --experimental-strip-types --test tests/client.test.ts tests/portability.test.ts: 111 pass, 0 failcd python && python3 -m unittest tests.test_sdk: 138 tests OK (1 skipped)Follow-ups (verifier P3s, non-blocking)
\x1c5versus a BOM prefix), and Python now refuses Unicode-digit quotas that it used to accept. The CHANGELOG mentions neither.900719926and Python١٢٣.