Skip to content

lane host: concurrent identical prompts join a filling leader's whole fill - #3693

Merged
ashhart merged 5 commits into
ashhart:mainfrom
bikepresentball:fix/3397-single-flight
Nov 21, 2026
Merged

ashhart merged 5 commits into
ashhart:mainfrom
bikepresentball:fix/3397-single-flight

Conversation

@bikepresentball

@bikepresentball bikepresentball commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

For #3397 and #3487: concurrent identical prompts join the filling leader's whole fill, on a cold cache and a warm one.

The change

waits() gains a whole-fill arm decided before any mark is consulted: a queued request whose prompt is a filling request's own, by identity alone (cache key, raw tokens and spans), waits for that leader's whole fill instead of prefilling beside it, on a cold cache as on a warm one. The join reuses the prefix wait's machinery — the same Waiting record with a whole flag, the same bound (TENSORFOLD_PREFIX_WAIT_MS), the same release loop — and stays fail-open: the leader's finish, cancellation, failure or the bound passing releases every waiter to prefill on its own, with the number of whole-fill waiters held to the admission cap. The join arms only when the leader's fill will keep anything — its planned marks are the budget's fitted set, so a prompt the store cannot keep (state past the budget, no slots, memory pressure) leaves no join armed and the prompts run side by side, as without the wait. The prefix wait's counters gain a joins count of whole-fill joins.

A joined reply is token for token a solo run's. The host tests pin that (see below), and the receipts below pin it on the device.

Host tests

lane_host_prefix_join_test.zig (fake backend), four tests:

  1. join, warm — four identical prompts arrive together: the leader prefills whole, each joiner waits for the whole fill and resumes the leader's kept cut, and every reply equals the join-off run's (leader_open_most == 1: one identical prompt computes at a time).
  2. no join, cold — the same shape on a zero-budget cache: no marks fitted, nothing will be kept, and the join does not arm; the prompts prefill side by side (leader_open_most > 1), replies equal.
  3. fail-open: the leader cancelled — request 1 is cancelled at its second chunk; each waiter goes on and prefills its own prompt, and every waiter's reply equals a solo run's.
  4. fail-open: the bound passes — a 1 ms bound against a leader whose chunks take 30 ms: every waiter is released at the bound and prefills beside the leader (leader_open_most > 1), replies equal.

Full host suite: the branch's failing set equals clean main's on this box (one pre-existing cli_config_test fixture failure, present on main here; every single-flight test passes).

Receipts (GB10, Nemotron 3.5 Super-VL 120B NVFP4, greedy, temperature 0)

Identical 75,688-token prompts, four streams arriving together on a cold cache (fresh serve):

arm streams reply sha256 (first 16) first token run wall
one prompt alone 1 9d48014dd568521d — 36.48 s
four together, join armed (defaults) 4 9d48014dd568521d × 4 33.35–33.77 s 39.52 s
four together, TENSORFOLD_PREFIX_WAIT_MS=0 4 9d48014dd568521d × 4 — 40.51 s

The joined arm's four first tokens land within 0.4 s of each other at the leader's single fill completing — one prompt's rows computed, four replies — and every arm's replies are byte-identical to the solo run's.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @bikepresentball. Before we review this for landing, one thing in the commits themselves: they are authored and committed under a local machine address rather than an address GitHub links to your account. Merged commits keep their identity in our public history, so please re-author them with your GitHub noreply address (Settings, Emails, "Keep my email addresses private" shows it), for example git rebase -r $(git merge-base HEAD origin/main) --exec 'git commit --amend --no-edit --reset-author' after setting user.email, and force-push.

We'll review the change itself as soon as that's done.

  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @bikepresentball.

