Skip to content

fix(tp): yield prefill to pending snapshots before locking - #17

Open
LostVector wants to merge 1 commit into
neuhaus:rdmafrom
LostVector:fix/prefill-yield-pending-snapshots
Open

LostVector wants to merge 1 commit into
neuhaus:rdmafrom
LostVector:fix/prefill-yield-pending-snapshots

Conversation

@LostVector

@LostVector LostVector commented Nov 12, 2026 •

Copy link
Copy Markdown

In plain English: Saving a chat's progress and processing another chat's prompt share the same machinery. New prompt work can repeatedly get ahead of a save that is already waiting, making the first chat wait longer. This change gives the waiting save a chance to go first before more prompt work starts.

When a snapshot is waiting for the TP call mutex, another request's prefill can acquire that mutex ahead of it. The existing snapshot gate protects advance/decode calls but does not cover prefill.

Take the existing TpSnapshotGate::Turn before the prefill call mutex. Pending captures can then acquire the mutex while prefill waits outside it. This does not preempt an active model call or change the instruction protocol, model results, or collective ordering.

Tests exercise the real mirrored runner with two states: prefill waits on a held reservation while snapshot capture must still acquire the mutex and complete. A private GUFO_CACHE_TESTING friend creates the test reservation without adding a production API. The existing two-rank held-capture cancellation test also gains assertions for unsettled state before release, bounded completion afterward and an explicit cancelled result, retaining next-request cache reuse checks.

Validation on Neuhaus rdma base f070a179:

  • tp_executor_test and tp_snapshot_gate_test pass.
  • Removing the prefill guard fails the pending-reservation assertion.
  • Moving the wait inside the call mutex fails the capture-progress deadline; restoring the candidate passes.
  • Formatting and extension API checks pass.

These are CPU scheduler/control tests, not a new USB4 or GPU throughput benchmark. The existing gate check and mutex acquisition are separate operations, so this does not promise atomic priority for a reservation arriving after the check. Draft for manual review; no changes to the running cluster.

@neuhaus

neuhaus commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR and the careful tests.

This is not merged yet. The change itself looks right for rdma at f070a179: prefill waits on the snapshot gate before the call mutex, as decode and advance already do.

The next rdma merge (upstream through v0.34, not pushed yet) has no TpSnapshotGate. The port to upstream's component cache removed it, together with the rank-1 snapshot table, because rank 0 now owns all retained state and captures run through upstream's cache code. So this diff no longer applies, and neither do the test hooks (ReserveSnapshotForTesting, the held-capture assertions) that depend on the gate.

What is still open is whether the starvation you describe can still happen in that design: a capture waiting while new prompt work keeps getting ahead of it. Upstream's gufo-org#1181 (resume captured prefills before repeating peer work) covers part of it. I will test this on two hosts with a pending capture and concurrent prefills once the merge builds, and report the result here.

Until then I'd keep this PR open, not close it. If you can reproduce the starvation on the merged tree, a failing case would help more than a port of this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants