Commit Graph
98 Commits
Author SHA1 Message Date
Pavlo Ratushnyi e765c06ae3 STRA-338 S7: last_activity at the start and end of a request reads the request's clock
run_backend_worker (twice per request) and the stdio worker's run_session (once per request) stamp last_activity with
ObsHandle::now(). The stamps at attach or READY and the per-engine-line stamp keep Instant::now(). The instant-now ratchet
of strata-control falls from 26 to 23. Docs: gateway-ports.md lists what is and is not behind the Clock.
2026-11-06 01:36:49 +01:00
Pavlo Ratushnyi c0f6888310 STRA-338 S21: the pure part of the Anthropic Messages adapter moves to leleka-gateway-domain
messages/request.rs (the Messages request types and Request::into_responses, CountRequest, text and block helpers) and
messages/reply.rs (message, stop reason, tool_use block, usage, the error type table and envelope as functions of the
status number) are in crates/gateway-domain. strata-control keeps the route layers, the SSE adaptation and the HTTP errors;
error_value(StatusCode, ..) is a wrapper over the domain function. The adapter tests stay where they are and pass on the
moved code (same test ids). The long functions are added to docs/architecture/tech-debt.md, the continuation is recorded in
docs/experiments/stra-338-gateway-track.md (90 golden cases; an earlier commit message says 96, which was a miscount).
2026-11-06 01:29:57 +01:00
Pavlo Ratushnyi 4394ac3337 STRA-338 S21: the Harmony prompt of a gpt-oss request moves to leleka-gateway-domain
harmony_conversation (the Responses input as Harmony messages), harmony_render (developer message, tools, rendering through
leleka-harmony, the date given by the caller) and prompt_date (PromptDate, its parser, civil_date) are in
crates/gateway-domain/src/responses/. strata-control keeps the process-wide prompt date, today() and render(request) in
responses/harmony_prompt.rs with the inline tests, so the byte-exact Harmony prompt tests keep their ids and pass on the
moved code. render_at lost its cfg(test) because the tests live in the other crate. Function texts are unchanged; the long
ones are added to docs/architecture/tech-debt.md.
2026-11-06 01:21:16 +01:00
Pavlo Ratushnyi 339a4c82cc STRA-338 S7: the request record and the worker request stamps read the Clock port
ReqCtx (the per-request record behind the structured request line) holds the Clock from Observe and stamps admitted,
engine_start, first_token and the line itself with it; Record::from_state takes the time as an argument. The backend
worker (serve_one start, conclude end) and the stdio worker (combine_done start) read the request's own clock through
ObsHandle::now(), which falls back to the system clock when the request has no record. These are request-level stamps;
the per-event stamps (last_progress, drain and stop deadlines, activity stamps) keep calling Instant::now() and stay on
the instant-now ratchet, which fell from 31 to 26 for strata-control.

New test: the_record_stamps_come_from_the_injected_clock (a ManualClock gives queue_ms 40 and ttft_ms 100).
Docs: gateway-ports.md says which stamps are behind the port, describes the serve() phases, and records the S10 default
(the offline CLI groups stay in strata-control).
2026-11-06 01:13:30 +01:00
Pavlo Ratushnyi a0052cda6c STRA-338 S7: serve() is a list of phase functions (state, engine, http children), none over 30 lines
serve() was one function of about 240 lines. It is now the ordered list of start-up phases (load config and history, check
host, embedded engine, provision, bind, state, MCP, CORS warning, codec, vision, prompt switches, runtime worker, worker or
pool, idle unload, serve, stop) and the phases live in serve/state.rs, serve/engine.rs and serve/http.rs. The order of the
side effects is the old order; the state is still handed to the router by value (the engine channel closes when the server
stops); every string literal of the old file (log and error texts) is present unchanged. The 149-column log line is now
wrapped with a string continuation that produces the same text.
2026-11-06 01:12:37 +01:00
Pavlo Ratushnyi 5d2564f4ff STRA-338 S6: control-plane/src/responses.rs children named by responsibility (intake, create, route, history, resources, errors, tool_recovery, reasoning, render)
responses.rs is 97 lines (311 at the start of this step, after the domain move); the mechanical child names impl_* and
*_fn are gone. Function texts are moved without change; the fields and constants that sibling modules read became
pub(super). Public paths (responses::create, create_route, retrieve, delete, input_items, count_input_tokens,
ResponseHistory, HistoryResponseStore, TracedJson, PromptDate, set_prompt_date, set_tool_call_recovery and the domain
types) are unchanged. Functions that still miss the limits are listed in docs/architecture/tech-debt.md.

