10 Commits
Author SHA1 Message Date
Robert KarlandClaude Fable 5.1 698b02e1a2 frontend: a picture encoded once is a picture encoded once (USTRAT-15)
A chat client resends the whole conversation every turn, pictures included, and the vision encoder is the slow part
of a request: 6 s a screenshot on 16 CPU threads, 18 s on 6, every turn, while the engine reuses the prompt's KV
prefix in a fraction of a second. Upstream's Python server kept the encoder's output per picture in an LRU of 64
files keyed by the SHA-256 of the picture's bytes (serve/server.py, class Vision); this is that cache for the C++
front end, in memory.

frontend/picture_cache.hpp (header-only, no llama.cpp): PictureCache keeps PictureRows (the projector's output,
n_tok rows of the embedding width) under mtmd's chunk id, which is the SHA-256 of the bitmap's bytes. Shared
pointers, so a request keeps the rows it is writing when the cache lets go of them; two limits, entries and bytes,
the newest entry always kept. engine_key() turns the id into the 64-bit key the engine's conversation cache takes
(img_keys= on the GENI line, #2228), so a picture encoded again with other bits still matches its KV prefix.

encode_pictures is now six short functions: open the file, fill it, find the chunk, its id, its rows (cache or
encoder), its grid, write the record. --picture-cache N (default 64, 1 GiB) sets the size; 0 turns it off.

frontend/tests/picture_cache_test.cpp: hit/miss and counters, LRU order and the entry limit, the byte limit and the
oversize newest entry, a held entry outliving its eviction and a key replaced, off and an empty key, the engine
keys, eight threads at once. In make test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-20 10:33:30 -07:00
Robert KarlandClaude Fable 5.1 b4e28c767a e2e: the literal oracle splits only the literals themselves, as tokenize_plain does
An ordinary one-token text such as "<th" is not split by the server (its attribute is not CONTROL or USER_DEFINED);
the oracle split it and was one token off against the Flash-Next vocabulary.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-19 23:40:54 -07:00
Robert KarlandClaude Fable 5.1 cd3be94f42 frontend: a control token's text inside a message is text (USTRAT-14)
The rendered prompt was tokenized whole with specials parsed, so "<|image_pad|>" in a
document an agent read became the image pad token and the engine refused the request
("the prompt has more images than the embeddings file"); "<|im_end|>" in a tool
result ended a turn. Upstream's Python server marked these literals before the template
rendered (#537, #554); the C++ front end lost that with the server's removal.

frontend/literals.hpp: the texts of the vocabulary's control tokens and marker-like
added tokens (<think>, <tool_call>, [gMASK]) are swapped for private-use marks in the
messages and tools before oaicompat_chat_params_parse renders the template, swapped
back after, and the spans they covered are tokenized as text: parse_special off, and an
added token the tokenizer matches regardless is split until none is left. Media parts
are not scanned. An assistant message keeps a leading whole <think>...</think> block
as the model's markers (clients that send reasoning inline), as upstream did. A mark
that a template's tojson(ensure_ascii=True) escaped as a surrogate pair is read too.
A request without literals renders and tokenizes exactly as before.

mtmd's logger wrote every level to stderr, its debug line add_text() among them: the
whole rendered prompt once per request into the journal. It now goes through the
common log, where debug lines need the server's verbosity raised.

Tests: frontend/tests/literals_test.cpp (no model; nlohmann json, the interface
common_json copies) in make test; e2e.sh runs a third fake-engine server with upstream's
Qwen3 template (frontend/tests/data/qwen3-chat-template.jinja) and checks
usage.prompt_tokens against the prompt tokenized by hand with the literals as text, for
user content, a tool description and an assistant history message.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-19 23:35:32 -07:00
Robert KarlandClaude Fable 5.1 a8469d55b5 step 13: acceptance harness (pi in Docker, four tasks, judges), API-only acceptance script, GLM vocabulary load fix
tools/acceptance/: Dockerfile (pi 0.85.1 image), run-task.sh / run-all.sh / judge.sh / pretty.py, tasks md-toc,
kvstore, bugfix (seeded), minesweeper with hidden tests / black-box judges, models.tsv, README. Runs go to
runs/ (ignored); curated results land under bench/unbiased/ when the campaign closes.

frontend/tests/acceptance-real-engine.sh: PLAN.md step 13 (c): sampled checks, seeded repeat, tool call, decode and
prompt-reading speed against an expected figure with a 15 % band.

frontend/strata_context.cpp: the vocabulary-only load is retried with general.architecture overridden to "llama"
when llama.cpp does not know the file's architecture; GLM 5.3 Flash's file says glm5-next (neurall's fork) and
the front end refused to start (USTRAT-6). Verified on the 2x B200 pod: GLM starts, template renders, answers.

tools/pod/README.md: pod-to-pod tree copy (90 s against hours from the laptop), bringup must wait for the tree.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-18 19:19:36 -07:00
Robert KarlandClaude Fable 5.1 71886db022 Step 8: pictures through the front end, encoded in-process on the CPU, handed to the engine as GENI
--mmproj FILE loads the model's vision projector with llama.cpp's mtmd in the server
process (CPU, --threads or half the cores; the card is the engine's), after checking
that the projector's output width (clip.vision.projection_dim) equals the model's
embedding width from the GGUF metadata and that the vocabulary has <|image_pad|>.
A request's image_url parts come through llama.cpp's own parser as media chunks;
launch() encodes each chunk, writes strata-vision records ('SVE1', rows, nx, ny,
width, float32 rows) to a per-request temp file removed with the slot, replaces the
chunk's placeholders by image_pad ids, and sends GENI <max_new> ... image_pad=<id>
<file> <ids>, which strata-poly (take_pictures) and strata read. Without --mmproj
the parser refuses images with llama.cpp's message; e2e.sh checks that.

Reference: upstream tools/vision/strata_vision.cpp (same records, a child process)
and UnbiasedStrata 1's frontend/vision.hpp. Qwen family only (the pad token);
tiled encoders (MiniCPM-V canvases) are refused. Gate on a real engine follows.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-18 00:21:28 -07:00
Robert KarlandClaude Fable 5.1 96f4ef1fbb frontend: always send usage in the final streamed chunk; fix e2e checks
Upstream PolyStrata's server reports usage on every streamed reply, and its
tools/strata_bench.py reads prompt_tokens from it without sending
stream_options.include_usage. llama.cpp only adds the usage chunk on request,
so the fork's step-9 Flash-Next arm recorded prompt_tokens = null. Set
include_usage on every task result: the last chunk has usage, timings and an
empty choices array (OpenAI's documented shape).

e2e.sh: the health check from 453d3015 compared the json boolean to 'True'
instead of 'true'; the stream checks now skip the empty-choices chunk and
assert usage on it.

Verified: make test under sandbox-exec (engine_test 7 cases, e2e all checks).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-17 23:36:52 -07:00
Robert KarlandClaude Fable 5.1 453d301599 frontend: /health advertises service=strata and loaded=true for upstream clients
Upstream's tools/strata_bench.py (is_strata, wait_ready) only talks to a server
whose /health has service == "strata" and loaded; the fork answered llama.cpp's
{status, busy} only, so the step-9 fork arms never left the readiness wait
(fork-flash-next on the pod sat ready for 30 min, then was killed as 'failed
to start'). Add service, loaded, model, max_context; keep status and busy.
e2e.sh checks the two required fields.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-17 23:28:24 -07:00
Robert KarlandClaude Fable 5.1 2f9004ba5c Step 7: the request shapes a coding agent sends, and pi's task, on both engines; Qwen3.6 UD-Q3_K_M on the A6000
frontend/tests/shapes-real-engine.sh runs seven request shapes against a live server (PLAN.md section 9, step 7): no
max_tokens; max_tokens 32768; a prior assistant message with reasoning_content and tool_calls followed by a tool
result; two tool calls asked for in one turn; a call with its optional arguments before the required one; a client
that disconnects two seconds into a stream, then a clean request; an 18k-token prompt streamed, timing the first byte
and counting SSE pings. Records: bench/unbiased/2026-10-17-{a6000-qwen36-ud-iq4xs-mtp,3090pod-flash-next-iq3xxs}-step7-
shapes/ and -step7-pi/, plus the A6000's Qwen3.6 UD-Q3_K_M smoke (…-a6000-qwen36-ud-q3km-mtp-step6/). docs/MODEL-FILES.md
describes the checks and the SSE ping default.

Verified 2026-10-17:
- Qwen3.6 UD-IQ4_XS on the A6000 and Flash-Next IQ3_XXS on the 3090 pod answer all seven shapes. Without max_tokens the
  front end fills the context (n_predict 32,747); max_tokens 32,768 beyond the context is clamped, not refused; the
  reasoning_content history is accepted and answered from the tool result; the optional-arguments-first call parses
  ("limit", "offset", then "path"); the disconnected stream is cancelled at the engine (finish=cancel after 387 and 172
  tokens) and the next request answers in 0.09 s and 0.24 s; the 18,589-token prompt streams its first byte after 5.2 s
  (Qwen3.6, A6000) and 8.0 s (Flash-Next, pod). Qwen3.6 issued the two parallel calls asked for; Flash-Next chose one
  bash call instead, which is the model's choice, not a parsing fault. No ping was seen because the pinned server pings
  after 30 s of silence (--sse-ping-interval); the run lines will set it lower for long prompts.
- pi 0.85.1 against Flash-Next on the pod completed the same multi-step task as against Qwen3.6: read, --json flag, 7
  unittest tests, all passing, one commit (it also noticed and untracked __pycache__). 17 requests, 16 finish=stop and
  the one cancel from the shapes run, prompts up to 4,644 tokens, max_tokens 32,768 passed through, no parse failure.
- Qwen3.6 UD-Q3_K_M (8966dd0c...) on the A6000: all six smoke checks, 214 to 235 tokens/s decode on short prompts.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-17 22:28:14 -07:00
Robert KarlandClaude Fable 5.1 ef1ee031c7 Step 6: first end-to-end chats through the front end on both engines, equal to upstream; the model-file table
Records under bench/unbiased/, one directory per box and model: the exact launch script, the fork commit, the engine's
info lines and the raw responses of frontend/tests/smoke-real-engine.sh (health, /v1/models, a greedy chat without
thinking, a sampled chat with thinking, a stream, a tool call). docs/MODEL-FILES.md tracks every model file tried, by
source repository, size and SHA-256, with its status; the same quantization from two Unsloth repositories is two rows,
because only the Qwen3.6-35B-A3B-MTP-GGUF files carry the draft block. Upstream's docs/MODELS.md is unchanged.

Verified 2026-10-17:
- Flash-Next GSQ-RCO IQ3_XXS on `strata`, with the pack, the expert profile, spec 4 and MTP exactly as upstream
  PolyStrata v0.1.45-poly.1 ran it on the RTX 3090 pod on 2026-10-17: the front end serves all six checks on the pod
  and on the A6000 VM. The greedy answer ("101\n103\n107", 12 completion tokens) is the same on both boxes and the same
  as upstream PolyStrata's Python server on the same engine binary and files on the pod (upstream-compare/), which is
  the step-6 gate of PLAN.md section 9.
- Qwen3.6-35B-A3B UD-IQ4_XS (MTP repository, SHA-256 df27a780...) on `strata-poly` with upstream setup.py's flags for
  the family: all six checks on the A6000, 207 to 215 tokens/s decode on short prompts, 83% of drafts accepted. The
  stream check ended by max_tokens with thinking on, as expected for a 200-token cap.
- Through an SSH tunnel, pi 0.85.1 with an openai-completions provider pointed at the Qwen3.6 server completed a
  multi-step task in one run: read two files, added a --json flag, wrote 11 unittest tests, ran them, fixed nothing,
  committed. pi sent no max_tokens cap below 28,229 and no min_p; the front end passed both through.
- The pod's /workspace is a geesefs FUSE volume that stalls to a few MB/s when the engine fills its expert cache from
  it while anything writes; the engine then never becomes ready. bench/unbiased/*3090pod*/stage.sh stages the files
  on the container disk (hashes of pack and MTP checked against the pod's artifacts.sha256, shard sizes equal).

Not yet: a speed comparison (the pod's fork decode on the two short smoke prompts was 64 tok/s against upstream's
112 tok/s sustained benchmark; step 9 measures both the same way), Qwen3.6 UD-Q3_K_M (downloaded and hashed, not run).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-17 22:22:10 -07:00
Robert KarlandClaude Fable 5.1 4c25aa6f6a Front end: llama.cpp's server files with the Strata engine behind them (design C), with fake-engine tests
frontend/strata_context.cpp replaces tools/server/server-context.cpp. The other seven server files
(server-http, -queue, -task, -common, -chat, -schema, -stream) compile unmodified from the submodule into
the static library strata_llama_server; frontend/ui_stub/ supplies the empty web-UI asset table that
server-http.cpp references. The context runs one slot: the engine is a child process spoken to over its
line protocol (docs/BACKENDS.md), a vocab-only llama_model provides tokenizing, the chat template and the
reasoning and tool-call parsers, and the server's own task and result types carry the OpenAI JSON, SSE
framing and client-disconnect cancel. Routes kept: /health, /v1/models, /v1/chat/completions, /tokenize,
/detokenize. The strata engine's 8-token reserve is kept out of max_new. A supervisor thread ends the
process with exit code 1 when the engine dies, for a unit with Restart=on-failure.

frontend/engine.hpp is the child adapter: fork+exec, READY/INFO, GEN/GENI, T/PP/RESUME/DONE/ERR/FATAL,
STOP with drain to DONE, non-blocking reap. quit() and the supervisor's reap_exit() share the pid through
an atomic that quit() takes over by exchange, and only a positive local copy ever reaches kill(). The
first draft kept a plain pid_t and the supervisor set it to -1 on reaping, so a SIGTERM during shutdown
raced into kill(-1, SIGKILL), which killed every process of the user; it did so twice on 2026-10-17.

Build: STRATA_FRONTEND (default on) gates the llama.cpp libraries and the front end, not CUDA, so they
build on a machine without a GPU. Makefile: unbiased-strata joins `make build`; `make frontend` builds it
alone without CUDA into build-frontend/; `make test` builds engine_test there and runs it and
frontend/tests/e2e.sh against a fake engine (frontend/tests/fake-engine.py). The nvcc probes run only
when there is an nvcc and only the build and configure goals demand one. UPSTREAM.md records all of it.

Verified on macOS arm64 without CUDA: `make frontend` and `make test` pass. engine_test, 7 cases: READY,
a request, STOP mid-request with drain and a clean next request, a 100k-token burst the caller abandons,
ERR leaves the adapter usable, the engine dying mid-request is diagnosed, a DONE with the wrong prompt
size is visible. e2e.sh, 12 checks: /health, /v1/models, a non-streaming chat with content, finish and
usage, a stream whose deltas join to the content and end with finish_reason and [DONE], a client that
disconnects mid-stream (the server logs the cancel and the next request completes), an oversize prompt
refused with 400, a tokenize/detokenize round trip. Zero new patch lines to llama.cpp, so the step-4
gate of PLAN.md section 5 passes and design C stands. Not yet run against a real engine.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-17 21:31:05 -07:00