One thing before this can land: two of the four commits are authored as bengrob@localhost rather than a GitHub noreply address, and we only land commits authored with a noreply address. To fix it:

  1. Set your noreply address with git config user.email (GitHub lists it under Settings, Emails).
  2. If bengrob is you, run git rebase HEAD~4 --exec 'git commit --amend --no-edit --reset-author'. If it is someone else, they need to re-author those two commits with their own noreply address, or tell us and we will credit them with a Co-authored-by line instead.
  3. Force-push.

We will pick it up again as soon as the new head is up.

  • Synthena

@bikepresentball
bikepresentball force-pushed the fix/3397-single-flight branch 2 times, most recently from 2a15cbd to be46dad Compare November 20, 2026 06:31
@bikepresentball

Copy link
Copy Markdown
Contributor Author

Done — all commits re-authored with the noreply address ([email protected]) and force-pushed. Same two commits, same content; head is now be46dad.

@AIFlowML

Copy link
Copy Markdown
Contributor

I verified the two commits at be46dad2e both have GitHub noreply author addresses, and the head trial-merges cleanly into 124052c97.

The first test gap I found is that the description lists four single-flight cases, but lane_host_prefix_join_test.zig at this head has two: warm join and cold join. To reproduce those on M5 Max with Zig 0.17.0, I added a scratch build target in zig/build/lane_halt_host.zig that runs the existing api test module with .filters = &.{"single-flight:"}. That target plus zig build test-lane-interrupted-host test-lane-strand-host -Dcpu=apple_m1 -j4 --summary all passed 111 tests, including both join cases by name.

I also added the described timeout case locally using the existing fixture, fanout(1, 30, 0, &bounded) against fanout(0, 30, 0, &disabled). The focused run passed 34 tests: all three waiters timed out, the queue drained, and all four token arrays matched the wait-disabled control. I didn't run a whole-fill leader-cancellation case. Adding that case and the timeout case to the PR, or updating the description to match the two checked-in cases, would make the coverage clear.

Igor Lessio - AIFLOW LABS

@bikepresentball

Copy link
Copy Markdown
Contributor Author

Both gaps are closed at f69cd52 — the four cases in the description are now the four cases in the file.

The leader-cancellation case cancels the leader (id 1) on its second prompt chunk via the prefill hook, against the same-shaped no-join run: the leader's reply is the cancellation in both, and each released waiter finishes whole, token for token the no-join run's reply. Counters pin the shape — 3 joins armed, 3 waits, 0 timeouts, and 0 joins in the no-join control.

The bound case is your shape exactly — fanout(1, 30, 0, &bounded) against fanout(0, 30, 0, &disabled): every waiter arms, the 1 ms bound against 30 ms chunks releases all three (3 timeouts), and the released waiters fill side by side (leader_open_most > 1), each reply equal to the no-join run's. The timeout case you added locally matched this on M5 Max; ours agrees on this box.

Focused run: 35/35 single-flight tests pass (zig build filter "single-flight:"), plus test-lane-interrupted-host 42/42 and test-lane-strand-host 35/35 alongside. The fanout helper gained a cancel_at parameter (cancels the leader at a prompt chunk) — the two existing cases are untouched call sites.

  • bikepresentball

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @bikepresentball for re-authoring the commits.

Your re-authoring: the noreply authorship was our only ask, and that part looks done from your reply. We'll confirm it on the commit list when this lands.

The change itself: this is our first review of it. It applies cleanly to today's main, and the design is small and well tested. Joined replies equal solo ones in all four host tests, and your GB10 receipts show four byte-identical replies from one fill.

One thing to settle before it lands: joining when the leader's fill can't be kept.

  • What happens now: a joiner waits for the leader's whole fill and then resumes from what the cache kept. When nothing is kept, it waits out the whole fill and then prefills its own prompt from the start.

    • Your cold-cache test pins exactly this case (lane_host_prefix_join_test.zig:194-199): every lookup misses and nothing is resumable, yet the three joins still arm.
    • In a serve, that's any prompt whose state is larger than the cache budget (prompt_cache_keep.zig:38 refuses to keep it).
  • The cost: the second and later identical requests then see roughly the leader's prefill time plus their own before a first token. Today they would run side by side.

  • Could you either:

    • arm the whole-fill join (lane_host_prefix.zig:51) only when the store would keep the leader's prompt, or
    • show main-against-branch time to first token for identical prompts too large to keep (or with a zero budget), so we can see the join doesn't cost latency there?
  • Synthena

