From 7b1922d11669243bab08a243c19f50de3f70dab5 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Thu, 5 Nov 2026 13:32:25 +0100 Subject: [PATCH] gateway-text: prompt, response_tools and tool_output become one crate; desktop-core no longer compiles them twice (STRA-338 S8) control-plane/src/{prompt,response_tools,tool_output}.rs (pure text logic: pinned chat template renderer, tool catalog, tool-call parser) move by git mv to the new leaf crate crates/gateway-text. strata-control re-exports them under the same module paths (crate::prompt, crate::tool_output keep working for tests and callers); strata-desktop-core replaces its three #[path] includes with imports. The leleka-runtime GPU proof modules that hash prompt.rs follow the new location. The only text change in the moved files is the relative include_str path to engine/strata. serde_json features (preserve_order + float_roundtrip) equal what both hosts already got through unification. Verified: cargo test strata-control + strata-desktop-core + gateway-text on the host: 504 tests, 0 failed; the 30 tests that vanish are exactly the duplicate runtime_prompt/runtime_tool_catalog/runtime_tool_parser copies of the same 30 tests (11+2+17), which now run once. WSL x86_64-linux cargo check --tests leleka-runtime: 62 warnings, unchanged. fmt clean on the new crate. --- Cargo.lock | 16 ++++++++++++++ Cargo.toml | 4 ++-- architecture-baseline.json | 12 +++++----- architecture.json | 2 +- control-plane/Cargo.toml | 1 + control-plane/src/lib.rs | 6 ++--- crates/gateway-text/Cargo.toml | 22 +++++++++++++++++++ crates/gateway-text/src/lib.rs | 8 +++++++ .../gateway-text}/src/prompt.rs | 7 ++++-- .../gateway-text}/src/response_tools.rs | 0 .../gateway-text}/src/tool_output.rs | 0 .../src/gpu_proofs/fivecase_frames.rs | 2 +- .../src/gpu_proofs/fivecase_runtime.rs | 2 +- .../long_public_request.rs | 4 ++-- .../native_down_adaptive_candidate_only.rs | 4 ++-- .../gpu_proofs/native_down_candidate_only.rs | 18 +++++++-------- .../src/gpu_proofs/native_down_public_pair.rs | 4 ++-- desktop-core/Cargo.toml | 1 + desktop-core/src/lib.rs | 16 +++++--------- docs/api-contract.md | 2 +- docs/offline-port.md | 2 +- docs/port-status.md | 2 +- docs/tool-call-corpus.md | 2 +- scripts/check-local.sh | 2 +- scripts/ci-coverage.json | 1 + 25 files changed, 94 insertions(+), 46 deletions(-) create mode 100644 crates/gateway-text/Cargo.toml create mode 100644 crates/gateway-text/src/lib.rs rename {control-plane => crates/gateway-text}/src/prompt.rs (99%) rename {control-plane => crates/gateway-text}/src/response_tools.rs (100%) rename {control-plane => crates/gateway-text}/src/tool_output.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index c0d79f77..bd8bf941 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1319,6 +1319,20 @@ dependencies = [ "serde_json", ] +[[package]] +name = "leleka-gateway-text" +version = "0.1.0" +dependencies = [ + "hex", + "minijinja", + "minijinja-contrib", + "regex", + "regex-syntax", + "serde", + "serde_json", + "sha2", +] + [[package]] name = "leleka-gguf" version = "0.1.0" @@ -2774,6 +2788,7 @@ dependencies = [ "http-body-util", "jsonschema", "leleka-backend-api", + "leleka-gateway-text", "leleka-gguf", "leleka-harmony", "leleka-kar-codec", @@ -2812,6 +2827,7 @@ dependencies = [ "hex", "jsonschema", "leleka-backend-api", + "leleka-gateway-text", "leleka-obs", "leleka-runtime", "leleka-runtime-client", diff --git a/Cargo.toml b/Cargo.toml index df5c157c..25a76efd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] resolver = "3" -members = ["crates/backend-api", "crates/cpu-kernels", "crates/cpu-sys", "crates/cpu-worker", "crates/gguf", "crates/gptoss", "crates/gptoss-igpu", "crates/harmony", "crates/igpu", "crates/kar-codec", "crates/igpu-worker", "crates/shm", "crates/openvino", "crates/npu-service", "crates/gptoss-npu", "crates/npu-worker", "crates/gpu-npu-worker", "crates/tokenizer", "control-plane", "desktop-core", "crates/libc-shim", "crates/runtime-client", "crates/model-format", "crates/offline-tools", "crates/quant-core", "crates/context", "crates/cuda-driver", "crates/leleka-runtime", "crates/leleka-memory", "crates/deploy", "crates/obs", "crates/native-cpu-expert", "crates/native-parity-bench", "crates/sampler-ref", "crates/experimental-ref", "crates/serving-policy"] -default-members = ["crates/backend-api", "crates/cpu-kernels", "crates/cpu-sys", "crates/cpu-worker", "crates/gguf", "crates/gptoss", "crates/gptoss-igpu", "crates/harmony", "crates/igpu", "crates/kar-codec", "crates/igpu-worker", "crates/shm", "crates/openvino", "crates/npu-service", "crates/gptoss-npu", "crates/npu-worker", "crates/gpu-npu-worker", "crates/tokenizer", "control-plane", "desktop-core", "crates/runtime-client", "crates/model-format", "crates/offline-tools", "crates/quant-core", "crates/context", "crates/leleka-memory", "crates/sampler-ref", "crates/experimental-ref", "crates/serving-policy", "crates/deploy", "crates/obs"] +members = ["crates/backend-api", "crates/cpu-kernels", "crates/cpu-sys", "crates/cpu-worker", "crates/gguf", "crates/gptoss", "crates/gptoss-igpu", "crates/harmony", "crates/igpu", "crates/kar-codec", "crates/igpu-worker", "crates/shm", "crates/openvino", "crates/npu-service", "crates/gptoss-npu", "crates/npu-worker", "crates/gpu-npu-worker", "crates/tokenizer", "crates/gateway-text", "control-plane", "desktop-core", "crates/libc-shim", "crates/runtime-client", "crates/model-format", "crates/offline-tools", "crates/quant-core", "crates/context", "crates/cuda-driver", "crates/leleka-runtime", "crates/leleka-memory", "crates/deploy", "crates/obs", "crates/native-cpu-expert", "crates/native-parity-bench", "crates/sampler-ref", "crates/experimental-ref", "crates/serving-policy"] +default-members = ["crates/backend-api", "crates/cpu-kernels", "crates/cpu-sys", "crates/cpu-worker", "crates/gguf", "crates/gptoss", "crates/gptoss-igpu", "crates/harmony", "crates/igpu", "crates/kar-codec", "crates/igpu-worker", "crates/shm", "crates/openvino", "crates/npu-service", "crates/gptoss-npu", "crates/npu-worker", "crates/gpu-npu-worker", "crates/tokenizer", "crates/gateway-text", "control-plane", "desktop-core", "crates/runtime-client", "crates/model-format", "crates/offline-tools", "crates/quant-core", "crates/context", "crates/leleka-memory", "crates/sampler-ref", "crates/experimental-ref", "crates/serving-policy", "crates/deploy", "crates/obs"] [workspace.package] edition = "2024" diff --git a/architecture-baseline.json b/architecture-baseline.json index b09ea0d7..38052599 100644 --- a/architecture-baseline.json +++ b/architecture-baseline.json @@ -26,7 +26,6 @@ "control-plane/src/native_pack.rs": 1390, "control-plane/src/prepare_preview.rs": 2214, "control-plane/src/prometheus.rs": 746, - "control-plane/src/prompt.rs": 1370, "control-plane/src/reasoning_budget.rs": 617, "control-plane/src/request_log.rs": 1031, "control-plane/src/request_monitor.rs": 723, @@ -35,7 +34,6 @@ "control-plane/src/server_api.rs": 692, "control-plane/src/service_install.rs": 935, "control-plane/src/service_switch.rs": 792, - "control-plane/src/tool_output.rs": 1844, "control-plane/src/vision.rs": 779, "control-plane/src/wait_ready.rs": 444, "control-plane/src/wire.rs": 446, @@ -179,6 +177,8 @@ "crates/experimental-ref/src/layout.rs": 464, "crates/experimental-ref/src/remote_experts.rs": 536, "crates/experimental-ref/tests/emulated_kernels.rs": 467, + "crates/gateway-text/src/prompt.rs": 1373, + "crates/gateway-text/src/tool_output.rs": 1844, "crates/gguf/src/lib.rs": 560, "crates/gguf/tests/synthetic.rs": 460, "crates/gptoss-igpu/src/lib.rs": 524, @@ -355,6 +355,7 @@ "env-read:leleka-cpu-worker": 2, "env-read:leleka-cuda-driver": 126, "env-read:leleka-deploy": 41, + "env-read:leleka-gateway-text": 2, "env-read:leleka-gptoss": 6, "env-read:leleka-gptoss-npu": 1, "env-read:leleka-gpu-npu-worker": 2, @@ -369,7 +370,7 @@ "env-read:leleka-obs": 2, "env-read:leleka-runtime": 239, "env-read:leleka-tokenizer": 2, - "env-read:strata-control": 21, + "env-read:strata-control": 19, "env-read:strata-desktop-core": 15, "instant-now:leleka-backend-api": 2, "instant-now:leleka-cpu-worker": 9, @@ -391,8 +392,9 @@ "path-include:leleka-model-format": 2, "path-include:leleka-native-cpu-expert": 2, "path-include:leleka-runtime": 94, - "path-include:strata-desktop-core": 5, + "path-include:strata-desktop-core": 2, "process-global:leleka-cuda-driver": 108, + "process-global:leleka-gateway-text": 5, "process-global:leleka-gptoss-npu": 3, "process-global:leleka-libc-shim": 13, "process-global:leleka-memory": 10, @@ -401,6 +403,6 @@ "process-global:leleka-obs": 7, "process-global:leleka-runtime": 102, "process-global:leleka-tokenizer": 4, - "process-global:strata-control": 16 + "process-global:strata-control": 11 } } diff --git a/architecture.json b/architecture.json index eec27fc5..dee677b7 100644 --- a/architecture.json +++ b/architecture.json @@ -9,7 +9,7 @@ "L1": [ "leleka-obs", "leleka-context", "leleka-sampler-ref", "leleka-quant-core", "leleka-serving-policy", "leleka-harmony", "leleka-tokenizer", "leleka-gguf", "leleka-kar-codec", "leleka-experimental-ref", "leleka-cpu-sys", "leleka-cpu-kernels", - "leleka-shm", "leleka-openvino", "leleka-memory" + "leleka-shm", "leleka-openvino", "leleka-memory", "leleka-gateway-text" ], "L2": [], "L3": [ diff --git a/control-plane/Cargo.toml b/control-plane/Cargo.toml index 2465cb2a..f93e6314 100644 --- a/control-plane/Cargo.toml +++ b/control-plane/Cargo.toml @@ -15,6 +15,7 @@ axum = "0.8" futures-core = "0.3" hex = "0.4" leleka-gguf = { path = "../crates/gguf" } +leleka-gateway-text = { path = "../crates/gateway-text" } leleka-obs = { path = "../crates/obs" } leleka-kar-codec = { path = "../crates/kar-codec" } leleka-harmony = { path = "../crates/harmony" } diff --git a/control-plane/src/lib.rs b/control-plane/src/lib.rs index b33a0c7d..65d47f94 100644 --- a/control-plane/src/lib.rs +++ b/control-plane/src/lib.rs @@ -70,9 +70,9 @@ pub mod prefix_view; pub mod preflight; pub mod prepare_preview; pub mod prometheus; -pub mod prompt; +pub use leleka_gateway_text::prompt; pub mod request_monitor; -mod response_tools; +use leleka_gateway_text::response_tools; pub mod responses; pub mod runtime_config; pub mod service_install; @@ -81,7 +81,7 @@ pub mod stream_parts; pub mod tensor_export; pub use leleka_tokenizer as tokenizer; pub mod tokenizer_assets; -pub mod tool_output; +pub use leleka_gateway_text::tool_output; pub mod wire; pub mod worker; diff --git a/crates/gateway-text/Cargo.toml b/crates/gateway-text/Cargo.toml new file mode 100644 index 00000000..4195e1ee --- /dev/null +++ b/crates/gateway-text/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "leleka-gateway-text" +version = "0.1.0" +description = "Pure text logic shared by the gateway and the desktop daemon: the pinned chat template renderer, the tool catalog and the tool-call parser. No I/O." +edition.workspace = true +license.workspace = true +rust-version.workspace = true + +[dependencies] +hex = "0.4" +regex = "=1.13.1" +regex-syntax = "=0.8.11" +minijinja = { version = "=2.24.0", default-features = false, features = ["builtins", "macros", "multi_template", "adjacent_loop_items", "serde", "preserve_order", "loop_controls"] } +minijinja-contrib = { version = "=2.24.0", default-features = false, features = ["pycompat"] } +serde = { version = "1", features = ["derive"] } +# `preserve_order`: tool-call arguments and tool schemas reach the model in the order the client wrote them (see prompt.rs). +# `float_roundtrip` is what both consumers already get through leleka-runtime / strata-control. +serde_json = { version = "1", features = ["float_roundtrip", "preserve_order"] } +sha2 = "0.11" + +[lints] +workspace = true diff --git a/crates/gateway-text/src/lib.rs b/crates/gateway-text/src/lib.rs new file mode 100644 index 00000000..bf8a9967 --- /dev/null +++ b/crates/gateway-text/src/lib.rs @@ -0,0 +1,8 @@ +//! Pure text logic shared by the gateway (`strata-control`) and the desktop daemon (`strata-desktop-core`). +//! +//! These three modules used to live in `control-plane/src` and were compiled a second time into `desktop-core` through `#[path]`. +//! They depend on nothing but `minijinja`, `serde`, `serde_json` and `sha2`, so they are a leaf crate that both hosts use. + +pub mod prompt; +pub mod response_tools; +pub mod tool_output; diff --git a/control-plane/src/prompt.rs b/crates/gateway-text/src/prompt.rs similarity index 99% rename from control-plane/src/prompt.rs rename to crates/gateway-text/src/prompt.rs index 236c4a74..a418e215 100644 --- a/control-plane/src/prompt.rs +++ b/crates/gateway-text/src/prompt.rs @@ -31,7 +31,7 @@ use serde::{ use serde_json::Value as Plain; /// The pinned chat template, embedded at build time. -pub const PINNED_TEMPLATE: &str = include_str!("../../engine/strata/serve/chat_template.jinja"); +pub const PINNED_TEMPLATE: &str = include_str!("../../../engine/strata/serve/chat_template.jinja"); // --------------------------------------------------------------------------------------------------------------- // ordered JSON @@ -898,7 +898,10 @@ mod tests { } fn golden() -> Vec { - serde_json::from_str(include_str!("../../engine/strata/serve/chat_golden.json")).unwrap() + serde_json::from_str(include_str!( + "../../../engine/strata/serve/chat_golden.json" + )) + .unwrap() } /// All ten cases of `serve/chat_golden.json`, straight through the Jinja template: system merging, tool diff --git a/control-plane/src/response_tools.rs b/crates/gateway-text/src/response_tools.rs similarity index 100% rename from control-plane/src/response_tools.rs rename to crates/gateway-text/src/response_tools.rs diff --git a/control-plane/src/tool_output.rs b/crates/gateway-text/src/tool_output.rs similarity index 100% rename from control-plane/src/tool_output.rs rename to crates/gateway-text/src/tool_output.rs diff --git a/crates/leleka-runtime/src/gpu_proofs/fivecase_frames.rs b/crates/leleka-runtime/src/gpu_proofs/fivecase_frames.rs index 03f7c51e..4a83408a 100644 --- a/crates/leleka-runtime/src/gpu_proofs/fivecase_frames.rs +++ b/crates/leleka-runtime/src/gpu_proofs/fivecase_frames.rs @@ -73,7 +73,7 @@ pub(super) fn prepare(inputs: &Inputs<'_, '_, '_>) -> (PathBuf, String) { requests.push((req, ids)); } assert_eq!(requests.len(), CASE_IDS.len()); - let renderer = sha(include_bytes!("../../../../control-plane/src/prompt.rs")); + let renderer = sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")); let mut entries = Vec::new(); // Check all five genuine products BEFORE writing the first frame. The // frozen consumer later independently re-tokenizes every frame again. diff --git a/crates/leleka-runtime/src/gpu_proofs/fivecase_runtime.rs b/crates/leleka-runtime/src/gpu_proofs/fivecase_runtime.rs index 0972eed8..d4785b4e 100644 --- a/crates/leleka-runtime/src/gpu_proofs/fivecase_runtime.rs +++ b/crates/leleka-runtime/src/gpu_proofs/fivecase_runtime.rs @@ -87,7 +87,7 @@ fn admit(tokenizer: &Tokenizer, manifest: &Value) -> Vec { assert_eq!(number(manifest, "case_count"), CASE_COUNT as u64); assert_eq!(text(manifest, "baseline_frame_sha256"), BASE_FRAME_SHA); assert_eq!(text(manifest, "model_digest"), MODEL_DIGEST); - let renderer = sha(include_bytes!("../../../../control-plane/src/prompt.rs")); + let renderer = sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")); assert_eq!(text(manifest, "renderer_source_sha256"), renderer); let entries = manifest["cases"].as_array().expect("five public cases required"); assert_eq!(entries.len(), CASE_COUNT); diff --git a/crates/leleka-runtime/src/gpu_proofs/long_public_preflight/long_public_request.rs b/crates/leleka-runtime/src/gpu_proofs/long_public_preflight/long_public_request.rs index 471718be..075514cc 100644 --- a/crates/leleka-runtime/src/gpu_proofs/long_public_preflight/long_public_request.rs +++ b/crates/leleka-runtime/src/gpu_proofs/long_public_preflight/long_public_request.rs @@ -9,7 +9,7 @@ use std::{ os::unix::fs::OpenOptionsExt, path::Path, }; -#[path = "../../../../../control-plane/src/prompt.rs"] +#[path = "../../../../../crates/gateway-text/src/prompt.rs"] #[allow(dead_code)] mod public_renderer; const BYTE_CAP: usize = 1024 * 1024; @@ -184,7 +184,7 @@ pub(crate) fn produce_on_bound_tokenizer( bytes: binary, }); } - let frame = json!({"schema":"public-long-preflight-v1","model_digest":bound_model_digest,"renderer_source_sha256":digest(include_bytes!("../../../../../control-plane/src/prompt.rs")),"tokenizer_implementation_source_sha256":"e675d8cbcccc071ff1ae69574e6042dc33b6b71e26bb756f7c65ae527dfcd38b","tokenizer_provenance":"caller must supply the actual already-bound pinned model tokenizer","parse_special":true,"effort":"none","public_fixture":true,"frames":frames,"aggregate_cap_bytes":ARTIFACT_CAP,"request_cap_bytes":BYTE_CAP,"prompt_cap_bytes":BYTE_CAP,"inference_executed":false,"KV_artifacts":false,"MTP_exercised":false,"quality_or_speed_claim":false}); + let frame = json!({"schema":"public-long-preflight-v1","model_digest":bound_model_digest,"renderer_source_sha256":digest(include_bytes!("../../../../../crates/gateway-text/src/prompt.rs")),"tokenizer_implementation_source_sha256":"e675d8cbcccc071ff1ae69574e6042dc33b6b71e26bb756f7c65ae527dfcd38b","tokenizer_provenance":"caller must supply the actual already-bound pinned model tokenizer","parse_special":true,"effort":"none","public_fixture":true,"frames":frames,"aggregate_cap_bytes":ARTIFACT_CAP,"request_cap_bytes":BYTE_CAP,"prompt_cap_bytes":BYTE_CAP,"inference_executed":false,"KV_artifacts":false,"MTP_exercised":false,"quality_or_speed_claim":false}); let frame_bytes = json_bytes(&frame)?; if frame_bytes.len() > 65536 { return Err(refused("shared frame summary cap")); diff --git a/crates/leleka-runtime/src/gpu_proofs/native_down_adaptive_candidate_only.rs b/crates/leleka-runtime/src/gpu_proofs/native_down_adaptive_candidate_only.rs index ac5e589e..b8a70c21 100644 --- a/crates/leleka-runtime/src/gpu_proofs/native_down_adaptive_candidate_only.rs +++ b/crates/leleka-runtime/src/gpu_proofs/native_down_adaptive_candidate_only.rs @@ -52,13 +52,13 @@ fn pinned_five_public_cases_strata_adaptive_slots() { save( &root, "BASELINE-ADMISSION.json", - &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), + &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), ); save(&root, "PUBLIC-REQUEST.json", &canonical); save( &root, "FRAME.json", - &json!({"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), + &json!({"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), ); let inherited = InheritedKarArchive::open(fd, path("LELEKA_STRA169_KAR_PROVENANCE")) .expect("inherited sealed KAR failed"); diff --git a/crates/leleka-runtime/src/gpu_proofs/native_down_candidate_only.rs b/crates/leleka-runtime/src/gpu_proofs/native_down_candidate_only.rs index 6be30e5d..17c1f821 100644 --- a/crates/leleka-runtime/src/gpu_proofs/native_down_candidate_only.rs +++ b/crates/leleka-runtime/src/gpu_proofs/native_down_candidate_only.rs @@ -10,7 +10,7 @@ use std::{ panic::{AssertUnwindSafe, catch_unwind, resume_unwind}, }; // EXACT existing daemon pure renderer, Effort::None. No hand-built ChatML. -#[path = "../../../../control-plane/src/prompt.rs"] +#[path = "../../../../crates/gateway-text/src/prompt.rs"] #[allow(dead_code)] mod public_renderer; const ARTIFACT_CAP: usize = 16 * 1024 * 1024; @@ -535,13 +535,13 @@ fn pinned_new_slowpaths_match_completed_public_output() { save( &root, "BASELINE-ADMISSION.json", - &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), + &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), ); save(&root, "PUBLIC-REQUEST.json", &canonical); save( &root, "FRAME.json", - &json!({"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), + &json!({"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), ); let inherited = InheritedKarArchive::open(fd, path("LELEKA_STRA169_KAR_PROVENANCE")) .expect("inherited sealed KAR failed"); @@ -870,13 +870,13 @@ fn pinned_five_public_cases_one_loaded_owner() { save( &root, "BASELINE-ADMISSION.json", - &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), + &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), ); save(&root, "PUBLIC-REQUEST.json", &canonical); save( &root, "FRAME.json", - &json!({"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), + &json!({"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), ); let inherited = InheritedKarArchive::open(fd, path("LELEKA_STRA169_KAR_PROVENANCE")) .expect("inherited sealed KAR failed"); @@ -1146,13 +1146,13 @@ fn pinned_five_public_cases_retained_qk_qsa_owner() { save( &root, "BASELINE-ADMISSION.json", - &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), + &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), ); save(&root, "PUBLIC-REQUEST.json", &canonical); save( &root, "FRAME.json", - &json!({"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), + &json!({"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), ); let inherited = InheritedKarArchive::open(fd, path("LELEKA_STRA169_KAR_PROVENANCE")) .expect("inherited sealed KAR failed"); @@ -1424,13 +1424,13 @@ fn pinned_five_public_cases_resident_owners() { save( &root, "BASELINE-ADMISSION.json", - &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), + &json!({"baseline_sha256":BASELINE_SHA,"retained_run":"24993ad2-9c7c-4a90-bfac-3e6e0b5685c1","retained_source_sha256":"ea8b6183c4f9bb5851054f908913d87b06c896c6408e8b737b97da77e3aba7e1","actual_baseline_phase":"warm","model_digest":MODEL_DIGEST,"profile":KAR_MTP_PROFILE,"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_ids_match":true,"context_tokens":262144,"temperature_milli":0,"max_output_tokens":CAP,"historical_timing_used":false,"baseline_campaign_succeeded":false}), ); save(&root, "PUBLIC-REQUEST.json", &canonical); save( &root, "FRAME.json", - &json!({"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), + &json!({"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), ); let inherited = InheritedKarArchive::open(fd, path("LELEKA_STRA169_KAR_PROVENANCE")) .expect("inherited sealed KAR failed"); diff --git a/crates/leleka-runtime/src/gpu_proofs/native_down_public_pair.rs b/crates/leleka-runtime/src/gpu_proofs/native_down_public_pair.rs index 70bbf8cf..9231aca8 100644 --- a/crates/leleka-runtime/src/gpu_proofs/native_down_public_pair.rs +++ b/crates/leleka-runtime/src/gpu_proofs/native_down_public_pair.rs @@ -11,7 +11,7 @@ use std::{ // EXACT existing daemon pure renderer, Effort::None. No hand-built ChatML. #[path = "long_public_preflight/long_public_request.rs"] mod long_public_preflight; -#[path = "../../../../control-plane/src/prompt.rs"] +#[path = "../../../../crates/gateway-text/src/prompt.rs"] #[allow(dead_code)] mod public_renderer; const ARTIFACT_CAP: usize = 16 * 1024 * 1024; @@ -377,7 +377,7 @@ fn pinned_single_load_public_native_vs_native_down_outer256_pair() { save( &root, "FRAME.json", - &json!({"renderer_source_sha256":sha(include_bytes!("../../../../control-plane/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), + &json!({"renderer_source_sha256":sha(include_bytes!("../../../../crates/gateway-text/src/prompt.rs")),"framed_prompt":req.prompt,"framed_prompt_sha256":sha(req.prompt.as_bytes()),"input_token_ids":ids,"framed_count":ids.len(),"model_digest":MODEL_DIGEST,"max_output_tokens":CAP,"temperature_milli":0}), ); let inherited = InheritedKarArchive::open(fd, path("LELEKA_STRA169_KAR_PROVENANCE")) .expect("inherited sealed KAR failed"); diff --git a/desktop-core/Cargo.toml b/desktop-core/Cargo.toml index e4a1e3ff..910482f9 100644 --- a/desktop-core/Cargo.toml +++ b/desktop-core/Cargo.toml @@ -16,6 +16,7 @@ leleka-runtime = { path = "../crates/leleka-runtime" } leleka-runtime-client = { path = "../crates/runtime-client" } leleka-sampler-ref = { path = "../crates/sampler-ref" } leleka-serving-policy = { path = "../crates/serving-policy" } +leleka-gateway-text = { path = "../crates/gateway-text" } minijinja = { version = "=2.24.0", default-features = false, features = ["builtins", "macros", "multi_template", "adjacent_loop_items", "serde", "preserve_order", "loop_controls"] } minijinja-contrib = { version = "=2.24.0", default-features = false, features = ["pycompat"] } serde = { version = "1", features = ["derive"] } diff --git a/desktop-core/src/lib.rs b/desktop-core/src/lib.rs index ab6c5a30..b44f7f44 100644 --- a/desktop-core/src/lib.rs +++ b/desktop-core/src/lib.rs @@ -14,17 +14,11 @@ pub mod runtime_rpc; mod runtime_sampling; pub mod runtime_tool_response; pub mod runtime_tools; -// Reuse the verified pure Rust template; no control-plane crate/C bridge link. -#[path = "../../control-plane/src/prompt.rs"] -#[allow(dead_code)] -// Native text and experimental daemon tools use Effort::None. -mod runtime_prompt; -#[path = "../../control-plane/src/response_tools.rs"] -#[allow(dead_code)] -mod runtime_tool_catalog; -#[path = "../../control-plane/src/tool_output.rs"] -#[allow(dead_code)] -mod runtime_tool_parser; +// The verified pure Rust template, tool catalog and tool-call parser come from the leaf crate shared with the gateway (no control-plane +// crate or C bridge link, and no second compile of the same files). Native text and experimental daemon tools use Effort::None. +use leleka_gateway_text::prompt as runtime_prompt; +use leleka_gateway_text::response_tools as runtime_tool_catalog; +use leleka_gateway_text::tool_output as runtime_tool_parser; mod operation_journal; diff --git a/docs/api-contract.md b/docs/api-contract.md index ccb6b5b4..31ad02d4 100644 --- a/docs/api-contract.md +++ b/docs/api-contract.md @@ -836,7 +836,7 @@ or parallel GPU requests. ## Tool-call parsing The Qwen model writes a call as ``, ``, one `` ... `` per argument, -``, ``. `control-plane/src/tool_output.rs` reads it; a call is published only after it is whole, and an +``, ``. `crates/gateway-text/src/tool_output.rs` reads it; a call is published only after it is whole, and an argument value is the exact text between its tags. The specimens that pin this are listed in [tool-call-corpus.md](tool-call-corpus.md). This section is what a client can observe. diff --git a/docs/offline-port.md b/docs/offline-port.md index 444ab7ec..a43c0175 100644 --- a/docs/offline-port.md +++ b/docs/offline-port.md @@ -26,7 +26,7 @@ Two kinds of check exist for each package: | 6. Small packers | `crates/offline-tools` | `embd_bf16_pack.py`, `ple_fp8_pack.py`, `draft_vocab.py`, `make_profile.py` | `diff_tools.py`, `tools_oracle.json` | | 7. MTP | `crates/offline-tools/src/mtp_rt.rs`, `control-plane/src/mtp_fetch.rs` | `mtp_rt.py`, `mtp_fetch.py` | `diff_tools.py`; `diff_mtp_fetch.py` and `tests/mtp_fetch.rs` against a local HTTP mirror | | 8. RoPE / RAM policy | `crates/context` (`rope_scaling`, `context_policy` from `claude/port-rope`, plus `setup_policy.rs`) | `setup.py` | `setup_policy_oracle.json` | -| 9. Chat template | `control-plane/src/prompt.rs` (minijinja `=2.24.0`) | `serve/frontend.py` `ChatTemplate` (jinja2) | `diff_chat_template.py` (3000 cases by default, 12000 run once; 0 failures), `chat_template_oracle.json`, all 10 `chat_golden.json` cases as unit tests | +| 9. Chat template | `crates/gateway-text/src/prompt.rs` (minijinja `=2.24.0`) | `serve/frontend.py` `ChatTemplate` (jinja2) | `diff_chat_template.py` (3000 cases by default, 12000 run once; 0 failures), `chat_template_oracle.json`, all 10 `chat_golden.json` cases as unit tests | | 9. Reasoning budget | `control-plane/src/reasoning_budget.rs` | `serve/server.py` `Service.reasoning_budget` / `Service.run` | `reasoning_budget_oracle.json` (247 budget lookups, 400 generations of the real `Service.run` over a scripted engine) | ## Deliberate divergences diff --git a/docs/port-status.md b/docs/port-status.md index 652a41b8..2c000c95 100644 --- a/docs/port-status.md +++ b/docs/port-status.md @@ -39,7 +39,7 @@ A `.cu` file may sit at **S** while its Rust host side sits at **L** or **O**; b | `mtp_fetch.py` | `control-plane/src/mtp_fetch.rs` | full | O: `diff_mtp_fetch.py` and `tests/mtp_fetch.rs` against a local HTTP mirror | | `mtp_pack.py` (BF16 to Q2_0/Q4_0/Q8_0 experts GGUF) | `control-plane/src/mtp_pack.rs` is a structural validator of the output only | partial: validator only, producer absent | T | | `setup.py` RoPE and RAM/context policy | `crates/context/src/setup_policy.rs` | full for the pure policy functions | O: `setup_policy_oracle.json` | -| `serve/frontend.py` `ChatTemplate` | `control-plane/src/prompt.rs` (minijinja 2.24.0) | full for the pinned template | O: `diff_chat_template.py` (3000 cases), `chat_golden.json` (10 cases) | +| `serve/frontend.py` `ChatTemplate` | `crates/gateway-text/src/prompt.rs` (minijinja 2.24.0) | full for the pinned template | O: `diff_chat_template.py` (3000 cases), `chat_golden.json` (10 cases) | | `Service.reasoning_budget` / `Service.run` | `control-plane/src/reasoning_budget.rs`, `crates/serving-policy/src/reasoning.rs` | full as a pure loop; not wired into the live worker | O: 247 budget lookups, 400 generations of the real `Service.run` | | `pack_index.py`, `strata_pack.py`, `pack_layer.py`, `canonical_xcheck.py` | none | absent by decision (Q2_0/AVX-512 path only) | not applicable | | `setup.py` hardware probing, installer, AMD/HIP/Windows parts | none | different (`doctor.rs`, `cuda_memory.rs`, `preflight.rs`, `service_*.rs`) | T | diff --git a/docs/tool-call-corpus.md b/docs/tool-call-corpus.md index 9a80088f..299fe937 100644 --- a/docs/tool-call-corpus.md +++ b/docs/tool-call-corpus.md @@ -3,7 +3,7 @@ The Strata upstream keeps a corpus of 49 model outputs for its tool-call and reasoning parser (`serve/test_tool_corpus.py`) and a file of quoted-call value shapes (`serve/test_quoted_call_values.py`), both MIT licensed. They are ported as `control-plane/tests/fixtures/tool_corpus/specimens.json` (provenance and licence in `NOTICE.md` next to it) and run by -`control-plane/tests/tool_corpus.rs` against `control-plane/src/tool_output.rs`. This page records which of them the parser reads +`control-plane/tests/tool_corpus.rs` against `crates/gateway-text/src/tool_output.rs`. This page records which of them the parser reads as upstream expects, stage by stage, so a fix can be shown to change the result it claims to change. Origin of the question: upstream issue #4078 (a string argument that quotes a tool call is cut at the quoted text), and #4427, diff --git a/scripts/check-local.sh b/scripts/check-local.sh index f1ada374..c06d4e59 100755 --- a/scripts/check-local.sh +++ b/scripts/check-local.sh @@ -155,7 +155,7 @@ product_path() { local host_tests=(dry_run_prints_the_plan_and_changes_nothing a_failing_preflight_stops_before_any_change_and_says_how_to_fix_it) PATH="${smi_path}" gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-deploy --features test-fakes -- --skip "${host_tests[0]}" --skip "${host_tests[1]}" PATH="${smi_path}" gate debt cargo test "${manifest[@]}" -p leleka-deploy --features test-fakes --test e2e -- "${host_tests[@]}" - gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-memory -p leleka-runtime-client -p strata-control -p strata-desktop-core + gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-memory -p leleka-runtime-client -p leleka-gateway-text -p strata-control -p strata-desktop-core gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-cuda-driver --features cuda-driver gate cargo test "${manifest[@]}" --no-fail-fast -p leleka-runtime -p leleka-native-cpu-expert # the remaining default-members (CPU, iGPU and NPU runtime, formats); the strict crates and experimental-ref run in the fast path diff --git a/scripts/ci-coverage.json b/scripts/ci-coverage.json index cf3868f5..35239533 100644 --- a/scripts/ci-coverage.json +++ b/scripts/ci-coverage.json @@ -13,6 +13,7 @@ "leleka-deploy", "leleka-memory", "leleka-runtime-client", + "leleka-gateway-text", "strata-control", "strata-desktop-core", "leleka-cuda-driver",