Linux test ids of strata-control, strata-desktop-core, leleka-gateway-text and leleka-gateway-domain: 0 changed,
0 missing against the tip before S21 wider (2 new: the golden test and its ignored regenerator).
2026-11-06 01:00:39 +01:00
Pavlo Ratushnyi 3aa96fbf0e STRA-338 S21: the pure Responses protocol moves from strata-control to leleka-gateway-domain
CreateRequest, TextOptions, TextFormat, its validation and tool-choice rules, OutputItem, Usage, ResponseTrace with its
event stream, the prompt rendering (render_request_with), the output parsing and reasoning split (parse_output_items_with,
decode_generation_noted), reasoning_effort and the schema checks now live in crates/gateway-domain/src/responses/.
strata-control re-exports the types under responses::* and keeps thin wrappers with the old signatures for the places that
need a process flag, a stage span or a log line. The text of the moved functions is unchanged; the edits are listed in
docs/architecture/tech-debt.md (S21 wider).

Evidence: the golden fixture committed just before this (control-plane/tests/fixtures/golden/responses_pure.json, recorded
from the old code, 96 cases of render, validate, trace and parse) passes on the new code, and the Linux test ids of
strata-control, strata-desktop-core, leleka-gateway-text and leleka-gateway-domain are unchanged (0 changed, 0 missing).

Gate: --update-baseline --allow-increase was used for two entries. process-global:leleka-gateway-domain 0 -> 3 is the
memo of tool_schema_accepted moving with its function (process-global:strata-control fell 14 -> 11, the sum is unchanged).
render.rs is a new moved file of 405 lines (one 385-line legacy function), listed as debt.
2026-11-06 00:50:30 +01:00
Pavlo Ratushnyi 02b5aedc23 STRA-338 S21: golden fixture of the pure Responses protocol (validation, prompt rendering, response trace, tool-call parsing), recorded from the code before it moves 2026-11-06 00:39:42 +01:00
Pavlo Ratushnyi 705125f858 STRA-338 S21: Clock in three more handlers, gateway-track report and ports doc
server_api::{ensure_loaded, model_busy, load_post} stamp last_activity from state.services.clock instead of
tokio::time::Instant::now() (instant-now:strata-control 34 -> 31; SystemClock returns the same value). The baseline is
tightened. docs/experiments/stra-338-gateway-track.md records the commands, the per-step test-outcome comparison (Linux:
597 ok before, 615 ok after, 0 changed, 0 missing), the gate movement and what was not done;
docs/architecture/gateway-ports.md shows the AppState groups and the domain crate.
2026-11-05 20:49:47 +01:00
Pavlo Ratushnyi ff6cb3dcbf STRA-338 S21: leleka-gateway-domain (layer L2): the pure gateway domain leaves strata-control
New crate crates/gateway-domain, the first member of layer L2 in architecture.json (L2 is now a pure layer: tokio, axum,
reqwest, libc and the other adapter crates are forbidden dependencies there). It depends on serde, serde_json,
leleka-sampler-ref and leleka-tokenizer only. Moved out of control-plane/src with git mv, content unchanged apart from
paths: sampling (request sampling extensions, validation) and EngineTune (was in wire.rs), reasoning_budget (the budget
driver and its tests), codec (Family, TextCodec, TokenDecoder, QwenCodec), json_order, and the Chat Completions
translation (chat_completions: Request -> Responses request, reply fields; the axum handlers stay in chat.rs).
strata-control re-exports codec, json_order, reasoning_budget and sampling under their old paths, and wire.rs re-exports
EngineTune, so no caller and no test outside the moved modules changed. 4 new tests cover the chat translation.

Architecture gate: layer entry added; dyn-trait:leleka-gateway-domain = 5 appears because the five dyn in the moved
code (Box<dyn TokenDecoder>, Box<dyn Iterator> in the budget driver, &dyn Fn, ...) change crate; dyn-trait:strata-control
fell 21 -> 16 in the same step, so the total is unchanged (--allow-increase was needed for the new per-crate key only).
Test outcomes: 597 ok / 2 ignored before, 615 ok / 2 ignored after (18 new tests); the 13 moved tests keep their ids in the
new crate and their outcome.
2026-11-05 20:42:48 +01:00
Pavlo Ratushnyi 5dc28316ab STRA-338 S7: split worker, vision, prometheus, service_install and config by responsibility; name the modules after what they hold
* worker.rs (1271 lines, 1120 of them tests) is 149 lines; the supervisor tests are worker/tests.rs (shared fixtures) and
  worker/tests/{deadlines,handshake,generation,restart,lifecycle,reasoning}.rs. The test names are unchanged; their path
  gains the topic module (worker::tests::restart::..., see scripts/dev/test-outcomes.py compare: 23 MOVED, outcomes equal).
* vision.rs 402 -> 120 lines (tests are vision/tests.rs, same test ids); prometheus.rs 441 -> 50 (the series table is
  prometheus/series.rs); service_install.rs 436 -> 30 (the unix half is service_install/unix.rs and unix/tests.rs, same ids).
* config: Config::load_with_path (430 lines in one function) hands its limits, engine-worker and MCP sections to
  config/methods/load_sections.rs; the same checks run in the same order with the same messages.
* mcp, request_log, vision, worker, config: impl_*/note_*/check_* file names are now hub.rs, server.rs, stdio_transport.rs,
  http_transport.rs, parse_config.rs, obs_handle.rs, engine_counters.rs, encoder.rs, cleanup.rs, generation_result.rs, ...
  Public paths are unchanged (the modules re-export with glob as before).

