Skip to content

DeepSeek-V4.1 hand-off: the CUDA producer exports while the prompt prefills and the decoder pulls beside it - #3729

Open
BlivionIaG wants to merge 98 commits into
ashhart:mainfrom
BlivionIaG:pr/dsv41-handoff-stream
Open

BlivionIaG wants to merge 98 commits into
ashhart:mainfrom
BlivionIaG:pr/dsv41-handoff-stream

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before, a --mcdma-produce server exports a DeepSeek-V4.1 prompt's state only after the prompt has prefilled, and the decoder's pull starts only once the export is whole. After, the producer announces the export when the request starts; a worker thread reads back each finished segment's comp and index pool pages on its own stream and converts them, and frames are served as they turn ready. The cut converts only the swa, carry and ring parts. The decoder can ask for a streamed export (Expect.stream), asks again for a frame the producer answers WAIT to, and accepts frames in any order. A decoder that does not ask still waits for the whole export, and a failed stream falls back to the whole export at the cut. This is a transport change of the chain in #3553: the export is byte-identical to the one the producer makes without it. It adds no flag and no setting, and changes no output token.

Reading the producer thread turned up three defects with more than one live slot, fixed in 2072ff489d: a second hand-off's start replaced the first's stream, so the first's cut could take the second's drain (an export with no paged parts reads as converted) and omit pages it still needed, or convert a part beside the thread still converting it; and the worker thread, its stream and its pinned buffer lasted as long as the export was held. The cut now drains its own export's feeder before it converts, a stream answers only for the slot it was fed from (a stream fed from two slots falls back to the cut), and the worker ends at every cut, including after a queue failure or on another slot, once accepted work is quiet.

Evidence

  • Exports byte-identical between the producer without and with this change at 7.8k, 16k and 32k prompt tokens: the manifest and every part (swa, carry, comp, ixk, rings). Measured on a GB10 pair, one export per size and variant, on b1368a7d1f and again with the producer code of 2072ff489d (one slot; the same cold requests, byte-identical to the build without this change). Repeat 16k requests show drafter rings that also vary between runs of the build without this change; every export with the change equals one of those.
  • Compatibility, measured: an older decoder against the streaming producer gets WAIT until the export is whole; a decoder with this change against an older producer works.
  • Time to first token on a Mac decoder with a streamed pull against the same decoder without it, same producer, alternating, 6 salted samples per size, measured on an M5 Ultra with a GB10 pair as producer: 7.8k 4.22 to 4.02 s, 16k 7.66 to 7.24 s, 32k 14.20 to 13.42 s. The transfer left exposed after the producer finishes: 0.22, 0.41 and 0.78 s before, 0.00 s after. That decoder wiring is not part of this PR.
  • Greedy output at 8 tokens (all sizes) and 256 tokens (16k) is the same with and without it for that decoder.
  • Two-slot hardware follow-up, with the producer fixes from 2072ff489d ported to 23368ec308: generated the three missing captured variants (130 total) and ran three warm-cache pairs and three cold, independently salted pairs of simultaneous 7,838- and 16,095-token requests on a GB10 pair. Every concurrent export matched the corresponding solo export's manifest (handoff id normalized) and every payload byte. All requests completed without a missing-variant error. The observed prefills were serialized; this does not prove overlapping GPU prefill or overlapping feeders.
  • With that two-slot producer, the Mac consumer completed two simultaneous requests at 8 generated tokens and the 16k request at 256 generated tokens with the expected generation hashes. All three used remote prefixes, without fallback or protocol errors. These were warm-cache correctness runs, not new TTFT measurements; the consumer wiring is still outside this PR.

