mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3643] [Engine] Jev System One decision endpoint (/v1/systemone): typed decisions with calibrated probabilities #4732
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4732
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3643
Author: @justindressler
Created: 10/21/2026
Status: 🔄 Open
Base:
main← Head:jev-port-r2📝 Commits (10+)
b45edd2test(systemone): RED - /v1/systemone validation, readout math, frozen prompt (10 failing)866b8b1feat(systemone): M3.0 GREEN - POST /v1/systemone decision endpoint8506fabtest(brow): RED - StrataEngine.final_row_logits wire (BROW->BROWD, fail-closed)bd274cffeat(brow): GREEN - StrataEngine.final_row_logits (BROW->BROWD wire, fail-closed) + jev.handle wired to real contract15718e9test(brow-engine): RED - Verifier::brow_row fail-closed pre-run contract (CUDA test target)9edf521feat(brow-engine): GREEN - Verifier::brow_row (fail-closed row gather, CUDA+Metal), --jev-brow flag, serve-loop BROW handler; golden battery fixture9dff4fatest(jev-golden): battery harness - 12 items, invariants+repeat determinism; CMake CPU guard fixed (15/15)7081104fix(jev-brow): restore the usage() indent the --jev-brow insertion swallowed (review r1)b00b4fafeat(jev-calib): M3.2 calibration port - Platt+temperature, donor apply order, /admin/calib hot-swap, B1.1 log rows233aa7efix(jev-render): donor prompt fidelity - three render bugs found by the live M3.2 bench📊 Changes
26 files changed (+6491 additions, -4 deletions)
View changed files
📝
.github/workflows/terminal-minimal-server.yml(+10 -0)📝
CMakeLists.txt(+16 -0)➕
docs/JEV-SYSTEMONE.md(+237 -0)📝
include/strata/core/verify.hpp(+41 -0)➕
include/strata/program/jevpos.hpp(+62 -0)➕
serve/jev.py(+1001 -0)➕
serve/jev_calib.py(+412 -0)➕
serve/jev_golden.jsonl(+12 -0)➕
serve/jev_golden.py(+149 -0)📝
serve/server.py(+295 -1)➕
serve/test_jev_allmodes.py(+231 -0)➕
serve/test_jev_calib.py(+595 -0)➕
serve/test_jev_calib_task.py(+173 -0)➕
serve/test_jev_concurrency.py(+229 -0)➕
serve/test_jev_context.py(+404 -0)➕
serve/test_jev_golden.py(+316 -0)➕
serve/test_jev_image.py(+222 -0)➕
serve/test_jev_metamorphic.py(+176 -0)➕
serve/test_jev_then.py(+185 -0)➕
serve/test_jev_vmode.py(+197 -0)...and 6 more files
📄 Description
Problem and result
Strata can answer questions, but it cannot decide. A typed decision — "is this prompt a threat?", "which of these three actions?", "how urgent, 0 to 4?" — had no surface of its own: the caller had to generate prose and parse it, which is slow, uncalibrated and impossible to automate against.
This PR adds an opt-in decision endpoint,
POST /v1/systemone, plus the same readout folded into the chat surface. A question is answered from one decode step: the label logits are read off the final row of the last verify window over a newBROWengine wire line, and the ported jev readout math turns that row into a typed answer with a calibrated probability. Nothing is generated to produce it.Before: no typed decision surface at all. After, measured on the RTX 3090 (QFN,
Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS, engine built from this revision): a state carrying three questions of different types —noul,choice,score— answers each from its own readout, every answer carries its own calibrator id (platt_v1,T_choice_v1,T_score_v1), amargin(top1−top2, the cascade-routing number) andusage.readout_tokens: 3.It is opt-in, and the default path is untouched.
--jev-browis off by default and the engine refusesBROWwithout it (ERR BROW, fail-closed, the session stays in step).STRATA_JEV_MODESunset meanschatonly: a process that never mentions jev behaves exactly like stock Strata, and the decision surfaces answer404 not_found_errorrather than advertising themselves.Related discussion
main, re-run on 0.2.0-beta, area-tagged title, template filled in, then/reopen. This revision is that rebase and that validation; the/reopencomment follows.docs/JEV-SYSTEMONE.mdanddocs/JEV-PR.md, both in this PR.Approach
Ported from jevcpp's
src/server.cpponto Strata's serve layer, wire-compatible with the donor (request/response shapes, the422with afielderror contract, the calibration math).--jev-brow, and one line protocol on stdin/stdout.BROW <tok> <tok> ...answers the final row of the last accepted verify window, gathered to the ids asked:BROWD <n> <tok>:<logit> .... It fails closed — flag off, token out of range, or no window yet all answerERRand leave the engine in step.Verifier::brow_row()guards the null, empty-range, zombie-window andcudaMemcpy-failure paths separately, each with its own error string andreturn false; no path returns a partial or invented row./v1/systemone(text, image and decide-then-generate) and thejevextension on/v1/chat/completions, both gated bySTRATA_JEV_MODES. Calibration is post-hoc, monotone and argmax-preserving: it reshapes probabilities and can never pick a different label.The rebase onto
011c9e60replayed all 42 commits with zero conflicts. To show the feature code itself did not change in the move, the 38 added files are byte-identical to the pre-rebase head, and for the 5 modified files the set of added lines is identical (CMakeLists 5, verify.hpp 8, server.py 128, verify.cpp 32, generate.cpp 36).Validation
Revision
140f0a93, rebased onto011c9e60. Build host: WSL2, GNU 14.2.0, nvcc 13.0.88 (STRATA_ENABLE_CUDA=ON,CMAKE_CUDA_ARCHITECTURES=86,-j1). GPU: RTX 3090 (24 GiB), driver as shipped in the runtime container.Passed:
CUDA build —
cmake --build build-cuda -j1→ exit 0, binary 77,075,904 bytes, 22 warnings. Two of them are in files this PR touches and both are pre-existing lines, not added ones:verify.cppunusedf(only used in the_WIN32branch) andgenerate.cppunusedw(the batch timing line). 0 warnings introduced.ctest, 156 tests configured (
-DSTRATA_BUILD_TESTS=ON): 82 passed.verify_brow_test— the C++ half of this feature, CUDA builds only — printsverify_brow_test: OK (fail-closed pre-run contract).The same GPU tests, re-run where a driver exists (the build container cannot create a CUDA context; every one of its 71 GPU failures is the single line
CUDA driver version is insufficient for CUDA runtime version). Inside the runtime container:verify_parityPASS,verify_batch_parityPASS,dequant_s2_paritybit-exact against the scalar dequantizer,mmvq_multi_parityok,kv_q8_parityOK (worst INT8-vs-FP16 error 0.590 quantization steps),sampler_parity0 failures,s2_gemv_parityagrees with the scalar decode,qsa_topk_parity --selftestPASS.Terminal and Control suites (
pytest tests): 1,639 passed, 16 failed, 48 skipped, 234 subtests passed in 552.75 s. All 16 failures are pre-existing and none touches this PR's files: each failing file was re-run on a clean011c9e60tree, where the same tests fail (test_shared_models_folder9,test_discovery2,test_ready,test_procs,test_private_files,test_no_acquisition,test_launch_tui— the last two give identical 1-failure results on both trees).Installer tests (
tools/test_setup_*.py, run as scripts as AGENTS.md documents): 46 of 48 exit 0;test_setup_golden.py(48 failing assertions) andtest_setup_unsloth.py(4) fail identically on the clean011c9e60tree.The 71 GPU-class ctest tests, re-run where a driver exists — 70 pass. The one exception is
prefill_mmq_kquant_test, which needslibstrata_kq.sobeside the engine; that library is not produced by this CMake configuration, so the test reportsQ4_K gate/up-0: not covered by this buildand the experts take the FP16 prompt path.Decision test suite — 73 tests, all OK:
test_systemone13,test_jev_calib26,test_jev_then9,test_jev_image9,test_jev_vmode6,test_jev_golden5,test_jev_metamorphic3,test_jev_concurrency2.Serve suite —
python3 -m unittest discover -s serve -p 'test_*.py': Ran 1002 tests in 328.664s, 1 failure, 14 skipped. The single failure istest_lifeline.Lifeline.test_the_portable_watcher_ends_the_child_when_the_server_is_killed—AssertionError: False is not true : the child outlived a killed server (watcher). On CI the samesuite can also fail on
test_server_close_ends_the_sampler(AssertionError: 1 != 2) — it did onthe first run of this branch. Both are pre-existing defects in
serve/, not in this PR: the first isserve/lifeline.pybuilding a child's identity from apsstate column that changes while theprocess runs, the second a count-based assertion plus a sampler loop that dies on its first failed
sample. Both are fixed in #3590, which is not part of
011c9e60yet. With #3590 in the base thissuite is green; the 14 skips are environmental by their own reason strings.
Live decision readout on the GPU — the engine started with
--serve --jev-brow --gpu 1, one ordinary request to create a window, then the wire line:Real final-row logits for the four ids asked, from the CUDA build, on the 3090. A pre-rebase build of the same commits on the same card returned the same four values, so the rebase moved nothing in this path.
Live decision over HTTP on the GPU — the whole stack, not just the engine:
python3 -m serve.server --engine strata --config … --port 18311withSTRATA_JEV_MODES=chat,decisionand the engine started with--jev-brow --gpu 1on the RTX 3090.POST /v1/systemonewith one state and three questions of different types returned200:noulwithcalib: platt_v1and margin 0.7980,choicewithcalib: T_choice_v1and margin 0.4725,scorewithcalib: T_score_v1and margin 0.3066,usage: {prompt_tokens: 299, readout_tokens: 3}— three typed, calibrated answers and three readout tokens. The inlinejevextension on/v1/chat/completionsanswered the same way (T_choice_v1, margin 0.9861, one readout token) alongside a normal chat completion.Failed:
scorequestion written withscaleinstead ofcriteriareturned422with{"error": {"field": "questions.urgency.criteria", "message": "must be an array of 2..10 levels"}}— a field-level refusal, not a 500 and not a silently wrong answer.platform_memory_test(mlockrefused under the container'sulimit -l),ple_parity(the Q2_0 PLE fixture is not in this tree),ggml_tq_overlay(needsSTRATA_GGML_DIRpointed at the agention llama.cpp fork for the trellis types).Not run:
STRATA_HAVE_CUDA_BUILD/transport seam the rest of the file uses, but I have not compiled it for those backends and do not claim they build.docs/JEV-PR.mdwere measured before the rebase on the same model and the same code, and I am not presenting them as re-measured today.npm testinapps/host) — this checkout has nonode_modulesand no build of the web UI.drafts accepted 0 of 0), so this revision says nothing either way about draft acceptance.Limits
220:9.72173 13:6.12896 271:8.52014 198:11.5419, about 0.4 % away from the 3090's row. Both runs are internally consistent and the difference is small enough that no label flipped, but I have not established whether it is card-dependent or run-to-run, so nothing in this PR should be read as a cross-GPU reproducibility guarantee.calib/is resolved relative to the server's working directory (STRATA_JEV_CALIB_DIRoverrides it). A first run with no matching per-tuple file answerscalib: identity— correct, but easy to mistake for a bug; the answers above are calibrated becausecalib-D/L/S.jsonsit beside the server.calib/README.md); a mismatched file is refused at load rather than silently applied.brow_rowbut were not executed here.calib/,reports/anddocs/bench-artifacts/trees in this PR are the measurement artifacts behind §4 ofdocs/JEV-PR.md; they are data, not code, and are not regenerated by any build.CI on this PR — what is failing, and why it is not this branch
Written for @leonardomurillo, who built and benchmarked this branch himself and will see the same checks. Two separate things are going on.
1. The three check suites are
action_required, not failedGitHub does not run workflows for a pull request opened from a fork until a maintainer of the base repository approves them. All three suites on this PR have sat at
action_requiredsince the first push, and zero check-runs have been created — nothing has run, so nothing has failed. That state is not something the author can clear.The same workflow, dispatched inside the fork at the exact head commit, is green:
39966907103— Minimal serving runtime,justindressler/Strata6b6618ffpython -m unittest discover -s serve(1049 tests, 14 skipped)2. Two tests in the shared suite are flaky, and both fail on
mainwithout this branchtest_lifeline.Lifeline.test_the_portable_watcher_ends_the_child_when_the_server_is_killed—serve/test_lifeline.py:98The test starts a server, kills it, and asserts the watched child dies with it. On a loaded runner the child is sometimes not reaped inside the test's wait window. It failed 3 out of 3 times on the base commit
011c9e60, which predates every line of this PR, and it failed one of two runs at the same head sha where the other run passed — a flake by definition, not a regression.test_responses.NoLeakedSampler.test_server_close_ends_the_sampler—serve/test_responses.py:284It counts live threads whose name ends in
(_loop)and expects exactly one more than before the server started. On a loaded runner the sampler's loop thread is not always visible at the moment of the count. Seen once ata8b6d38b, absent at6b6618ff.Neither test imports or exercises
serve/jev.py; both are pre-existing concurrency-timing assumptions in the suite.What was actually run against this branch
python -m unittest serve.test_systemone serve.test_jev_calibpython tools/minimal_server_smoke.py{"passed": true}011c9e60🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.