Architecture gate: five oversize entries leave the baseline (worker.rs, vision.rs, prometheus.rs, service_install.rs,
config impl_config_2_2.rs); no number rose.
2026-11-05 20:33:04 +01:00
Pavlo Ratushnyi 3530208024 STRA-338 S7: AppState in four groups, app/ routes split by role, main.rs becomes a dispatcher plus the composition root
AppState (app/state.rs) is now lifecycle + EngineLink (client port, control channel, worker status, pool,
queue timeout) + HttpPolicy (api key, CORS, trusted origins) + ModelView (name, aliases, tokenizer, template,
vision port, prefix-cache and memory views) + Services (response store, monitor, MCP port, settings, clock,
started_at). Field uses were rewritten mechanically (state.worker -> state.engine.worker, ...); no handler logic
changed. The old impl_default_for_appstate.rs, which held the route table and the admin handlers, is app/routes.rs,
app/admin_routes.rs and app/readiness.rs.

main.rs (1156 lines: an 840-line argument match, the serve function, two helpers) is now 8 lines. The argument match
is split into command groups under src/cli/ (operations, model_fetch, model_inspect, model_ensure, model_prepare,
kar_inspect, kar_verify, kar_overlay, model_text; each owns its arms in their old order and answers Ok(false) for a
line it does not own), serve() and shutdown_signal() are src/serve.rs (the composition root), the usage text is
cli/usage.rs. The binary name and every command line are unchanged.

Architecture gate: control-plane/src/main.rs leaves the oversize list (1156 -> 8). --allow-increase was used because
the type change forces the AppState struct literals in seven already-oversize test/example files to nest by group:
cp_replay.rs +7, responses/tests.rs +11, backend_worker_http.rs +14, mcp_hub.rs +3, memory_gate_http.rs +7,
vision_http.rs +6, desktop-core api_over_runtime.rs +6 (55 lines in all, against 1148 lines removed from main.rs).
Test outcomes are unchanged (597 ok / 2 ignored before and after, 14 new tests from S16).
2026-11-05 20:22:10 +01:00
Pavlo Ratushnyi 35bf3a03d3 STRA-338 S16: gateway ports (EngineClient, ResponseStore, Clock, ToolHub, VisionEncoder) with adapters and fakes
AppState now holds ports instead of concrete types: `engine: Option<SharedEngine>` replaces the
mpsc::Sender<GenerationCommand>, `responses: SharedResponseStore` replaces Arc<RwLock<ResponseHistory>>,
`clock: SharedClock` serves queue deadlines, uptime and response timestamps, `mcp` is a ToolHub and `vision` a
VisionEncoder. The channel (adapters::ChannelEngine), the history with its disk snapshot
(responses::HistoryResponseStore), the system clock, mcp::Hub and vision::Vision are the adapters; main.rs serve()
composes them. No behaviour change: the HTTP handlers make the same calls in the same order, the queue claim race is
unchanged, only the deadline now reads the injected clock.

Ports are called per request, never per token or stream event (docs/architecture/gateway-ports.md).
ports/fakes has an in-memory adapter per port; control-plane/tests/ports_fakes.rs (12 tests), queue.rs and
adapters/channel_engine.rs add tests that drive the real handlers through them.

Architecture gate: dyn-trait:strata-control fell 35 -> 21 (a BoxError alias replaces 20 `Box<dyn Error>` spellings,
which pays for the 6 new port aliases); main.rs 1156 -> 1155 lines. Also adds scripts/dev/test-outcomes.py (per-test
outcome comparison of two cargo test logs) and scripts/dev/wsl-cargo.sh.
2026-11-05 20:06:28 +01:00
Pavlo Ratushnyi cb790da36b STRA-338 S12d: long impl blocks are cut between methods and the remaining oversize modules split (53 files)
The splitter now cuts an inherent impl longer than its target into several impl blocks of the same type between associated items (the generics and where clause repeated, the doc comment kept on the first block), so the giant impls left by S12b/S12c (up to 2,000 lines) split too. 53 further module files of the cold and hot crates are split; the baseline drops to 127 oversize files holding 109,000 lines (329 files and 303,000 lines on main). Types, constants, macros, tests and the files kar-off-ab edits stay; crate roots and bins are untouched.
2026-11-05 16:16:36 +01:00
Pavlo Ratushnyi 3254b1912b STRA-338 S12b (fix): the child module of reasoning_budget no longer shares its parent's name (clippy::module_inception) 2026-11-05 15:34:16 +01:00
Pavlo Ratushnyi 6b5fcd242e STRA-338 S12b: fns and impl blocks of 59 cold oversize modules move into child modules (model-format, gateway, desktop-core, leaf libraries)
scripts/dev/split_module.py (lexer-based, with 16 self-tests) moves the top-level fn and impl items of 59 oversize module files in control-plane, desktop-core, model-format, gateway-text, leleka-memory, experimental-ref, context, serving-policy, tokenizer, backend-api, quant-core, harmony, igpu, libc-shim, npu-service and runtime-client into foo/<name>.rs groups of about 250 lines; types, constants, macros, nested modules and tests stay, every path stays valid through pub use re-exports, restricted visibilities keep their scope one level down, include paths and super:: paths are shifted. Not touched: leleka-runtime, cuda-driver, native-cpu-expert, sampler-ref and cpu-* (hot path, next wave) and the files kar-off-ab edits.