Checks on this head

  • Head commit: cf14cc1c20
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 165 problems on upstream/main 4c79cfe346, 165 on this head, 0 new (tools/zig/lean_new.py). tools/pr_check.py --base 4c79cfe346 --pr 3729: 0 errors, 1 advisory warning, inherited from Prefill on a GB10, decode on a Mac: long prompts for Qwen3.8-27B handed over ConnectX (#1594, step 2b)  #2648 (cli_remote.zig:40 names 192.0.2.20, a documentation address).
  • What the merge of main needed, all on this head:
    • lane_stream.zig takes main's kept() helper, with .remote carried on the reuse and the remote hold still deciding whether a lookup runs at all.
    • metal.zig keeps main's Inkling 2 additions (inkling2_loop formats, the native open, the drafter refusal) and routes isGemma4/readMemory/ownsQwen27 through metal_models.zig, which now passes TF_QWEN27_TIED_HEAD to qwen27_engine.owns (main's owns takes it; the shared copy did not).
    • environment_test.zig keeps main's newest refusal rows beside ours.
    • The closed-host refusal test closes the host through halt, because main's submit publishes status after the lock and full teardown freed what it writes.
  • Tests run, with the command and pass, fail and skip counts (macOS arm64, Zig 0.17.0, -Dcpu=apple_m1 -j4):
    • zig build -Dcpu=apple_m1 -j4: exit 0.
    • test-dsv41-handoff 92, test-handoff-routes-host 35, test-dsv41-cuda-host 111, test-lane-api-host 812, test-wait-reasons-host 40, test-qwen27-reply-cache-host 10: 39/39 steps, 0 fail, 0 skip.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • CI: all ten jobs passed and the two nightly jobs were skipped on the previous head d8c1be78fd (run 45129445301). The refreshed head reruns them.
  • Not run, and why: an automated GPU test of cuda_export_stream.zig, overlapping GPU prefills/feeders, and the full suite locally. The worker was exercised manually on hardware in the one-slot measurements and the two-slot simultaneous-request checks in "Evidence"; those ran earlier tips, not this head.

Receipt

  • Boxes it reaches: DeepSeek-V4.1 on CUDA with --mcdma-produce.
  • New switch? None.
  • Exactness: export bytes identical (above); output tokens unchanged.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

