Skip to content

Team Drift step 1: hand a kept prompt state to another session of the same model (#2349) - #5729

Merged
ashhart merged 45 commits into
ashhart:mainfrom
ThinkOffApp:team-drift-2349-step1
Dec 3, 2026
Merged

ashhart merged 45 commits into
ashhart:mainfrom
ThinkOffApp:team-drift-2349-step1

Conversation

@ThinkOffApp

@ThinkOffApp ThinkOffApp commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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/handover makes a private scope and answers an id and a token, shown once.
  • A chat with "handover": {"id", "token"} looks up and keeps only in that scope's own prompt store. It never
    reads or writes the shared cache, the disk tier, Recall's record or folded memory.
  • POST /v1/imprint/export writes 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/import on another process checks the bundle file by file, copies it into a private tree, reads
    the 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 between
    racing 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/handover forgets 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, the
chat answers 409 handover_not_loaded before any token. After either, every chat in that handover answers 409, and
a 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.

The gate, item by item

Gate item (10 and 12 Nov) What checks it Where Run
Off unless the server is started with it --handover defaults off and is refused without the disk cache handover_cli_test.zig Mac host, passes
Disk cache on, flag off: the four routes answer 404 unknown path; a chat with or without a handover field is unchanged late_system_test.zig Mac host, passes
Tokens unchanged when no handover is used Flag on and off, the same plain turns give the same replies and cached tokens handover_http_test.zig Mac host, passes
The shared-cache paths only gained scope == 0 guards; main's lane host suite passes unchanged zig build test-lane-api-host Mac host, 848 pass
Time to first token unchanged when no handover is used Main against branch on a real checkpoint, flag off and on, same GPU clock and power Flash Next on a GB10 30 Nov: medians 3.2933 s main, 3.2890 s off, 3.2878 s on (below)
Digest across processes, both directions and a third session tf-cuda-test handover-save and handover-load: resume_tests.zig's digest (attention rows, recurrent state, last hidden row, logits, first token) equals a fresh pass in each new process zig/tests/cuda/handover_tests.zig, handover_flashnext.zig GB10, 30 Nov: Nemotron equal in all three loads; Flash Next equal at three save points (below)
The same chain over HTTP with the fake target: A exports, B imports and exports again, C imports; each reply equals a fresh server's handover_http_test.zig Mac host, passes
Cached tokens equal the state's length Over HTTP with the fake target: cached_tokens equals loaded_tokens in B and in C; the same request without the handover resumes 0 handover_http_test.zig Mac host, passes
The same on a real checkpoint, A to B to C as separate servers, real replies in the conversation Nemotron and Flash Next on a GB10 30 Nov: cached equals loaded in B and C on both (below)
Each planted fault answers its own code Wrong token 403, missing bundle 404, foreign build 409, corrupt bundle 422, refused restore 409, each followed by 409 handover_not_loaded, never a reply handover_http_test.zig Mac host, passes
Flipped byte, cut or deleted block, extra file, links, other-user bits, a file swapped after the first open handover_bundle.zig, handover_bundle_test.zig, lane_host_scope_test.zig Mac host, passes
Shorter RAM state while the handed-over one fails to read (12 Nov) Session B holds shorter states of the prompt in its scope and its shared cache; the bundle's block passes its sha256 but fails its read: import 422, the next scoped requests 409 with nothing resumed or sent, an ordinary request still resumes the shared shorter state lane_host_scope_read_test.zig Mac host, passes
Shorter RAM state while the handed-over one fails to restore (12 Nov) The fake backend refuses the longer state's restore only: 409, never the shorter state, and the scope stays failed lane_host_scope_test.zig, handover_http_test.zig Mac host, passes
A reader without the token gets nothing Scoped requests never reach the shared cache, and the shared cache never serves a scoped one lane_host_scope_test.zig, handover_http_test.zig Mac host, passes

Run on a CUDA box, 30 Nov 2026:

  • Box and build: a GB10 (sm_121), driver 580.178.04, nvcc 13.0, built natively from 50f837d57 with -Dnvcc.
  • Model: Nemotron 3.5 Lightning 30B-A3B MLX 4-bit with its MTP weights.
  • Prompt: 4,096 ids. Each step below ran as its own tf-cuda-test process.
  • handover-save at 4,091: fresh-pass digest 2ea93bb7f2e3085b. Two later handover-load processes each read
    4,091 tokens, resumed 5, and matched the fresh pass's full digest. The second of them is the third session.
  • handover-save at 3,000, then a new handover-load: read 3,000, resumed 1,096, digest equal.
  • Control: one byte flipped in the bundle's 50.9 MB state file, with the manifest's sha256 rewritten to match. The
    bundle check then passes, but handover-load fails with RowsHash, so the store's own hash refuses it before any
    restore.

Flash Next, the same GB10, 30 Nov 2026:

  • Build 408767fa0. Checkpoint nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6. Prompt
    zig/tests/cuda/flashnext/lr7/long12k.ids (12,001 ids). Runner handover-save-fn / handover-load-fn, each step its
    own process.
  • Saved at 11,996, 6,144 and 2,049 tokens. Each load resumed the rest, and its digest equalled the fresh pass's
    (fdb101c03ba66f81).
    • What the digest covers: the DeltaNet conv windows and recurrent states, the attention layers' key, value and
      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.
    • The load must also report exactly the saved length restored, so a refused restore can't recompute from 0 and still
      match.
  • Control: the same corrupted-state control as Nemotron's is refused with RowsHash.
  • Scope: Flash Next keeps rows per stream, so before the restore the runner releases the other prompt's lane. The new
    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.
  • Nemotron's runner, refactored to share save and load with Flash Next, passed again on this build.

Over HTTP on a real server, the same GB10, 30 Nov 2026 (tensorfold-native serve with --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 disk
root; each later turn carries the previous server's real reply):

  • Nemotron, build d14d5aec1: A exported 4,275 tokens; B imported 4,275, its chat resumed cached_tokens 4,275, and it
    exported 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), a
    missing id (404), the shorter state in the shared cache never used for the handover's chats (409), and the four routes
    404 without --handover.
  • Flash Next, build 408767fa0: A exported 4,232; B imported 4,232, resumed 4,232, exported 4,274; C imported 4,274
    and 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.
  • Time to first token, Flash Next, no handover named: main 33e716462 against this branch with --handover off 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-gib whose
eighth holds the handed-over state; otherwise the export answers 404 handover_no_state (or, with #5466, hands over
an earlier cut).

Checks on this head

  • Lean checker: tools/pr_check.py --base ef70b129b: 0 errors, 4 advisory warnings (inherited import cycles), lean 88
    vs 88, 0 new.
  • zig fmt --check build.zig zig and git diff --check: clean.
  • On an Apple Silicon Mac (-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 of
    11,752 tests pass (66 skipped), 0 fail. zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu: 12 of 12 steps
    (compile only).
  • Before the rebase, on main 33e716462: zig build test test-golden failed 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.
  • Planted controls, each run against the old code: the HTTP test fails (404 where 409 is expected) if a failed import
    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 from
    the host's lookups; and a retried import whose bundle is gone ends a loaded session (409 where 200 is expected).
  • CUDA: the digest, HTTP and time-to-first-token runs above, on a GB10 (Nemotron and Flash Next).

Receipt

  • Main against branch on a GPU: Flash Next on a GB10, main 33e716462 against this branch with --handover off 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).
  • New switch: --handover, default off, a store-true flag; refused at startup without --prompt-cache-disk DIR or
    --learn-conversations.
  • Platforms: the routes work wherever the lane host keeps prompt states with a disk tier. A host without scope
    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).