@bikepresentball

Copy link
Copy Markdown
Contributor Author

Both halves of the keep question are settled at 55c6dfa:

The join now arms only when the leader's fill will keep anything. The arm condition gains the store's own deterministic keep refusals: the join requires the leader to carry fitted marks (l.marks.len > 0) and free snapshot slots (store.most != 0) — the same two refusals prompt_cache_keep.zig applies before any copy. Since mark planning already fits each mark's state bytes against the budget (and plans none under memory pressure), empty marks covers every case where the store would refuse the leader's prompt: state past the budget, no slots, or hold. A prompt too large to keep therefore never arms the join, and its identical requests run side by side exactly as they would with TENSORFOLD_PREFIX_WAIT_MS=0 — the second-and-later requests keep today's time to first token by construction, no measurement needed.

Tests. The cold-cache case flipped to pin this: on a zero budget the join does not arm, the four prompts prefill beside each other (leader_open_most > 1), and every reply still equals the join-off run's. The bound case moved to a budget that fits marks so it still exercises the arming path. Focused run: 35/35 single-flight tests (zig build filter "single-flight:"), plus test-lane-interrupted-host and test-lane-strand-host green alongside; zig fmt --check clean and the lean check reports 0 new findings against the merge-base (the earlier head's zig job red was this branch's own two-line helper doc, now one line).

One scope note: with keeps refused, the pre-existing cut wait (waiting for a mark the leader never keeps) still arms on main's terms — unchanged by this branch, so a too-large prompt behaves exactly as it does on main.

  • bikepresentball

bikepresentball and others added 5 commits November 21, 2026 12:17
… fill

A queued request whose prompt is exactly a filling prompt's — same cache key,
same tokens, same spans, the leader's last mark serving it whole — now waits
for that fill to end (TENSORFOLD_PREFIX_WAIT_MS still bounds it) instead of
waiting for one cut and prefilling the rest beside the leader. Released only
when every keep is published, its lookup resumes the leader's deepest kept
state; a missed lookup, a failed or cancelled leader or the bound all fall
open to prefilling independently. Waits for a shared cut are unchanged.
The join v1 armed only where a filling leader had a planned mark whose
wouldServe would serve the waiter — nothing arms it on a cold cache, where
no mark is planned and nothing kept (the GB10 receipt: 4x identical 126k
cold prompts still prefilled independently). A queued request now joins a
filling leader on prompt identity alone: same cache key, same tokens, same
spans, no mark and no kept state consulted; waiters per leader are bounded
by the admission cap, and every release path (fill done, leader gone,
bound passed) still falls open to an independent prefill. The new test
drives the identical fanout over a zero-budget store — no marks, nothing
kept — and fails on v1 (joins 0 of 3) while passing here.
The description listed four single-flight cases; the file carried two. Adds the leader-cancellation and bound-passage fail-open cases AIFlowML asked for: a released waiter prefills its own prompt and its reply is token for token the no-join run's; the leader's cancellation releases without a timeout, the 1 ms bound against 30 ms chunks releases with one per joiner.
@ashhart
ashhart force-pushed the fix/3397-single-flight branch from 55c6dfa to fd321ae Compare November 21, 2026 12:17
@ashhart
ashhart merged commit 59b0bea into ashhart:main Nov 21, 2026
11 of 12 checks passed
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thank you @bikepresentball. 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 that referenced this pull request Nov 21, 2026
ashhart added a commit to hobbesd/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
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.

3 participants