From e77c9e529e5f98bb40dccce07f06e380c504bf4a Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Fri, 16 Oct 2026 02:14:17 +0200 Subject: [PATCH] docs: delivery gap audit, Rust runtime run recipe, example gateway config and systemd templates docs/delivery-gap-audit.md: host test counts, Python audit, Codex-direct and deployment gaps with file:line, recommended tasks with acceptance criteria. docs/rust-runtime-run.md: leleka-seal-exec + leleka-inference (--backend-mode original) behind leleka-daemon, what was executed without a model or GPU context. desktop-core/examples/daemon.original.json and deploy/rust-runtime/*: configuration and user-unit templates (systemd-analyze --user verify only; not run with the model). Co-Authored-By: Claude Sonnet 5.5 --- deploy/README.md | 2 + deploy/rust-runtime/leleka-daemon.service | 20 +++ deploy/rust-runtime/leleka-inference.service | 29 ++++ deploy/rust-runtime/runtime.env.example | 6 + desktop-core/examples/daemon.original.json | 13 ++ docs/delivery-gap-audit.md | 171 +++++++++++++++++++ docs/rust-runtime-run.md | 145 ++++++++++++++++ 7 files changed, 386 insertions(+) create mode 100644 deploy/rust-runtime/leleka-daemon.service create mode 100644 deploy/rust-runtime/leleka-inference.service create mode 100644 deploy/rust-runtime/runtime.env.example create mode 100644 desktop-core/examples/daemon.original.json create mode 100644 docs/delivery-gap-audit.md create mode 100644 docs/rust-runtime-run.md diff --git a/deploy/README.md b/deploy/README.md index 52bc427f..ec0cced4 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -4,6 +4,8 @@ Linux CI builds a statically linked musl CLI/control-plane preview and publishes For a local static CLI image smoke test, build `deploy/Dockerfile.static-cli` with a Linux/musl target. The final image is `scratch` plus the CLI binary. It is a packaging test, not the deployment image for inference. +The Rust engine pair (`leleka-inference` behind `leleka-daemon`) is a separate runtime from `strata-next` plus the C++ engine described below: its run recipe, example configuration and systemd templates are in [`docs/rust-runtime-run.md`](../docs/rust-runtime-run.md) and [`deploy/rust-runtime/`](rust-runtime/), and the open delivery items are in [`docs/delivery-gap-audit.md`](../docs/delivery-gap-audit.md). It needs CUDA 12 `libcublas.so.12` (not the `.so.13` named below) and a driver of 595 or newer. + ## Worker recovery Configure top-level JSON `max_in_flight_requests` or environment diff --git a/deploy/rust-runtime/leleka-daemon.service b/deploy/rust-runtime/leleka-daemon.service new file mode 100644 index 00000000..ea1095ef --- /dev/null +++ b/deploy/rust-runtime/leleka-daemon.service @@ -0,0 +1,20 @@ +# TEMPLATE, not run with the real model: user unit for the HTTP gateway (OpenAI Responses on loopback). +# The daemon reconnects to the engine by itself; it never loads a model. +[Unit] +Description=Leleka gateway (POST /v1/responses on loopback) +After=leleka-inference.service + +[Service] +Type=exec +EnvironmentFile=@STATE@/runtime.env +UMask=0077 +NoNewPrivileges=yes +Restart=on-failure +RestartSec=2 +# The daemon drains streams (10 s) on SIGINT only; SIGTERM would cut live SSE without a terminal event. +KillSignal=SIGINT +TimeoutStopSec=20 +ExecStart=@PREFIX@/leleka-daemon --config @STATE@/daemon.json + +[Install] +WantedBy=default.target diff --git a/deploy/rust-runtime/leleka-inference.service b/deploy/rust-runtime/leleka-inference.service new file mode 100644 index 00000000..2231336d --- /dev/null +++ b/deploy/rust-runtime/leleka-inference.service @@ -0,0 +1,29 @@ +# TEMPLATE, not run with the real model: user unit for the engine process (gRPC on loopback). +# Replace @PREFIX@ (binaries), @ASSETS@ (model assets), @STATE@ (private state dir) and install runtime.env +# next to it (mode 0600). The 55 GB KAR archive is copied into a sealed memfd at every start (RAM, minutes); +# nothing loads the model afterwards: run `leleka-cli ... load-mtp` (docs/rust-runtime-run.md). +[Unit] +Description=Leleka inference engine (Original serve path, gRPC on loopback) + +[Service] +Type=exec +EnvironmentFile=@STATE@/runtime.env +UMask=0077 +NoNewPrivileges=yes +# A failed engine start must be looked at, not retried into another 55 GB copy. +Restart=no +# leleka-inference and leleka-daemon handle SIGINT only (tokio ctrl_c); the default SIGTERM would end them abruptly. +KillSignal=SIGINT +TimeoutStopSec=60 +ExecStartPre=/usr/bin/install -d -m 0700 @STATE@/mtp-staging +ExecStart=@PREFIX@/leleka-seal-exec --file @ASSETS@/qwen-iq3-s-l2-v4.kar --expect-bytes 55295529472 -- \ + @PREFIX@/leleka-inference --listen 127.0.0.1:18766 --token-env LELEKA_RUNTIME_TOKEN \ + --shard0 @ASSETS@/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf \ + --shard1 @ASSETS@/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf \ + --gpu 0 --gpu-budget 25769803776 --context-tokens 262144 \ + --kar-archive-fd {FD} --kar-provenance @ASSETS@/qwen-iq3-s-l2-v4.kar.provenance.json \ + --mtp-pack @ASSETS@/data/mtp-rt --mtp-staging @STATE@/mtp-staging \ + --backend-mode original + +[Install] +WantedBy=default.target diff --git a/deploy/rust-runtime/runtime.env.example b/deploy/rust-runtime/runtime.env.example new file mode 100644 index 00000000..831d3faa --- /dev/null +++ b/deploy/rust-runtime/runtime.env.example @@ -0,0 +1,6 @@ +# Copy to @STATE@/runtime.env, mode 0600, outside Git. systemd EnvironmentFile syntax (no export, no quotes needed). +# Two independent secrets, 32..4096 printable ASCII bytes each (for example `openssl rand -base64 36`): +LELEKA_RUNTIME_TOKEN=replace-with-a-fresh-secret-of-at-least-32-bytes-1 +LELEKA_GATEWAY_TOKEN=replace-with-a-fresh-secret-of-at-least-32-bytes-2 +# leleka-inference dlopens libcublas.so.12 (and libcublasLt.so.12) by name: point at a CUDA 12 cuBLAS directory. +LD_LIBRARY_PATH=/opt/leleka/cublas-12.9.1.4/lib diff --git a/desktop-core/examples/daemon.original.json b/desktop-core/examples/daemon.original.json new file mode 100644 index 00000000..e520309a --- /dev/null +++ b/desktop-core/examples/daemon.original.json @@ -0,0 +1,13 @@ +{ + "schema_version": 1, + "listen": "127.0.0.1:18080", + "token_env": "LELEKA_GATEWAY_TOKEN", + "runtimes": [ + { + "id": "qwen-iq3", + "address": "127.0.0.1:18766", + "token_env": "LELEKA_RUNTIME_TOKEN", + "artifact_digest": "sha256:80d5e3333801cedbca81a5c19c24ed6bb48fd56977acd190318f66b23a1766a3" + } + ] +} diff --git a/docs/delivery-gap-audit.md b/docs/delivery-gap-audit.md new file mode 100644 index 00000000..3377b7d3 --- /dev/null +++ b/docs/delivery-gap-audit.md @@ -0,0 +1,171 @@ +# Delivery gap audit: control plane and packaging (M2) + +Branch `claude/m2-control-plane` (base `claude/port-gpu-bringup` @ `6cd926d`), audit of 2026-10-16. Host-side only: no model +was loaded, no GPU context was created, and nothing here is a performance or model-quality result. File:line references are +to this branch. The run recipe is [`rust-runtime-run.md`](rust-runtime-run.md). + +## 0. Findings that decide the next work + +1. **Two serving stacks exist and the full API is wired to the wrong one.** `strata-next` (`control-plane/`) has the Responses / + Chat / Messages surface, text.format, custom tools, reasoning, drain, history, MCP hub, but it drives an *engine process over + the Original stdio wire protocol* (`READY`/`GEN `/`T `/`DONE`, `control-plane/src/wire.rs`). The Rust engine + (`leleka-inference`) speaks gRPC with a **text prompt in, text deltas out** (`crates/backend-api/src/lib.rs:130-211`) and is + fronted only by `leleka-daemon`, whose `/v1/responses` is a narrow text subset. No adapter joins them. Codex cannot use the + Rust engine directly today (section 4). +2. **The daemon rejects a Codex-shaped request.** A body with `reasoning`, `include`, `tool_choice` or `parallel_tool_calls` + gets 400 `unsupported_request_field` (`desktop-core/src/runtime_gateway.rs:422-431`, observed live, section 2); `max_output_tokens` + defaults to 256 and is capped at 4096 (`:442-443`); tools are off unless `experimental_native_tools` is set (`:642`). +3. **Every Original-path request starts from an empty context** (no conversation or prefix reuse is bound, + `docs/original-serve.md:97-104`); the backend serves one generation at a time (`backend.rs:759`). +4. **Delivery of the Rust pair is absent**: no image, no installer, no health/ready endpoint on the daemon, no SIGTERM + handling, no readiness after restart without a manual `load-mtp`. Existing packaging (`deploy/`) ships `strata-next` plus the + C++ engine only. +5. **Gate A evidence is synthetic.** Every committed Responses fixture is marked `synthetic` + (`benchmarks/fixtures/responses/*.json`); no recorded Codex session or comparison against the Python server exists + (`docs/roadmap.md` P3 last item, charter backlog item 3). +6. Found and fixed here: a dead log sink killed the worker supervisor and left readiness true (section 6, `e743764`); the static + CLI image could not build (`e5c7c32`); three smoke/test expectations were stale (`203b88f`, `6ca48b8`). + +## 1. Host test suites (no GPU, no model) + +Linux x86_64 (`rnr5090`: Ubuntu 26.04.1, Rust 1.99.0, own tree `~/work/leleka-m2`, `nice -n 15 cargo test --locked -j 8 +--no-fail-fast`, default workspace members): + +| run | passed | failed | ignored | targets | note | +| --- | --- | --- | --- | --- | --- | +| 1, base `6cd926d` | 898 | 6 | 1 | 72 | see failures below | +| 2, HEAD after the fixes | 910 | 0 | 2 | 73 | includes 4 `leleka-seal-exec` and 3 `log_failure_sse` tests | + +Failures of run 1: + +| test | cause | status | +| --- | --- | --- | +| `desktop-core/tests/native_tools_sdet.rs` `declarations_are_bounded_unique_and_closed_before_render` | stale: asserted temperature 0.4 is refused, valid since `cce4333` | fixed `203b88f` | +| `strata-desktop-core --lib` `operation_journal::tests::{append_failure_preserves_existing_evidence, terminal_history_survives_and_incomplete_is_not_replayed}` (and `recovered_uncertainty...` in reruns) | `journal already owned or locking unavailable` under the parallel lib run; pass alone and with `--test-threads=1`; 4 of 5 parallel reruns failed once, run 2 passed. Root cause not isolated (suspected: the `flock` of one test inherited by a concurrent child process until `exec`) | **open, flaky** | +| `strata-control --lib` `responses::tests::durable_history_roundtrip_delete_eviction_and_faults` | same message from `history.lock`; 3 of 3 reruns passed | **open, flaky** | +| `runtime_gateway_sdet` `daemon_http_disconnect_cancels_one_runtime_generation` | timed out (13 s) in the loaded run; 3 of 3 isolated runs passed | load-sensitive | + +Other checks on Linux: `cargo clippy -p strata-control --all-targets --no-deps -- -D warnings` clean; with dependencies it stops +at known debt in `leleka-model-format` (`pinned_arena_plan.rs:325` `type_complexity`), so `scripts/check-local.sh` full mode fails +at the control-plane Clippy step. `cargo fmt -p strata-desktop-core --check` also reports existing drift (`leleka-inference.rs`, +untouched here). + +HTTP/SSE smokes against `strata-next` with scripted engines (Python 3.14 as test driver only), debug binary: pass +`test-live-responses-replay` (21 corrupt streams rejected, JSON+SSE tool continuation), `smoke-tool-policy` (216 cases), +`smoke-custom-tools`, `smoke-sse-keepalive`, `smoke-input-tokens`, `smoke-response-history` (+`--durable`), `smoke-native-drain`, +`smoke-signal-drain`, `smoke-generation-deadline`, `smoke-worker-cancel`, `smoke-native-auth`, `smoke-queue-deadline`, +`smoke-config-check`, `smoke-wait-ready`, `smoke-chat-completions`, `smoke-messages` (the last two after `6ca48b8`; before it +they failed on stale expectations). `replay-responses --sse` on the structured-tool fixture ends in `response.completed`. +Not run: `smoke-static-cli`, `smoke-embedded-engine`, packaging and container smokes, the live Python-oracle differentials. + +Windows 11 (Rust 1.99.0): the 8 portable crates (`leleka-backend-api`, `-tokenizer`, `-quant-core`, `-context`, `-sampler-ref`, +`-experimental-ref`, `-serving-policy`, `-offline-tools`): **341 passed, 0 failed**. The default workspace does not build +here: `desktop-core` pulls `leleka-runtime` -> `leleka-cuda-driver` (Linux-only items, 29 compile errors), `strata-control` lib tests use +`std::os::unix` (`vision.rs:499,513`), `leleka-model-format` lib tests need the unix-only `RangeSource for KarInspection` +(`kar_levels.rs:582`, used at `tests/kar_ple/mod.rs:693`). Windows is not a delivery target; use Linux. + +## 2. Synthetic verification of the request path + +| layer | what ran | result | +| --- | --- | --- | +| daemon gateway, mock backend, real HTTP/2 + gRPC | `runtime_gateway_sdet` (8 tests): ordered SSE with one terminal, finish reason `stop` -> `completed`, `length` -> `incomplete`, missing terminal / tool reason / accepted fault -> `response.failed` without retry, disconnect cancels one generation | pass | +| daemon process + `leleka-inference` process (real binaries, **no Load**) | `/runtime/status` connected, `model_ready: false`; `/v1/responses` valid body -> 503 `model_not_ready`; unsupported field -> 400; no token -> 401 | as expected; recipe in `rust-runtime-run.md` | +| `strata-next` over a scripted engine | live SSE: `created, in_progress, output_item.added, content_part.added, output_text.delta*, done events, output_item.done, function_call_arguments.delta*/done, ... completed`; token budget -> `response.incomplete` (`max_output_tokens`); worker error -> `response.failed` (unit tests `responses.rs:5428,5490`) | pass | +| log failure | real binary, stderr consumer gone, protocol failure mid-stream | stream ends `response.failed`; readiness drops (after `e743764`) | + +## 3. Python audit + +Production serving path (what `strata-next serve`, `leleka-daemon`, `leleka-inference` start at run time): **no Python**. + +| item | where | class | +| --- | --- | --- | +| external processes spawned by `strata-next` | `nvidia-smi` (`doctor.rs:50`, `cuda_memory.rs:134`), `systemctl` (`service_install.rs:543,627`), operator `engine.executable` / `@embedded` memfd (`worker.rs:441`, `embedded_engine.rs`), operator `strata-vision` (`vision.rs:222`), operator `before_load` argv or `sh` (`worker.rs:235-244`), operator MCP server commands (`mcp.rs:135`), `kill` (`mcp.rs:346,355`) | no Python hard-coded; an MCP server or `before_load` the operator configures may be anything | +| chat template | `include_str!(engine/strata/serve/chat_template.jinja)` rendered by minijinja (`prompt.rs:32`) | data file, not Python | +| `leleka-inference` / `leleka-daemon` / `leleka-cli` / `leleka-seal-exec` | `ldd`: libc, libm, libgcc_s; dlopen `libcuda.so.1`, `libcublas.so.12` | none | +| error text only | `original_mtp_rt.rs:71` says "run tools/mtp_rt.py" (offline conversion; ported to `crates/offline-tools`) | message | +| KAR sealing for the engine | bring-up used operator scripts `seal_exec.py` / `kar_holder.py` (outside the repo) | replaced by `leleka-seal-exec` (`414169b`) | +| offline-only tooling | `scripts/offline/diff_*.py` (oracle differentials), `engine/strata/tools/*.py` (Original converters; Rust ports in `native_pack.rs`, `offline-tools`; `mtp_pack` producer still absent), `scripts/gpu-bringup/*.py` (compile/seal PTX), `scripts/build-linux-package.py`, `build-runtime-image.py`, `bootstrap-cuda-toolkit.py`, `publish-gitea-release.py` | build / offline | +| test-only | `scripts/smoke-*.py`, `scripts/test-*.py` (83 `.py` files in `scripts/`, including benches and installers), `desktop/tests/*.py`, `control-plane/tests/mcp_hub.rs` (spawns `python3` for a fake MCP server) | CI / test | +| client-side launchers | `scripts/install-qwen-native*.py`, `qwen_native_api.py`, `qwen_native_service.py` (`qwen-codex-ctl` on the laptop) | not serving | +| reference only | `engine/strata/serve/server.py` (Original Python server): differential goldens (`tests/fixtures/golden/*`, `http_surface.rs`) | not started by any Rust code | +| images | `Dockerfile.runtime` is `scratch`-like plus the binary; `Dockerfile.systemd-smoke` installs python3 for its fixture | test image only | + +Residual risk: CI itself (`linux.yml`, `desktop.yml`, `port.yml`) needs Python; production does not. + +## 4. Codex-direct audit + +"strata-next" = `control-plane/`; "daemon" = `desktop-core/src/runtime_gateway.rs`. Wire contract: `docs/api-contract.md`. + +| requirement | strata-next | daemon (Rust engine) | gap / location | +| --- | --- | --- | --- | +| `POST /v1/responses`, bearer auth, SSE | yes (`responses.rs:1078`, streams `:1951,2122,2423`) | yes | none | +| Codex-shaped body (`include`, `reasoning`, `store:false`, `parallel_tool_calls`, `tool_choice:auto`, `prompt_cache_key`, `client_metadata`) | accepted (`responses.rs:487-521`, `:709-722`) | **400** `unsupported_request_field` (`runtime_gateway.rs:422-431`; tool path `runtime_tools.rs:393-418`) | daemon | +| unknown top-level or `text` fields | **rejected** by `deny_unknown_fields` (`responses.rs:486,524`): `service_tier`, `text.verbosity`, `max_tool_calls`, `user` would 400 | rejected | decide accept-and-ignore for harmless fields | +| `reasoning.effort` / `summary` | effort none..xhigh; summary only `auto`/null (`:1361-1388`); `minimal` and `concise`/`detailed` -> 400 | thinking never enabled (`Effort::None`) | strata-next: map `minimal`; daemon: absent | +| `text.format` text / json_object / json_schema | prompt guidance + validation of the finished text; buffered until DONE; invalid -> `response.failed` (`:684-707`, render `:1625-1640`, `api-contract.md` "Live structured text") | only `{"format":{"type":"text"}}` (`runtime_tools.rs:432-437`) | **no constrained decoding anywhere**; daemon: absent | +| function tools | yes, schema-validated before publication (`:765-791`); names `[A-Za-z0-9_-]` up to 64 bytes | behind `experimental_native_tools` (default off, `:642`), buffered, one regeneration on invalid output, at most 128 tools (`runtime_tools.rs:14`) | daemon: default-off, no streaming of arguments | +| custom tools (text) and regex format | yes, validation-only (`response_tools.rs:62-101`) | tool adapter covers namespaced custom regex (test `native_tools_sdet`) | no grammar-constrained sampling | +| custom tools with **Lark** grammar | rejected 400 (`response_tools.rs:87-89`) | rejected | a Codex that sends its freeform `apply_patch` as a Lark custom tool gets 400; needs the function variant or Lark support | +| hosted tools (`web_search`, `local_shell`, `image_generation`, `file_search`) | rejected (`response_tools.rs:65-67`) | rejected | acceptable unless Codex config enables them | +| `tool_choice` auto / none / required / forced function or custom / `allowed_tools` | yes (`:589-652`, `:730-763`, `validate_live_subset` `:2684`) | adapter only | forced namespaced selectors -> 501 | +| `parallel_tool_calls:false` enforcement | yes (`:645`) | adapter | none | +| streaming event order, `sequence_number`, one terminal | tested (`responses.rs:4851,5153,5369,5527`) | `Trace` (`runtime_gateway.rs:519-594`) | none | +| terminal event on every failure | worker error, DONE missing, store failure -> `response.failed` (`:2098-2113`, `:2293`, `:2614`); **log-sink failure fixed** `e743764` | stream error -> `interrupted()` `response.failed` | no SIGTERM handler in the daemon: a stop cuts live SSE (`leleka-daemon.rs:38`, SIGINT only) | +| max output tokens | default min(32768, context minus prompt) (`:1135-1140`) | default **256**, max 4096 (`:442-443`) | daemon | +| long-prefill keep-alive | `: keep-alive` after 15 s (`native_events.rs:9-11`) | only in the tool path (`:902-917`) | text path silent while prefilling | +| conversation / prefix reuse across turns | engine-side (`RESUME`/`REUSED` lines) | none: every request resets to position 0 (`original-serve.md:97-104`) | full re-prefill per Codex turn | +| stored responses, `previous_response_id`, input_items, DELETE | yes (`api-contract.md`, in-memory or durable) | no | daemon | +| `/v1/responses/input_tokens`, `/v1/chat/completions`, `/v1/messages` | yes | no | daemon | +| MCP | Codex executes MCP tools itself; the server only sees function tools named `mcp__server__tool` (accepted). Server MCP hub `mcp.rs` is tested (`tests/mcp_hub.rs`, 5 tests) but nothing executes tools for a client (`api-contract.md:208`) | same as function tools | the real Codex+LeaseVibe MCP episode is not recorded | +| approval / review turns | developer messages coalesced into the system section (`api-contract.md` "Approval/review requests") | untested | no real capture | +| reasoning item replay | requires raw `reasoning_text` content; `encrypted_content` or summary-only -> 400 (`responses.rs:1660-1668`) | n/a | unverified against what Codex actually re-sends | +| concurrency | one generation at a time; admission 429 / drain 503 | `max_concurrent_generations: 1` (`backend.rs:759`) | charter G8 later | +| transport | HTTP on loopback, no TLS (use SSH forwarding) | same | rented server needs a tunnel | +| error body | `{"error":{"message","type","param","code"}}` | `{"error":{"message":code,"type":code}}` | differing shapes | +| evidence | all fixtures synthetic | synthetic | **no recorded Codex session, no comparison with the Python server** | + +## 5. Deployment audit (clean Ubuntu 24.04 / 26.04, NVIDIA driver >= 595) + +| item | state | evidence | missing | +| --- | --- | --- | --- | +| driver floor | `doctor` / `gpu_requirement` know only `cuda-13.0-linux` = 580.65.06 | `doctor.rs:27,44` | the sealed PTX contains ISA 9.2 (36 `.ptx` files, nvcc 13.2) and the target floor is 595: a `cuda-13.2-linux` profile; no check for `libcublas.so.12` | +| cuBLAS | the Rust engine dlopens CUDA **12** `libcublas.so.12` by name | `ple_batch_ffi.rs:147` | not packaged, not preflighted; `deploy/README.md` still says `libcublas.so.13` for the C++ engine; version pin undecided (bring-up 12.9.1.4, Ubuntu 26.04 `libcublas12` 12.4.5.8) | +| binaries | `cargo build --release -p strata-desktop-core --bin leleka-inference ...` needs only Rust + a C compiler | `ldd` of the debug build | no release job, no checksum/provenance for the Rust pair; `linux.yml` builds only `strata-next` + C++ engine; `port.yml` only type-checks | +| one-command install | `strata-next service-install` (user unit, `--start-ready`) exists for `strata-next` | `deploy/README.md:77-130` | nothing for `leleka-inference` + `leleka-daemon`; no asset fetch/verify chain for the KAR archive, MTP pack and shards of the Rust path | +| sealed KAR | `leleka-seal-exec` (`414169b`) | tests | 55 GB RAM per engine start; no preflight of free RAM/`/proc`/memfd | +| systemd | templates `deploy/rust-runtime/*.service` pass `systemd-analyze --user verify`; `strata-next` has a user unit (`service_unit.rs:44-63`, `Restart=no`) | | never run with the real model; no system-wide unit; lingering is never configured (`deploy/README.md:240-246`), so a user unit does not start at boot without admin action | +| signals | `strata-next` has shutdown grace; the Rust pair handles SIGINT only | `leleka-daemon.rs:38`, `leleka-inference.rs:211` | observed on the daemon: SIGTERM ends the process with status 143, SIGINT exits 0; templates set `KillSignal=SIGINT` as a workaround | +| readiness / health | `strata-next`: `/health`, `/ready`, `/status`, `wait-ready`; daemon: authenticated `/runtime/status` only | `runtime_gateway.rs:220` | no unauthenticated probe, no `wait-ready` equivalent, no auto-load: after any engine restart the model is not loaded until `leleka-cli load-mtp` | +| OCI image | `Dockerfile.runtime` = `strata-next` + embedded C++ engine on an Ubuntu 26.04 digest, non-root, `NVIDIA_VISIBLE_DEVICES=void` default | `deploy/Dockerfile.runtime`, `build-runtime-image.py` | no image for the Rust pair; `Dockerfile.static-cli` context was broken (fixed `e5c7c32`) | +| model volume / no re-download | asset manifests with SHA-256, resumable fetch, atomic publish for `strata-next` | `deploy/README.md:646-770` | not wired to the Rust path's inputs (shards + KAR + provenance + MTP pack) | +| observability | JSON `/metrics` on `strata-next` (not Prometheus) | `api-contract.md:265` | none on the daemon/engine; `DBG arena` `eprintln!` lines remain on the engine load path (`cache_original_prompt.rs:31-62`) | +| security | loopback only, bearer tokens from env, 0700/0600 checks in `strata-next`; tokens for the Rust pair read from env | `leleka-inference.rs:112` | systemd `EnvironmentFile` mode not enforced by tooling | +| clean-host test | none for either stack (`docs/roadmap.md` P4 acceptance open) | | | + +## 6. Changes made on this branch + +| commit | change | +| --- | --- | +| `203b88f` | `desktop-core/tests/native_tools_sdet.rs`: stale temperature assertion corrected (accept 0.4, refuse 2.5) | +| `e743764` | `control-plane`: `elog!` replaces every `eprintln!` (it panics when stderr is unwritable); new `tests/log_failure_sse.rs` (control case plus dead-sink case on the real binary, and a source scan) | +| `6ca48b8` | `smoke-chat-completions.py`, `smoke-messages.py`: refusal cases use out-of-range values; picture block is countable | +| `414169b` | `desktop-core`: `leleka-seal-exec` (sealed memfd launcher), `rustix` target dependency | +| `e5c7c32` | `.dockerignore` / `Dockerfile.static-cli`: carry `chat_template.jinja` | +| docs commit | this page, `rust-runtime-run.md`, `desktop-core/examples/daemon.original.json`, `deploy/rust-runtime/` templates | + +Not changed: `engine/strata/`, `crates/cuda-driver`, `crates/leleka-runtime`, the flaky tests, the Windows test portability. + +## 7. Recommended tasks (priority order) + +| # | task | acceptance | +| --- | --- | --- | +| 1 | **One API in front of the Rust engine.** Add token-level generation to `backend-api` (prompt token ids in, `TokenDelta` out, versioned) and a worker trait in `control-plane` with the stdio and the gRPC/in-process implementations; or move the daemon onto the control-plane router | the `control-plane` HTTP fixtures (tools, custom/regex, text.format, reasoning, cancel, drain, history, Chat, Messages) pass unchanged against a fake `Backend`; a Codex-shaped body returns 200 with the section-4 event order; `leleka-daemon` route set equals `strata-next`'s | +| 2 | **Record and sanitize real Codex sessions** (plain turns, MCP tool turns with LeaseVibe, approval/review, long context) and replay them through `strata-next` and the Python server, then the Rust path | N sessions, zero protocol errors, zero streams without a terminal event, unchanged tool arguments, a written diff against the Python server; fixtures free of credentials and prompts that are not public | +| 3 | **Rust-pair delivery**: one command that preflights (driver >= 595, `libcublas.so.12`, `/proc`, free RAM >= 56 GB, disk), verifies assets by SHA-256, seals, starts engine and gateway, loads, waits for readiness | on a clean Ubuntu 24.04 and 26.04 VM with a GPU: one command -> authenticated `/ready` true -> one `/v1/responses` completes; a restart reaches ready again without re-download | +| 4 | **OCI image for the Rust pair** (pinned base digest, pinned CUDA 12 cuBLAS with SHA-256, four binaries, non-root) and a CI job building it | loader test without GPU passes (`ldd`, `--help`, dlopen failure messages); `docker run --gpus all` smoke on the GPU runner; provenance file lists binary digests | +| 5 | **Lifecycle of the daemon/engine**: SIGTERM drain with terminal SSE events, unauthenticated `/health` + `/ready`, `--autoload`/`wait-ready`, readiness false after engine restart | kill -TERM during a stream ends it with `response.failed`/`completed`; a killed engine flips `/ready` and returns to ready by itself | +| 6 | Conversation/prefix reuse on the Original path and a per-turn token budget default | second turn of a 50K-token conversation re-prefills only the new suffix (token counts reported, greedy output equal to the full re-prefill) | +| 7 | Constrained decoding for `text.format` and tool arguments (regex first, then JSON schema) | schema-valid output on a fixed adversarial schema set without retries; validation still runs | +| 8 | Compatibility edges: Lark custom tools or the function form of `apply_patch`, harmless-field policy (`service_tier`, `text.verbosity`), `reasoning.effort=minimal` | each Codex request shape from task 2 accepted or refused with a documented reason | +| 9 | Linux CI job for the default workspace (`cargo test`), fix the lock-inheritance flakes (serialize lock-holding tests or isolate them), clear the Clippy debt so `check-local.sh` is green | 10 consecutive green parallel runs; `check-local.sh` full exits 0 | +| 10 | Driver profile `cuda-13.2-linux` (595) and cuBLAS check in `doctor`; remove `DBG` `eprintln!` from the engine load path; telemetry per charter G10 | `doctor` fails on driver 580 and on missing `libcublas.so.12`; no stderr noise on a quiet load | diff --git a/docs/rust-runtime-run.md b/docs/rust-runtime-run.md new file mode 100644 index 00000000..4d5782f0 --- /dev/null +++ b/docs/rust-runtime-run.md @@ -0,0 +1,145 @@ +# Running the Rust runtime (`leleka-inference` + `leleka-daemon`, Original serve path) + +Status 2026-10-16, branch `claude/m2-control-plane`. This page records how the Rust engine process and the gateway are started +against the model assets, and what was and was not executed to check it. **No model load, no inference and no GPU context +was involved in any check on this page**; it makes no performance or quality claim. The model-facing steps (`load-mtp`, a +real `/v1/responses`) belong to the GPU bring-up and are written down here from the code, not from a run. + +## Processes + +```text +client (curl / Codex) --HTTP /v1/responses, Bearer LELEKA_GATEWAY_TOKEN--> leleka-daemon 127.0.0.1:18080 +leleka-daemon --gRPC, Bearer LELEKA_RUNTIME_TOKEN-----------------> leleka-inference 127.0.0.1:18766 +leleka-inference --CUDA driver API (dlopen libcuda.so.1, libcublas.so.12), no Python anywhere +leleka-cli --HTTP /runtime/{status,load,unload,operation}-------> leleka-daemon (typed lifecycle control) +``` + +`leleka-seal-exec` is a launcher, not a daemon: it copies the KAR archive into a sealed memfd and `exec`s `leleka-inference` +with the descriptor number substituted for `{FD}`. All four binaries live in `desktop-core/` (package `strata-desktop-core`). +`leleka-inference` starts with model admission closed; its CUDA owner thread waits for an explicit `Load` and creates no +CUDA context before it. + +## Host prerequisites + +| item | requirement | source | +| --- | --- | --- | +| OS / CPU | Linux x86_64, glibc (built and tested on Ubuntu 26.04, glibc 2.43, g++ 15.2) | `backend.rs` refuses other targets | +| NVIDIA driver | `libcuda.so.1` from driver >= 595 (the bring-up host has 595.99.02) | `cuda-driver/src/api.rs` dlopen | +| cuBLAS | **CUDA 12** `libcublas.so.12` and `libcublasLt.so.12` on `LD_LIBRARY_PATH` | `cuda-driver/src/ple_batch_ffi.rs:147` dlopen by name | +| build | Rust 1.99.0 (`rust-toolchain.toml`), a C compiler; no nvcc, no CMake, no Python (PTX is checked in and pinned) | `ldd` of the debug binary: libc, libm, libgcc_s only | +| RAM | the sealed memfd is the whole archive: 55,295,529,472 bytes of shmem for as long as the process lives | `PINNED_ARCHIVE_BYTES` | + +The bring-up host uses the CUDA 12.9.1.4 redistributable (`https://developer.download.nvidia.com/compute/cuda/redist/libcublas/linux-x86_64/libcublas-linux-x86_64-12.9.1.4-archive.tar.xz`, +archive sha256 `546addc4a9d82b8f23aa9ba9274b6bc0429a63008a31c759884ac24880796057`) unpacked to `~/cuda-toolkits/cublas-12.9.1.4/lib`. +Ubuntu 26.04 also ships `libcublas12` 12.4.5.8 (multiverse). Which cuBLAS version the PLE batch GEMM must be pinned to for +numerical reproducibility is not decided anywhere in the repository. + +## Build + +```sh +cd # branch claude/m2-control-plane +cargo build --release --locked -p strata-desktop-core \ + --bin leleka-inference --bin leleka-daemon --bin leleka-cli --bin leleka-seal-exec +# binaries: target/release/{leleka-inference,leleka-daemon,leleka-cli,leleka-seal-exec} +``` + +(The debug profile of the same four binaries is what the checks below used.) + +## Files + +Gateway configuration: [`desktop-core/examples/daemon.original.json`](../desktop-core/examples/daemon.original.json). The runtime member `id` +is the model name clients send. `artifact_digest` is the digest of the pinned IQ3_S shard pair +(`crates/leleka-runtime/src/backend.rs` `MODEL_DIGEST`); the daemon refuses a runtime whose loaded descriptor differs. + +```json +{ + "schema_version": 1, + "listen": "127.0.0.1:18080", + "token_env": "LELEKA_GATEWAY_TOKEN", + "runtimes": [ + {"id": "qwen-iq3", "address": "127.0.0.1:18766", "token_env": "LELEKA_RUNTIME_TOKEN", + "artifact_digest": "sha256:80d5e3333801cedbca81a5c19c24ed6bb48fd56977acd190318f66b23a1766a3"} + ] +} +``` + +Environment (both tokens: 32..4096 printable ASCII bytes, different values, never in argv or Git): +`LELEKA_RUNTIME_TOKEN`, `LELEKA_GATEWAY_TOKEN`, and `LD_LIBRARY_PATH` including the CUDA 12 cuBLAS directory. +Templates: [`deploy/rust-runtime/`](../deploy/rust-runtime/) (`runtime.env.example`, two user units). + +## Commands (bring-up server paths) + +```sh +A=/home/para/leleka-gates/assets +S=$HOME/leleka-run # private state; staging must be mode 0700 +install -d -m 0700 "$S" "$S/mtp-staging" +export LD_LIBRARY_PATH=$HOME/cuda-toolkits/cublas-12.9.1.4/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} +export LELEKA_RUNTIME_TOKEN=... LELEKA_GATEWAY_TOKEN=... # from a private env file, not typed + +# 1. engine (copies 55 GB into a sealed memfd first, then execs leleka-inference with that fd) +leleka-seal-exec --file $A/qwen-iq3-s-l2-v4.kar --expect-bytes 55295529472 -- \ + leleka-inference --listen 127.0.0.1:18766 --token-env LELEKA_RUNTIME_TOKEN \ + --shard0 $A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf \ + --shard1 $A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf \ + --gpu 0 --gpu-budget 25769803776 --context-tokens 262144 \ + --kar-archive-fd {FD} --kar-provenance $A/qwen-iq3-s-l2-v4.kar.provenance.json \ + --mtp-pack $A/data/mtp-rt --mtp-staging $S/mtp-staging \ + --backend-mode original + +# 2. gateway +leleka-daemon --config desktop-core/examples/daemon.original.json + +# 3. explicit load (the Original serve path requires the KAR PLE MTP profile); returns "accepted" at once +leleka-cli --config desktop-core/examples/daemon.original.json load-mtp qwen-iq3 qwen4exp-kar-ple-mtp-v1 +leleka-cli --config desktop-core/examples/daemon.original.json status # repeat until "model_ready": true +leleka-cli --config desktop-core/examples/daemon.original.json models # lists qwen-iq3 only when ready + +# 4. request +curl -N -H "Authorization: Bearer $LELEKA_GATEWAY_TOKEN" -H 'content-type: application/json' \ + -d '{"model":"qwen-iq3","input":"hello","max_output_tokens":64,"stream":true}' http://127.0.0.1:18080/v1/responses +``` + +Notes taken from the code: + +* `--gpu-budget` 25769803776 is 24 GiB, the default of the bring-up serve smoke (`BUDGET`), not a tuned value. +* `--context-tokens` must be 1..=262144 for `--backend-mode original` (the MTP drafter bank is frozen at the trained context). + 2x256K and 1x512K are outside this path. +* `{FD}` must appear in the command; the descriptor is 3 or higher, has no close-on-exec and carries WRITE|GROW|SHRINK|SEAL. + `leleka-inference` reopens it through `/proc/self/fd/N`, so it needs `/proc`. +* `--backend-mode original` never falls back; `auto` also picks the Original path when the configuration is eligible and + prints `backend=preview (reason)` on stderr otherwise; `preview` is the Rust-native decoder chain. Record the mode used. +* Optional: `--original-prefill-capacity` (256, 512, 1024, 2048, 3072, 4096, 6144, 8192; default 2048), `--mtp-rt-dir`, + `--spec-min-p`. +* `load-mtp` is asynchronous (the daemon's `leleka-cli` HTTP timeout is 10 s). A lost answer is reconciled with + `leleka-cli ... operation MODEL OPERATION_UUID EPOCH`; the CLI prints both before it sends. It never retries. +* After an engine restart the model is **not** loaded again automatically; issue `load-mtp` again (new epoch). +* `leleka-inference` and `leleka-daemon` shut down gracefully on SIGINT only (observed: the daemon exits 0 on SIGINT and with status 143 on SIGTERM); under systemd use `KillSignal=SIGINT`, as the templates do. + +## What was executed for this page (host-side, no model, no GPU context) + +Host: Ubuntu 26.04.1, kernel 7.0.0-38, driver 595.99.02, RTX 5090 idle apart from the bring-up job, which was left alone. +Debug build of the four binaries; `leleka-inference` was started with a **sparse** sealed memfd of the pinned length (no RAM +used) and the real `*.provenance.json`, and stopped before any `Load`. + +| check | result | +| --- | --- | +| `leleka-cli validate` on the example config | `configuration_valid` | +| `leleka-inference ... --backend-mode original` with the sealed sparse fd, the real provenance (SHA-256 verified), real shard/MTP paths | starts, listens on 127.0.0.1:18766, silent on stderr; same for `auto` (no `backend=preview` line) and `preview` | +| same with an unsealed fd | `inherited KAR descriptor is not a pinned sealed archive` | +| same without `--mtp-pack` | `Original serve cannot start: the Original path needs the MTP pack` then `original_serve_unavailable` | +| daemon + inference, before `Load` | `/runtime/status`: `connected: true`, `model_ready: false`; `/v1/models`: empty list; no token: 401 | +| `POST /v1/responses` valid text body, model not loaded | 503 `model_not_ready` | +| body with `previous_response_id`, `tools`, `text.format` json_schema, or a Codex-shaped body (`reasoning`, `include`, `parallel_tool_calls`, `tool_choice`) | 400 `unsupported_request_field` (see `delivery-gap-audit.md`, section 4) | +| `max_output_tokens` 99999 | 400 `invalid_output_limit` | + +Request validation, SSE ordering and finish reasons through the real HTTP/2 gateway are covered by the project's own synthetic +backend (`desktop-core/tests/runtime_gateway_sdet.rs`: `actual_http2_text_maps_single_ordered_sse_terminal`, +`accepted_faults_missing_terminal_and_tool_reason_fail_without_retry`, `daemon_http_disconnect_cancels_one_runtime_generation`) +and, for the full Responses surface, through `strata-next` against scripted engines (`control-plane` tests, +`scripts/test-live-responses-replay.py`, `scripts/smoke-*.py`; results in `delivery-gap-audit.md`, section 1). The synthetic +fixtures are not recorded Codex traffic. + +## Not covered here + +`Load`, any generation, the numerical behaviour of the Original path, systemd operation of the two unit templates (they pass +`systemd-analyze --user verify` only), containers, and any throughput or latency figure.