Notes for review

  • After a failed import, the id stays known on that server only when the bundle was found and the token was its own
    (so a later chat answers 409); a missing bundle or a wrong token leaves it unknown (404), so guessed ids cannot grow
    the registry.
  • Two main features postdate the prototype. A filling job now lends its kept state back to the store until its first
    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.
  • A scope holds at most two states and an eighth of the shared budget, carved out of the shared store. Its own later
    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_tokens shows it.
  • A re-import whose bundle is gone (404) leaves an already-loaded scope as it was, since nothing was read or restored;
    a scope is marked lost only when the import proved the bundle was its own and then failed.
  • Export and import key the reply spans the way the host's own lookups do: on a backend that keeps no reply rows'
    bits (decoded_rows false, as on CUDA Nemotron) they drop them, so a conversation holding an earlier reply
    exports and imports like any other.

@ashhart

ashhart commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Thanks, @ThinkOffApp. This is a thorough first step, and the gate table made it easy to check. Confirmed on this head:

  • Nothing changes without a handover. Every change in the shared lane code only applies when a request carries a handover, so ordinary requests use the shared cache exactly as before. The flag is off by default.
  • The handed-over state must carry the same store identity the disk cache already uses, and every file must match its sha256.
  • The token is random, kept only as a digest, compared in constant time, and it expires.
  • No silent fallback. A state that fails to restore fails the request before any token, and later requests in that handover don't quietly prefill instead.
  • Exactness. Your GB10 digests show the resumed state equal to a fresh pass in each new process, for Nemotron and Flash Next. Time to first token with the flag off matches main.

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.

  • Synthena

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@ashhart ashhart added the synthena:ready Reviewed by Synthena and ready for group train label Dec 3, 2026
@ashhart ashhart removed the synthena:ready Reviewed by Synthena and ready for group train label Dec 3, 2026
@ashhart
ashhart force-pushed the team-drift-2349-step1 branch from 9b33ce4 to 138e3ca Compare December 3, 2026 05:37
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@ashhart ashhart added the synthena:ready Reviewed by Synthena and ready for group train label Dec 3, 2026
@ashhart ashhart removed the synthena:ready Reviewed by Synthena and ready for group train label Dec 3, 2026
@ashhart
ashhart force-pushed the team-drift-2349-step1 branch from 138e3ca to 2e1f085 Compare December 3, 2026 07:58
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@ashhart ashhart added the synthena:ready Reviewed by Synthena and ready for group train label Dec 3, 2026
@ashhart ashhart added synthena:needs-changes Reviewed by Synthena; changes requested and removed synthena:ready Reviewed by Synthena and ready for group train labels Dec 3, 2026
@ashhart
ashhart force-pushed the team-drift-2349-step1 branch from 2e1f085 to cef5540 Compare December 3, 2026 09:39
@ashhart ashhart added the kind:feature Classified by Synthena as feature addition label Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Needs changes (kind:feature)

Adds opt-in conversation handover: private per-scope prompt stores, export/import bundles with sha256 manifests, and scoped chat requests that never touch the shared cache. The core isolation and single-use rename logic look sound, but the CLI flag parsing has a syntax error and the handover status override leaks into unrelated refusals.

Findings:

  • [BLOCKER] zig/src/server/cli.zig: The --handover branch is written as a single-line else if ... else if without braces, so the --learn-daily-gib branch's body (out.learn_daily_gib = try gib(...)) is now inside the --handover arm's condition chain; the closing brace placement makes --learn-daily-gib unreachable or a parse error depending on how Zig resolves the dangling else if block. Suggested fix: Rewrite as } else if (is(name, "--handover")) { out.handover = true; } else if (is(name, "--learn-daily-gib")) { with explicit braces so both flags parse independently.
  • [BLOCKER] zig/src/server/errors.zig: handover_status is set on the shared per-request Cx and status() checks it first, but nothing scopes it to handover-specific failures; any later non-handover refusal on the same connection/request context (e.g. a capacity error after a handover check) would inherit the stale 403/404/409/422 status. Suggested fix: Clear cx.handover_status = null in fail()/other()/capacity() (or only consult it when cx.code starts with the handover prefix) so the override cannot leak into unrelated error replies.
  • [WARNING] zig/src/server/chat_generation.zig: Mapping a 400-class engine failure to 409 by string-prefix matching on the engine's message text is fragile: any message that merely begins with that phrase (or a future rewording) changes the HTTP status, and the prefix check can misfire on unrelated failures. Suggested fix: Have the engine surface a typed error (e.g. error.HandoverNotLoaded) or a structured code field on the failure message instead of matching message text prefixes.
  • [WARNING] zig/src/core/lane_host_pressure.zig: Scoped stores are shed with g.mark(x.store.budget) but their eviction/shed path may not be registered with the host's pressure accounting the way the shared store is, so a scoped store can hold memory the host does not count when deciding critical levels. Suggested fix: Verify scoped stores participate in the same budget accounting as h.cache (or document why their memory is excluded) and add a pressure test covering a populated scope store.
  • Synthena

@ashhart
ashhart force-pushed the team-drift-2349-step1 branch from cef5540 to 63e6521 Compare December 3, 2026 10:39
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Needs changes (kind:feature)

Adds opt-in conversation handover: private per-scope prompt stores, export/import bundles with sha256 manifests, and scoped chat requests that never touch the shared cache. The core isolation and single-use rename logic look sound, but the CLI flag wiring has a syntax-level defect and the failure-path status mapping relies on string-prefix matching.

Findings:

  • [BLOCKER] zig/src/server/cli.zig: The new branch is spliced into the if/else chain without braces around its body, so out.handover = true becomes the body of the else if and the following else if (is(name, "--learn-daily-gib")) attaches to that assignment expression; the out.learn_daily_gib = try gib(...) line is left outside the chain and --learn-daily-gib parsing is broken or the block structure is malformed. Suggested fix: Wrap the handover branch in braces: } else if (is(name, "--handover")) { out.handover = true; } else if (is(name, "--learn-daily-gib")) {.
  • [WARNING] zig/src/server/chat_generation.zig: The 409 mapping depends on the engine's failure message beginning with the exact string "handover_not_loaded"; any wording change or prefixing in the engine message silently degrades scoped failures to 400, violating the documented before-any-token 409 contract. Suggested fix: Plumb a structured error code (e.g. an error enum or a dedicated field on the failure message struct) from the engine to the server instead of matching on message text.
  • [WARNING] zig/src/core/lane_host_pressure.zig: Scoped stores are shed with g.mark(x.store.budget) while the shared store uses mark.? from the governed level; if the shared store is null the early return skips this loop, but when the shared store exists the scoped shed runs even for scopes whose stores were already released, risking use of a freed store if slot removal is not synchronized with this engine-thread loop. Suggested fix: Confirm scoped slot mutation only happens on the engine thread, or guard the loop against slots mid-release; ideally reuse the same mark value as the shared store for consistent shedding.
  • Synthena

@ashhart ashhart removed the synthena:needs-changes Reviewed by Synthena; changes requested label Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@ashhart ashhart added the synthena:ready Reviewed by Synthena and ready for group train label Dec 3, 2026
@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Thanks for the Windows fixes and the READY on 63e65211a. We are leaving this head as it is so it can land.

For the record, we checked the four points from the automated review against the code. Three we could not reproduce: the --handover chain in cli.zig is valid and both flags parse; handover_status has no reachable leak, because a Cx is made per request and both setters return Refused at once; and scoped stores are opened, dropped and shed on the engine thread, with the governor reading OS pressure. One is real but narrow: an engine failure whose text happens to begin with handover_not_loaded answers 409 where an ordinary failure answers 500.

We have a small follow-up ready for that: an optional failure_code on Event.finished in place of the text match, plus tests for the flag order and for a populated scope store under pressure. We will open it as its own PR once this one lands. Say if you would rather have it on this branch.

ThinkOffApp and others added 17 commits December 3, 2026 18:11
…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.
@ashhart
ashhart force-pushed the team-drift-2349-step1 branch from 63e6521 to 535318e Compare December 3, 2026 18:11
@ashhart
ashhart merged commit 4375405 into ashhart:main Dec 3, 2026
6 of 10 checks passed
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

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.

ashhart added a commit to mrv777/TensorFold that referenced this pull request Dec 3, 2026
ashhart added a commit that referenced this pull request Dec 3, 2026
ashhart added a commit that referenced this pull request Dec 3, 2026
ashhart added a commit that referenced this pull request Dec 3, 2026
ashhart added a commit that referenced this pull request Dec 3, 2026
ashhart added a commit that referenced this pull request Dec 3, 2026
ashhart added a commit that referenced this pull request Dec 3, 2026
ashhart added a commit that referenced this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:feature Classified by Synthena as feature addition synthena:ready Reviewed by Synthena and ready for group train

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants