Repository navigation
Conversation
tawei-amd
marked this pull request as ready for review
October 19, 2026 13:47
tawei-amd
commented
Oct 19, 2026
Collaborator
Author
There was a problem hiding this comment.
Self-review (author). One finding, an availability problem: large JSON objects parse in quadratic time. Happy to fix it here or in a follow-up, whichever reviewers prefer.
🤖 Generated with Claude Code
A byte-exact C++ port of the d3 (Decision 3.0) System One contract from the upstream package vllm-sr/d3-lite v3.1.3 (d3_format.py, d3_runtime.py, d3_server.py): request checks and their 422 texts, question validation, the prompt the model reads, the answer codes, the 255-way readout and the answer objects (choice / noul / score, confidence, legend, usage). The prompt shows non-string values as Python's json.dumps text, so src/common/decision/py_json.* keeps exactly what json.loads builds (integers of any size, duplicate-key order) and reproduces json.dumps / repr (float repr switch points, ', ' separators) and Python 3.12's compensated sum(). src/test/d3_contract replays fixtures rendered by the upstream package itself (308 golden requests + 1,000 fixed-seed fuzz bodies): prompts byte-identical, errors identical, every answer number bit-identical; with the tokenizer, every token id and the 255 answer codes too. CPU only; runs in ubuntu-build. Co-Authored-By: Claude <[email protected]>
d3_server hands the raw body to json.loads, which detects the encoding first: a UTF-8 BOM is accepted, UTF-16/32 bodies are decoded, and invalid UTF-8 is reported as CPython's UnicodeDecodeError text with its byte positions. Found by the HTTP parity rig (a BOM body: 200 upstream, 422 here). The contract test checks 12 byte-level cases against CPython 3.12's messages. Co-Authored-By: Claude <[email protected]>
Object members were added with PyValue::set(), which scans the members already read, so an object with n keys cost n^2/2 string compares: 200,000 keys (a 2.7 MB body) took 24.6 s, while the System One route holds the NPU queue. Keys are now indexed while an object is read; a repeated key still keeps its first position and takes the last value, like Python's dict. 200,000 keys: 108 ms. The contract test still passes (1,308 requests incl. 598 fuzz bodies with duplicate keys, 5,519 checks, 0 failures). Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
tawei-amd
force-pushed
the
feat/d3-contract
branch
from
October 22, 2026 21:32
f936ce6 to
8dd2bc6
Compare
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.
Summary
A byte-exact C++ port of the d3 (Decision 3.0) System One contract, the request/prompt/answer rules of vLLM Semantic Router's decision models, from the upstream package
vllm-sr/d3-liteatv3.1.3(d3_format.py,d3_runtime.py,d3_server.py). No NPU code; this is the part of d3 support that has to match upstream to the byte and is testable on any CI runner. The model/serving side is the stacked PR #816.src/{include,common}/decision/d3_contract.*: request checks and their 422 texts,normalize_question, the prompt (user_prompt, chat text), the 255 answer codes, the fp32 readout,product_answer(choice / noul / score, confidence, legend) andrespond.src/{include,common}/decision/py_json.*: the prompt shows non-string values as Python'sjson.dumpstext, and nlohmann can't reproduce that. This keeps exactly whatjson.loadsbuilds (integers of any size, duplicate keys at their first position with the last value) and writesjson.dumps/repr(float repr switch points such as1e-05and1e+16,", "separators), plus Python 3.12's compensatedsum()for the answer numbers.src/test/d3_contract: replays fixtures rendered by the upstream package itself: 308 golden requests and 1,000 fixed-seed fuzz bodies (every JSON type, big ints, unicode/control/special-token text, falsy values, malformed JSON, unknown fields, invalid questions). It requires byte-identical prompts, identical errors and bit-identical answer numbers; with-DFLM_D3_TEST_TOKENIZER=ONit also checks every token id and the 255 answer codes.gen_fixtures.pyregenerates the fixtures from the package.ubuntu-build.yml: newd3-contractjob (CPU, ctest).Test results
test_d3_contract(with tokenizer, locally): 1,308 requests, 1,642 prompts byte-identical, 1,642 token-id sequences identical, 2,617 answers bit-identical, 82 request-level refusals and 6 malformed bodies identical; 0 failures.🤖 Generated with Claude Code