Repository navigation
System One: TypeSafe confidence formulas, strict schema 422s, bounded token counting - #1143
Merged
Merged
Conversation
Validating an external review of /v1/systemone: - `confidence` now follows TypeSafe's definitions: choice `(p_max - 1/n) / (1 - 1/n)`, score `1 - sum(p_i |i - m|) / MAD_unif` with m the most likely level. Entropy peakedness, inherited from the Privatemode reference, read 0.53 where the spec says 0.80 on a 90/10 choice. SDK doc comments updated (no SDK behaviour change). - The handler parses the raw body itself with deny_unknown_fields at every level, so `files` instead of `images` is a 422 naming the field (system_one_unknown_field) instead of a billed answer about nothing; missing fields, unknown question types and type mismatches are 422s with their own codes. Only serde's key-name details are forwarded, never values. Malformed JSON stays 400. - tokens::count_tokens splits whitespace-free runs over 1 KiB: BPE merging is quadratic per run, so a 200k-character word took 16 s (release build) on a worker thread; ordinary text counts are unchanged. System One also rejects a state over 1 MiB or a question block over 512 KiB before counting. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Why
A review of
POST /v1/systemoneby an external agent (relayed by Anthony) made three claims. Validated against docs.typesafe.ai and the local stack (notes:~/workspaces/_notes/systemone-claims-2026-10-11/FINDINGS.md):confidencedid not follow the TypeSafe spec. True. We returned entropy peakedness1 - H/ln n(from the Privatemode reference) for choice and score. The spec defines choice(p_max - 1/n) / (1 - 1/n)and scoremax(0, 1 - Σ p_i|i - m| / MAD_unif)withmthe most likely level. The gap is largest where thresholds live: a 90/10 choice was 0.53, the spec says 0.80.filesinstead ofimagesreturned a confident answer about nothing and billed it;criterionin a question oryesin noul criteria were dropped the same way; a misspelled required field, an unknowntype, a missingquestionsor malformed JSON all came back as a bare 400 with no code and no field (the middleware's parse failure). The spec says validation failures are 422.While checking the state limit:
tokens::count_tokens(tiktoken cl100k BPE) is quadratic per whitespace-free run and runs synchronously in the handler. Release build, one word of repeatedx: 40k chars 0.6 s, 100k 3.8 s, 200k 16 s (25,000 tokens, so not rejected as too large). The body cap is 50 MB. Reachable by any authenticated caller, nothing billed. The helper serves ~30 call sites on client text, so chat and Responses share the exposure.Changes
choice_confidenceandscore_confidencereplaceconfidence; SDK doc comments updated (comments only, no SDK behaviour change).deny_unknown_fieldsat every level. New codes:system_one_unknown_field("Unknown fieldfiles, expected one ofmodel,state,questions,images,temperature."),system_one_missing_field,system_one_unknown_question_type,system_one_malformed_body. Only serde's unknown/missing-field details are forwarded (they contain the caller's own key names, cut at 200 chars); type mismatches get a fixed message because serde's text would echo values. Malformed JSON stays 400. Compatible with TypeSafe clients: their schema has no fields beyondstate/model/questionsandtype/instructions/criteria; our SDKs send only known fields.count_tokenssplits whitespace-free runs longer than 1 KiB (200k chars: 16 s → under 0.1 s; ordinary text counts are unchanged). System One rejects a state over 1 MiB or a question block over 512 KiB with 413 before counting.Verification
cargo test --bin opensecret -- system_one tokensin the service's nix shell: 48 passed (new:confidence_follows_the_typesafe_formulas,shape_errors_name_the_field_and_never_echo_values,byte_caps_reject_before_counting_tokens,long_runs_are_counted_in_bounded_pieces).cargo clippy --tests -- -D warningsclean; the full unit suite: 791 passed, 0 failed, 31 ignored./v1/systemone:filesinstead ofimagessystem_one_unknown_field: "Unknown fieldfiles, expected one ofmodel,state,questions,images,temperature."yes/nosystem_one_unknown_field: "Unknown fieldyes, expectedtrueorfalse."instructiontyposystem_one_unknown_fieldnaminginstruction"type": "boolean"system_one_unknown_question_typequestionssystem_one_missing_fieldcriteria: "SECRET"on a choicesystem_one_malformed_body, value not echoedconfidenceequals the spec formula computed from the returned probabilities (0.9519 vs 0.9520, 0.1312 vs 0.1312)tiktoken-rs0.5 cl100k): 40k-char word 0.60 s, 100k 3.8 s, 200k 16.1 s unsplit; 200k in 1 KiB pieces 90 ms; ordinary prose count differs by 0 (pieces are cut only inside long runs).TYPESAFE_BASE_URL/TYPESAFE_DEFAULT_MODEL, the Python one ignores unknown response fields (pydanticextra: ignore), the JS one castsJSON.parseoutput.Rollout
Backend only; no SDK or proxy code change. Land before the production deploy of #1045 so the public
confidencenumbers never change under anyone. Docs: maple-marketing #99 updated in the same pass, held until the deploy.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.