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>
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>
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>
Adds the 49 specimens of Strata upstream's serve/test_tool_corpus.py (MIT, provenance and licence in
control-plane/tests/fixtures/tool_corpus/NOTICE.md; reporter handles removed) and the six quoted-call value shapes of
serve/test_quoted_call_values.py as control-plane/tests/tool_corpus.rs. 41 specimens are Qwen-form and run against
tool_output (whole through parse_complete, streamed through Incremental in pieces of 1/3/7 and cut at every character);
the 8 DSML specimens are skipped, there is no DSML parser here.
On main 11 of 41 specimens and 2 of 6 quoted value shapes are read as upstream expects. The rest are listed in
KNOWN_FAILURES / KNOWN_QUOTED_FAILURES (strict both ways: a listed specimen that starts passing fails the test) and in
docs/tool-call-corpus.md. No parser change in this commit.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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>
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>
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>
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>
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>
- deploy/Dockerfile.windows-build cross-compiles the six executables (mingw, no Visual Studio needed)
- control-plane/build.rs: the ggml link stubs are used for every Windows target, not only MSVC
- scripts/windows/Start-Leleka.ps1 (igpu | cpu | npu modes, speculation and cache slots on by default) and Package-Windows.ps1
- docs/windows-runtime.md; stale statements in docs/cpu-runtime.md corrected
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The Codex tic-tac-toe run (job 943) ended after 4 minutes: the model wrote the whole index.html in one tool call, hit the
runtime's 4096-token output cap three times (tool call unterminated -> response.failed 'tool parameter is incomplete', then
'incomplete: max_output_tokens' -> turn.failed -> Codex exit 1). The Original server has no such cap (max_tokens 0 = the rest
of the context). RuntimeServer, the engine request check, strata-next's runtime default, the leleka-deploy generated config
and the examples now use leleka_backend_api::MAX_OUTPUT_TOKENS = 32768. /v1/status keeps the Python server's key set when no
prefix cache exists (http_surface golden regressed with the prefix-cache merge).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- guard_archive maps a private read-only reopen of the descriptor (a write-sealed memfd refuses a shared mapping that could become writable on
kernels up to 5.15); the residency read runs on its own thread; the sampler survives a panic and a stale level is re-evaluated by the
requests themselves; cgroup v1 memory controller limits (WSL2 hybrid, old container hosts) are honoured.
- examples/swap_ab + scripts/memory/swap_ab.sh: A/B (unlocked, heal, mlock) of the memfd under real pressure fenced into one cgroup.
- Miri: procfs/host/plan/pressure/inventory/census/ledger/governor run clean (61 tests).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- leleka-runtime: memory_governor glue (startup plan with refusal, KAR memfd lock/residency guard, VRAM check, load-ledger stages,
inventory classes), prefix budget from the governor (auto/explicit clamped), shed directive applied per request and per prefill chunk,
engine-side admission (503 memory_pressure text), page-cache release of the shards after the resident bank load, cgroup-aware
available_memory.
- backend-api: Backend::memory_report (default None) and ScriptedEngine support; proto Snapshot.memory_json; desktop-core runtime_rpc and
runtime-client carry it.
- control-plane: MemoryView, /v1/status `memory`, /metrics `memory`, 503 memory_pressure + Retry-After gate before queueing, engine-side
refusal text mapped to the same 503; tests incl. a 600-request model-free soak (threads/fds/RSS flat).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
reasoning_budget_tokens, strata_tune, experimental_speed_projection and sampling finer than the
text contract's fixed point were queued and then refused as 502 generation_failed; the HTTP layer
now answers 400 unsupported_request_field / invalid_sampling_precision for a text-level engine.
Every failed generation logs its client-visible message; STRATA_DEBUG_FAILED_OUTPUT=1 also logs
the generated text of a failed tool turn (operator debugging only).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The gpt-oss template writes "Current date: <UTC today>" into the system message, which is part of
the prefix a worker's KV cache is matched on, so every cache missed once a day at midnight UTC.
prompt_date in the config (STRATA_PROMPT_DATE) now selects: utc (default, unchanged), a fixed
YYYY-MM-DD, or none, which leaves the line out (RenderOptions::omit_date; the blank line after it
stays) for clients that give the date as a function tool. The control plane does not host tools;
the client supplies the tool.
Teacher-forced on four 770-957 token prompts the model is not indifferent: dropping the line
moves the next-token distribution by mean KL 0.034-0.056 (best token same at 89-90%), changing
only the date value by 0.023-0.040 (92-93%), numerical noise 0.005-0.023 (93-97%). Task quality
was not measured, so none is opt-in. Checked end to end through the control plane: 68 input
tokens for "Hi" with the date, 57 without, 68 with a fixed date; a bad value is refused at start.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
engine.extra_workers starts further supervised workers behind the one request channel
(control-plane/src/pool.rs). A dispatcher hands each request to an idle, ready worker,
preferring the one whose last prompt shares the longest prefix with it, so each conversation
keeps its cached prefix. It learns completion by relaying the result channel, so the worker
and its tests are unchanged. /ready and /status need every member ready. 4 dispatcher tests;
the 13 failing control-plane tests fail identically at 3ebcb3f (Windows).
Paired A/B, two scripted 4-turn episodes sent at once (Compare-ConcurrentEpisodes.ps1, 3
alternating pairs each), time until both are done:
- one iGPU worker, interleaved: 686-713 s; pool: 254-306 s, 2.33-2.73x. Mostly the second
KV cache: the single worker re-prefilled every turn.
- one iGPU worker running the episodes in sequence: 317-342 s; pool: 292-303 s,
1.05-1.14x. This is the second device's own share. Per-turn latency in the pool is higher.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The KAR codec moves unchanged from control-plane/src/kar_codec.rs into crates/kar-codec
(re-exported there, so the control plane's KAR tests are unchanged and pass). Probes, off
unless set: LELEKA_EXPERIMENTAL_KAR_LEVELS / _KAR_TENSORS for attention and output weights,
and LELEKA_EXPERIMENTAL_KAR_EXPERT_LEVELS / _KAR_EXPERT_LAYERS for the MXFP4 experts
(level 0 is a storage-only control). Teacher-forced against llama.cpp, baseline KL 0.016:
attention+output at 6.5/5.5/4.5 bits give KL 0.063/0.095/0.213 (uniform rounding was
0.071/0.112/0.270), and every tensor group fails alone; experts of 6 of 24 layers at 3.5
bits give KL 0.081 (control 0.018). No KAR rate passes the gate on this model. Corrects the
earlier doc claim that a KAR layout is the same as uniform rounding.
iGPU and NPU prefill run at the same time give 93-98 tok/s in total against 73-77 for the
faster device alone (2048 tokens each, two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
flock belongs to the open file description. A child that another test forks while the handle
is open keeps the description until it execs, so a lock can outlive drop() by milliseconds in a
parallel run. The journal and history tests now retry the reopen for up to 10 s; production keeps
refusing a held lock at once. 12 of 12 consecutive parallel runs of the desktop-core lib suite
pass (3 of 5 failed before). Also: documented runtime config example, validated by a test.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
text.format becomes optional so a text object may carry only a verbosity. concise/detailed
summaries, max_tool_calls and other include values stay refused. New HTTP tests run a Codex-shaped
two-turn exchange with stateless replay and the tool_choice / parallel_tool_calls enforcement
through the runtime stack.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fake_runtime is a leleka.runtime.v1 server (the real RuntimeServer) whose engine is the same
engine.sh the smokes already use; fixture.runtime_stack() swaps strata-next's engine child for
it when STRATA_TEST_FAKE_RUNTIME is set, otherwise nothing changes. scripts/test-api-over-runtime.py
runs the ten smokes whose assertions do not depend on strata-next owning the engine process.
The HTTP layer clamps reasoning_tokens to the engine-reported output total, which a text-level
engine's re-tokenized pieces can otherwise exceed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
runtime.{address,token_env,tokenizer_dir,model,mode,max_context} are validated at load
(loopback only, credential from the environment and never printed, exclusive with
engine/native_model/mtp_pack/vision/gpu). serve spawns backend_worker over GrpcBackend.
The worker carries the runtime's output-token cap in WorkerStatus; a default budget never
exceeds it, an explicit request above it is refused. Request ids are UUIDs, as the
runtime contract requires.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
backend_worker drives any leleka_backend_api::Backend through the GenerationCommand
channel strata-next already uses. It maps the rendered prompt to the engine contract
(verified round trip of the ids), re-tokenizes text deltas with a byte-equality check,
recognises the stop literals, maps finish reasons, cancels on client disconnect,
guarantees a terminal event when the engine dies, and re-attaches by itself. What the
text contract cannot carry is refused. 23 HTTP tests over a scripted engine cover
Responses (JSON/SSE), Chat, tools, text.format, cancellation and engine faults.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
eprintln! panics when stderr is unwritable (consumer gone: EPIPE, disk full:
ENOSPC). worker.rs logged before it marked the worker Failed, so with a dead log
consumer the supervisor task died, readiness stayed true and later requests hit a
dead worker (charter M1 / Gate A). All diagnostics now go through the
non-panicking elog! macro.
tests/log_failure_sse.rs starts the real strata-next binary with a scripted
engine, drops the stderr consumer after startup and provokes a protocol failure
inside a streamed Responses request: the stream must end with response.failed and
readiness must drop (the control case with a live sink passes before and after;
the dead-sink case failed before). A source scan keeps eprintln! out of the crate.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>