Skip to content

train 1201001616: #5729 (CI only) - #5789

Closed
ashhart wants to merge 39 commits into
mainfrom
lead/train-1201001616
Closed

ashhart wants to merge 39 commits into
mainfrom
lead/train-1201001616

Conversation

@ashhart

@ashhart ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

CI for a landing train: #5729 stacked on main in that order. Nothing merges from this PR: each PR above lands on its own once this tip is green, and this PR is then closed.

… checked file by file (#2349)

The registry hands out a scope value, an id and a token, keeps only the
token's sha256, and checks a presented token in constant time. A bundle is
written into a part directory and renamed into place after its manifest; on
import every listed file must match its size and sha256, and a file the
manifest doesn't list is refused, so no planted state rides in. Not wired to
the server or the engine yet.
…#2349)

A scope's store has the shared store's family and rules and no disk tier,
so nothing kept in it reaches the shared cache, --learn or the disk. Its
states and bytes are taken from the shared store (whose entries are evicted
to fit) and given back when it goes, so all stores together stay inside the
family's snapshot slots. A running job holds a reference, so a dropped
scope's store is freed only when its last job ends. At most four scopes.
…re (#2349)

api.Request carries a scope (0: the shared cache). A lane host resolves a
scoped job's store when its stream opens, before any lookup, keep or warm
pass, holds a reference until the job finishes, and never falls back to the
shared cache: a scope with no store here finishes the job as
handover_not_loaded. Scoped jobs never prefetch from the shared disk, never
wait on a shared fill, are not written to the --recall record and are not
reported to the shared store's repeat log. The scope stores go with the
engine thread's last flush.
…d cache (#2349)

With the shared cache holding the very same prompt's state, a scoped request
prefills from 0 and keeps only in its scope's store; its next turn resumes
from that store; an ordinary request still resumes from the shared cache;
and a request naming a scope with no store here fails without a lookup or a
keep anywhere. The scope stores go when the host stops.
… per job (#2349)

Export writes the scope's longest state for the prompt with a rows store of
the shared store's keying opened at the bundle's part directory, then seals
and renames it. Import checks the bundle file by file first, reads its one
state with every error returned and adds the entry only after the read, so a
failure leaves nothing in RAM. An ask the engine never answers reads as a
failure.

From review: a job takes its scope reference once, not on every
admission, and a readmitted job whose scope was dropped while it waited
fails; changed weights clear the scope stores too. Regression tests requeue
a scoped request under memory pressure and readmit it.
… renders (#2349)

POST /v1/imprint/handover makes a scope and answers its id and token once;
DELETE /v1/imprint/handover forgets it, its store and its bundle. POST
/v1/imprint/export writes the scope's state into a bundle; POST
/v1/imprint/import adopts the id on this server, checks the bundle and reads
it into the scope's store, and a failed first import forgets the id again.
A chat body's "handover": {"id", "token"} is checked before anything is
rendered and sets the request's scope; the server's warm pass keeps a scoped
reply in the same scope. Each refusal carries its status and code: 404
handover_not_found or handover_no_state, 403 handover_denied, 409
handover_foreign_build, 422 handover_corrupt. Expired scopes are swept on
each handover call.
…hared one (#2349)

From review: lane_host_pressure.step held and shed only the shared
store, so a scope's store could keep states under pressure.
…ot_loaded (#2349)

A request whose scope was dropped while it waited fails in the lane host with
handover_not_loaded; the server now answers that as 409 with its code, not as
a bare 400. After a failed first import the id is forgotten, so a chat with it
answers 404 handover_not_found: keeping failed ids would let anyone grow the
registry by importing random ids.
Server.deinit ended with gpa.destroy(srv), so a deferred registry deinit ran
on freed memory: every server stopping after a handover call segfaulted at
shutdown (seen on the GB10 and the Mac gates). The registry goes first now.
…nk (#2349)

From review of the bundle: seal now syncs every file, the
manifest, the store and part directories, renames, then syncs the bundles
root, so a sealed bundle survives a crash; bundle directories are 0700 and
their files 0600. verify checks entry kinds before reading anything: the
manifest must be a plain file, the store a directory and every store entry a
plain file, so a link is refused by name and nothing is read through one.
What stays: a process running as the server's own user can still change files
between verify and read; the store's own per-file hash still checks them as
they are read.
… capped (#2349)

From a second review of the bundle: the bundles root and part directory are
made 0700 before the engine's writer (or a copy) puts anything in them, so no
bundle byte is ever readable by another user whatever the umask. Files are
hashed in 1 MiB pieces, never read whole, opened without following a link in
the last part of the path, and a bundle is capped at 4096 files and 32 GiB,
refused before anything is read. The checks are by path and done before the
store's own reads, so a process running as the server's own user changing
files in between is outside this prototype.
tf-cuda-test handover-save DIR MODEL IDS keeps the prompt's state a few
tokens before its end through a prompt store with the disk writer attached,
as a server keeps it, and seals it into a bundle; handover-load DIR MODEL IDS,
a new process, checks the bundle, reads the state back, restores it over
another prompt's rows and resumes. resume_tests.zig's digest (each layer's KV
rows, the Mamba states, the head's rows, the last hidden row, the logits and
the first token) must equal a fresh pass's in both processes.

The runner imports engine_api and a module rooted at native/cuda_disk.zig
for the store and Nemotron's disk image; engine_api exports handover_bundle.

On a GB10 (Nemotron 3.5 Lightning NVFP4, a 7,653-token prompt): a
state at 7,648 sealed, read back in a new process and resumed 5 tokens to a
digest equal to the fresh pass's and the writer's.
… token (#2349)

From review: an import answered 200 after reading the state, but
the restore runs when the next request's prompt pass starts, and a backend
that refuses a kept state prefills from 0, so a handover could quietly
become a fresh prefill. Now a scoped job whose restore failed sends nothing:
firstCommitted holds back its first token, and the fill path and the
whole-prompt path drop it as handover_not_loaded (409 at the server) before
any round runs. Scoped jobs never go to the lone driver, which commits tokens
inside one backend call. The fake backend gains refuse_restores, and a lane
host test checks the failure and that no token reaches the client.

tf-cuda-test handover-save takes the row to keep at (default: five before the
prompt's end).
…lback keeps nothing (#2349)

From review: a failed restore drops the bad entry, so
retrying the same scoped request found an empty store and prefilled; and
Job.kept could run during the backend call and keep the fallback prefill's
states. Now a refused restore marks the scope lost, Job.kept keeps nothing
for a scoped job whose restore failed, and a request in a lost scope, or in
an imported scope whose store is empty, fails as handover_not_loaded. The
lane host test retries the same request: it fails again, and neither the
shared nor the scoped store gains an entry.
…r one fails (#2349)

Ash's planted fault: a scope can hold a shorter RAM state of the same prompt
while the handed-over (longer) state fails to restore or a later import fails
to read. Both paths now return their handover errors (409 handover_not_loaded
after a refused restore, 422 handover_corrupt on a bad bundle) and mark the
scope lost, so a later request cannot resume the shorter state. Fake can
refuse a restore of one length while a shorter one of the same prompt would
still restore. Lean comments are one line, and the files this series pushed
over 600 lines are back under the cap vs current main.
…bSystem memcpy (#2349)

A typed std.json.parseFromSlice(Manifest) pulls compiler-rt's memcpy over libSystem's.
zig build test failed the tensorfold-native nm check; main 3f1290f passed it.
Value parse matches flashnext/tp_settings.zig. Native memcpy check and zig build test pass.
Import opened <root>/<id> with link following, so a link to a valid bundle
passed the no-symlink check. Open with no-follow and do every check and
read relative to that directory handle.
Verify checked types and digests but never uid or mode, so a copied
world-readable bundle imported. Before any read, the id directory, the
store directory and each file must be this user's with no group or world
bits; otherwise handover_corrupt. Docs say what import requires.
)

reader() attached the global Recall store for any drafted request, so a
handover scope could copy another session's draft history. Guard it the
same way writes() already excludes scope != 0. Stream-local suffix and
MTP drafts stay; only the shared record is withheld.
…ate copy (#2349)

The parent of the private copy is opened once with no-follow, must be this
uid with no group/world write, and the temp and the id directory are created
and opened relative to that handle. A symlink parent and a world-writable
parent both refuse the import.
…flag is off (#2349)

POST /v1/imprint/handover, /export, /import and DELETE /v1/imprint/handover
are unknown paths unless the server was started with --prompt-cache-disk DIR
or --learn-conversations. A chat body's handover field is ignored when the
flag is off. docs/api.md lists the routes, the single-use token, the error
codes, owner-only import and the 2.00 GiB in 7.6 s copy.
…sk cache (#2349)

Ash: open the PR off unless the server is started with it. Hanging the
routes on --prompt-cache-disk would give every disk-cache server four new
routes after an update. --handover is refused at startup without
--prompt-cache-disk DIR (or --learn-conversations). With the disk cache
on and --handover absent, the four routes answer 404 unknown path and a
chat with or without a handover field is unchanged.
… cuda_disk (#2349)

Zig 0.17: a source file may belong to only one module. The runner roots
cuda_disk.zig as its own module for the handover gate. Current main's
prompt_pages file-imports cuda_snaps.zig, and that file's request-starts
test imported cuda.zig, which file-imports cuda_disk.zig. compile-cuda-tests
then fails. cuda.zig.registry is cuda_families.registry; import that file.
…hat answers 409 (#2349)

Ash's condition 2 on 12 Nov: when the handed-over state fails to read, the
import answers 422 handover_corrupt, and a request after it answers 409
handover_not_loaded. A failed first import used to forget the id, so that
request answered 404 handover_not_found instead.

verify now reports once the bundle is found and the caller's token is its
own and unexpired. A failure after that (a foreign build, a file that fails
its check, a state that fails to read, a prompt it is not a prefix of, no
room) keeps the id on this server with no store, so the next chat in that
handover answers 409. A missing bundle or a token that is not the bundle's
proves nothing and still leaves the id unknown, so a stranger cannot grow the
registry by guessing ids.
…500 (#2349)

Only the lane host sends handover asks to handover_engine. Flash Next's
Metal host answers imprint asks through Ask.answer, which returned early for
them and left error.HandoverUnanswered, so POST /v1/imprint/handover answered
500 handover_failed there. Ask.answer now names them unsupported, and the
route answers 501 handover_unsupported. An ask left when an engine stops is
still unanswered.
The import kept its own copy of rows_read's room check from before main
taught it that a pool without trim (GLM's snapshot pages) reads into spare
storage it reuses. It now calls rows_read.ready, so the two cannot drift.
Ash on 10 Nov: a handover is single use, so a third session gets its own
export from the second. A bundle stayed on disk after a successful import, so
another process holding the token could import the same state again. The
import now removes the bundle once its state is in the scope's store; the
second session's export writes a new one. A failed import leaves it.
…ck beside a shorter one (#2349)

Ash's condition 2: a shorter state of the same prompt sits in RAM while the
handed-over state fails to read. Session A keeps a 300-token prompt's state
in its scope and exports it through the store's own writer; one payload byte
of its block file is flipped and the manifest's sha256 sealed again, so every
file passes its check and only the read fails. Session B, a new lane host
over the same disk, holds shorter states of that prompt in its shared cache
and in its scope. The import answers handover_corrupt (422) with no file
named and the token proven; both scoped requests after it, the longer prompt
and the shorter one's own, fail as handover_not_loaded (409) with nothing
resumed, sent or kept; an ordinary request still resumes the shared shorter
state. With the scope not marked lost on a failed import, the test fails.
ThinkOffApp and others added 9 commits December 1, 2026 00:16
…s code, the off path (#2349)

The real routes, server and lane host with the fake target, each serving
process a new server over one disk root:

- A makes a scope, answers one turn and exports; B imports, resumes exactly
  the state's length (cached_tokens equal to loaded_tokens) with a reply equal
  to a fresh server's, and the same request without the handover resumes 0;
  B's longer turn is exported and a third server C imports and resumes it.
  The bundle is gone after each import.
- Each planted fault answers its own code: a token not the bundle's 403, a
  missing bundle 404, a foreign build 409 then 409 handover_not_loaded, a
  refused restore 409 handover_not_loaded on that request and every later one
  in the handover, a corrupt bundle 422 then 409; none sends a reply, and a
  shorter state of the same prompt in the shared cache never stands in.
- With --handover on and no handover named, replies and cached tokens equal
  the flag off.

The fake target is not a model: the digests, cached counts and time to first
token on a real checkpoint are the CUDA gate's.
tf-cuda-test roots native/cuda_disk.zig as its own module for the handover
gate, and Zig 0.17 lets a file belong to one module only. Two test imports on
main tied that module's files to the runner's prompt_pages module:
cuda_snaps_test.zig took the family registry through cuda.zig, and
cuda_kept.zig's test block reached cuda_refusal.zig, cuda_kv_pool.zig and
cuda_prompt_pages.zig. The registry now comes from cuda_families.zig, as
cuda_snaps.zig's own test already does, and cuda_kept_test.zig is registered
from cuda.zig's test block, which test-cuda-kept-host's root still reaches.

The gate's prefillFrom calls pass the empty cut list main's resume_tests.zig
passes since prefill took explicit request cuts.

zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu builds tf-cuda-test;
nothing ran on a GPU.
A successful import deleted its bundle afterwards and ignored a failed
delete, so the bundle could be imported again. The import now renames
<root>/<id> to .<id>.used-<random> before the state goes live. One rename
wins between racing imports in any process, and a failed rename refuses
the import. A failed install renames the bundle back. A leftover from a
failed delete has a name no import can ask for, and dropping the scope
retries the delete.

The new HTTP test makes the bundle undeletable before session B imports
it. Session C's import of the same id must answer 404. Against the old
import code it answers 200.
…2349)

On a backend that keeps no reply rows' bits (decoded_rows false, as on
CUDA Nemotron), the lane host keys kept states with no reply spans, but
the handover export and import passed the request's spans through. Any
conversation holding an earlier reply never matched: export answered
404 handover_no_state while a chat in the same handover resumed the
state. Found running the HTTP gate on a GB10 with Nemotron.

New lane test: a scoped turn with a reply span is kept, exported and
imported into another scope, and resumes the exported length. Before
this change its export fails with HandoverNoState.
…as (#2349)

A failed import marked an existing scope lost for any error, so retrying
an import whose bundle this scope had already consumed (404) threw away
the state it held, and every later chat answered 409. Nothing was read
or restored on that path. A scope is now marked lost only when the
import proved the bundle was its own and then failed (a read, restore
or build mismatch), which keeps the 422 then 409 gate as before.

The three-session HTTP test retries B's import after it succeeded: 404
handover_not_found, then B's chat in that handover still resumes exactly
the loaded tokens. With the old rule that chat answers 409.
…2349)

tf-cuda-test handover-save-fn DIR MODEL IDS [AT] and handover-load-fn DIR MODEL IDS
do for Flash Next what handover-save and handover-load do for Nemotron: the same
store, disk tier, bundle, checks and output. save and load take the run as a type;
Nemotron's keep pass and resume moved into its Run with their lines unchanged.

handover_flashnext.zig opens the family as the server does (native.open, the MTP
head on, a 16,384-token window). Its keep pass marks AT through the lane host's
hook into a store whose copies are the family's snap_* decls and whose disk image is
cuda_disk.keptDisk's. The new process resumes the read-back state as a served
request does, a stream whose reuse names it, after the reversed prompt ran through
the same engine and gave its lane blocks back; the stream must report AT cached.

The digest hashes the lane after the prompt: each DeltaNet layer's conv window and
recurrent state; each attention layer's key, value and indexer-key rows and its
complete pooled blocks; the n-gram tail and history; the MTP head's cache, a row
short; the hidden row the head reads; the logits row; the first token. Its byte
count must equal snap_bytes at the prompt's length.

zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu builds tf-cuda-test;
nothing ran on a GPU.
… fd (#2349)

On Linux a plain openDir is an O_PATH descriptor, and fchmod refuses it,
so the test failed in CI before reaching its checks. Opening the store
directories for iteration gives an ordinary descriptor on every
platform. Test-only change.
Requests with no handover scope (scope 0) never take the new refusal, scoped
store or report branch, so the default serving path is unchanged.
@ashhart ashhart closed this Dec 1, 2026
@ashhart ashhart reopened this Dec 1, 2026
@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner Author

Conflicts with main (main moved after stacking); restacking.

@ashhart ashhart closed this Dec 1, 2026
@ashhart
ashhart deleted the lead/train-1201001616 branch December 1, 2026 03:21
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.

2 participants