Update after review

  • Head cf14cc1c20: drain sets closing once the queue is quiet, before the failure and wrong-slot returns. Two new tests show the worker exits before the export is released. test-dsv41-cuda-host 17/17 steps, 480 pass, 0 fail (red before: 478 pass, 2 fail, the new tests). The cuda-host run together with test-dsv41-handoff and test-handoff-routes-host: 23/23 steps, 245/245. The drain and race test binary passed 200/200 repetitions. Lean 165 vs 165, 0 new; tools/pr_check.py --base 4c79cfe346 --pr 3729: 0 errors, 1 advisory inherited from Prefill on a GB10, decode on a Mac: long prompts for Qwen3.8-27B handed over ConnectX (#1594, step 2b)  #2648; zig fmt --check build.zig zig clean.

  • Head cf14cc1c20: test-dsv41-cuda-host 17/17 steps, 473 pass, 0 fail (red before on d855b9bb5d: 472 pass, 1 fail, the new cuda_export_stream_drain_test.zig); test-dsv41-handoff 94; test-handoff-routes-host 35. Lean 165 vs 165, 0 new; tools/pr_check.py --base 4c79cfe346 --pr 3729: 0 errors, 1 advisory inherited from Prefill on a GB10, decode on a Mac: long prompts for Qwen3.8-27B handed over ConnectX (#1594, step 2b)  #2648 (cli_remote.zig:40, documentation address). Hosted CI is queued behind the runner backlog.

ThinkOffApp and others added 30 commits November 14, 2026 10:39
…, sent as KV handoff protocol 2

hybrid_state gives Qwen3.8-27B's recurrent and attention state one byte order, header and token sha256 that CUDA and Metal both read. Protocol 2 sends a recurrent layer's state part by part with a CRC-32 a frame (ARMv8 CRC instructions where present); protocol 1 readers refuse it. The producer table holds exports for a hand-off, refuses a reused id, expires them, and caps the bytes held (HeldExportsFull). fabric_handoff and tf-mcdma-pair tests cover the fake link and the frames. (ashhart#1594 step 2b)
…a kept state, and is kept as remote

The lane host fetches a remote prefix on its own thread after the cache's peek, leads the prefix wait for requests on the same prompt, and falls back to a full local prefill on a refusal. With TF_PREFILL_KEEP (default 1) the states a pulled prefix builds are kept in the prompt cache marked remote, never written to disk or learned from, so a chat's follow-ups resume on the Mac. Tests pin provenance (remote_prefix, pulled_prefix), the keep rules and slot 0's let-go. (ashhart#1594 step 2b)
…ls them over an MKVH link

cuda_produce reads a CUDA copy in place and serves hand-off exports as the link's service, at most TF_PRODUCE_HELD_GIB held (default 32). On the Mac, qwen27_remote pulls a prefix into a blank state, checks model, checkpoint, token sha, TP, geometry and protocol, and refuses a checkpoint whose state is not Qwen3.8-27B's (Qwen3.5-9B) at start. remote_trigger asks the GB10 over bounded HTTP, with TF_PREFILL_API_KEY_FILE's key as a Bearer token and a named 401. A detected mismatch turns remote prefill off; a refusal or timeout does not. The TF_PREFILL_* settings join the environment registry. (ashhart#1594 step 2b)
… a GB10, and the hand-off's API fields

A completion's kv_transfer_params.mcdma_handoff becomes its hand-off; a malformed one now returns 400 on every native server. Replies on a remote prefix report exact_mode "remote_prefix" with remote_prefix, pulled_prefix and kept_remote_cache_tokens. docs/api.md and docs/environment.md describe both. Off unless both machines are started with the new options. (ashhart#1594 step 2b)
…ecks on real weights

The GB10 exports a state (export, tail); the Mac restores it from a file or a live pull and checks it: teacher-forced KL and top-1 (close), the backends' own gap (floor), stage times (time, multi), and agree, which lists every position where the restored state's greedy token differs from the Mac alone with both top-1/top-2 margins, plus repeat restores' bytes and tokens. State files are read in 1 GiB pieces, as macOS refuses one read over 2 GiB. (ashhart#1594 step 2b)
…rrow and no promise

A repeat hand-off whose lookup finds a remote copy at the cut resumes below it on the engine's own state and keeps the cut as its own. When a queued chat protects the remote copy and the budget has no room beside it, the guard refuses that keep (CachePromised). The test shows the export and the reply still go on, the borrow from below() is let go, no job is left holding a promise, and the remote copy still serves the next chat.
…umes on the Mac

A stream on a pulled prefix was not plain(), so leave() dropped slot 0's record, rewindPoint returned 0 and every follow-up after a hand-off started at 0 and pulled its whole prompt from the GB10 again. Such a stream now counts as plain for slot 0: its pass makes a rewind point at the history end past the cut, and leave() keeps the record, marked remote (Standing.remote). A pass that resumes on that record, here or back at its point, takes its rows' origin (inherit: reuse.remote set, reuse.pulled cleared), so its reply reports the prefix as kept remote and its keeps are marked remote, never the Mac's own. A refused copy that ran here from 0 leaves an own record. With TF_PREFILL_KEEP=0 slot 0 keeps no record and no rewind point of a hand-off's rows, and Job.kept and Job.keep keep nothing on a remote prefix. The unplanned cache checkpoint still skips remote streams. The decisions move into qwen27_resume.zig (plain, leftRemote, inherit, rewindAt, Standing.left, Standing.point, Standing.keeps), where host tests pin the hand-off chain, a refused import, each case that keeps nothing (TF_PREFILL_KEEP=0, a cancelled or failed reply, images, prompt logprobs, untaught rows) and a pull that reaches the history end, which makes no rewind point. (ashhart#1594 step 2b)
New host tests (qwen27_handoff_test.zig, "qwen27 hand-off:", run by test-qwen27-reply-cache-host) drive the real lane host with a fake backend over a device-less Metal whose slot 0 choices are qwen27_slots' own: resumeAt as the lane host's resume_peek, opening where slot 0 resumes, rewindPoint and leave. A pulled turn leaves a remote record with its rewind point at the history end; its follow-up pulls nothing, resumes in place where the turn left slot 0 and reports the prefix as kept remote. With TF_PREFILL_KEEP=0 the follow-up pulls again. A pass on slot 0's remote rows makes no unplanned checkpoint, on its own rows it does, and either way it clears a pull it overtook. To reach these host-side, takeStanding inherits the origin once after its switch (here or back), attach's TF_PREFILL_KEEP goes through remote.keepRule (lane host and slot 0 alike), and leave and rewindPoint are pub.
The cache plans a fill's marks without slot 0's in-place resume, so a follow-up that resumes slot 0 (its own rows, or a hand-off's since the last commit) can carry marks below where its pass begins. It never stands at them, yet a request arriving during its pass waited for one until the pass ended, then computed the prefix itself. The prefix wait now skips a leader's marks at or below its stream's cached rows. A request picked in the same admission as the leader, before its first chunk, is not covered: the leader's start is not known yet. Host tests: a request arriving during a fill waits for its cut and resumes it; one arriving during a fill that resumed past the cut does not wait.
…DA export needs

compile-qwen35-rounds-host builds zig/tests/qwen35_cuda_main.zig as its own module, with cuda, qwen35, core and lanes only. Since the main imports qwen35_cuda_export.zig, which reads @import("hybrid_state"), that step stopped compiling. It now gets the same hybrid_state module zig/build/cuda.zig gives tf-qwen35-cuda, built for the census target. (ashhart#1594 step 2b)
inherit now takes the plan and leaves a stream's origin alone for .none, so the decision that a pass resumed here or back at the rewind point stands on the record's rows (remote or not) lives in qwen27_resume.zig, not in takeStanding's arms. The .back arm needs rewindSlot, a GPU blit, so no host test reaches it in qwen27_slots.zig; the rule it calls is pinned by the resume tests, whose helper now calls inherit as takeStanding does instead of deciding by itself. (ashhart#1594 step 2b)
…ixture

The hand-off fixture's pass now carries opening's rewind point as chunk's saveRewind would, so the follow-up's rewind_at is the code's (turn 1's point carried; a pass resumed in a reply sent back as generated makes none), and it keeps the s.cached opening set over the fake's own fill instead of setting it again from the resumed position, so qwen27_slots.opening's line is what the reported remote prefix reads. Slot 0's hand-off rules (qwen27_resume_remote_test.zig) also run in zig build test on every OS; the Metal fixture's tests stay in test-qwen27-reply-cache-host, macOS only. (ashhart#1594 step 2b)
Adds the host-only record library for the DeepSeek-V4.1 prefill hand-off: the release geometry,
the codec between CUDA's fp8 cache records and the neutral bf16/f32 parts, the E2M1/E4M3 FP4
mirrors of the Metal packers, the part plan (what travels, cut into frames of at most 2 MiB)
and the CUDA-side export of a snapshot's copies into those parts. Each piece is tested against
independent tables or f64 references; `test-dsv41-handoff` runs them on the host.

Not included: the Metal packers and importer, protocol 2 adapter, landing sink and stream
file, the CUDA export, and any transport.
… landing sink

Adds the Metal side of the host-only hand-off library: the packers that write the neutral
bf16/f32 parts into the release lane's and the served lane's cache layouts, the importer that
accepts exactly the parts a shape implies, the export from a Metal snapshot, the protocol 2
adapter (`p2`: manifest check and a sink for `fabric.decoder.pull`), the landing sink and a
test-only hand-off file (`blob`). Export-to-import round trips cover both layouts, replicated and
split pools, and protocol 2 runs end to end over a fake link.

Not included: the CUDA export, the byte-stream file, any transport, and the tests and checks
that read the served lane's source.
…ompt state, and GET /v1/handoff/<id> serves it

A DeepSeek-V4.1 CUDA server started with --mcdma-produce LINK (or TF_DSV41_HANDOFF_DUMP) reads the active
slot's state back at a hand-off request's cut (the prompt less its last token, armed through the draft
lanes and run by the GPU target), builds the library's bf16 parts and holds them under the request's id
until the decoder closes them (TF_PRODUCE_HELD_GIB). `--mcdma-produce http` holds them the same way and
serves them on the server's own port: GET streams the protocol-2 replies under a Content-Length, DELETE
releases, behind the key gate and the inference scope. `handoff_file` is the stream format the dump and
the HTTP body share.

A request cancelled by its cut captures no export: exportAt returned a snapshot to the exporter even when the request had been cancelled in the pass before the cut, leaving a held export nobody reads until its time to live ends. The prompt pass itself is not cancelled: on the GB10 pair the follower rank runs every pass the leader runs, so abandoning one on the leader alone would leave the follower waiting on a collective.

Not included: the decoder's side (pull, landing, HTTP fetch), replay-mode and piece-wise prefill, a split
KV pool, and the operator guide. The export refuses those configurations at start-up by name.
…at their cut

With TF_DSV41_PREFILL=replay the cut stands after the decoder replay, so the live slot holds the decoder
layers' rings (the last 127 positions the replay wrote). The window's oldest position of those layers was
never written by the replay and is zero in the export, which is otherwise the full export's bytes. The
drafter's rings of a replay-mode slot stand outside the snapshot and are read at the cut. The producer also
logs the read-back and build times of each export.

A prompt run in pieces is exported at the step that finishes it: after its last piece and the decoder
replay, before the last token's window. The draft lanes arm the export point when the prompt begins and the
GPU target runs it once, so `--mcdma-produce` no longer refuses TF_DSV41_PREFILL_PIECES and the other
streams keep decoding while the pieces run. An export point left by a prompt that never finished, or by one
that leaves, is cleared.

The read-back stays at the cut, on the engine thread; the conversion of the snapshot's bytes to the
protocol's bf16 parts runs on its own thread, at most two at a time (a third converts inline). A reader that
asks for an export still converting waits for it (up to two minutes) instead of finding it missing, and
`stop` waits for the converters.

Not included: the exact decoder replay and a split KV pool.
…porting its own

A rank's export holds the pages it stores (shard k of the world); shard 0 also carries the rings, the
carries and the drafter rows. The producer's responder answers as tp_rank k of tp_size world, and capture
reads this rank's pool pages instead of refusing a split pool. An export of at most 8 ranks is accepted;
`--mcdma-produce http` still serves a replicated pool only.

Rank 0 sends each follower an export op at the cut (and a fail op when no export will come); a follower
started with TF_DSV41_PRODUCE_LINK=NAME, an mcdma-rpcd listen link of its own host, snapshots its pool
pages there and serves them under the same hand-off id, so a split pool is exported one shard a link.
TF_DSV41_PRODUCE_LINK is registered in platform/environment.zig and read by `tf-dsv41 follow`.

Not included: the decoder's pull of the shards.
…efills and the decoder pulls beside it

The producer announces the export when the request starts; a worker thread reads back each finished segment's comp and index pool pages on its own stream and converts them, and frames are served as they turn ready. The cut converts only the swa, carry and ring parts. The decoder asks for a streamed export (`Expect.stream`), asks again for a frame answered WAIT, and accepts frames in any order. A decoder that did not ask still waits for the whole export; a failed stream falls back to the whole export at the cut. The exported bytes are unchanged.
…let in early or a refused wait now fail them

The fake-link test served parts that were whole from the start, so a producer that ignored readiness, or a decoder that never asked again after WAIT, still passed. The export's parts now start as zeros and the feed converts them: the first part is held until every other part has landed, so its WAIT is certain, and the landing order, the export's state at the first landing and the imported bytes are checked. A decoder that did not ask is checked to land nothing before the export is whole. The decoder's give-up, working and aborted paths are covered, and the converted-window test checks which parts are ready before the cut.
… reads one slot's pages and ends at the cut

Review of the producer thread: with more than one live slot a second hand-off's start replaced the first's stream, so the first's cut could take the second's drain (an export with no paged parts reads as converted) and omit the pages it still needed, or convert a part beside the thread that was still converting it. The cut now drains the export's own feeder before it converts, a stream remembers the slot it was fed from and answers only for that slot, and a stream fed from two slots falls back to the cut. The worker thread, its stream and its pinned buffer end at the cut instead of lasting as long as the export is held. Host tests drive the producer's streamed lifecycle with a fake feeder: fed, drained, completed, failed, released once and never while the engine feeds it. The exported bytes are unchanged by construction; this was not re-measured on hardware.
An E2M1 index block holding 6 and 1.25 came back as 6 and 1: the packers wrote codes
and never checked what those codes decode to. Each packer now dequantises its own bytes
and returns error.NotExact when any value moves, so a record whose values are off the
lane's grid is refused instead of rounded. The synthetic world is generated on that
grid, so the import, landing and protocol-2 cases still land, and a raw fp8 index row
is the refusal they check.
…failure

A failed queue sets broken from the engine thread while an earlier segment is still being
converted, and drain returned on that flag before the worker finished, so the cut could
convert the same parts beside it. The wait now outlasts the failure: queued reaches zero
only after the worker's last conversion, including its own failure path. The test holds
queued at one with broken set, runs the cut's drain against a worker holding the parts, and
fails on the pre-fix drain.
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Fixed in 6a22dbc4b4. drain no longer returns on broken before its own worker is done: it waits until queued reaches zero, which happens only after the worker's last conversion (its failure path decrements in the same defer), so the cut can no longer convert a part beside the worker. The new cuda_export_stream_drain_test.zig (wired into cuda_test.zig) builds exactly the reported state — queued 1, broken set, a worker thread holding a part — runs the cut's drain on a second thread, and asserts it has not returned a quarter second later, returns only once the worker frees the parts, and answers false so the cut reads the pages itself.

Red before on d855b9bb5d: the test fails at expect(!early) (test-dsv41-cuda-host: 472 of 473 pass, this one fails). Green on 6a22dbc4b4: 17/17 steps, 473 pass, 0 fail; test-dsv41-handoff 94 pass; test-handoff-routes-host 35 pass. Lean 165/165, 0 new; pr_check.py --base 9fa8863bcf --pr 3729: 0 errors, 1 inherited advisory.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @BlivionIaG. The packers now refuse non-exact rows, and waiting for queued work closes the earlier fallback overlap.

One failure race remains: progress can pass its broken check, then the worker can fail and finish cleanup before queue appends. That leaves queued nonzero with no worker, so drain waits forever. Please synchronize terminal failure with enqueue under the queue lock. The new test also clears queued before its converting marker, which can falsely fail the final assertion; publish completion only after clearing that marker and synchronize cut entry.

  • Synthena

…a late segment is refused

The test's worker clears its converting marker before it publishes its last segment, and the cut is in its drain before the wait is timed.
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Thanks, fixed in e955adbaae.

  • The worker's end and the enqueue now meet under the queue lock. run ends in retire, which sets terminal, frees the jobs left and takes them out of queued in one locked section. queue appends through enqueue, which refuses with error.StreamStopped under the same lock once terminal is set. A segment whose progress check passed before the worker failed and finished cleanup is now refused: queued stays at zero, progress marks the stream broken, and the cut reads those pages itself instead of waiting forever.
  • New regression in cuda_export_stream_drain_test.zig: a barrier holds the worker until the engine's broken check has passed. The worker then fails and runs the production retire before the engine calls enqueue. The test expects error.StreamStopped, queued == 0, and a drain that returns false.
  • The overlap test's worker now clears converting before it publishes completion (queued = 0). The main thread starts the 250 ms window only after the cut thread has entered drain (entered).

Red before: with only the two fix lines reverted (the terminal check in enqueue and the store in retire), test-dsv41-cuda-host fails this test with expected error.StreamStopped, found void (473/474). Running that red binary 200 times fails at that assertion 200/200.
Green on e955adbaae: test-dsv41-cuda-host 17/17 steps, 113/113; test-dsv41-handoff 94/94; test-handoff-routes-host 35/35. Running the green binary (all 113 tests) 200 times passed 200/200. zig fmt --check build.zig zig and git diff --check are clean. pr_check.py --base 9fa8863bcf --pr 3729 reports 0 errors and 1 inherited advisory (cli_remote.zig:40); lean is 165 vs 165, 0 new.

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks, @BlivionIaG. The shared queue lock closes the terminal-enqueue hang, and the test now publishes completion in the right order. The reported repeated red and green runs are useful evidence.

One cleanup path remains: after a queue-side failure, drain waits for conversions but returns before setting closing. A healthy worker then stays alive with its stream and 4 MiB pinned buffer until the held export is released. Please close the worker on failure and wrong-slot cuts too, after accepted work is quiet, and cover its exit before export release. Keep the repaired queue locking and wait-before-fallback behavior.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I tested the worker cleanup on e955adbaae in a checkout of the PR head. Two host cases call the real drain() with an already-quiet queue and an idle test worker. One sets queue failure on the same slot and the other uses a different slot. Both check that the cut requests shutdown, the worker retires before export release, and the cut still returns false for fallback. The test joins the worker on either result.

Both cases fail on this head. Moving closing.store(true, .release) to immediately after the wait for queued == 0, before the two early returns, passes 244/244 across these suites on M5 Max. The existing overlap test still passes, so the cut waits for conversion before fallback.

zig build test-dsv41-cuda-host test-dsv41-handoff test-handoff-routes-host -Dfixed-cpu -j2 --summary all

This was a host check on the PR head with the local change. The current-main merge still has conflicts and a live CUDA cleanup run remains unverified.

Igor Lessio - AIFLOW LABS

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Merged the refreshed parent (main 4c79cfe346 inside) to clear the conflicts. Head 8b02a6f3f6; lean 165 vs 165, 0 new; pr_check 0 errors (the one warning is the documentation IP at cli_remote.zig:40 from #2648); fmt clean; host steps green on an M4 Pro (the #3729 head: handoff 94/94, handoff routes 36/36, CUDA host 478/478, lane API 823/823, reply cache 12/12, environment 36/36; the retire/enqueue race test binary 200/200).

@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged 8b02a6f3f6 cleanly into d1ff890729 and got 644/644 host tests on an M5 Max. The merge also remains clean after the 1.3.5 release commits at d2b43908db.

zig build test-dsv41-cuda-host test-dsv41-handoff test-handoff-routes-host test-environment-host -Dfixed-cpu -j2 --summary all

The two idle-worker tests from my earlier check still fail on the revised head. In the focused run, the queue-failure and wrong-slot cuts return before requesting shutdown, leaving two failures and four passes. Moving the shutdown request immediately after the queue wait restored 6/6 in scratch, with the wait for conversion before fallback intact. No CUDA device run in this check.

Igor Lessio - AIFLOW LABS

…er slot

The cut set closing only on the converted path, so after a queue failure or a wrong-slot cut the worker kept its stream and pinned buffer until the export was released. Closing is now set as soon as the queue is quiet, before either early return.
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Thanks. Fixed in cf14cc1c20: drain now sets closing as soon as the queue is quiet (queued == 0), before the failure and wrong-slot returns, so the worker ends at every cut once accepted work is done, not when the export is released. The queue locking and the wait-before-fallback are unchanged; drain never takes the queue lock, and nothing is enqueued after a cut, so it cannot deadlock with enqueue. The worker's idle wait is now Stream.next, and two new tests in cuda_export_stream_drain_test.zig run a worker on it, one after a queue-side failure and one after a wrong-slot cut. Each checks that the worker has exited after the cut, without stop, while the export is still held. Both fail on the previous order (478 pass, 2 fail) and pass now (test-dsv41-cuda-host 17/17 steps, 480/480; with test-dsv41-handoff and test-handoff-routes-host, 23/23 steps, 245/245). The binary with the drain and retire/enqueue race tests passed 200/200 repetitions. Lean 165 vs 165, 0 new; pr_check 0 errors; fmt clean. Thanks also to @AIFlowML for independently confirming the same move (244/244 on M5 Max).

This branch has not been deployed

No deployments
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.

4 participants