The baseline drops from 311 to 263 oversize files and from 273,600 to about 233,000 lines; the path-include ratchet ignores dir/name.rs child declarations.
2026-11-05 15:29:39 +01:00
Pavlo Ratushnyi 84880a1a6d STRA-338 S12a (fix): rustfmt the moved test files of the format-gated crates
The dedent by four spaces changed how rustfmt wraps some test lines; the 25 affected tests.rs files (strata-control, desktop-core, runtime-client, deploy, gateway-text and the strict crates) are formatted so cargo fmt --check stays clean for the crates that CI gates on. Only test files change.
2026-11-05 15:00:36 +01:00
Pavlo Ratushnyi f78b89757c STRA-338 S12a: inline unit-test modules move to sibling tests.rs files in 118 oversize files
scripts/dev/extract_tests.py moves a trailing cfg(test) mod tests block into foo/tests.rs for 118 files of leleka-runtime, cuda-driver, control-plane, gateway-text, deploy and nine smaller crates (31,000 lines), leaving production code and test ids untouched; 22 files that are themselves loaded through a path attribute carry an explicit path to their tests file. Not touched: the files the kar-off-ab branch edits (backend.rs, backend_original_serve.rs, backend_original_serve_replay.rs, qwen4exp_resident_expert_source.rs and seven deploy files).

Verified: cargo check --all-targets for the whole workspace on x86_64 Linux and on the Windows host; the 2429 library unit-test ids of the workspace are identical before and after (Linux listing diff empty); the loadable sections of leleka-inference, leleka-daemon, leleka-cli and strata-next are byte-identical between a release build before and after (scripts/dev/elf-sections-equal.sh), so the shipped code is the same. The architecture ratchets exclude tests.rs from the path-include count; the baseline drops from 329 to 311 oversize files and from 302,000 to 273,600 lines.
2026-11-05 15:00:09 +01:00
Pavlo Ratushnyi 28192c2fcd STRA-338 S6 (improve): ToolStream stays private to the tools module
The re-export of ToolStream from responses/stream.rs was unused and failed Clippy -D warnings on Linux (unused import); the struct is only used inside tools.rs, so it is private again and only stream_live_tools is re-exported.
2026-11-05 14:09:51 +01:00
Pavlo Ratushnyi c10563ab08 STRA-338 S6 (improve): streaming splits into text, buffered and tools modules; authored lines wrapped to 120 columns
responses/stream.rs (755 lines) becomes three modules of 173, 199 and 327 lines plus a 74-line root that re-exports them, a pure move with only the visibility widened to the responses tree; the documentation lines written in this work for worker-protocol, gateway-text and stream.rs are wrapped to the 120-column limit of the maintainability rules, and AGENTS.md names the architecture gate. cargo test -p strata-control and cargo fmt --check stay green.
2026-11-05 14:05:07 +01:00
Pavlo Ratushnyi 52d554e72c STRA-338 S6 part 2: SSE streaming leaves responses.rs; architecture gate rewritten to the 301 limits
The text, buffered and tool-call streaming code of the Responses API (750 lines) moves from control-plane/src/responses.rs to responses/stream.rs without a logic change, and the architecture gate becomes a small package (scripts/archcheck) whose functions stay within 30 lines, complexity 10, nesting 4 and 5 parameters.

The source counters now stop only at a column-0 cfg(test) module, so a single cfg(test) function no longer hides the code after it; that raises some measured baselines (cuda-driver, runtime, model-format, strata-control) without any code change, and the baseline was rewritten using --allow-increase for that reason alone.

Verified: cargo test -p strata-control 277 lib tests, 0 failed; 18 gate self-tests pass; fmt clean.
2026-11-05 13:47:14 +01:00
Pavlo Ratushnyi 810c13721f control-plane: responses.rs unit tests move to responses/tests.rs (STRA-338 S6, part 1)
Pure move of the 2960-line #[cfg(test)] module into a child file (responses.rs 6490 -> 3528 lines); one relative include_str path
adjusted. Architecture gate: a split into a same-stem directory is accepted when the family does not grow; test files are not counted
by the source ratchets (they replace inline cfg(test) modules, which were already skipped).

Verified: cargo test -p strata-control --lib 277 passed, 0 failed (baseline 279 minus the 2 tests moved by S9); fmt clean.
2026-11-05 13:40:55 +01:00
Pavlo Ratushnyi 6155c871b0 worker-protocol: one crate for both ends of the gateway/worker line protocol (STRA-338 S9)
New dependency-free crate crates/worker-protocol (L0): events (Event, Done, Finish, parse_line, moved from control-plane/src/wire.rs),
command (GEN/STOP/QUIT parser, moved from cpu-worker/src/protocol.rs) and lines (READY/T/PP/REUSED/ERR/DONE writers, moved from
cpu-worker). Finish was defined twice (gateway and worker) and is now one enum with a word(). wire.rs re-exports the event types and
cpu-worker/protocol.rs re-exports the old paths, so no caller changes. The gateway's rich GEN writer (golden-tested against the Python
server) stays in wire.rs. New golden: every line the worker writes round-trips through the gateway parser.

Verified (host): cargo test leleka-worker-protocol 8/8, cpu-worker, strata-control all green (0 failed); the 6 moved tests keep their
bodies; clippy -D warnings clean on the new crate; fmt clean.
2026-11-05 13:37:05 +01:00
Pavlo Ratushnyi 7b1922d116 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.
2026-11-05 13:32:35 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 97c33d8b2c Offline differentials: port the Strata 0.1.50 chat-template empty-turn filter, GGUF types 143-146, native PLE key types; fix two stale smokes
chat template (prompt bytes): ChatTemplate.render (#843) drops completed empty assistant turns
(no text after strip, no picture, no tool calls; the final message is kept; STRATA_KEEP_EMPTY_TURNS=1
keeps them) before the template runs. prompt.rs now does the same in Renderer::render and in the typed
render_with_images path. diff_chat_template: 136/3000 -> 0 (also 2 x 12000). chat_template_oracle.json
regenerated from the Original; one responses.rs test asserted the old behaviour.

gguf: block_geometry knows the APR trellis types 143-146 (PTQ1_0, TQ2_T, TQK6, TQK7); gguf_headers.json
regenerated. diff_gguf_header: 188/400 -> 0.

native pack: NATIVE_PLE_KEY gained IQ3_XXS/IQ4_XS (#381); NVFP4 expert tails and prism.hadamard experts
are refused (not ported, the runtime reads neither). diff_native_pack f16_nan uses a quiet NaN (numpy's
widening of a signaling NaN differs between builds). The live differential still needs one run on Linux.

smoke-mtp-pack.py reads the Q8_0 names from required[]/wq(); Dockerfile.systemd-smoke drops its apt
version pins. docs/ci-audit.md findings 14, 15, 16, 18 updated in place.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 03:39:53 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 2e7c28a11f fix: error tool_result wrapper has sorted keys again; key order of model-visible JSON is explicit, not a feature-unification accident
serde_json/preserve_order was switched on for strata-next on 2026-10-14 by leleka-harmony (c2290e114, which noted the
effect on tool-call arguments and changed one test) and the Messages error wrapper {"content":...,"is_error":true}
became {"is_error":true,"content":...} without a line of it changing; scripts/smoke-messages.py (sort_keys=True) went red.

* control-plane/src/json_order.rs: to_string_sorted (recursive, independent of the feature) and error_result_text;
  messages.rs uses it, and its unit test asserts the exact bytes instead of the parsed value.
* preserve_order is declared by strata-control and strata-desktop-core (and documented in leleka-harmony): the Original is
  Python, so replayed tool-call arguments, tool schemas, text.format schemas and MCP result blocks keep the order the client
  or the model wrote. A build of desktop-core alone (docs/deploy.md section 8) sorted them before.
* guard tests that fail when the feature is off (control-plane, desktop-core, harmony), tests for the order of replayed and
  model-written tool-call arguments in both gateways, and corrected comments in prompt.rs and mcp.rs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 01:42:08 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 72fc3b0820 style: cargo fmt on strata-control, strata-desktop-core, leleka-runtime-client; clear Clippy lints and two red tests on main
Mechanical rustfmt (control-plane, desktop-core and the runtime client had 360 hunks of drift; the CI format steps for control-plane and
desktop-core were red), plus, found by running `cargo clippy -D warnings` and the tests on Linux:
* control-plane/tests/log_failure_sse.rs `no_panicking_log_macros_in_the_serving_crate` was red on main since the observability merge: two
  test-only `eprintln!` samples (prometheus.rs, request_log.rs) trip its source scan. They now write to stderr with `write_fmt` and
  ignore a failed write, which is what the test asks for; the output is the same.
* tool_output.rs `is_multiple_of(2)`, an unneeded `mut` in a control-plane test, a collapsible `if` in leleka-inference.rs,
  `#[allow(dead_code)]` on observer_adaptive_slots (compiled into leleka-inference-evaluation too).
* crates/deploy/src/facts.rs: `lab_holder_running` moved above `mod tests` (clippy::items_after_test_module); code moved, not changed.
Kept as its own commit so it can be redone with `cargo fmt` if other branches touch these crates first. No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 00:30:27 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 92fd4c636c observability: middleware test, display scrub in leleka logs, engine line fields in leleka-memory, keep "fatal:" in the supervisor's message
* request_log: a test drives the real `observe` layer over HTTP (id header, session header hashed, rejection counted).
* leleka logs scrubs credentials once more on display (lines written by other programs or older builds).
* the engine's per-request line is built by leleka_memory::telemetry::request_line_fields (pure, tested for content and size: 313 bytes);
  the tier share of one request is tier_shares().
* the supervisor's fatal event keeps the "fatal: " text in its message, which crates/deploy/tests/e2e.rs and operators' greps rely on
  (crates/deploy e2e on Linux: an_engine_that_cannot_start_fails_the_service_and_names_the_log passes again).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 23:30:32 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 fb10bf0e70 observability: structured bounded logs, per-request record, metrics, leleka logs / report
* crates/obs (leleka-obs, std only): one event per line (JSON under `leleka run`, key=value on a terminal, the lab's plain lines when a
  binary is started by hand into a file), UTC ms timestamp, level, component, event, flat fields; prompt/completion text and credentials
  never appear (key classes + value scrub + registered secrets), per-event token buckets with a `suppressed` count, value and line caps,
  histogram with Prometheus exposition, size-capped file sink for requests.log.
* control-plane: `observe` middleware gives every generation request an id (x-leleka-request-id header) and a session tag (hash of the
  client's session header); the worker marks engine start / first token / terminal / error on it and one record is written at request end
  (tokens, cached prefix, queue wait, TTFT, prefill/decode tok/s, finish, error class, engine restart, GPU clock/temp/throttle). All
  elog! lines go through the log layer (sampled per call site). /metrics?format=prometheus gains request counters and histograms, engine
  lost/attached counters, uptime and supervisor restarts, PCIe, memory clock, throttle reasons, speculative tokens per round, expert-tier
  entries by tier and hit ratio.
* engine: one structured line per request with the same id (rounds, tokens per round, expert-tier share served from VRAM/PCIe/CPU for that
  request); telemetry gains spec / expert_tier / last_request; NVML sampler reads PCIe throughput, memory clock, throttle reasons.
* supervisor: structured events (engine exit, health, restarts), secrets registered with the log layer, children get LELEKA_REQUEST_LOG,
  LELEKA_STATUS_FILE, LELEKA_PROFILE and JSON logging; runtime-client and gateway log connect/probe failures as sampled events.
* leleka logs (--tail/--since/--level/--component/--source/--request/--follow), leleka report (sanitized support bundle, written only with
  --yes, nothing sent anywhere), request statistics in leleka status / verify --quick.
* generation, sampling and kernels are untouched; the lab scripts keep their plain lines (LELEKA_LOG_FORMAT=legacy or a hand-started binary).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 23:25:24 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 ab54ae208f feat: experimental tool_call_recovery for drifted tool-call forms (default OFF)
Adds Options::recovery to tool_output and an opt-in setting, `tool_call_recovery` (config key) / STRATA_TOOL_CALL_RECOVERY=1
(environment, wins over the file; 0/false turns it off; anything else stops the start). It is off unless set, is read once at
start, logs "tool_call_recovery is ON (experimental)" at start, and logs every call it accepts. It is NOT part of the default
contract and has not passed a quality gate (docs/api-contract.md, "Tool-call recovery (experimental)").

With it on, a call for a DECLARED tool written next to the template form is read as the call (upstream 3fcb2106, #3441):
* <parameter=NAME> where <function=NAME> belongs; <=NAME>, <function:NAME>, <function =NAME> or <NAME> after <tool_call>;
* {"name": ..., "arguments": {...}} inside <tool_call>, also in a Markdown fence, arguments possibly a JSON string;
* a bare <function=NAME> ... </function> at the start of a line outside a code fence and inline code (a stray </tool_call>
  after it is dropped); the Markdown state is tracked over the text that has left the stream buffer, so streamed and whole
  readings agree;
* a second call in the same <tool_call>;
* for array/object arguments, brackets left open at the end and a bare string where an object member belongs (dropped).
An undeclared name stays an error in every form. Streaming: a batch is delivered when its </tool_call> arrives, a bare call when
the text after it shows it is over or at the end.

With the option off the reading is byte for byte the step-3 reading. The corpus test now reads every specimen twice (off and on)
and lists the failures of each; every streamed cut agrees with the whole reading in both. Recovery rate on the 41 Qwen specimens:
off 24/41 (58.5 %), on 30/41 (73.2 %); the 6 specimens that need recovery: off 0/6, on 6/6. That is code reach on upstream's
failure corpus, not a rate for real sessions. strata-control lib 339 passed (new: 3 recovery tests, 1 config test), corpus and the
quoted-value shapes pass with the option on and off.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 03:54:39 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 f528844ff9 fix: read the recoverable tool-call cases instead of failing the response
Four shapes that ended in response.failed (or 502 tool_call_parse_failed) are now calls, each logged on stderr as
"tool call accepted beyond the template form (closers supplied: N, arguments repaired: M, ...)":

* </function> left out: a </parameter> followed by </tool_call> ends the value and the call, but only when no </parameter>
  followed by <parameter= or </function> ends the value (upstream d7113273, #4427/#4077). A streamed response delivers such
  a call when the generation ends, not at its </tool_call>: only the end can tell it from </parameter></tool_call> quoted
  inside a value.
* </tool_call> left out: the call is whole when the next <tool_call><function=NAME> follows its </function>, or when its
  </function> ends a generation that stopped by itself (finish stop). A generation cut by the token limit never gets this.
* A call inside the reasoning (no </think>): a normal stop whose text ends on whole calls of declared tools, the first at
  the start of a line outside a code fence and inline code, is reasoning (completed) followed by those calls (upstream
  805ebe17/d7113273, #804). The calls' markup was already streamed as reasoning deltas; the final reasoning item ends before it.
* Damaged array/object arguments of a parameter declared array or object (not a union with string): a trailing or doubled
  comma, single quotes, Python True/False/None, extra closing brackets, and an array written as a JSON string of itself are read
  as written (upstream _Lenient, A4). Nothing is invented or dropped; open brackets and bare strings are not repaired here.

Undeclared tool names: upstream returns the call as text and counts it. That is NOT adopted. Text without a call ends an
agent's turn as if it were the answer, while a failed response is retried by the client (docs/e2e-run.md records a session that
survived one such failure), and native_tools_sdet / backend_worker_http pin the refusal. An undeclared tool is still an error;
it is never run and never published.

API: tool_output::{Options, Notes, Parsed, parse_with, calls_at_end}, Incremental::{with_options, finish_after, notes};
parse_complete and Incremental::new keep their strict default reading. Documented in docs/api-contract.md ("Tool-call
parsing") and docs/tool-call-corpus.md.

Corpus: 24 of 41 specimens read as upstream expects (13 before this commit). New unit tests cover each shape whole and
streamed; strata-control lib 334 passed, native_tools_sdet 14 passed, existing tests unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 03:48:29 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 9b07fdd995 fix: a string argument that quotes a tool call is no longer cut at the quoted text
tool_output::find_parameter_end ended a value at the first </parameter> followed by <parameter= or </function>, so a write
whose content quoted a whole call (a file that documents the format, a heredoc, a test) was published with content cut at the
quote and the rest as plain text, whole and streamed, without any error (upstream #4078, fixed there in 77794e34 and b72f56e0).
It now follows upstream's quote rule: a close inside a call the value itself quotes (more quoted <function=NAME> openers
followed by <parameter= or </function> than </function> closers before it) is part of the value. One forward pass over the
value. Incremental also stops re-trying candidate call ends it has already rejected.

A call whose value quotes an opener and never closes it is now unterminated (an error) instead of being cut at the first
plausible close, so a long write that quotes a call and is itself cut by the token limit is not published truncated.

Deliberately not taken from upstream: a value that reopens its own parameter (</parameter><parameter=content> inside content).
Upstream reads it as text; here it is byte for byte a parameter written twice, which desktop-core's
native_tools_sdet::unknown_incomplete_duplicate_or_late_invalid_call_refuses_entire_output requires to be refused, and merging
the two into one argument would hide a malformed call. It stays an error (duplicate tool parameter), listed as known failure.

Regression tests: specimens 4078-nested-call and 4078-heredoc and the quoted-value shapes "quoted call", "quoted call at the
end" and "heredoc" of the ported corpus failed on the previous commit and pass here (13 of 41 specimens, 5 of 6 shapes), plus a
unit test for the cut outer call. The 8 existing tool_output tests and the 14 native_tools_sdet tests pass unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 03:45:24 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 3bedec6107 test: mcp unknown-block text keeps key order (serde_json preserve_order via leleka-harmony)
Linux / keyless-cuda-gate (push) Skipped
Rust port / port-typecheck (push) Failing after 9s
Rust port / port-oracles (push) Failing after 10s
Rust port / port-linux-tests (push) Failing after 15s
Rust port / port-fast (push) Failing after 9s
Linux / verify (push) Failing after 18s
Linux / keyless-cuda (push) Skipped
Linux / static-cuda-package (push) Skipped
Linux / hosted-cuda-package (push) Skipped
Linux / linux-static-cli (push) Skipped
Linux / linux-cli-container (push) Skipped
Linux / release-cli (push) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-27 08:36:02 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 b3274c1130 Merge claude/port-gpu-bringup (CUDA runtime port, upstream sync) into main
Linux / keyless-cuda-gate (push) Skipped
Rust port / port-typecheck (push) Failing after 8s
Desktop foundation / core (ubuntu-latest) (push) Failing after 11s
Rust port / port-oracles (push) Failing after 11s
Rust port / port-linux-tests (push) Failing after 14s
Rust port / port-fast (push) Failing after 9s
Linux / verify (push) Failing after 17s
Linux / keyless-cuda (push) Skipped
Linux / static-cuda-package (push) Skipped
Linux / hosted-cuda-package (push) Skipped
Linux / linux-static-cli (push) Skipped
Linux / linux-cli-container (push) Skipped
Linux / release-cli (push) Skipped
Brings the Rust/CUDA port of the Strata mode17 serve path together with the
CPU/iGPU/NPU gpt-oss runtime that main gained meanwhile.

Control plane: the Qwen tokenizer is the implementation behind the Qwen35
variant of codec::TextCodec (qwen(), encode_prompt() widen the trait; QwenCodec
derefs to the tokenizer), so control-token marks, images, chat template, the
runtime backend and vision keep their behavior, while the gpt-oss/Harmony path
and the worker pool keep main's. Config carries the union of fields; extra_workers
is rejected together with runtime, lazy_load, idle_unload_s and vision; the
gpt-oss family refuses top_k/min_p/penalties (its GEN line has no such keys).
leleka-kar-codec takes f16_bits_to_f32 from leleka-quant-core (identical code).
Workspace members and default-members are the union of both sides.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-27 08:32:33 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 f7ab3fd59c Control-token text inside messages is ordinary text (plan 0.1; upstream c16f31f8, 98b7ea94, 0d613031)
leleka_tokenizer::LiteralMarks swaps every special literal (GGUF token type 3 and 4) in a client string for a plane-15 private-use mark
before the chat template runs (a forged mark is escaped); Tokenizer::encode_marked parses the template's own literals as special tokens and
encodes each mark's literal as ordinary text. render_request marks instructions, message text, reasoning, call arguments, tool outputs and
tool descriptions/schemas; the gateway's own tool markers stay literal. Generation and /input_tokens share the one encoding; the text
contract carries the marked string and leleka-runtime reads it with encode_marked.

Not covered: strata-desktop-core still renders unmarked text; live Codex session (gate L) not run.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 23:31:05 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 c5be696205 Windows: stop the children with Ctrl-Break in their own process groups (the engine, gateway and API handle it), so leleka down takes seconds instead of three grace periods; hidden mode hides the console instead of freeing it; no readiness summary after up --mode none
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 16:58:41 +01:00
Pavlo Ratushnyi e64a3da1b7 Merge branch 'claude/platform' into claude/port-gpu-bringup
# Conflicts:
#	crates/deploy/src/app.rs
#	crates/deploy/src/cli.rs
2026-10-25 14:06:50 +01:00
Pavlo Ratushnyi 4965126d14 Merge branch 'claude/windows' into claude/port-gpu-bringup
Rust port / port-fast (push) Failing after 10s
Rust port / port-typecheck (push) Failing after 10s
Rust port / port-oracles (push) Failing after 16s
Rust port / port-linux-tests (push) Failing after 22s
2026-10-25 13:15:34 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 da6f8f2f48 metrics: empty hardware blocks and a null telemetry member while the engine publishes nothing
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 13:05:12 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 1a77b2805c metrics: history is the last 60 health-tick samples, documented as such
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:57:51 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 1bbb9d1b8e desktop-core and control-plane build and test natively on Windows: api-key init (hard-link publish, user profile ACL), atomic no-replace directory publish via MoveFileExW, tokenizer export without directory fsync, MSVC link stubs for the ggml bridge, Unix-only shell-script tests gated
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:45:21 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 4d28f0a250 reconfigure: kv_resident is fixed per process and cpu_workers is 1..=15 (found by live job 9r1); reconfigure takes 7 s and waits for the request in flight
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:42:33 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 02abdddf70 tests: real nvidia-smi output as fixtures; /api/requests is behind the API key
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:42:04 +01:00
Pavlo Ratushnyi 75e7e47dcc control-plane: /api/requests monitor, the Python Monitor members of /metrics, Prometheus text exposition
Opt-in api_monitor keeps the last 100 requests of the chat, messages and responses dialects; /metrics gains engine, live, requests, totals, hardware, history; ?format=prometheus (or a scraper Accept) renders the same document as gauges and counters. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:18:32 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 60b48d8225 runtime reconfiguration: reopen the serve stack with new context/cache/resource settings without reloading the model
serve_tuning (settings document, validation, effective settings), Command::Reconfigure in the Original serve loop with rollback,
Backend::reconfigure, gRPC Runtime.Reconfigure, POST /v1/reconfigure, telemetry.settings; tests for each layer.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 03:01:53 +01:00
Pavlo RatushnyiandClaude Sonnet 5.5 9e0914df26 gateway: an undeclared apply_patch function call runs through the declared shell tool instead of failing the stream
The model sometimes calls apply_patch as a function although Codex declares only exec_command/write_stdin; the stream
failed, Codex retried into the same call and the turn died (live job 9e1 after 6 requests).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 22:22:28 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 08e2c78761 runtime telemetry: GPU load/VRAM (NVML), RAM, CPU cores, prefill/decode tok/s, cache hits, context
leleka-memory::telemetry (sampler + per-request records) -> Backend::telemetry_report -> Snapshot.telemetry_json
(gRPC) -> control plane /v1/status machine -> leleka status.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 19:58:28 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 ea80310017 cp-latency: schema-validation memo, live A/B client and report, live job 9f1 (real engine, baseline and current API servers on one engine)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 01:45:54 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 6bbb26f67a cp-latency: native chat rendering for text conversations (verified against the template), log writes off the response path, replay --verify (captured Codex prompt ids)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 01:30:26 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 95340330ac cp-latency: fast tokenizer (scanner + id BPE + segment cache), pass the prompt text through, TCP_NODELAY on the runtime gRPC server, gRPC replay example
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 01:13:50 +02:00