Repository navigation
Team Drift step 1: hand a kept prompt state to another session of the same model (#2349) - #5729
Conversation
|
Thanks, @ThinkOffApp. This is a thorough first step, and the gate table made it easy to check. Confirmed on this head:
It merges cleanly with main. What's left is a green CI run on this head. We'll add the changelog line when it lands.
|
|
READY to land on this head. Reviewed at this head: we added one commit that re-pins zig/src/core/lane_host.zig in the serving identities (the zig job failed only on that pin; requests with no handover scope never reach the new code). With the flag off nothing changes; a handed state carries the disk tier's identity and a timing-safe token, the resumed digests on a GB10 equal fresh ones, and this head's CI passed.
|
df8e01d to
9b33ce4
Compare
|
READY to land on this head. Rebased onto main with the author's commits kept; the only conflict was the serving pins row for lane_host.zig, carried with both notes and re-hashed. This head was cleared to land before it fell behind main, and the handover routes stay off unless --handover is given.
|
9b33ce4 to
138e3ca
Compare
|
READY to land on this head. Rebased onto main, plus our Windows fix: the bundle code read and wrote through C read/write on a Windows file handle, which failed and was taken as a length; reads and writes now go through the platform I/O layer, and the 24 handover tests that panicked on Windows run there. Handover stays off unless --handover is given.
|
138e3ca to
2e1f085
Compare
|
READY to land on this head. Rebased onto main with two of our fixes: the bundle code reads and writes through the platform I/O layer, and --handover refuses at startup on Windows by name with its tests skipped there, as the page disk tier does. POSIX behaviour and tests are unchanged, and handover stays off unless --handover is given.
|
2e1f085 to
cef5540
Compare
Synthena Initial Review — Needs changes (
|
cef5540 to
63e6521
Compare
Synthena Initial Review — Needs changes (
|
|
READY to land on this head. This head adds our Windows fixes. File syncs in the handover bundle open the file for writing on Windows only, because Windows flushes need write access. --handover itself stays refused on Windows, since its owner-only and no-follow checks need POSIX, so the three --handover HTTP tests skip there by name; no other test is skipped. A test server that fails to start now cleans up its node, which removed a crash and five leaks. Windows tests pass on this head. Served tokens are unchanged; handover is a new opt-in path.
|
|
Thanks for the Windows fixes and the READY on For the record, we checked the four points from the automated review against the code. Three we could not reproduce: the We have a small follow-up ready for that: an optional |
…hart#2349) 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 (ashhart#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.
…s code, the off path (ashhart#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.
…rt#2349) 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.
…shhart#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 (ashhart#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.
…shhart#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 (ashhart#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.
…an on main docs/api.md is over 600 lines on main and must not grow. The handover section moves to docs/handover.md word for word, with its four routes in a table there; the API route table names them in one row that links to the page, run-guide.md's --handover row links there too, and one wrapped paragraph in api.md takes one line fewer.
…roduct compiles handover_bundle.syncPath called std.c.open, whose flags type is void on Windows, so compile-native-cuda-windows failed in seal and exportState. It now uses @import("sys").c: std.c itself on POSIX (the same calls as before) and the repo's Windows shim's open, close and fsync on Windows.
…ts run on Windows hashFd, slurp and copy's hashWrite called libc's read and write on an Io.File's handle. On Windows that handle is a HANDLE, not a C runtime descriptor: std.c.read is declared over HANDLE and isize, the CRT's read takes an int and returns an int, so the call failed and its 32-bit -1 came back as 4294967295, past the `n < 0` check, and buf[0..n] panicked (index out of bounds) in write -> seal -> hashAt. They now read with File.readPositional and write with File.writePositionalAll through `io`, the same bytes on every platform; a failed read or write is HandoverCorrupt. seal closes the store directory before the part is renamed, as Windows renames no directory with a handle open inside it. verify checks that the root and bundle directories it opened with no follow are directories (Windows opens the link itself there, which stat names), and the two link tests skip where Windows lets this user make no symlink.
…e tests skipped there The handover bundle relies on POSIX symlink refusal, no-follow opens and owner-only modes, and GitHub's Windows leg still failed its tests after the panic was fixed. As main does for the page disk tier (PageDiskPlatform), Server.init now refuses --handover on Windows with error.HandoverPlatform before anything is made, and serve prints why. handover_bundle.zig's and handover_bundle_test.zig's tests and the two lane_host_scope_test cases that write a bundle skip on Windows (error.SkipZigTest, "Windows refuses --handover"); on every POSIX host they run unchanged. Two --handover: tests check the refusal on Windows and that POSIX keeps the flag.
syncPath opened every path read-only and fsynced it. On Windows the sys shim opens a read-only file with GENERIC_READ only, and its fsync is _commit, that is FlushFileBuffers, which needs a handle with write access, so every file sync failed and a handover export ended in HandoverSync. Directories were not affected: the shim gives them its own directory handle, whose fsync succeeds. syncPath now takes what it syncs. On Windows a file opens read-write; directories, and every path on Linux and macOS, open read-only as before, so POSIX behaviour and the bundle's bytes are unchanged.
… node stops its lane host Windows still refuses --handover at startup (handover.platform): a bundle there gets no owner-only modes (chmod only sets the read-only attribute) and no owner check of the files it opens (owned() returns at once on Windows), so the reasons for the refusal stand; only the flush now works there. The three HTTP tests that start a server with --handover therefore skip on Windows, as the bundle and CLI handover tests do. Node.init in handover_http_test.zig started its lane host and then built the server with no errdefer. When the server refused, the host thread kept waiting on the node's condition after the test allocator had taken the node back: the next test's waitTimeout panicked (integer overflow on Windows, a segfault on Linux with the refusal planted), and the node's prompt store and rows were reported leaked. Each step of Node.init now undoes itself on failure, in deinit's order.
63e6521 to
535318e
Compare
|
Thank you @ThinkOffApp. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
What this changes
A second session can now take over the prompt state a first session built, on the same model and build, without
prefilling it again. It is off unless the server is started with
--handover(which needs--prompt-cache-disk DIR).POST /v1/imprint/handovermakes a private scope and answers an id and a token, shown once."handover": {"id", "token"}looks up and keeps only in that scope's own prompt store. It neverreads or writes the shared cache, the disk tier, Recall's record or folded memory.
POST /v1/imprint/exportwrites the scope's state into an owner-only bundle with a manifest (build identity,token digest, size and sha256 of every file).
POST /v1/imprint/importon another process checks the bundle file by file, copies it into a private tree, readsthe state into the scope's store, and removes the bundle (a handover is single use). Before the state goes live
the import renames the bundle to a name no import can ask for (
.<id>.used-<random>). One rename wins betweenracing imports in any process. If that rename fails, the import is refused. If the delete that follows fails, the
leftover can't be imported, and dropping the scope tries the delete again.
DELETE /v1/imprint/handoverforgets the scope, its store and its bundle.When the handed-over state fails to read, the import answers 422
handover_corrupt. When it fails to restore, thechat answers 409
handover_not_loadedbefore any token. After either, every chat in that handover answers 409, anda shorter state of the same prompt kept in RAM, in the scope or in the shared cache, is never resumed in its place.
#2694's fallback to a shorter RAM state stays as it is for ordinary requests.
atc overlap --json(ATC 0.9.6, 30 Nov): incomplete coverage (its pull request and time limits left 80 of 90 openpull requests unknown); 9 clean; one textual conflict, with kolibri1: the published EAGLE-3 drafter behind --drafter on CUDA (don't land yet: c=8 -1.1 %, a cold prompt's second token 58 ms later) #3590 in
zig/src/families/kolibri1/forward.zig, a filethis change does not touch (kolibri1: the published EAGLE-3 drafter behind --drafter on CUDA (don't land yet: c=8 -1.1 %, a cold prompt's second token 58 ms later) #3590 conflicts with main itself there). prompt cache: SSD write on second sight and a RAM read cache, same bytes #5681, Prompt cache: keep the largest earlier checkpoint that fits #5466 and Inkling 2 CUDA: keep prompt and conversation state on disk across restarts #5647 are covered below.
ef70b129b(30 Nov). The GPU runs below were on the same commits before this rebase, on main33e716462; of main's 61 newer commits only one touches a file this change touches (the CUDA test dispatcher,zig/tests/cuda/main.zig), and the rebase applied cleanly.The gate, item by item
--handoverdefaults off and is refused without the disk cachehandover_cli_test.zighandoverfield is unchangedlate_system_test.zighandover_http_test.zigscope == 0guards; main's lane host suite passes unchangedzig build test-lane-api-hosttf-cuda-test handover-saveandhandover-load:resume_tests.zig's digest (attention rows, recurrent state, last hidden row, logits, first token) equals a fresh pass in each new processzig/tests/cuda/handover_tests.zig,handover_flashnext.zighandover_http_test.zigcached_tokensequalsloaded_tokensin B and in C; the same request without the handover resumes 0handover_http_test.zighandover_not_loaded, never a replyhandover_http_test.zighandover_bundle.zig,handover_bundle_test.zig,lane_host_scope_test.ziglane_host_scope_read_test.ziglane_host_scope_test.zig,handover_http_test.ziglane_host_scope_test.zig,handover_http_test.zigRun on a CUDA box, 30 Nov 2026:
50f837d57with-Dnvcc.tf-cuda-testprocess.handover-saveat 4,091: fresh-pass digest2ea93bb7f2e3085b. Two laterhandover-loadprocesses each read4,091 tokens, resumed 5, and matched the fresh pass's full digest. The second of them is the third session.
handover-saveat 3,000, then a newhandover-load: read 3,000, resumed 1,096, digest equal.bundle check then passes, but
handover-loadfails withRowsHash, so the store's own hash refuses it before anyrestore.
Flash Next, the same GB10, 30 Nov 2026:
408767fa0. Checkpointnvidia/Qwen3.8-Flash-Next-FP4-Localatb9ce18a6. Promptzig/tests/cuda/flashnext/lr7/long12k.ids(12,001 ids). Runnerhandover-save-fn/handover-load-fn, each step itsown process.
(
fdb101c03ba66f81).indexer-key rows plus their pooled blocks, the n-gram tail, the MTP head's rows, the last hidden row, the logits and
the first token.
match.
RowsHash.lane then reuses the engine's shared scratch and draft buffers. This tests that reused scratch can't leak into a
resumed state. It does not test isolation from another lane that is live at the same time, which Nemotron's runner
does.
Over HTTP on a real server, the same GB10, 30 Nov 2026 (
tensorfold-native servewith--parallel 1 --context 16384 --temperature 0 --no-thinking --prompt-cache-gib 8 --prompt-cache-disk <root> --handover; A, B and C each a new server over one diskroot; each later turn carries the previous server's real reply):
d14d5aec1: A exported 4,275 tokens; B imported 4,275, its chat resumedcached_tokens4,275, and itexported 4,306 after its own turn; C imported 4,306 and resumed 4,306. Every reply equals a fresh server's cold reply.
Also on this build: single use (a second import answers 404) and a corrupt bundle (422, then 409 with no reply). On
the build before it,
50f837d57(the same routes and codes, before the reply-span keying fix): a wrong token (403), amissing id (404), the shorter state in the shared cache never used for the handover's chats (409), and the four routes
404 without
--handover.408767fa0: A exported 4,232; B imported 4,232, resumed 4,232, exported 4,274; C imported 4,274and resumed 4,274. Replies equal two fresh servers' cold replies. After B's import, a second import answers 404 and the
next chat still resumes 4,232. A corrupt bundle answers 422, then 409.
33e716462against this branch with--handoveroff and on,7 distinct 4,207-token prompts with no prompt-cache hits (0 to 2 cached tokens, the template's first ones), two rounds in alternating order, one server at a time. Medians
3.2933 s (main), 3.2890 s (off), 3.2878 s (on); each server's spread is 18 to 29 ms. Every server ran at P0 with the SM
clock at 1092 MHz, median power 24.5 to 24.7 W. Five more prompts with distinct questions gave equal replies on all three.
A scope's store is an eighth of the shared prompt-cache budget, so the CUDA runs need a
--prompt-cache-gibwhoseeighth holds the handed-over state; otherwise the export answers 404
handover_no_state(or, with #5466, hands overan earlier cut).
Checks on this head
tools/pr_check.py --base ef70b129b: 0 errors, 4 advisory warnings (inherited import cycles), lean 88vs 88, 0 new.
zig fmt --check build.zig zigandgit diff --check: clean.-Dcpu=apple_m1), after the rebase:zig build test-lane-api-host test-server-cpu test-serve-flags-host test-cuda-host: 591 of 591 steps, 11,686 of11,752 tests pass (66 skipped), 0 fail.
zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu: 12 of 12 steps(compile only).
33e716462:zig build test test-goldenfailed only where main fails on the same Mac(TFQ5 Split-K in two modules, "info prices a Qwen3.8-27B start", the inkling2 capabilities check, and the qwen27_lanes
phase_trace and lfm3 compile errors); goldens 69/69 and 340/353 equal with 0 unexpected differences.
forgets an id it proved; three lane host tests fail if a failed import no longer marks the scope lost; a second
import of a bundle whose delete failed succeeds (200 where 404 is expected) without the claim-by-rename; a scope
turn holding an earlier reply fails to export (
HandoverNoState) when the handover keys reply spans differently fromthe host's lookups; and a retried import whose bundle is gone ends a loaded session (409 where 200 is expected).
Receipt
33e716462against this branch with--handoveroff and on,no handover named: median time to first token 3.2933 / 3.2890 / 3.2878 s at the same clock and power, and equal replies
(see the gate section).
--handover, default off, a store-true flag; refused at startup without--prompt-cache-disk DIRor--learn-conversations.stores (Flash Next's two-Mac Metal host) answers the routes 501
handover_unsupported.Open pull requests this meets
None of these is merged on main yet (checked 30 Nov 16:55Z). Before the rebase, each merged into this branch without a
textual conflict (checked with
git merge-tree).TENSORFOLD_ROWS_SECOND_SIGHT=1, the export's bundlestore is a fresh rows store whose ledger has never seen the state, so
rows.write.queuedholds the first sightback and the export answers 500. Checked on a local trial merge: the two HTTP handover tests that export fail with
500 when the switch is on and pass with it off. Once prompt cache: SSD write on second sight and a RAM read cache, same bytes #5681 lands, the export's bundle store should skip second
sight. Its read cache is per store, so an import's private copy starts empty and is freed with it.
state being resumed, so it never changes what a request resumes. After a failed read or restore the scope is lost
and the refused pass keeps nothing, so its extra cut cannot become a shorter state that stands in. A scope's budget
is an eighth of the shared one: with Prompt cache: keep the largest earlier checkpoint that fits #5466 a long prompt whose newest state does not fit keeps an earlier cut, and
the export then hands over that shorter state, with
tokenssaying so. On a local trial merge every handover testpasses (860 lane host tests with Prompt cache: keep the largest earlier checkpoint that fits #5466's own, and the 3 HTTP tests).
with
--handoverthe routes would reach Inkling 2 with no change here. Not gated: it needs its own digest run, and arestore its position or identity check refuses must reach the lane host as a refused restore (
reuse_failed), so ascoped request answers 409 rather than computing the prompt again.
Notes for review
(so a later chat answers 409); a missing bundle or a wrong token leaves it unknown (404), so guessed ids cannot grow
the registry.
call and looks again if it was evicted; a scoped job keeps its borrow instead, since looking again could find a
shorter state. Folded memory never routes a scoped request, since its snapshot would stand in for the handed-over
state.
turns can evict the imported state like any kept state. A later request in that handover then resumes the
longest state the scope itself still holds, which this session built after the import, or computes the prompt.
It never resumes the shared cache's state. That is ordinary cache behaviour, not a failed read or restore, so it
answers normally, and the reply's
cached_tokensshows it.a scope is marked lost only when the import proved the bundle was its own and then failed.
bits (
decoded_rowsfalse, as on CUDA Nemotron) they drop them, so a conversation holding an earlier replyexports and imports like any other.