Skip to content

Merge upstream main - #57

Merged
plotarmordev merged 85 commits into
mainfrom
feat/65-merge-upstream-main
Nov 14, 2026
Merged

plotarmordev merged 85 commits into
mainfrom
feat/65-merge-upstream-main

Conversation

@plotarmordev

Copy link
Copy Markdown
Owner

laudney and others added 30 commits November 14, 2026 07:24
A serve config file needs a reader, and Zig's standard library has
none for TOML. This one takes a strict subset of TOML 1.0, top-level
key = value lines with strings, decimal numbers, booleans and arrays
of them, and refuses the rest by line, so every file it accepts is
valid TOML with the same meaning and tables stay free for later use.
A launch of ten to twenty flags could live only in a shell script,
where vLLM and SGLang take a config file. serve --config FILE.toml
now turns the file's keys into flags ahead of the command line's,
so the one parser runs and the command line wins; each key is
checked against the flag table first, so an unknown key, a wrong
type or an unserved flag is refused with the file and its line.
Operators need the key rule, the precedence and its three
consequences before they move a launch into a file. This adds the
flag's row to the README table, a page with an example, the value
types, what the reader refuses and how errors name the file, and
the changelog line that also records the --compact-at fix.
The engine now lists --config in its capabilities, so the launcher
took it as an extra flag while it checks only the tokens it sees,
and a file could turn on --cortheon, a learning flag or a key that
Settings manages. The flag joins the managed set, with tests for
both spellings, and the config page states that an integer loses
its leading plus and that the launcher refuses the flag.
The maintainer accepted serve --config with four conditions, since
the file chooses what is served and can hold a key. A relative path
now starts at the file's folder, a file that other users can write
is refused before it is read, a pair of switches has one key
(thinking = false), and arrays hold strings only; the flag table
marks which flags name a path.
The maintainer's review of serve --config found that a refused
value named no line, that a command-line key left the file's key in
force, and that the file was checked by path and then read by path.
Each value now runs its flag's own check before the merge, a
repeatable flag on the command line replaces the file's list, the
file is opened once without following a link and read through that
handle, an api-key file must be unreadable by others, and a path
flag refuses a tilde.
…a_forward.zig has room for TF_GLM_DSEL

A move only: row_step, max_pieces, ranges and Pieces keep their text in
cuda_forward_pieces.zig, beside the pieced exchanges that use them, and
cuda_forward.zig re-exports them, so fw.Pieces, fw.ranges and the rest keep
working. cuda_forward.zig was at the 600-line limit; it is 545 now.
…GLM_DSEL)

MiaAI-Lab's patch 0067 (glm-dsa-decode-select-many-ctas, in
MiaAI-Lab/GLM-5.3-Flash-DGX-Sparks-1104 0049d7c, Apache-2.0), moved onto
main 8be9c40. For decode windows (rows <= Scratch.bits_rows, np >= 4096)
tf_glm_select_rows_wide (one 1,024-thread CTA a row) gives way to two
launches in glm_index_decode.cuh: tf_glm_dsel_scan marks each span's pools
above and at a sampled floor on many CTAs, and tf_glm_dsel_merge picks a
row's K pools from those words (the ties at the floor, the candidates
through tf_glm_select_rows' radix select, or the full-row select). Every
path returns tf_glm_select_rows' bytes. TF_GLM_DSEL=0 keeps today's select
(unset or 1: on; anything else is refused). Decode buffers' Scratch.ls
grows to hold the bit words (about 0.8 MiB a set at 864K); prefill buffers
keep bits_rows 0.

The patch was cut on Mia's stack: the context naming absorb_mma and
glm_glue_p2p/num (not on main) is left out, the rest is as written.
Checks: test-glm-index-host (the switch and the scan's grid) and
test-glm-index-emulate (the kernels as host C++, all four paths, against a
plain top-K); glm-index-check (GPU) compares the device paths.
…e select's comments are one line each

TF_GLM_DSEL is a glm row of platform/environment.zig (a flag: 0 or 1, default
on), in docs/environment.md and in cuda_env_test.zig's switches, so a malformed
value is refused by name with the other GLM settings when the model opens, and
cuda_sparse.zig's own parser goes. The decode select's comments in
glm_index_decode.cuh, cuda_sparse.zig, cuda_glue.zig and glm_index_check.zig are
one line each within 120 columns; the merge's paths are named at its branches.
lean_check.py finds nothing new against main.
… nvcc 13.0's and 13.3's records

contract_glm_dsel.zig registers tf_glm_dsel_scan and tf_glm_dsel_merge as a replacement of tf_glm_select_rows on
the wide select's scores, host rule and checks: each row's K pools come out of cuda_sparse.decodeSelect, their bytes
must equal the 128-thread kernel's on the same scores, then every row's picks the host's rule. It runs at the wide
select's three shapes, where cuda_sparse launches the decode select instead, and at a 1M window's bucket (8 rows of
260,096 pools), in the Index group beside the index scores and the wide select. Its planted control, the same
launches told past two spans that the bucket is one span (4,096 pools) short, goes red at the shapes gate. Gate 5's
records come from kernel-contract-limits over sm_80 to sm_121 fatbins of nvcc 13.0.88 and 13.3.73; 13.3 differs for
the scan on sm_120 and sm_121 (45 registers, 48 on 13.0). nvcc 13.2 was not at hand. The docs name both launches
and the scan in 13.3's set.
…st test, the CHANGELOG line, and one-line comments above

cuda_state.zig's selectLs gives a Buffers' selectTokens list bytes (`ls`) and
the rows of decode select bit words they hold (`bits_rows`), and make() takes
both from it. A host test checks, at a 4K and a 1M window, that a decode's ls
holds bitsBytes(bits_rows, np_max) with bits_rows min(seg, wide_rows), and that
a prompt's buffers keep bits_rows 0. The comments commit 3 had put at the ends
of long lines (cuda_glue.zig's Set, cuda_sparse.zig's decodeSelect path
argument, Scratch, dsel_target and dselScanCtas' 0, and glm_index_check.zig's
planted scores) are one-line comments above. CHANGELOG.md has an Unreleased
line for ashhart#2722 with the credit.
stage.zig stages device memory through tcp.zig behind the same Collective VTable (Kind.tcp). A call only queues on its
stream: the stream writes the call's ready word, then waits for its done word, 64-bit words in pinned host memory. A
proxy thread sees ready, copies the input into a pinned slab on a stream of its own, moves it with tcp.zig, copies the
result back and sets done. The caller's stream gets no copies of ours: with copies queued on it around the wait, two
ranks of one process hung or read stale bytes on ROCm 10.0. A call larger than Options.part_bytes (default 4 MiB,
checked alike when the ranks open) moves in parts, and the frame header's spare word now names the part, so one call in
two parts never pairs with two whole calls.
A failure sets every done word, so no stream waits on it, and shows at the next call or at check. A capturing stream is
refused, and allGatherV moves whole strides.

stage_hip.zig is the HIP device: hipStreamWriteValue64 and hipStreamWaitValue64 on mapped coherent host memory, refused
by name on a GPU without them, and the proxy's copies on a non-blocking stream of its own. stage_test.zig runs
host_test's contract bodies over a device whose copies are memcpy, whole and in 64-byte parts, plus part, size, capture
and device-failure refusals; stage_later_test.zig uses streams that run later, so calls return before anything moves
and an abort still lets a held stream drain; stage_hip_test.zig checks the same on a GPU, two ranks of one device over
loopback, and skips without HIP. `tf-tp-test tcp-hip` runs tcp-host's checks and timings from HIP memory. Nothing
selects it yet, and no other backend changes.
Keep headless per-stream verification at one row while opting into exact cross-stream rounds. Retain the pipelined lone path and test shared transitions without drafts or copies.
…e watch, not a 2 s wall bound

The bring-up test for a peer that stops after agreeing asserted that it was
found dead in under 2 s. Membership promises only that a member is dead once
it has been quiet for dead_ns, found at the watch's first step after that; on
a loaded hosted runner the step came late and the bound failed, sending a
landing train red. The test keeps what the code promises: dead by name, never
before dead_ns, and found by the dead rule before the watch gives up. The
watch window, now watch_ns, grows from 5 s to 30 s so a slow runner still
finds it; a passing run returns at the dead time as before. No change to the
code under test.
…ne, page or slot (ashhart#2135)

The real lane host on the fake target, its lanes taking pages from a counted kv pool, runs 200 requests down each way a request can end without finishing: the six refusals (busy, closed, stale, memory pressure, invalid request, bad decode spans), a cancel while queued behind full lanes, at once, mid-prompt and mid-decode, a backend error in the prompt pass and in a round, and no lane memory with nothing else running, then a mixed run through all of them, on whole and stepped prompts. After each request every host list, load-ledger count, live stream, fake lane, pool lease and page must be back at its idle value, and a normal request is then served. No path strands anything. The rig publishes the pool's census once before it starts, as a paged backend does, so the ledger shows the paged capacity group.
)

GLM-5.3's template writes "Reasoning Effort: Max" when it hears no effort,
so a thinking-off request could not ask for High or Low. With thinking off,
native now passes the template the effort the request (or
--reasoning-effort) named, on the template's levels. With none named, or
`none`, it passes null as before, so default prompts keep their bytes.
Prefix probes, the warm pass and the token-count route carry the same
named effort, so their renders match the request's.

Host tests: GLM-5.3 thinking-off requests with high, low, none, no effort
and a server effort, checked against the template's own render, and
namedEffort's rule (no Kimi max fallback, none is unnamed, request wins).
…shhart#1911)

--reasoning-effort no longer reaches a thinking-off prompt, so default
bytes stay unchanged for every server configuration. The reply's
tensorfold.reasoning_effort names the effort the template heard (the
request's, or none), and the Messages count_tokens route sets the named
effort as the chat route does.

Host tests: a server started with --reasoning-effort high keeps main's
thinking-off prompt; Qwen3.8's template takes a named effort with
thinking off (and reads it only while thinking, so its prompt is
unchanged), with its template and tokenizer config as fixtures.
ashhart and others added 28 commits November 14, 2026 14:20
The serial side of the eight-chain draft test panicked with incorrect
alignment on Linux CI: candidates() reads the top-k columns as i32 from
the draft's u16 host buffer, and a stack [N]u16 is only 2-aligned.
Production host buffers come from the allocator at row scale.
… tool tests, so pytest from the root imports them
…a private journal, checked graph states

The four fixes the review on this PR asked for, each with a test that fails before it:

- transport: a loopback client builds its opener with an empty ProxyHandler, so an ambient
  http_proxy never receives a request or its Authorization header; --allow-remote keeps the
  environment's proxies.
- transport: SSE lines are read with readline(1 MiB + 1), so an oversized line is refused
  without reading it whole, and one stream keeps at most 4 MiB of event data and 4096 events.
- ledger: missing journal directories are created 0700 and the database 0600 (SQLite gives its
  WAL and SHM the same mode); an existing database, WAL or SHM open to other users is refused
  by name. An existing parent directory keeps its mode.
- transport and controller: every graph read checks each fact's state against the native
  graph's states (queued, learning, learned, missed, replaced, deleting, deleted); a missing,
  non-string or unknown state stops the controller before any lesson.
…are the ones checked when SQLite opens them

The re-check of the journal fix found a gap: a file could appear between the mode checks and
SQLite opening it, and the journal accepted a 0666 database, WAL and SHM planted there.

- The journal's own directory must be a real directory owned by this user with mode 0700, or the
  ledger is refused by name; missing directories are created 0700. Only this user can then add
  or replace files in it.
- The database is created O_EXCL|O_NOFOLLOW at 0600; on a collision the existing file is opened
  O_NOFOLLOW and must be a regular file of ours with mode 0600. The lock file is opened
  O_NOFOLLOW too.
- After SQLite opens the database, and again after WAL mode creates the WAL and SHM, the directory
  and database must still be the same files (device and inode), and all three files private;
  anything else is refused before a fact is written.
- The default ledger moves to ~/.local/state/tensorfold/living-weights-v2/ledger.sqlite3, a
  directory of its own, and the docs say what the journal requires.

Regressions: a database swapped in before SQLite opens, one created in the gap after the
directory check, a WAL planted before the open, a linked database, and a shared or linked
directory are each refused, with nothing written to the planted file.
…el lands

On a loaded runner the test thread could lose the CPU between submit and cancel for long enough that the fake engine's 4,096-token reply finished first, so the request ended with length, not cancelled (two strand tests red on train ashhart#3346). The request now pauses in its prompt pass until cancelled, as the queued-cancel test's blockers do; mid-decode cancels stay covered by cancel_decode, which cancels from the host's own first-tokens event.
…d, /api/tags, /api/show, /api/ps, /api/version) over the native engine (ashhart#3117)
…, and the refused-field bodies are JSON

Every test in ollama_e2e_test.zig hung until its 30 s poll timed out, then panicked in deinit.
The cause is the fixture, not the routes: the fake engine sent prefilled and its three tokens
but never `finished`. The engine API says every request ends with `finished`
(core/engine_api.zig:37 and :420), and the server's generation loop
(server/chat_generation.zig:216) ends a reply only when it arrives, so the reply, its socket
and the open connection never ended. The other loopback fixtures (auth_scope_http_test.zig)
send it.

With that fixed, "format, tools and images are mapped or refused by name" failed on its own
bodies: `format":"xml` and the other two fragments lacked their opening quote, so each request
was refused as malformed JSON and the reply never named the field. They are now whole JSON
fields, and each refusal is checked to name its field.

test-ollama-e2e-host runs these loopback tests alone. No route or server code changes.
A stream that sends stream_options.tensorfold_token_stream_version: 1
interleaves tensorfold.token.chunk events (offset and committed IDs)
with the usual chunks, and each chunk carries a tensorfold_stream anchor
(token count, last ID, and each logprob entry's raw token position,
shaped like the chunk's logprobs). Engine integrations such as exo's
proposed TensorFold backend need the real IDs while generation runs,
without retokenizing text that merges UTF-8 pieces, reasoning or tool
syntax. capabilities --json advertises token_stream_versions [1].
Without the option the wire output is unchanged.
…ap body, and proves the cap without a race

"GET body of 65537 bytes against the unread cap" failed on a hosted runner with "[Errno 107]
Transport endpoint is not connected". The server refuses that request on its declared length
(http_body.zig:79) and closes without reading the body, so the unread bytes reset the
connection; on a busy runner the reset can reach the client while it is still sending or
shutting down its side, before it reads the 400.

- exchange() can treat a reset, a closed pipe or a no-longer-connected socket as the server
  closing first. Only the over-cap case asks for that; every other case still fails on it.
- When the server closed first, whatever arrived must not be a 2xx reply, and a complete reply
  must be the expected 400.
- A new case sends only the head declaring 65,537 bytes. Nothing is left unread, so the server
  closes cleanly and its 400 always arrives: the cap is proved on every run, with no race.
…o a run never executes a file mid-write

A hosted runner failed with "failed to spawn and capture stdio from
./zig-out/bin/check-release-paths: FileBusy" (ETXTBSY). Zig 0.17's run step executes an
artifact's installed copy whenever the same build installs it
(lib/compiler/Maker/Step/Run.zig:388, `installed_path orelse` the cache path), without waiting
for the install. compile-release-paths-host installed the same checker that the release
directory and command tests run, so a build doing both, such as test-host, could start a run
while the install was still writing zig-out/bin/check-release-paths.

compile-release-paths-host now installs a compile of its own; the tests' checker is never
installed, so every run starts the finished file in the cache. Both compiles share one cache
entry, so nothing builds twice. Traced with strace in one build of compile-release-paths-host,
test-release-directory-host and test-release-paths-command-host: on main 17 of 18 runs
executed ./zig-out/bin/check-release-paths; now all 18 run from the cache.
…quests, not 150

"sessions writes: on real files the tier writes and reads back exactly what the bench accounts"
timed out at its 20-minute limit on a loaded hosted runner. Its time goes to disk: two runs of
150 mixed requests on real files wrote 576 MiB and read back 382 MiB with O_DIRECT, behind 237
fdatasync calls, one a parked file.

The test now runs 40 requests with every token size halved (pool, slot capacity, prompts,
turns, replies and the conversation cap) and a 512 KiB chunk. That still spills, parks, drops,
reads back and, with SKIP_COVERED, writes deltas and drops covered entries; it now also asserts
the plain drops, the covered drops, and that files average over one chunk, so a restore still
reads across chunks. Real files and the accounted tier must still agree on every count and on
peak use. On this box: 46.6 MiB written, 21.4 MiB read, 46 fdatasync calls; the run takes
0.6 s instead of 5 s.

No change to the code under test.
Folds ashhart#3306 (its three corrections and the unnumbered duplicate it removes) and the lines checked since.
@plotarmordev
plotarmordev merged commit 988fce2 into main Nov 14, 2026
@plotarmordev
plotarmordev deleted the feat/65-merge-upstream-main branch November 14, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants